d3d11/tests: Add format compatibility tests for DXGI_FORMAT_R9G9B9E5_SHAREDEXP.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob1fbc91bb5e147a4e1eec55068aab5066c7113758
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 struct srv_desc
285 DXGI_FORMAT format;
286 D3D11_SRV_DIMENSION dimension;
287 unsigned int miplevel_idx;
288 unsigned int miplevel_count;
289 unsigned int layer_idx;
290 unsigned int layer_count;
293 static void get_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *d3d11_desc, const struct srv_desc *desc)
295 d3d11_desc->Format = desc->format;
296 d3d11_desc->ViewDimension = desc->dimension;
297 if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1D)
299 U(*d3d11_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
300 U(*d3d11_desc).Texture1D.MipLevels = desc->miplevel_count;
302 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1DARRAY)
304 U(*d3d11_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
305 U(*d3d11_desc).Texture1DArray.MipLevels = desc->miplevel_count;
306 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
307 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
309 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
311 U(*d3d11_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
312 U(*d3d11_desc).Texture2D.MipLevels = desc->miplevel_count;
314 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
316 U(*d3d11_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
317 U(*d3d11_desc).Texture2DArray.MipLevels = desc->miplevel_count;
318 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
319 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
321 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
323 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
324 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
326 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE3D)
328 U(*d3d11_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
329 U(*d3d11_desc).Texture3D.MipLevels = desc->miplevel_count;
331 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
333 U(*d3d11_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
334 U(*d3d11_desc).TextureCube.MipLevels = desc->miplevel_count;
336 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
338 U(*d3d11_desc).TextureCubeArray.MostDetailedMip = desc->miplevel_idx;
339 U(*d3d11_desc).TextureCubeArray.MipLevels = desc->miplevel_count;
340 U(*d3d11_desc).TextureCubeArray.First2DArrayFace = desc->layer_idx;
341 U(*d3d11_desc).TextureCubeArray.NumCubes = desc->layer_count;
343 else if (desc->dimension != D3D11_SRV_DIMENSION_UNKNOWN
344 && desc->dimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
346 trace("Unhandled view dimension %#x.\n", desc->dimension);
350 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
351 static void check_srv_desc_(unsigned int line, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc,
352 const struct srv_desc *expected_desc)
354 ok_(__FILE__, line)(desc->Format == expected_desc->format,
355 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
356 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
357 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
359 if (desc->ViewDimension != expected_desc->dimension)
360 return;
362 if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D)
364 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
365 "Got MostDetailedMip %u, expected %u.\n",
366 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
367 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
368 "Got MipLevels %u, expected %u.\n",
369 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
371 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
373 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
374 "Got MostDetailedMip %u, expected %u.\n",
375 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
376 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
377 "Got MipLevels %u, expected %u.\n",
378 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
379 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
380 "Got FirstArraySlice %u, expected %u.\n",
381 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
382 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
383 "Got ArraySize %u, expected %u.\n",
384 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
386 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
388 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
389 "Got FirstArraySlice %u, expected %u.\n",
390 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
391 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
392 "Got ArraySize %u, expected %u.\n",
393 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
395 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D)
397 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
398 "Got MostDetailedMip %u, expected %u.\n",
399 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
400 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
401 "Got MipLevels %u, expected %u.\n",
402 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
404 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
406 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
407 "Got MostDetailedMip %u, expected %u.\n",
408 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
409 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
410 "Got MipLevels %u, expected %u.\n",
411 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
413 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
415 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MostDetailedMip == expected_desc->miplevel_idx,
416 "Got MostDetailedMip %u, expected %u.\n",
417 U(*desc).TextureCubeArray.MostDetailedMip, expected_desc->miplevel_idx);
418 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MipLevels == expected_desc->miplevel_count,
419 "Got MipLevels %u, expected %u.\n",
420 U(*desc).TextureCubeArray.MipLevels, expected_desc->miplevel_count);
421 ok_(__FILE__, line)(U(*desc).TextureCubeArray.First2DArrayFace == expected_desc->layer_idx,
422 "Got First2DArrayFace %u, expected %u.\n",
423 U(*desc).TextureCubeArray.First2DArrayFace, expected_desc->layer_idx);
424 ok_(__FILE__, line)(U(*desc).TextureCubeArray.NumCubes == expected_desc->layer_count,
425 "Got NumCubes %u, expected %u.\n",
426 U(*desc).TextureCubeArray.NumCubes, expected_desc->layer_count);
428 else if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
430 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
434 struct rtv_desc
436 DXGI_FORMAT format;
437 D3D11_RTV_DIMENSION dimension;
438 unsigned int miplevel_idx;
439 unsigned int layer_idx;
440 unsigned int layer_count;
443 static void get_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *d3d11_desc, const struct rtv_desc *desc)
445 d3d11_desc->Format = desc->format;
446 d3d11_desc->ViewDimension = desc->dimension;
447 if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1D)
449 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
451 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1DARRAY)
453 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
454 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
455 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
457 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
459 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
461 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
463 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
464 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
465 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
467 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
469 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
470 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
472 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE3D)
474 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
475 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
476 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
478 else if (desc->dimension != D3D11_RTV_DIMENSION_UNKNOWN
479 && desc->dimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
481 trace("Unhandled view dimension %#x.\n", desc->dimension);
485 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
486 static void check_rtv_desc_(unsigned int line, const D3D11_RENDER_TARGET_VIEW_DESC *desc,
487 const struct rtv_desc *expected_desc)
489 ok_(__FILE__, line)(desc->Format == expected_desc->format,
490 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
491 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
492 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
494 if (desc->ViewDimension != expected_desc->dimension)
495 return;
497 if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D)
499 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
500 "Got MipSlice %u, expected %u.\n",
501 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
503 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
505 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
506 "Got MipSlice %u, expected %u.\n",
507 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
508 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
509 "Got FirstArraySlice %u, expected %u.\n",
510 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
511 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
512 "Got ArraySize %u, expected %u.\n",
513 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
515 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
517 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
518 "Got FirstArraySlice %u, expected %u.\n",
519 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
520 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
521 "Got ArraySize %u, expected %u.\n",
522 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
524 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE3D)
526 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
527 "Got MipSlice %u, expected %u.\n",
528 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
529 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
530 "Got FirstWSlice %u, expected %u.\n",
531 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
532 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
533 "Got WSize %u, expected %u.\n",
534 U(*desc).Texture3D.WSize, expected_desc->layer_count);
536 else if (desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
538 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
542 struct dsv_desc
544 DXGI_FORMAT format;
545 D3D11_DSV_DIMENSION dimension;
546 unsigned int miplevel_idx;
547 unsigned int layer_idx;
548 unsigned int layer_count;
551 static void get_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *d3d11_desc, const struct dsv_desc *desc)
553 d3d11_desc->Format = desc->format;
554 d3d11_desc->ViewDimension = desc->dimension;
555 d3d11_desc->Flags = 0;
556 if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1D)
558 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
560 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1DARRAY)
562 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
563 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
564 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
566 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2D)
568 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
570 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
572 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
573 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
574 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
576 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
578 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
579 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
581 else if (desc->dimension != D3D11_DSV_DIMENSION_UNKNOWN
582 && desc->dimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
584 trace("Unhandled view dimension %#x.\n", desc->dimension);
588 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
589 static void check_dsv_desc_(unsigned int line, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc,
590 const struct dsv_desc *expected_desc)
592 ok_(__FILE__, line)(desc->Format == expected_desc->format,
593 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
594 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
595 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
597 if (desc->ViewDimension != expected_desc->dimension)
598 return;
600 if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D)
602 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
603 "Got MipSlice %u, expected %u.\n",
604 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
606 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
608 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
609 "Got MipSlice %u, expected %u.\n",
610 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
611 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
612 "Got FirstArraySlice %u, expected %u.\n",
613 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
614 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
615 "Got ArraySize %u, expected %u.\n",
616 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
618 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
620 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
621 "Got FirstArraySlice %u, expected %u.\n",
622 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
623 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
624 "Got ArraySize %u, expected %u.\n",
625 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
627 else if (desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
629 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
633 struct uav_desc
635 DXGI_FORMAT format;
636 D3D11_UAV_DIMENSION dimension;
637 unsigned int miplevel_idx;
638 unsigned int layer_idx;
639 unsigned int layer_count;
642 static void get_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC *d3d11_desc, const struct uav_desc *desc)
644 d3d11_desc->Format = desc->format;
645 d3d11_desc->ViewDimension = desc->dimension;
646 if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1D)
648 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
650 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
652 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
653 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
654 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
656 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2D)
658 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
660 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
662 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
663 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
664 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
666 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE3D)
668 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
669 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
670 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
672 else if (desc->dimension != D3D11_UAV_DIMENSION_UNKNOWN)
674 trace("Unhandled view dimension %#x.\n", desc->dimension);
678 #define check_uav_desc(a, b) check_uav_desc_(__LINE__, a, b)
679 static void check_uav_desc_(unsigned int line, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc,
680 const struct uav_desc *expected_desc)
682 ok_(__FILE__, line)(desc->Format == expected_desc->format,
683 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
684 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
685 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
687 if (desc->ViewDimension != expected_desc->dimension)
688 return;
690 if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2D)
692 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
693 "Got MipSlice %u, expected %u.\n",
694 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
696 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
698 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
699 "Got MipSlice %u, expected %u.\n",
700 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
701 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
702 "Got FirstArraySlice %u, expected %u.\n",
703 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
704 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
705 "Got ArraySize %u, expected %u.\n",
706 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
708 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE3D)
710 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
711 "Got MipSlice %u, expected %u.\n",
712 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
713 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
714 "Got FirstWSlice %u, expected %u.\n",
715 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
716 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
717 "Got WSize %u, expected %u.\n",
718 U(*desc).Texture3D.WSize, expected_desc->layer_count);
720 else
722 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
726 static void set_viewport(ID3D11DeviceContext *context, float x, float y,
727 float width, float height, float min_depth, float max_depth)
729 D3D11_VIEWPORT vp;
731 vp.TopLeftX = x;
732 vp.TopLeftY = y;
733 vp.Width = width;
734 vp.Height = height;
735 vp.MinDepth = min_depth;
736 vp.MaxDepth = max_depth;
738 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
741 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, 0, c, d)
742 #define create_buffer_misc(a, b, c, d, e) create_buffer_(__LINE__, a, b, c, d, e)
743 static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
744 unsigned int bind_flags, unsigned int misc_flags, unsigned int size, const void *data)
746 D3D11_SUBRESOURCE_DATA resource_data;
747 D3D11_BUFFER_DESC buffer_desc;
748 ID3D11Buffer *buffer;
749 HRESULT hr;
751 buffer_desc.ByteWidth = size;
752 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
753 buffer_desc.BindFlags = bind_flags;
754 buffer_desc.CPUAccessFlags = 0;
755 buffer_desc.MiscFlags = misc_flags;
756 buffer_desc.StructureByteStride = 0;
758 resource_data.pSysMem = data;
759 resource_data.SysMemPitch = 0;
760 resource_data.SysMemSlicePitch = 0;
762 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
763 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
764 return buffer;
767 struct resource_readback
769 ID3D11Resource *resource;
770 D3D11_MAPPED_SUBRESOURCE map_desc;
771 ID3D11DeviceContext *immediate_context;
772 unsigned int width, height, depth, sub_resource_idx;
775 static void init_resource_readback(ID3D11Resource *resource, ID3D11Resource *readback_resource,
776 unsigned int width, unsigned int height, unsigned int depth, unsigned int sub_resource_idx,
777 ID3D11Device *device, struct resource_readback *rb)
779 HRESULT hr;
781 rb->resource = readback_resource;
782 rb->width = width;
783 rb->height = height;
784 rb->depth = depth;
785 rb->sub_resource_idx = sub_resource_idx;
787 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
789 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, resource);
790 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context,
791 rb->resource, sub_resource_idx, D3D11_MAP_READ, 0, &rb->map_desc)))
793 trace("Failed to map resource, hr %#x.\n", hr);
794 ID3D11Resource_Release(rb->resource);
795 rb->resource = NULL;
796 ID3D11DeviceContext_Release(rb->immediate_context);
797 rb->immediate_context = NULL;
801 static void get_buffer_readback(ID3D11Buffer *buffer, struct resource_readback *rb)
803 D3D11_BUFFER_DESC buffer_desc;
804 ID3D11Resource *rb_buffer;
805 ID3D11Device *device;
806 HRESULT hr;
808 memset(rb, 0, sizeof(*rb));
810 ID3D11Buffer_GetDevice(buffer, &device);
812 ID3D11Buffer_GetDesc(buffer, &buffer_desc);
813 buffer_desc.Usage = D3D11_USAGE_STAGING;
814 buffer_desc.BindFlags = 0;
815 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
816 buffer_desc.MiscFlags = 0;
817 buffer_desc.StructureByteStride = 0;
818 if (FAILED(hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D11Buffer **)&rb_buffer)))
820 trace("Failed to create staging buffer, hr %#x.\n", hr);
821 ID3D11Device_Release(device);
822 return;
825 init_resource_readback((ID3D11Resource *)buffer, rb_buffer,
826 buffer_desc.ByteWidth, 1, 1, 0, device, rb);
828 ID3D11Device_Release(device);
831 static void get_texture1d_readback(ID3D11Texture1D *texture, unsigned int sub_resource_idx,
832 struct resource_readback *rb)
834 D3D11_TEXTURE1D_DESC texture_desc;
835 ID3D11Resource *rb_texture;
836 unsigned int miplevel;
837 ID3D11Device *device;
838 HRESULT hr;
840 memset(rb, 0, sizeof(*rb));
842 ID3D11Texture1D_GetDevice(texture, &device);
844 ID3D11Texture1D_GetDesc(texture, &texture_desc);
845 texture_desc.Usage = D3D11_USAGE_STAGING;
846 texture_desc.BindFlags = 0;
847 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
848 texture_desc.MiscFlags = 0;
849 if (FAILED(hr = ID3D11Device_CreateTexture1D(device, &texture_desc, NULL, (ID3D11Texture1D **)&rb_texture)))
851 trace("Failed to create texture, hr %#x.\n", hr);
852 ID3D11Device_Release(device);
853 return;
856 miplevel = sub_resource_idx % texture_desc.MipLevels;
857 init_resource_readback((ID3D11Resource *)texture, rb_texture,
858 max(1, texture_desc.Width >> miplevel), 1, 1, sub_resource_idx, device, rb);
860 ID3D11Device_Release(device);
863 static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
864 struct resource_readback *rb)
866 D3D11_TEXTURE2D_DESC texture_desc;
867 ID3D11Resource *rb_texture;
868 unsigned int miplevel;
869 ID3D11Device *device;
870 HRESULT hr;
872 memset(rb, 0, sizeof(*rb));
874 ID3D11Texture2D_GetDevice(texture, &device);
876 ID3D11Texture2D_GetDesc(texture, &texture_desc);
877 texture_desc.Usage = D3D11_USAGE_STAGING;
878 texture_desc.BindFlags = 0;
879 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
880 texture_desc.MiscFlags = 0;
881 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb_texture)))
883 trace("Failed to create texture, hr %#x.\n", hr);
884 ID3D11Device_Release(device);
885 return;
888 miplevel = sub_resource_idx % texture_desc.MipLevels;
889 init_resource_readback((ID3D11Resource *)texture, rb_texture,
890 max(1, texture_desc.Width >> miplevel),
891 max(1, texture_desc.Height >> miplevel),
892 1, sub_resource_idx, device, rb);
894 ID3D11Device_Release(device);
897 static void get_texture3d_readback(ID3D11Texture3D *texture, unsigned int sub_resource_idx,
898 struct resource_readback *rb)
900 D3D11_TEXTURE3D_DESC texture_desc;
901 ID3D11Resource *rb_texture;
902 unsigned int miplevel;
903 ID3D11Device *device;
904 HRESULT hr;
906 memset(rb, 0, sizeof(*rb));
908 ID3D11Texture3D_GetDevice(texture, &device);
910 ID3D11Texture3D_GetDesc(texture, &texture_desc);
911 texture_desc.Usage = D3D11_USAGE_STAGING;
912 texture_desc.BindFlags = 0;
913 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
914 texture_desc.MiscFlags = 0;
915 if (FAILED(hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, (ID3D11Texture3D **)&rb_texture)))
917 trace("Failed to create texture, hr %#x.\n", hr);
918 ID3D11Device_Release(device);
919 return;
922 miplevel = sub_resource_idx % texture_desc.MipLevels;
923 init_resource_readback((ID3D11Resource *)texture, rb_texture,
924 max(1, texture_desc.Width >> miplevel),
925 max(1, texture_desc.Height >> miplevel),
926 max(1, texture_desc.Depth >> miplevel),
927 sub_resource_idx, device, rb);
929 ID3D11Device_Release(device);
932 static void *get_readback_data(struct resource_readback *rb,
933 unsigned int x, unsigned int y, unsigned int z, unsigned byte_width)
935 return (BYTE *)rb->map_desc.pData + z * rb->map_desc.DepthPitch + y * rb->map_desc.RowPitch + x * byte_width;
938 static BYTE get_readback_u8(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
940 return *(BYTE *)get_readback_data(rb, x, y, z, sizeof(BYTE));
943 static WORD get_readback_u16(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
945 return *(WORD *)get_readback_data(rb, x, y, z, sizeof(WORD));
948 static DWORD get_readback_u32(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
950 return *(DWORD *)get_readback_data(rb, x, y, z, sizeof(DWORD));
953 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
955 return get_readback_u32(rb, x, y, z);
958 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
960 return *(float *)get_readback_data(rb, x, y, 0, sizeof(float));
963 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
965 return get_readback_data(rb, x, y, 0, sizeof(struct vec4));
968 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
970 return get_readback_data(rb, x, y, 0, sizeof(struct uvec4));
973 static void release_resource_readback(struct resource_readback *rb)
975 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
976 ID3D11Resource_Release(rb->resource);
977 ID3D11DeviceContext_Release(rb->immediate_context);
980 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
982 struct resource_readback rb;
983 DWORD color;
985 get_texture_readback(texture, 0, &rb);
986 color = get_readback_color(&rb, x, y, 0);
987 release_resource_readback(&rb);
989 return color;
992 #define check_readback_data_u8(a, b, c, d) check_readback_data_u8_(__LINE__, a, b, c, d)
993 static void check_readback_data_u8_(unsigned int line, struct resource_readback *rb,
994 const RECT *rect, BYTE expected_value, BYTE max_diff)
996 unsigned int x = 0, y = 0, z = 0;
997 BOOL all_match = FALSE;
998 RECT default_rect;
999 BYTE value = 0;
1001 if (!rect)
1003 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1004 rect = &default_rect;
1007 for (z = 0; z < rb->depth; ++z)
1009 for (y = rect->top; y < rect->bottom; ++y)
1011 for (x = rect->left; x < rect->right; ++x)
1013 value = get_readback_u8(rb, x, y, z);
1014 if (!compare_uint(value, expected_value, max_diff))
1015 goto done;
1019 all_match = TRUE;
1021 done:
1022 ok_(__FILE__, line)(all_match,
1023 "Got 0x%02x, expected 0x%02x at (%u, %u, %u), sub-resource %u.\n",
1024 value, expected_value, x, y, z, rb->sub_resource_idx);
1027 #define check_readback_data_u16(a, b, c, d) check_readback_data_u16_(__LINE__, a, b, c, d)
1028 static void check_readback_data_u16_(unsigned int line, struct resource_readback *rb,
1029 const RECT *rect, WORD expected_value, BYTE max_diff)
1031 unsigned int x = 0, y = 0, z = 0;
1032 BOOL all_match = FALSE;
1033 RECT default_rect;
1034 WORD value = 0;
1036 if (!rect)
1038 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1039 rect = &default_rect;
1042 for (z = 0; z < rb->depth; ++z)
1044 for (y = rect->top; y < rect->bottom; ++y)
1046 for (x = rect->left; x < rect->right; ++x)
1048 value = get_readback_u16(rb, x, y, z);
1049 if (!compare_uint(value, expected_value, max_diff))
1050 goto done;
1054 all_match = TRUE;
1056 done:
1057 ok_(__FILE__, line)(all_match,
1058 "Got 0x%04x, expected 0x%04x at (%u, %u, %u), sub-resource %u.\n",
1059 value, expected_value, x, y, z, rb->sub_resource_idx);
1062 #define check_readback_data_u24(a, b, c, d, e) check_readback_data_u24_(__LINE__, a, b, c, d, e)
1063 static void check_readback_data_u24_(unsigned int line, struct resource_readback *rb,
1064 const RECT *rect, unsigned int shift, DWORD expected_value, BYTE max_diff)
1066 unsigned int x = 0, y = 0, z = 0;
1067 BOOL all_match = FALSE;
1068 RECT default_rect;
1069 DWORD value = 0;
1071 if (!rect)
1073 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1074 rect = &default_rect;
1077 for (z = 0; z < rb->depth; ++z)
1079 for (y = rect->top; y < rect->bottom; ++y)
1081 for (x = rect->left; x < rect->right; ++x)
1083 value = get_readback_u32(rb, x, y, z) >> shift;
1084 if (!compare_uint(value, expected_value, max_diff))
1085 goto done;
1089 all_match = TRUE;
1091 done:
1092 ok_(__FILE__, line)(all_match,
1093 "Got 0x%06x, expected 0x%06x at (%u, %u, %u), sub-resource %u.\n",
1094 value, expected_value, x, y, z, rb->sub_resource_idx);
1097 #define check_readback_data_color(a, b, c, d) check_readback_data_color_(__LINE__, a, b, c, d)
1098 static void check_readback_data_color_(unsigned int line, struct resource_readback *rb,
1099 const RECT *rect, DWORD expected_color, BYTE max_diff)
1101 unsigned int x = 0, y = 0, z = 0;
1102 BOOL all_match = FALSE;
1103 RECT default_rect;
1104 DWORD color = 0;
1106 if (!rect)
1108 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1109 rect = &default_rect;
1112 for (z = 0; z < rb->depth; ++z)
1114 for (y = rect->top; y < rect->bottom; ++y)
1116 for (x = rect->left; x < rect->right; ++x)
1118 color = get_readback_color(rb, x, y, z);
1119 if (!compare_color(color, expected_color, max_diff))
1120 goto done;
1124 all_match = TRUE;
1126 done:
1127 ok_(__FILE__, line)(all_match,
1128 "Got 0x%08x, expected 0x%08x at (%u, %u, %u), sub-resource %u.\n",
1129 color, expected_color, x, y, z, rb->sub_resource_idx);
1132 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
1133 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
1134 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1136 struct resource_readback rb;
1138 get_texture_readback(texture, sub_resource_idx, &rb);
1139 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1140 release_resource_readback(&rb);
1143 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
1144 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
1145 DWORD expected_color, BYTE max_diff)
1147 unsigned int sub_resource_idx, sub_resource_count;
1148 D3D11_TEXTURE2D_DESC texture_desc;
1150 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1151 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1152 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1153 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1156 #define check_texture1d_sub_resource_color(a, b, c, d, e) check_texture1d_sub_resource_color_(__LINE__, a, b, c, d, e)
1157 static void check_texture1d_sub_resource_color_(unsigned int line, ID3D11Texture1D *texture,
1158 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1160 struct resource_readback rb;
1162 get_texture1d_readback(texture, sub_resource_idx, &rb);
1163 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1164 release_resource_readback(&rb);
1167 #define check_texture1d_color(t, c, d) check_texture1d_color_(__LINE__, t, c, d)
1168 static void check_texture1d_color_(unsigned int line, ID3D11Texture1D *texture,
1169 DWORD expected_color, BYTE max_diff)
1171 unsigned int sub_resource_idx, sub_resource_count;
1172 D3D11_TEXTURE1D_DESC texture_desc;
1174 ID3D11Texture1D_GetDesc(texture, &texture_desc);
1175 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1176 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1177 check_texture1d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1180 #define check_texture3d_sub_resource_color(a, b, c, d, e) check_texture3d_sub_resource_color_(__LINE__, a, b, c, d, e)
1181 static void check_texture3d_sub_resource_color_(unsigned int line, ID3D11Texture3D *texture,
1182 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1184 struct resource_readback rb;
1186 get_texture3d_readback(texture, sub_resource_idx, &rb);
1187 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1188 release_resource_readback(&rb);
1191 #define check_texture3d_color(t, c, d) check_texture3d_color_(__LINE__, t, c, d)
1192 static void check_texture3d_color_(unsigned int line, ID3D11Texture3D *texture,
1193 DWORD expected_color, BYTE max_diff)
1195 unsigned int sub_resource_idx, sub_resource_count;
1196 D3D11_TEXTURE3D_DESC texture_desc;
1198 ID3D11Texture3D_GetDesc(texture, &texture_desc);
1199 sub_resource_count = texture_desc.MipLevels;
1200 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1201 check_texture3d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1204 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
1205 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
1206 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
1208 struct resource_readback rb;
1209 unsigned int x = 0, y = 0;
1210 BOOL all_match = TRUE;
1211 float value = 0.0f;
1212 RECT default_rect;
1214 get_texture_readback(texture, sub_resource_idx, &rb);
1215 if (!rect)
1217 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1218 rect = &default_rect;
1220 for (y = rect->top; y < rect->bottom; ++y)
1222 for (x = rect->left; x < rect->right; ++x)
1224 value = get_readback_float(&rb, x, y);
1225 if (!compare_float(value, expected_value, max_diff))
1227 all_match = FALSE;
1228 break;
1231 if (!all_match)
1232 break;
1234 release_resource_readback(&rb);
1235 ok_(__FILE__, line)(all_match,
1236 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
1237 value, expected_value, x, y, sub_resource_idx);
1240 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
1241 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
1242 float expected_value, BYTE max_diff)
1244 unsigned int sub_resource_idx, sub_resource_count;
1245 D3D11_TEXTURE2D_DESC texture_desc;
1247 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1248 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1249 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1250 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1253 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
1254 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
1255 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
1257 struct resource_readback rb;
1258 unsigned int x = 0, y = 0;
1259 struct vec4 value = {0};
1260 BOOL all_match = TRUE;
1261 RECT default_rect;
1263 get_texture_readback(texture, sub_resource_idx, &rb);
1264 if (!rect)
1266 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1267 rect = &default_rect;
1269 for (y = rect->top; y < rect->bottom; ++y)
1271 for (x = rect->left; x < rect->right; ++x)
1273 value = *get_readback_vec4(&rb, x, y);
1274 if (!compare_vec4(&value, expected_value, max_diff))
1276 all_match = FALSE;
1277 break;
1280 if (!all_match)
1281 break;
1283 release_resource_readback(&rb);
1284 ok_(__FILE__, line)(all_match,
1285 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
1286 value.x, value.y, value.z, value.w,
1287 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1288 x, y, sub_resource_idx);
1291 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
1292 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
1293 const struct vec4 *expected_value, BYTE max_diff)
1295 unsigned int sub_resource_idx, sub_resource_count;
1296 D3D11_TEXTURE2D_DESC texture_desc;
1298 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1299 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1300 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1301 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1304 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
1305 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
1306 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
1308 struct resource_readback rb;
1309 unsigned int x = 0, y = 0;
1310 struct uvec4 value = {0};
1311 BOOL all_match = TRUE;
1312 RECT default_rect;
1314 get_texture_readback(texture, sub_resource_idx, &rb);
1315 if (!rect)
1317 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1318 rect = &default_rect;
1320 for (y = rect->top; y < rect->bottom; ++y)
1322 for (x = rect->left; x < rect->right; ++x)
1324 value = *get_readback_uvec4(&rb, x, y);
1325 if (!compare_uvec4(&value, expected_value))
1327 all_match = FALSE;
1328 break;
1331 if (!all_match)
1332 break;
1334 release_resource_readback(&rb);
1335 ok_(__FILE__, line)(all_match,
1336 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
1337 "at (%u, %u), sub-resource %u.\n",
1338 value.x, value.y, value.z, value.w,
1339 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1340 x, y, sub_resource_idx);
1343 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
1344 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
1345 const struct uvec4 *expected_value)
1347 unsigned int sub_resource_idx, sub_resource_count;
1348 D3D11_TEXTURE2D_DESC texture_desc;
1350 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1351 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1352 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1353 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
1356 static IDXGIAdapter *create_adapter(void)
1358 IDXGIFactory4 *factory4;
1359 IDXGIFactory *factory;
1360 IDXGIAdapter *adapter;
1361 HRESULT hr;
1363 if (!use_warp_adapter && !use_adapter_idx)
1364 return NULL;
1366 if (FAILED(hr = CreateDXGIFactory1(&IID_IDXGIFactory, (void **)&factory)))
1368 trace("Failed to create IDXGIFactory, hr %#x.\n", hr);
1369 return NULL;
1372 adapter = NULL;
1373 if (use_warp_adapter)
1375 if (SUCCEEDED(hr = IDXGIFactory_QueryInterface(factory, &IID_IDXGIFactory4, (void **)&factory4)))
1377 hr = IDXGIFactory4_EnumWarpAdapter(factory4, &IID_IDXGIAdapter, (void **)&adapter);
1378 IDXGIFactory4_Release(factory4);
1380 else
1382 trace("Failed to get IDXGIFactory4, hr %#x.\n", hr);
1385 else
1387 hr = IDXGIFactory_EnumAdapters(factory, use_adapter_idx, &adapter);
1389 IDXGIFactory_Release(factory);
1390 if (FAILED(hr))
1391 trace("Failed to get adapter, hr %#x.\n", hr);
1392 return adapter;
1395 static ID3D11Device *create_device(const struct device_desc *desc)
1397 static const D3D_FEATURE_LEVEL default_feature_level[] =
1399 D3D_FEATURE_LEVEL_11_0,
1400 D3D_FEATURE_LEVEL_10_1,
1401 D3D_FEATURE_LEVEL_10_0,
1403 const D3D_FEATURE_LEVEL *feature_level;
1404 UINT flags = desc ? desc->flags : 0;
1405 unsigned int feature_level_count;
1406 IDXGIAdapter *adapter;
1407 ID3D11Device *device;
1408 HRESULT hr;
1410 if (desc && desc->feature_level)
1412 feature_level = desc->feature_level;
1413 feature_level_count = 1;
1415 else
1417 feature_level = default_feature_level;
1418 feature_level_count = ARRAY_SIZE(default_feature_level);
1421 if (enable_debug_layer)
1422 flags |= D3D11_CREATE_DEVICE_DEBUG;
1424 if ((adapter = create_adapter()))
1426 hr = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags,
1427 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL);
1428 IDXGIAdapter_Release(adapter);
1429 return SUCCEEDED(hr) ? device : NULL;
1432 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags,
1433 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1434 return device;
1435 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags,
1436 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1437 return device;
1438 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags,
1439 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1440 return device;
1442 return NULL;
1445 static void get_device_adapter_desc(ID3D11Device *device, DXGI_ADAPTER_DESC *adapter_desc)
1447 IDXGIDevice *dxgi_device;
1448 IDXGIAdapter *adapter;
1449 HRESULT hr;
1451 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1452 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1453 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1454 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1455 IDXGIDevice_Release(dxgi_device);
1456 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1457 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1458 IDXGIAdapter_Release(adapter);
1461 static void print_adapter_info(void)
1463 DXGI_ADAPTER_DESC adapter_desc;
1464 ID3D11Device *device;
1466 if (!(device = create_device(NULL)))
1467 return;
1469 get_device_adapter_desc(device, &adapter_desc);
1470 trace("Adapter: %s, %04x:%04x.\n", wine_dbgstr_w(adapter_desc.Description),
1471 adapter_desc.VendorId, adapter_desc.DeviceId);
1472 ID3D11Device_Release(device);
1475 static BOOL is_warp_device(ID3D11Device *device)
1477 DXGI_ADAPTER_DESC adapter_desc;
1478 get_device_adapter_desc(device, &adapter_desc);
1479 return !adapter_desc.SubSysId && !adapter_desc.Revision
1480 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1481 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1484 static BOOL is_vendor_device(ID3D11Device *device, unsigned int vendor_id)
1486 DXGI_ADAPTER_DESC adapter_desc;
1488 if (!strcmp(winetest_platform, "wine"))
1489 return FALSE;
1491 get_device_adapter_desc(device, &adapter_desc);
1492 return adapter_desc.VendorId == vendor_id;
1495 static BOOL is_amd_device(ID3D11Device *device)
1497 return is_vendor_device(device, 0x1002);
1500 static BOOL is_intel_device(ID3D11Device *device)
1502 return is_vendor_device(device, 0x8086);
1505 static BOOL is_nvidia_device(ID3D11Device *device)
1507 return is_vendor_device(device, 0x10de);
1510 static BOOL is_d3d11_2_runtime(ID3D11Device *device)
1512 ID3D11Device2 *device2;
1513 HRESULT hr;
1515 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11Device2, (void **)&device2);
1516 if (SUCCEEDED(hr))
1517 ID3D11Device2_Release(device2);
1518 return hr == S_OK;
1521 static BOOL check_compute_shaders_via_sm4_support(ID3D11Device *device)
1523 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
1525 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1526 D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(options))))
1527 return FALSE;
1528 return options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x;
1531 static BOOL check_viewport_array_index_from_any_shader_support(ID3D11Device *device)
1533 D3D11_FEATURE_DATA_D3D11_OPTIONS3 options;
1535 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1536 D3D11_FEATURE_D3D11_OPTIONS3, &options, sizeof(options))))
1537 return FALSE;
1538 return options.VPAndRTArrayIndexFromAnyShaderFeedingRasterizer;
1541 static BOOL is_buffer(ID3D11Resource *resource)
1543 D3D11_RESOURCE_DIMENSION dimension;
1544 ID3D11Resource_GetType(resource, &dimension);
1545 return dimension == D3D11_RESOURCE_DIMENSION_BUFFER;
1548 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window,
1549 const struct swapchain_desc *swapchain_desc)
1551 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1552 IDXGISwapChain *swapchain;
1553 IDXGIDevice *dxgi_device;
1554 IDXGIAdapter *adapter;
1555 IDXGIFactory *factory;
1556 HRESULT hr;
1558 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1559 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1560 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1561 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1562 IDXGIDevice_Release(dxgi_device);
1563 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1564 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1565 IDXGIAdapter_Release(adapter);
1567 dxgi_desc.BufferDesc.Width = 640;
1568 dxgi_desc.BufferDesc.Height = 480;
1569 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1570 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1571 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1572 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1573 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1574 dxgi_desc.SampleDesc.Count = 1;
1575 dxgi_desc.SampleDesc.Quality = 0;
1576 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1577 dxgi_desc.BufferCount = 1;
1578 dxgi_desc.OutputWindow = window;
1579 dxgi_desc.Windowed = TRUE;
1580 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1581 dxgi_desc.Flags = 0;
1583 if (swapchain_desc)
1585 dxgi_desc.Windowed = swapchain_desc->windowed;
1586 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1587 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1588 if (swapchain_desc->width)
1589 dxgi_desc.BufferDesc.Width = swapchain_desc->width;
1590 if (swapchain_desc->height)
1591 dxgi_desc.BufferDesc.Height = swapchain_desc->height;
1593 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1594 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1597 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1598 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1599 IDXGIFactory_Release(factory);
1601 return swapchain;
1604 struct d3d11_test_context
1606 ID3D11Device *device;
1607 HWND window;
1608 IDXGISwapChain *swapchain;
1609 ID3D11Texture2D *backbuffer;
1610 ID3D11RenderTargetView *backbuffer_rtv;
1611 ID3D11DeviceContext *immediate_context;
1613 ID3D11InputLayout *input_layout;
1614 ID3D11VertexShader *vs;
1615 const DWORD *vs_code;
1616 ID3D11Buffer *vs_cb;
1617 ID3D11Buffer *vb;
1619 ID3D11PixelShader *ps;
1620 ID3D11Buffer *ps_cb;
1623 #define init_test_context(a, b) init_test_context_(__LINE__, a, b, NULL)
1624 #define init_test_context_ext(a, b, c) init_test_context_(__LINE__, a, b, c)
1625 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1626 const D3D_FEATURE_LEVEL *feature_level, const struct swapchain_desc *swapchain_desc)
1628 unsigned int rt_width, rt_height;
1629 struct device_desc device_desc;
1630 HRESULT hr;
1631 RECT rect;
1633 memset(context, 0, sizeof(*context));
1635 device_desc.feature_level = feature_level;
1636 device_desc.flags = 0;
1637 if (!(context->device = create_device(&device_desc)))
1639 skip_(__FILE__, line)("Failed to create device.\n");
1640 return FALSE;
1643 rt_width = swapchain_desc && swapchain_desc->width ? swapchain_desc->width : 640;
1644 rt_height = swapchain_desc && swapchain_desc->height ? swapchain_desc->height : 480;
1645 SetRect(&rect, 0, 0, rt_width, rt_height);
1646 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1647 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1648 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1649 context->swapchain = create_swapchain(context->device, context->window, swapchain_desc);
1650 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1651 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1653 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1654 NULL, &context->backbuffer_rtv);
1655 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1657 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1659 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1661 set_viewport(context->immediate_context, 0.0f, 0.0f, rt_width, rt_height, 0.0f, 1.0f);
1663 return TRUE;
1666 #define release_test_context(context) release_test_context_(__LINE__, context)
1667 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1669 ULONG ref;
1671 if (context->input_layout)
1672 ID3D11InputLayout_Release(context->input_layout);
1673 if (context->vs)
1674 ID3D11VertexShader_Release(context->vs);
1675 if (context->vs_cb)
1676 ID3D11Buffer_Release(context->vs_cb);
1677 if (context->vb)
1678 ID3D11Buffer_Release(context->vb);
1679 if (context->ps)
1680 ID3D11PixelShader_Release(context->ps);
1681 if (context->ps_cb)
1682 ID3D11Buffer_Release(context->ps_cb);
1684 ID3D11DeviceContext_Release(context->immediate_context);
1685 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1686 ID3D11Texture2D_Release(context->backbuffer);
1687 IDXGISwapChain_Release(context->swapchain);
1688 DestroyWindow(context->window);
1690 ref = ID3D11Device_Release(context->device);
1691 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1694 #define draw_quad(context) draw_quad_vs_(__LINE__, context, NULL, 0)
1695 #define draw_quad_vs(a, b, c) draw_quad_vs_(__LINE__, a, b, c)
1696 static void draw_quad_vs_(unsigned int line, struct d3d11_test_context *context,
1697 const DWORD *vs_code, size_t vs_code_size)
1699 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1701 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1703 static const DWORD default_vs_code[] =
1705 #if 0
1706 float4 main(float4 position : POSITION) : SV_POSITION
1708 return position;
1710 #endif
1711 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1712 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1713 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1714 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1715 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1716 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1717 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1718 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1719 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1720 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1721 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1722 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1723 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1724 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1725 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1727 static const struct vec3 quad[] =
1729 {-1.0f, -1.0f, 0.0f},
1730 {-1.0f, 1.0f, 0.0f},
1731 { 1.0f, -1.0f, 0.0f},
1732 { 1.0f, 1.0f, 0.0f},
1735 ID3D11Device *device = context->device;
1736 unsigned int stride, offset;
1737 HRESULT hr;
1739 if (!vs_code)
1741 vs_code = default_vs_code;
1742 vs_code_size = sizeof(default_vs_code);
1745 if (!context->input_layout)
1747 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1748 vs_code, vs_code_size, &context->input_layout);
1749 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1752 if (context->vs_code != vs_code)
1754 if (context->vs)
1755 ID3D11VertexShader_Release(context->vs);
1757 hr = ID3D11Device_CreateVertexShader(device, vs_code, vs_code_size, NULL, &context->vs);
1758 ok_(__FILE__, line)(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
1760 context->vs_code = vs_code;
1763 if (!context->vb)
1764 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1766 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1767 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1768 stride = sizeof(*quad);
1769 offset = 0;
1770 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1771 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1773 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1776 #define draw_quad_z(context, z) draw_quad_z_(__LINE__, context, z)
1777 static void draw_quad_z_(unsigned int line, struct d3d11_test_context *context, float z)
1779 static const DWORD vs_code[] =
1781 #if 0
1782 float depth;
1784 void main(float4 in_position : POSITION, out float4 out_position : SV_Position)
1786 out_position = in_position;
1787 out_position.z = depth;
1789 #endif
1790 0x43425844, 0x22d7ff76, 0xd53b167c, 0x1b49ccf1, 0xbebfec39, 0x00000001, 0x00000100, 0x00000003,
1791 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1792 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000b0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1793 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1794 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x52444853, 0x00000064, 0x00010040,
1795 0x00000019, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010b2, 0x00000000,
1796 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x05000036, 0x001020b2, 0x00000000, 0x00101c46,
1797 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
1800 struct vec4 data = {z};
1802 if (!context->vs_cb)
1803 context->vs_cb = create_buffer(context->device, D3D11_BIND_CONSTANT_BUFFER, sizeof(data), NULL);
1805 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1806 (ID3D11Resource *)context->vs_cb, 0, NULL, &data, 0, 0);
1808 ID3D11DeviceContext_VSSetConstantBuffers(context->immediate_context, 0, 1, &context->vs_cb);
1809 draw_quad_vs_(__LINE__, context, vs_code, sizeof(vs_code));
1812 static void set_quad_color(struct d3d11_test_context *context, const struct vec4 *color)
1814 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1815 (ID3D11Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1818 #define draw_color_quad(a, b) draw_color_quad_(__LINE__, a, b, NULL, 0)
1819 #define draw_color_quad_vs(a, b, c, d) draw_color_quad_(__LINE__, a, b, c, d)
1820 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context,
1821 const struct vec4 *color, const DWORD *vs_code, size_t vs_code_size)
1823 static const DWORD ps_color_code[] =
1825 #if 0
1826 float4 color;
1828 float4 main() : SV_TARGET
1830 return color;
1832 #endif
1833 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1834 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1835 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1836 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1837 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1838 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1839 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1840 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1841 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1842 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1843 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1846 ID3D11Device *device = context->device;
1847 HRESULT hr;
1849 if (!context->ps)
1851 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1852 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1855 if (!context->ps_cb)
1856 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1858 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1859 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1861 set_quad_color(context, color);
1863 draw_quad_vs_(line, context, vs_code, vs_code_size);
1866 static void test_create_device(void)
1868 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1870 D3D_FEATURE_LEVEL_11_0,
1871 D3D_FEATURE_LEVEL_10_1,
1872 D3D_FEATURE_LEVEL_10_0,
1873 D3D_FEATURE_LEVEL_9_3,
1874 D3D_FEATURE_LEVEL_9_2,
1875 D3D_FEATURE_LEVEL_9_1,
1877 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1878 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1879 ID3D11DeviceContext *immediate_context;
1880 IDXGISwapChain *swapchain;
1881 ID3D11Device *device;
1882 ULONG refcount;
1883 HWND window;
1884 HRESULT hr;
1886 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1887 &device, NULL, NULL)))
1889 skip("Failed to create HAL device.\n");
1890 if ((device = create_device(NULL)))
1892 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
1893 ID3D11Device_Release(device);
1895 return;
1898 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
1899 trace("Feature level %#x.\n", supported_feature_level);
1900 ID3D11Device_Release(device);
1902 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
1903 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1905 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
1906 &feature_level, NULL);
1907 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1908 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1909 feature_level, supported_feature_level);
1911 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
1912 ARRAY_SIZE(default_feature_levels), D3D11_SDK_VERSION, NULL, &feature_level, NULL);
1913 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1914 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1915 feature_level, supported_feature_level);
1917 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
1918 &immediate_context);
1919 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1921 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
1922 refcount = get_refcount(immediate_context);
1923 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1925 ID3D11DeviceContext_GetDevice(immediate_context, &device);
1926 refcount = ID3D11Device_Release(device);
1927 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1929 refcount = ID3D11DeviceContext_Release(immediate_context);
1930 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
1932 device = (ID3D11Device *)0xdeadbeef;
1933 feature_level = 0xdeadbeef;
1934 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1935 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1936 &device, &feature_level, &immediate_context);
1937 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
1938 ok(!device, "Got unexpected device pointer %p.\n", device);
1939 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1940 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1942 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
1944 swapchain_desc.BufferDesc.Width = 800;
1945 swapchain_desc.BufferDesc.Height = 600;
1946 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
1947 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
1948 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1949 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1950 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1951 swapchain_desc.SampleDesc.Count = 1;
1952 swapchain_desc.SampleDesc.Quality = 0;
1953 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1954 swapchain_desc.BufferCount = 1;
1955 swapchain_desc.OutputWindow = window;
1956 swapchain_desc.Windowed = TRUE;
1957 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1958 swapchain_desc.Flags = 0;
1960 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1961 &swapchain_desc, NULL, NULL, NULL, NULL);
1962 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1964 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1965 &swapchain_desc, NULL, NULL, &feature_level, NULL);
1966 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1967 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1968 feature_level, supported_feature_level);
1970 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1971 &swapchain_desc, &swapchain, &device, NULL, NULL);
1972 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1974 check_interface(swapchain, &IID_IDXGISwapChain1, TRUE, FALSE);
1976 memset(&obtained_desc, 0, sizeof(obtained_desc));
1977 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
1978 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
1979 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
1980 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
1981 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
1982 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
1983 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
1984 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
1985 obtained_desc.BufferDesc.RefreshRate.Numerator);
1986 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
1987 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
1988 obtained_desc.BufferDesc.RefreshRate.Denominator);
1989 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
1990 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
1991 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
1992 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
1993 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
1994 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
1995 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
1996 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
1997 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
1998 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
1999 ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
2000 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
2001 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
2002 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
2003 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
2004 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
2005 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
2006 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
2007 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
2008 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
2009 ok(obtained_desc.Flags == swapchain_desc.Flags,
2010 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
2012 refcount = IDXGISwapChain_Release(swapchain);
2013 ok(!refcount, "Swapchain has %u references left.\n", refcount);
2015 feature_level = ID3D11Device_GetFeatureLevel(device);
2016 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2017 feature_level, supported_feature_level);
2019 refcount = ID3D11Device_Release(device);
2020 ok(!refcount, "Device has %u references left.\n", refcount);
2022 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2023 NULL, NULL, &device, NULL, NULL);
2024 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2025 ID3D11Device_Release(device);
2027 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2028 NULL, NULL, NULL, NULL, NULL);
2029 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2031 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2032 NULL, NULL, NULL, &feature_level, NULL);
2033 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2034 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2035 feature_level, supported_feature_level);
2037 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2038 NULL, NULL, NULL, NULL, &immediate_context);
2039 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2040 ID3D11DeviceContext_Release(immediate_context);
2042 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2043 &swapchain_desc, NULL, NULL, NULL, NULL);
2044 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2046 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2047 &swapchain_desc, &swapchain, NULL, NULL, NULL);
2048 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2049 IDXGISwapChain_Release(swapchain);
2051 swapchain_desc.OutputWindow = NULL;
2052 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2053 &swapchain_desc, NULL, NULL, NULL, NULL);
2054 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2055 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2056 &swapchain_desc, NULL, &device, NULL, NULL);
2057 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2058 ID3D11Device_Release(device);
2060 swapchain = (IDXGISwapChain *)0xdeadbeef;
2061 device = (ID3D11Device *)0xdeadbeef;
2062 feature_level = 0xdeadbeef;
2063 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
2064 swapchain_desc.OutputWindow = NULL;
2065 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2066 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
2067 ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2068 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
2069 ok(!device, "Got unexpected device pointer %p.\n", device);
2070 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
2071 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
2073 swapchain = (IDXGISwapChain *)0xdeadbeef;
2074 device = (ID3D11Device *)0xdeadbeef;
2075 feature_level = 0xdeadbeef;
2076 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
2077 swapchain_desc.OutputWindow = window;
2078 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
2079 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2080 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
2081 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2082 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
2083 ok(!device, "Got unexpected device pointer %p.\n", device);
2084 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
2085 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
2087 DestroyWindow(window);
2090 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
2092 struct device_desc device_desc;
2093 IDXGIAdapter *dxgi_adapter;
2094 IDXGIDevice *dxgi_device;
2095 ID3D11Device *device;
2096 IUnknown *iface;
2097 ULONG refcount;
2098 HRESULT hr;
2100 device_desc.feature_level = &feature_level;
2101 device_desc.flags = 0;
2102 if (!(device = create_device(&device_desc)))
2104 skip("Failed to create device for feature level %#x.\n", feature_level);
2105 return;
2108 check_interface(device, &IID_IUnknown, TRUE, FALSE);
2109 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
2110 check_interface(device, &IID_IDXGIDevice, TRUE, FALSE);
2111 check_interface(device, &IID_IDXGIDevice1, TRUE, FALSE);
2112 check_interface(device, &IID_ID3D10Multithread, TRUE, TRUE); /* Not available on all Windows versions. */
2113 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
2114 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
2115 check_interface(device, &IID_ID3D11InfoQueue, enable_debug_layer, FALSE);
2117 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
2118 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
2119 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
2120 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
2121 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
2122 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
2123 IUnknown_Release(iface);
2124 IDXGIAdapter_Release(dxgi_adapter);
2125 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
2126 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
2127 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
2128 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
2129 IUnknown_Release(iface);
2130 IDXGIAdapter_Release(dxgi_adapter);
2131 IDXGIDevice_Release(dxgi_device);
2133 refcount = ID3D11Device_Release(device);
2134 ok(!refcount, "Device has %u references left.\n", refcount);
2136 device_desc.feature_level = &feature_level;
2137 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
2138 if (!(device = create_device(&device_desc)))
2140 skip("Failed to create debug device for feature level %#x.\n", feature_level);
2141 return;
2144 todo_wine check_interface(device, &IID_ID3D11InfoQueue, TRUE, FALSE);
2146 refcount = ID3D11Device_Release(device);
2147 ok(!refcount, "Device has %u references left.\n", refcount);
2150 static void test_immediate_context(void)
2152 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
2153 ULONG expected_refcount, refcount;
2154 ID3D11CommandList *command_list;
2155 ID3D11Multithread *multithread;
2156 ID3D11Buffer *buffer[2];
2157 ID3D11Device *device;
2158 unsigned int flags;
2159 BOOL enabled;
2160 HRESULT hr;
2162 static const unsigned int buffer_contents[] =
2164 0x11111111, 0x22222222, 0x33333333, 0x44444444,
2165 0x55555555, 0x66666666, 0x77777777, 0x88888888,
2168 if (!(device = create_device(NULL)))
2170 skip("Failed to create device.\n");
2171 return;
2174 expected_refcount = get_refcount(device) + 1;
2175 ID3D11Device_GetImmediateContext(device, &immediate_context);
2176 refcount = get_refcount(device);
2177 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
2178 previous_immediate_context = immediate_context;
2180 ID3D11Device_GetImmediateContext(device, &immediate_context);
2181 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
2182 refcount = get_refcount(device);
2183 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
2185 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
2186 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2187 refcount = ID3D11DeviceContext_Release(immediate_context);
2188 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2190 ID3D11Device_GetImmediateContext(device, &immediate_context);
2191 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
2192 refcount = ID3D11DeviceContext_Release(immediate_context);
2193 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2195 ID3D11Device_GetImmediateContext(device, &immediate_context);
2196 expected_refcount = get_refcount(immediate_context) + 1;
2197 hr = ID3D11DeviceContext_QueryInterface(immediate_context, &IID_ID3D11Multithread, (void **)&multithread);
2198 if (hr == E_NOINTERFACE)
2200 win_skip("ID3D11Multithread is not supported.\n");
2201 goto done;
2203 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2205 refcount = get_refcount(immediate_context);
2206 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2208 expected_refcount = refcount;
2209 refcount = get_refcount(multithread);
2210 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2212 enabled = ID3D11Multithread_GetMultithreadProtected(multithread);
2213 todo_wine ok(!enabled, "Multithread protection is %#x.\n", enabled);
2215 ID3D11Multithread_Release(multithread);
2217 ID3D11Device_GetImmediateContext(device, &immediate_context);
2219 flags = ID3D11DeviceContext_GetContextFlags(immediate_context);
2220 ok(!flags, "Got unexpected flags %#x.\n", flags);
2222 hr = ID3D11DeviceContext_FinishCommandList(immediate_context, FALSE, &command_list);
2223 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
2225 buffer[0] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 16, &buffer_contents[0]);
2226 buffer[1] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 16, &buffer_contents[4]);
2228 ID3D11DeviceContext_CopyResource(immediate_context, (ID3D11Resource *)buffer[1], (ID3D11Resource *)buffer[0]);
2230 hr = ID3D11DeviceContext_FinishCommandList(immediate_context, FALSE, &command_list);
2231 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
2233 ID3D11Buffer_Release(buffer[1]);
2234 ID3D11Buffer_Release(buffer[0]);
2235 ID3D11DeviceContext_Release(immediate_context);
2237 done:
2238 refcount = ID3D11DeviceContext_Release(immediate_context);
2239 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2240 refcount = ID3D11Device_Release(device);
2241 ok(!refcount, "Device has %u references left.\n", refcount);
2244 static void test_create_deferred_context(void)
2246 ULONG refcount, expected_refcount;
2247 struct device_desc device_desc;
2248 ID3D11DeviceContext *context;
2249 ID3D11Device *device;
2250 HRESULT hr;
2252 device_desc.feature_level = NULL;
2253 device_desc.flags = D3D11_CREATE_DEVICE_SINGLETHREADED;
2254 if (!(device = create_device(&device_desc)))
2256 skip("Failed to create single-threaded device.\n");
2257 return;
2260 hr = ID3D11Device_CreateDeferredContext(device, 0, &context);
2261 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Failed to create deferred context, hr %#x.\n", hr);
2263 refcount = ID3D11Device_Release(device);
2264 ok(!refcount, "Device has %u references left.\n", refcount);
2266 if (!(device = create_device(NULL)))
2268 skip("Failed to create device.\n");
2269 return;
2272 expected_refcount = get_refcount(device) + 1;
2273 hr = ID3D11Device_CreateDeferredContext(device, 0, &context);
2274 todo_wine ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
2275 if (FAILED(hr))
2276 goto done;
2277 refcount = get_refcount(device);
2278 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2279 refcount = get_refcount(context);
2280 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2282 check_interface(context, &IID_IUnknown, TRUE, FALSE);
2283 check_interface(context, &IID_ID3D11DeviceChild, TRUE, FALSE);
2284 check_interface(context, &IID_ID3D11DeviceContext, TRUE, FALSE);
2285 check_interface(context, &IID_ID3D11Multithread, FALSE, FALSE);
2287 refcount = ID3D11DeviceContext_Release(context);
2288 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2290 done:
2291 refcount = ID3D11Device_Release(device);
2292 ok(!refcount, "Device has %u references left.\n", refcount);
2295 static void test_create_texture1d(void)
2297 ULONG refcount, expected_refcount;
2298 D3D11_SUBRESOURCE_DATA data = {0};
2299 ID3D11Device *device, *tmp;
2300 D3D11_TEXTURE1D_DESC desc;
2301 ID3D11Texture1D *texture;
2302 unsigned int i;
2303 HRESULT hr;
2305 if (!(device = create_device(NULL)))
2307 skip("Failed to create device.\n");
2308 return;
2311 desc.Width = 512;
2312 desc.MipLevels = 1;
2313 desc.ArraySize = 1;
2314 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2315 desc.Usage = D3D11_USAGE_DEFAULT;
2316 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2317 desc.CPUAccessFlags = 0;
2318 desc.MiscFlags = 0;
2320 hr = ID3D11Device_CreateTexture1D(device, &desc, &data, &texture);
2321 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2323 expected_refcount = get_refcount(device) + 1;
2324 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2325 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2326 refcount = get_refcount(device);
2327 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2328 tmp = NULL;
2329 expected_refcount = refcount + 1;
2330 ID3D11Texture1D_GetDevice(texture, &tmp);
2331 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2332 refcount = get_refcount(device);
2333 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2334 ID3D11Device_Release(tmp);
2336 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2337 ID3D11Texture1D_Release(texture);
2339 desc.MipLevels = 0;
2340 expected_refcount = get_refcount(device) + 1;
2341 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2342 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2343 refcount = get_refcount(device);
2344 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2345 tmp = NULL;
2346 expected_refcount = refcount + 1;
2347 ID3D11Texture1D_GetDevice(texture, &tmp);
2348 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2349 refcount = get_refcount(device);
2350 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2351 ID3D11Device_Release(tmp);
2353 ID3D11Texture1D_GetDesc(texture, &desc);
2354 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2355 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2356 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2357 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2358 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2359 ok(desc.BindFlags == D3D11_BIND_SHADER_RESOURCE, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
2360 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
2361 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
2363 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2364 ID3D11Texture1D_Release(texture);
2366 desc.MipLevels = 1;
2367 desc.ArraySize = 2;
2368 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2369 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2371 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2372 ID3D11Texture1D_Release(texture);
2374 for (i = 0; i < 4; ++i)
2376 desc.ArraySize = i;
2377 desc.Format = DXGI_FORMAT_R32G32B32A32_TYPELESS;
2378 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2379 desc.MiscFlags = 0;
2380 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2381 ok(hr == (i ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2382 if (SUCCEEDED(hr))
2383 ID3D11Texture1D_Release(texture);
2386 refcount = ID3D11Device_Release(device);
2387 ok(!refcount, "Device has %u references left.\n", refcount);
2390 static void test_texture1d_interfaces(void)
2392 ID3D10Texture1D *d3d10_texture;
2393 D3D11_TEXTURE1D_DESC desc;
2394 ID3D11Texture1D *texture;
2395 ID3D11Device *device;
2396 unsigned int i;
2397 ULONG refcount;
2398 HRESULT hr;
2400 static const struct test
2402 BOOL implements_d3d10_interfaces;
2403 UINT bind_flags;
2404 UINT misc_flags;
2405 UINT expected_bind_flags;
2406 UINT expected_misc_flags;
2408 desc_conversion_tests[] =
2411 TRUE,
2412 D3D11_BIND_SHADER_RESOURCE, 0,
2413 D3D10_BIND_SHADER_RESOURCE, 0
2416 TRUE,
2417 D3D11_BIND_UNORDERED_ACCESS, 0,
2418 D3D11_BIND_UNORDERED_ACCESS, 0
2421 FALSE,
2422 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2423 0, 0
2426 TRUE,
2427 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2428 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2432 if (!(device = create_device(NULL)))
2434 skip("Failed to create ID3D11Device, skipping tests.\n");
2435 return;
2438 desc.Width = 512;
2439 desc.MipLevels = 0;
2440 desc.ArraySize = 1;
2441 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2442 desc.Usage = D3D11_USAGE_DEFAULT;
2443 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2444 desc.CPUAccessFlags = 0;
2445 desc.MiscFlags = 0;
2447 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2448 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2449 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2450 hr = check_interface(texture, &IID_ID3D10Texture1D, TRUE, TRUE); /* Not available on all Windows versions. */
2451 ID3D11Texture1D_Release(texture);
2452 if (FAILED(hr))
2454 win_skip("1D textures do not implement ID3D10Texture1D, skipping tests.\n");
2455 ID3D11Device_Release(device);
2456 return;
2459 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2461 const struct test *current = &desc_conversion_tests[i];
2462 D3D10_TEXTURE1D_DESC d3d10_desc;
2463 ID3D10Device *d3d10_device;
2465 desc.Width = 512;
2466 desc.MipLevels = 1;
2467 desc.ArraySize = 1;
2468 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2469 desc.Usage = D3D11_USAGE_DEFAULT;
2470 desc.BindFlags = current->bind_flags;
2471 desc.CPUAccessFlags = 0;
2472 desc.MiscFlags = current->misc_flags;
2474 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2475 /* Shared resources are not supported by REF and WARP devices. */
2476 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2477 "Test %u: Failed to create a 1d texture, hr %#x.\n", i, hr);
2478 if (FAILED(hr))
2480 win_skip("Failed to create ID3D11Texture1D, skipping test %u.\n", i);
2481 continue;
2484 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2486 hr = ID3D11Texture1D_QueryInterface(texture, &IID_ID3D10Texture1D, (void **)&d3d10_texture);
2487 ID3D11Texture1D_Release(texture);
2489 if (current->implements_d3d10_interfaces)
2491 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture1D.\n", i);
2493 else
2495 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture1D.\n", i);
2496 if (SUCCEEDED(hr)) ID3D10Texture1D_Release(d3d10_texture);
2497 continue;
2500 ID3D10Texture1D_GetDesc(d3d10_texture, &d3d10_desc);
2502 ok(d3d10_desc.Width == desc.Width,
2503 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2504 ok(d3d10_desc.MipLevels == desc.MipLevels,
2505 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2506 ok(d3d10_desc.ArraySize == desc.ArraySize,
2507 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2508 ok(d3d10_desc.Format == desc.Format,
2509 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2510 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2511 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2512 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2513 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2514 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2515 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2517 d3d10_device = (ID3D10Device *)0xdeadbeef;
2518 ID3D10Texture1D_GetDevice(d3d10_texture, &d3d10_device);
2519 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2520 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2522 ID3D10Texture1D_Release(d3d10_texture);
2525 refcount = ID3D11Device_Release(device);
2526 ok(!refcount, "Device has %u references left.\n", refcount);
2529 static void test_create_texture2d(void)
2531 ULONG refcount, expected_refcount;
2532 D3D11_SUBRESOURCE_DATA data = {0};
2533 D3D_FEATURE_LEVEL feature_level;
2534 ID3D11Device *device, *tmp;
2535 D3D11_TEXTURE2D_DESC desc;
2536 ID3D11Texture2D *texture;
2537 UINT quality_level_count;
2538 unsigned int i;
2539 HRESULT hr;
2541 static const struct
2543 DXGI_FORMAT format;
2544 UINT array_size;
2545 D3D11_BIND_FLAG bind_flags;
2546 UINT misc_flags;
2547 BOOL succeeds;
2548 BOOL todo;
2550 tests[] =
2552 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
2553 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
2554 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
2555 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
2556 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2557 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2558 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2559 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2560 FALSE, FALSE},
2561 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2562 FALSE, FALSE},
2563 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2564 FALSE, FALSE},
2565 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2566 TRUE, FALSE},
2567 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2568 TRUE, FALSE},
2569 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2570 TRUE, FALSE},
2571 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2572 TRUE, FALSE},
2573 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2574 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2575 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2576 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2577 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2578 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2579 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2580 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2581 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2582 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2583 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2584 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2585 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2586 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2587 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2588 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2589 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2590 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2591 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2592 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
2593 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2594 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2595 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
2596 TRUE, FALSE},
2597 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2598 TRUE, FALSE},
2599 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2600 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
2601 FALSE, TRUE},
2602 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2603 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
2604 FALSE, TRUE},
2605 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
2606 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
2607 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
2608 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2609 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2610 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2611 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2612 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2613 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2614 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2615 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2616 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2617 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2618 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2619 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2620 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2621 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2622 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2623 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2624 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2625 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2626 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2627 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
2628 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2629 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
2630 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
2631 FALSE, TRUE},
2632 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2633 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2634 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2635 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2636 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2639 if (!(device = create_device(NULL)))
2641 skip("Failed to create device.\n");
2642 return;
2645 feature_level = ID3D11Device_GetFeatureLevel(device);
2647 desc.Width = 512;
2648 desc.Height = 512;
2649 desc.MipLevels = 1;
2650 desc.ArraySize = 1;
2651 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2652 desc.SampleDesc.Count = 1;
2653 desc.SampleDesc.Quality = 0;
2654 desc.Usage = D3D11_USAGE_DEFAULT;
2655 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2656 desc.CPUAccessFlags = 0;
2657 desc.MiscFlags = 0;
2659 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
2660 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2662 expected_refcount = get_refcount(device) + 1;
2663 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2664 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2665 refcount = get_refcount(device);
2666 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2667 tmp = NULL;
2668 expected_refcount = refcount + 1;
2669 ID3D11Texture2D_GetDevice(texture, &tmp);
2670 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2671 refcount = get_refcount(device);
2672 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2673 ID3D11Device_Release(tmp);
2675 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2676 ID3D11Texture2D_Release(texture);
2678 desc.MipLevels = 0;
2679 expected_refcount = get_refcount(device) + 1;
2680 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2681 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2682 refcount = get_refcount(device);
2683 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2684 tmp = NULL;
2685 expected_refcount = refcount + 1;
2686 ID3D11Texture2D_GetDevice(texture, &tmp);
2687 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2688 refcount = get_refcount(device);
2689 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2690 ID3D11Device_Release(tmp);
2692 ID3D11Texture2D_GetDesc(texture, &desc);
2693 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2694 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
2695 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2696 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2697 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2698 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
2699 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
2700 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2701 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
2702 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
2703 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
2705 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2706 ID3D11Texture2D_Release(texture);
2708 desc.MipLevels = 1;
2709 desc.ArraySize = 2;
2710 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2711 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2713 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2714 ID3D11Texture2D_Release(texture);
2716 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
2717 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
2718 desc.ArraySize = 1;
2719 desc.SampleDesc.Count = 2;
2720 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2721 if (quality_level_count)
2723 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
2724 ID3D11Texture2D_Release(texture);
2725 desc.SampleDesc.Quality = quality_level_count;
2726 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2728 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2730 /* We assume 15 samples multisampling is never supported in practice. */
2731 desc.SampleDesc.Count = 15;
2732 desc.SampleDesc.Quality = 0;
2733 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2734 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2736 desc.SampleDesc.Count = 1;
2737 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2739 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
2740 BOOL todo = tests[i].todo;
2742 if (feature_level < D3D_FEATURE_LEVEL_10_1
2743 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
2744 && tests[i].array_size > 6)
2746 expected_hr = E_INVALIDARG;
2747 todo = TRUE;
2750 desc.ArraySize = tests[i].array_size;
2751 desc.Format = tests[i].format;
2752 desc.BindFlags = tests[i].bind_flags;
2753 desc.MiscFlags = tests[i].misc_flags;
2754 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2756 todo_wine_if(todo)
2757 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
2758 i, hr, desc.Format);
2760 if (SUCCEEDED(hr))
2761 ID3D11Texture2D_Release(texture);
2764 refcount = ID3D11Device_Release(device);
2765 ok(!refcount, "Device has %u references left.\n", refcount);
2768 static void test_texture2d_interfaces(void)
2770 ID3D10Texture2D *d3d10_texture;
2771 D3D11_TEXTURE2D_DESC desc;
2772 ID3D11Texture2D *texture;
2773 ID3D11Device *device;
2774 unsigned int i;
2775 ULONG refcount;
2776 HRESULT hr;
2778 static const struct test
2780 BOOL implements_d3d10_interfaces;
2781 UINT bind_flags;
2782 UINT misc_flags;
2783 UINT expected_bind_flags;
2784 UINT expected_misc_flags;
2786 desc_conversion_tests[] =
2789 TRUE,
2790 D3D11_BIND_SHADER_RESOURCE, 0,
2791 D3D10_BIND_SHADER_RESOURCE, 0
2794 TRUE,
2795 D3D11_BIND_UNORDERED_ACCESS, 0,
2796 D3D11_BIND_UNORDERED_ACCESS, 0
2799 FALSE,
2800 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2801 0, 0
2804 TRUE,
2805 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2806 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2809 TRUE,
2810 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
2811 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2815 if (!(device = create_device(NULL)))
2817 skip("Failed to create ID3D11Device, skipping tests.\n");
2818 return;
2821 desc.Width = 512;
2822 desc.Height = 512;
2823 desc.MipLevels = 0;
2824 desc.ArraySize = 1;
2825 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2826 desc.SampleDesc.Count = 1;
2827 desc.SampleDesc.Quality = 0;
2828 desc.Usage = D3D11_USAGE_DEFAULT;
2829 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2830 desc.CPUAccessFlags = 0;
2831 desc.MiscFlags = 0;
2833 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2834 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2835 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2836 hr = check_interface(texture, &IID_ID3D10Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
2837 ID3D11Texture2D_Release(texture);
2838 if (FAILED(hr))
2840 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
2841 ID3D11Device_Release(device);
2842 return;
2845 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2847 const struct test *current = &desc_conversion_tests[i];
2848 D3D10_TEXTURE2D_DESC d3d10_desc;
2849 ID3D10Device *d3d10_device;
2851 desc.Width = 512;
2852 desc.Height = 512;
2853 desc.MipLevels = 1;
2854 desc.ArraySize = 1;
2855 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2856 desc.SampleDesc.Count = 1;
2857 desc.SampleDesc.Quality = 0;
2858 desc.Usage = D3D11_USAGE_DEFAULT;
2859 desc.BindFlags = current->bind_flags;
2860 desc.CPUAccessFlags = 0;
2861 desc.MiscFlags = current->misc_flags;
2863 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2864 /* Shared resources are not supported by REF and WARP devices. */
2865 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2866 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2867 if (FAILED(hr))
2869 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
2870 continue;
2873 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2875 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2876 ID3D11Texture2D_Release(texture);
2878 if (current->implements_d3d10_interfaces)
2880 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2882 else
2884 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2885 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
2886 continue;
2889 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
2891 ok(d3d10_desc.Width == desc.Width,
2892 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2893 ok(d3d10_desc.Height == desc.Height,
2894 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2895 ok(d3d10_desc.MipLevels == desc.MipLevels,
2896 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2897 ok(d3d10_desc.ArraySize == desc.ArraySize,
2898 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2899 ok(d3d10_desc.Format == desc.Format,
2900 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2901 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
2902 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
2903 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2904 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
2905 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2906 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2907 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2908 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2909 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2910 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2911 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2912 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2914 d3d10_device = (ID3D10Device *)0xdeadbeef;
2915 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
2916 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2917 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2919 ID3D10Texture2D_Release(d3d10_texture);
2922 refcount = ID3D11Device_Release(device);
2923 ok(!refcount, "Device has %u references left.\n", refcount);
2926 static void test_create_texture3d(void)
2928 ULONG refcount, expected_refcount;
2929 D3D11_SUBRESOURCE_DATA data = {0};
2930 ID3D11Device *device, *tmp;
2931 D3D11_TEXTURE3D_DESC desc;
2932 ID3D11Texture3D *texture;
2933 unsigned int i;
2934 HRESULT hr;
2936 static const struct
2938 DXGI_FORMAT format;
2939 D3D11_BIND_FLAG bind_flags;
2940 BOOL succeeds;
2941 BOOL todo;
2943 tests[] =
2945 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
2946 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
2947 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2948 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2949 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2950 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2951 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2952 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2953 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2954 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2955 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2956 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2959 if (!(device = create_device(NULL)))
2961 skip("Failed to create ID3D11Device, skipping tests.\n");
2962 return;
2965 desc.Width = 64;
2966 desc.Height = 64;
2967 desc.Depth = 64;
2968 desc.MipLevels = 1;
2969 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2970 desc.Usage = D3D11_USAGE_DEFAULT;
2971 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2972 desc.CPUAccessFlags = 0;
2973 desc.MiscFlags = 0;
2975 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2976 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2978 expected_refcount = get_refcount(device) + 1;
2979 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2980 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2981 refcount = get_refcount(device);
2982 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2983 tmp = NULL;
2984 expected_refcount = refcount + 1;
2985 ID3D11Texture3D_GetDevice(texture, &tmp);
2986 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2987 refcount = get_refcount(device);
2988 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2989 ID3D11Device_Release(tmp);
2991 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2992 ID3D11Texture3D_Release(texture);
2994 desc.MipLevels = 0;
2995 expected_refcount = get_refcount(device) + 1;
2996 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2997 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2998 refcount = get_refcount(device);
2999 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3000 tmp = NULL;
3001 expected_refcount = refcount + 1;
3002 ID3D11Texture3D_GetDevice(texture, &tmp);
3003 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3004 refcount = get_refcount(device);
3005 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3006 ID3D11Device_Release(tmp);
3008 ID3D11Texture3D_GetDesc(texture, &desc);
3009 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
3010 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
3011 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
3012 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
3013 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
3014 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
3015 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
3016 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
3017 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
3019 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3020 ID3D11Texture3D_Release(texture);
3022 desc.MipLevels = 1;
3023 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3025 desc.Format = tests[i].format;
3026 desc.BindFlags = tests[i].bind_flags;
3027 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3029 todo_wine_if(tests[i].todo)
3030 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
3032 if (SUCCEEDED(hr))
3033 ID3D11Texture3D_Release(texture);
3036 refcount = ID3D11Device_Release(device);
3037 ok(!refcount, "Device has %u references left.\n", refcount);
3040 static void test_texture3d_interfaces(void)
3042 ID3D10Texture3D *d3d10_texture;
3043 D3D11_TEXTURE3D_DESC desc;
3044 ID3D11Texture3D *texture;
3045 ID3D11Device *device;
3046 unsigned int i;
3047 ULONG refcount;
3048 HRESULT hr;
3050 static const struct test
3052 BOOL implements_d3d10_interfaces;
3053 UINT bind_flags;
3054 UINT misc_flags;
3055 UINT expected_bind_flags;
3056 UINT expected_misc_flags;
3058 desc_conversion_tests[] =
3061 TRUE,
3062 D3D11_BIND_SHADER_RESOURCE, 0,
3063 D3D10_BIND_SHADER_RESOURCE, 0
3066 TRUE,
3067 D3D11_BIND_UNORDERED_ACCESS, 0,
3068 D3D11_BIND_UNORDERED_ACCESS, 0
3071 FALSE,
3072 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
3073 0, 0
3076 TRUE,
3077 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
3078 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
3082 if (!(device = create_device(NULL)))
3084 skip("Failed to create ID3D11Device.\n");
3085 return;
3088 desc.Width = 64;
3089 desc.Height = 64;
3090 desc.Depth = 64;
3091 desc.MipLevels = 0;
3092 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3093 desc.Usage = D3D11_USAGE_DEFAULT;
3094 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3095 desc.CPUAccessFlags = 0;
3096 desc.MiscFlags = 0;
3098 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3099 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
3100 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3101 hr = check_interface(texture, &IID_ID3D10Texture3D, TRUE, TRUE); /* Not available on all Windows versions. */
3102 ID3D11Texture3D_Release(texture);
3103 if (FAILED(hr))
3105 win_skip("3D textures do not implement ID3D10Texture3D.\n");
3106 ID3D11Device_Release(device);
3107 return;
3110 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
3112 const struct test *current = &desc_conversion_tests[i];
3113 D3D10_TEXTURE3D_DESC d3d10_desc;
3114 ID3D10Device *d3d10_device;
3116 desc.Width = 64;
3117 desc.Height = 64;
3118 desc.Depth = 64;
3119 desc.MipLevels = 1;
3120 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3121 desc.Usage = D3D11_USAGE_DEFAULT;
3122 desc.BindFlags = current->bind_flags;
3123 desc.CPUAccessFlags = 0;
3124 desc.MiscFlags = current->misc_flags;
3126 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3127 /* Shared resources are not supported by REF and WARP devices. */
3128 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
3129 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
3130 if (FAILED(hr))
3132 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
3133 continue;
3136 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3138 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
3139 ID3D11Texture3D_Release(texture);
3141 if (current->implements_d3d10_interfaces)
3143 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
3145 else
3147 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
3148 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
3149 continue;
3152 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
3154 ok(d3d10_desc.Width == desc.Width,
3155 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
3156 ok(d3d10_desc.Height == desc.Height,
3157 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
3158 ok(d3d10_desc.Depth == desc.Depth,
3159 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
3160 ok(d3d10_desc.MipLevels == desc.MipLevels,
3161 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
3162 ok(d3d10_desc.Format == desc.Format,
3163 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
3164 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
3165 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
3166 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
3167 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
3168 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
3169 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
3170 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
3171 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
3173 d3d10_device = (ID3D10Device *)0xdeadbeef;
3174 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
3175 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
3176 if (d3d10_device) ID3D10Device_Release(d3d10_device);
3178 ID3D10Texture3D_Release(d3d10_texture);
3181 refcount = ID3D11Device_Release(device);
3182 ok(!refcount, "Device has %u references left.\n", refcount);
3185 static void test_create_buffer(void)
3187 ID3D10Buffer *d3d10_buffer;
3188 HRESULT expected_hr, hr;
3189 D3D11_BUFFER_DESC desc;
3190 ID3D11Buffer *buffer;
3191 ID3D11Device *device;
3192 unsigned int i;
3193 ULONG refcount;
3195 static const struct test
3197 BOOL succeeds;
3198 BOOL implements_d3d10_interfaces;
3199 UINT bind_flags;
3200 UINT misc_flags;
3201 UINT structure_stride;
3202 UINT expected_bind_flags;
3203 UINT expected_misc_flags;
3205 tests[] =
3208 TRUE, TRUE,
3209 D3D11_BIND_VERTEX_BUFFER, 0, 0,
3210 D3D10_BIND_VERTEX_BUFFER, 0
3213 TRUE, TRUE,
3214 D3D11_BIND_INDEX_BUFFER, 0, 0,
3215 D3D10_BIND_INDEX_BUFFER, 0
3218 TRUE, TRUE,
3219 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
3220 D3D10_BIND_CONSTANT_BUFFER, 0
3223 TRUE, TRUE,
3224 D3D11_BIND_SHADER_RESOURCE, 0, 0,
3225 D3D10_BIND_SHADER_RESOURCE, 0
3228 TRUE, TRUE,
3229 D3D11_BIND_STREAM_OUTPUT, 0, 0,
3230 D3D10_BIND_STREAM_OUTPUT, 0
3233 TRUE, TRUE,
3234 D3D11_BIND_RENDER_TARGET, 0, 0,
3235 D3D10_BIND_RENDER_TARGET, 0
3238 TRUE, TRUE,
3239 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
3240 D3D11_BIND_UNORDERED_ACCESS, 0
3243 TRUE, TRUE,
3244 0, D3D11_RESOURCE_MISC_SHARED, 0,
3245 0, D3D10_RESOURCE_MISC_SHARED
3248 TRUE, TRUE,
3249 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
3250 0, 0
3253 FALSE, FALSE,
3254 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3257 FALSE, FALSE,
3258 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3261 FALSE, FALSE,
3262 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3265 TRUE, TRUE,
3266 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3267 D3D10_BIND_SHADER_RESOURCE, 0
3270 FALSE, FALSE,
3271 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3274 FALSE, FALSE,
3275 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3278 TRUE, TRUE,
3279 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3280 D3D11_BIND_UNORDERED_ACCESS, 0
3283 FALSE, FALSE,
3284 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3286 /* Structured buffers do not implement ID3D10Buffer. */
3288 TRUE, FALSE,
3289 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3292 TRUE, FALSE,
3293 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3296 FALSE, FALSE,
3297 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
3300 FALSE, FALSE,
3301 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
3304 FALSE, FALSE,
3305 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
3308 FALSE, FALSE,
3309 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
3312 FALSE, FALSE,
3313 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
3316 TRUE, FALSE,
3317 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
3320 FALSE, FALSE,
3321 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
3324 TRUE, FALSE,
3325 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
3328 TRUE, FALSE,
3329 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
3332 FALSE, FALSE,
3333 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
3336 TRUE, FALSE,
3337 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
3340 TRUE, TRUE,
3341 0, 0, 513,
3342 0, 0
3345 TRUE, TRUE,
3346 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
3347 D3D10_BIND_CONSTANT_BUFFER, 0
3350 TRUE, TRUE,
3351 D3D11_BIND_SHADER_RESOURCE, 0, 513,
3352 D3D10_BIND_SHADER_RESOURCE, 0
3355 TRUE, TRUE,
3356 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
3357 D3D11_BIND_UNORDERED_ACCESS, 0
3360 FALSE, FALSE,
3361 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3364 FALSE, FALSE,
3365 D3D11_BIND_SHADER_RESOURCE,
3366 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3369 TRUE, TRUE,
3370 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
3371 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
3375 if (!(device = create_device(NULL)))
3377 skip("Failed to create ID3D11Device.\n");
3378 return;
3381 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
3382 hr = check_interface(buffer, &IID_ID3D10Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
3383 ID3D11Buffer_Release(buffer);
3384 if (FAILED(hr))
3386 win_skip("Buffers do not implement ID3D10Buffer.\n");
3387 ID3D11Device_Release(device);
3388 return;
3391 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3393 const struct test *current = &tests[i];
3394 D3D11_BUFFER_DESC obtained_desc;
3395 D3D10_BUFFER_DESC d3d10_desc;
3396 ID3D10Device *d3d10_device;
3398 desc.ByteWidth = 1024;
3399 desc.Usage = D3D11_USAGE_DEFAULT;
3400 desc.BindFlags = current->bind_flags;
3401 desc.CPUAccessFlags = 0;
3402 desc.MiscFlags = current->misc_flags;
3403 desc.StructureByteStride = current->structure_stride;
3405 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
3406 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
3407 /* Shared resources are not supported by REF and WARP devices. */
3408 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
3409 i, hr, expected_hr);
3410 if (FAILED(hr))
3412 if (hr == E_OUTOFMEMORY)
3413 win_skip("Failed to create a buffer, skipping test %u.\n", i);
3414 continue;
3417 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
3418 desc.StructureByteStride = 0;
3420 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
3422 ok(obtained_desc.ByteWidth == desc.ByteWidth,
3423 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
3424 ok(obtained_desc.Usage == desc.Usage,
3425 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
3426 ok(obtained_desc.BindFlags == desc.BindFlags,
3427 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
3428 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
3429 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
3430 ok(obtained_desc.MiscFlags == desc.MiscFlags,
3431 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
3432 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
3433 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
3435 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
3436 ID3D11Buffer_Release(buffer);
3438 if (current->implements_d3d10_interfaces)
3440 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
3442 else
3444 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
3445 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
3446 continue;
3449 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
3451 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
3452 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
3453 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
3454 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
3455 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
3456 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
3457 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
3458 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
3459 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
3460 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
3462 d3d10_device = (ID3D10Device *)0xdeadbeef;
3463 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
3464 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
3465 if (d3d10_device) ID3D10Device_Release(d3d10_device);
3467 ID3D10Buffer_Release(d3d10_buffer);
3470 memset(&desc, 0, sizeof(desc));
3471 desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
3472 for (i = 0; i <= 32; ++i)
3474 desc.ByteWidth = i;
3475 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
3476 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
3477 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
3478 if (SUCCEEDED(hr))
3479 ID3D11Buffer_Release(buffer);
3482 refcount = ID3D11Device_Release(device);
3483 ok(!refcount, "Device has %u references left.\n", refcount);
3486 static void test_create_depthstencil_view(void)
3488 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
3489 D3D11_TEXTURE2D_DESC texture_desc;
3490 ULONG refcount, expected_refcount;
3491 ID3D11DepthStencilView *dsview;
3492 ID3D11Device *device, *tmp;
3493 ID3D11Texture2D *texture;
3494 unsigned int i;
3495 HRESULT hr;
3497 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3498 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
3499 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
3500 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
3501 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
3502 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
3503 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
3504 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
3505 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
3506 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
3507 static const struct
3509 struct
3511 unsigned int miplevel_count;
3512 unsigned int array_size;
3513 DXGI_FORMAT format;
3514 } texture;
3515 struct dsv_desc dsv_desc;
3516 struct dsv_desc expected_dsv_desc;
3518 tests[] =
3520 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
3521 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
3522 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3523 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
3524 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
3525 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3526 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3527 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3528 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3529 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3530 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
3531 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
3532 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
3533 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
3534 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
3535 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
3536 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
3537 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3538 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3539 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3540 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3541 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3542 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3543 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3544 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3545 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
3546 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
3548 static const struct
3550 struct
3552 unsigned int miplevel_count;
3553 unsigned int array_size;
3554 DXGI_FORMAT format;
3555 } texture;
3556 struct dsv_desc dsv_desc;
3558 invalid_desc_tests[] =
3560 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
3561 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
3562 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
3563 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
3564 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
3565 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3566 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
3567 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
3568 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
3569 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
3570 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
3571 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
3572 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
3574 #undef FMT_UNKNOWN
3575 #undef D24S8
3576 #undef R24G8_TL
3577 #undef DIM_UNKNOWN
3578 #undef TEX_1D
3579 #undef TEX_1D_ARRAY
3580 #undef TEX_2D
3581 #undef TEX_2D_ARRAY
3582 #undef TEX_2DMS
3583 #undef TEX_2DMS_ARR
3585 if (!(device = create_device(NULL)))
3587 skip("Failed to create device.\n");
3588 return;
3591 texture_desc.Width = 512;
3592 texture_desc.Height = 512;
3593 texture_desc.MipLevels = 1;
3594 texture_desc.ArraySize = 1;
3595 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
3596 texture_desc.SampleDesc.Count = 1;
3597 texture_desc.SampleDesc.Quality = 0;
3598 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3599 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3600 texture_desc.CPUAccessFlags = 0;
3601 texture_desc.MiscFlags = 0;
3603 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3604 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
3606 expected_refcount = get_refcount(device) + 1;
3607 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
3608 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
3609 refcount = get_refcount(device);
3610 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3611 tmp = NULL;
3612 expected_refcount = refcount + 1;
3613 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
3614 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3615 refcount = get_refcount(device);
3616 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3617 ID3D11Device_Release(tmp);
3619 memset(&dsv_desc, 0, sizeof(dsv_desc));
3620 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
3621 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
3622 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
3623 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
3624 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
3625 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
3627 ID3D11DepthStencilView_Release(dsview);
3628 ID3D11Texture2D_Release(texture);
3630 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3632 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
3634 texture_desc.MipLevels = tests[i].texture.miplevel_count;
3635 texture_desc.ArraySize = tests[i].texture.array_size;
3636 texture_desc.Format = tests[i].texture.format;
3638 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3639 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3641 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
3643 current_desc = NULL;
3645 else
3647 current_desc = &dsv_desc;
3648 get_dsv_desc(current_desc, &tests[i].dsv_desc);
3651 expected_refcount = get_refcount(texture);
3652 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
3653 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
3654 refcount = get_refcount(texture);
3655 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3657 /* Not available on all Windows versions. */
3658 check_interface(dsview, &IID_ID3D10DepthStencilView, TRUE, TRUE);
3660 memset(&dsv_desc, 0, sizeof(dsv_desc));
3661 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
3662 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
3664 ID3D11DepthStencilView_Release(dsview);
3665 ID3D11Texture2D_Release(texture);
3668 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3670 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3671 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
3672 texture_desc.Format = invalid_desc_tests[i].texture.format;
3674 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3675 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3677 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
3678 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
3679 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3681 ID3D11Texture2D_Release(texture);
3684 refcount = ID3D11Device_Release(device);
3685 ok(!refcount, "Device has %u references left.\n", refcount);
3688 static void test_depthstencil_view_interfaces(void)
3690 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
3691 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
3692 ID3D10DepthStencilView *d3d10_dsview;
3693 D3D11_TEXTURE2D_DESC texture_desc;
3694 ID3D11DepthStencilView *dsview;
3695 ID3D11Texture2D *texture;
3696 ID3D11Device *device;
3697 ULONG refcount;
3698 HRESULT hr;
3700 if (!(device = create_device(NULL)))
3702 skip("Failed to create device.\n");
3703 return;
3706 texture_desc.Width = 512;
3707 texture_desc.Height = 512;
3708 texture_desc.MipLevels = 1;
3709 texture_desc.ArraySize = 1;
3710 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
3711 texture_desc.SampleDesc.Count = 1;
3712 texture_desc.SampleDesc.Quality = 0;
3713 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3714 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3715 texture_desc.CPUAccessFlags = 0;
3716 texture_desc.MiscFlags = 0;
3718 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3719 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
3721 dsv_desc.Format = texture_desc.Format;
3722 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
3723 dsv_desc.Flags = 0;
3724 U(dsv_desc).Texture2D.MipSlice = 0;
3726 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
3727 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
3729 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
3730 ID3D11DepthStencilView_Release(dsview);
3731 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3732 "Depth stencil view should implement ID3D10DepthStencilView.\n");
3734 if (FAILED(hr))
3736 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
3737 goto done;
3740 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
3741 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
3742 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
3743 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
3744 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
3745 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
3747 ID3D10DepthStencilView_Release(d3d10_dsview);
3749 done:
3750 ID3D11Texture2D_Release(texture);
3752 refcount = ID3D11Device_Release(device);
3753 ok(!refcount, "Device has %u references left.\n", refcount);
3756 static void test_create_rendertarget_view(void)
3758 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
3759 D3D11_TEXTURE3D_DESC texture3d_desc;
3760 D3D11_TEXTURE2D_DESC texture2d_desc;
3761 D3D11_SUBRESOURCE_DATA data = {0};
3762 ULONG refcount, expected_refcount;
3763 D3D11_BUFFER_DESC buffer_desc;
3764 ID3D11RenderTargetView *rtview;
3765 ID3D11Device *device, *tmp;
3766 ID3D11Texture3D *texture3d;
3767 ID3D11Texture2D *texture2d;
3768 ID3D11Resource *texture;
3769 ID3D11Buffer *buffer;
3770 unsigned int i;
3771 HRESULT hr;
3773 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3774 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3775 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3776 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
3777 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
3778 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
3779 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
3780 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
3781 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
3782 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
3783 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
3784 static const struct
3786 struct
3788 unsigned int miplevel_count;
3789 unsigned int depth_or_array_size;
3790 DXGI_FORMAT format;
3791 } texture;
3792 struct rtv_desc rtv_desc;
3793 struct rtv_desc expected_rtv_desc;
3795 tests[] =
3797 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
3798 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
3799 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3800 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
3801 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
3802 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3803 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3804 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3805 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3806 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3807 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
3808 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
3809 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
3810 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
3811 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
3812 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
3813 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
3814 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3815 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3816 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3817 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3818 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3819 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3820 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3821 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3822 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3823 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3824 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3825 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3826 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3827 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3828 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3829 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
3830 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
3831 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
3832 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
3833 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3834 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3835 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
3836 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
3837 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
3838 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
3839 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
3840 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
3842 static const struct
3844 struct
3846 D3D11_RTV_DIMENSION dimension;
3847 unsigned int miplevel_count;
3848 unsigned int depth_or_array_size;
3849 DXGI_FORMAT format;
3850 } texture;
3851 struct rtv_desc rtv_desc;
3853 invalid_desc_tests[] =
3855 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3856 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3857 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3858 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3859 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
3860 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
3861 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
3862 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3863 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
3864 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
3865 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
3866 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
3867 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
3868 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
3869 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
3870 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3871 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3872 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3873 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3874 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3875 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3876 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3877 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3878 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
3879 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
3880 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3881 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3882 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
3883 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3884 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3885 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
3886 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
3887 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
3888 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
3889 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
3891 #undef FMT_UNKNOWN
3892 #undef RGBA8_UNORM
3893 #undef RGBA8_TL
3894 #undef DIM_UNKNOWN
3895 #undef TEX_1D
3896 #undef TEX_1D_ARRAY
3897 #undef TEX_2D
3898 #undef TEX_2D_ARRAY
3899 #undef TEX_2DMS
3900 #undef TEX_2DMS_ARR
3901 #undef TEX_3D
3903 if (!(device = create_device(NULL)))
3905 skip("Failed to create device.\n");
3906 return;
3909 buffer_desc.ByteWidth = 1024;
3910 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3911 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3912 buffer_desc.CPUAccessFlags = 0;
3913 buffer_desc.MiscFlags = 0;
3914 buffer_desc.StructureByteStride = 0;
3916 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
3917 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3919 expected_refcount = get_refcount(device) + 1;
3920 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3921 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3922 refcount = get_refcount(device);
3923 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3924 tmp = NULL;
3925 expected_refcount = refcount + 1;
3926 ID3D11Buffer_GetDevice(buffer, &tmp);
3927 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3928 refcount = get_refcount(device);
3929 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3930 ID3D11Device_Release(tmp);
3932 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3933 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
3934 U1(U(rtv_desc).Buffer).ElementOffset = 0;
3935 U2(U(rtv_desc).Buffer).ElementWidth = 64;
3937 if (!enable_debug_layer)
3939 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
3940 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3943 expected_refcount = get_refcount(device) + 1;
3944 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
3945 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
3946 refcount = get_refcount(device);
3947 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3948 tmp = NULL;
3949 expected_refcount = refcount + 1;
3950 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
3951 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3952 refcount = get_refcount(device);
3953 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3954 ID3D11Device_Release(tmp);
3956 /* Not available on all Windows versions. */
3957 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3959 ID3D11RenderTargetView_Release(rtview);
3960 ID3D11Buffer_Release(buffer);
3962 texture2d_desc.Width = 512;
3963 texture2d_desc.Height = 512;
3964 texture2d_desc.SampleDesc.Count = 1;
3965 texture2d_desc.SampleDesc.Quality = 0;
3966 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3967 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3968 texture2d_desc.CPUAccessFlags = 0;
3969 texture2d_desc.MiscFlags = 0;
3971 texture3d_desc.Width = 64;
3972 texture3d_desc.Height = 64;
3973 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3974 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3975 texture3d_desc.CPUAccessFlags = 0;
3976 texture3d_desc.MiscFlags = 0;
3978 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3980 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3982 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3984 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3985 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3986 texture2d_desc.Format = tests[i].texture.format;
3988 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3989 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3990 texture = (ID3D11Resource *)texture2d;
3992 else
3994 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3995 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3996 texture3d_desc.Format = tests[i].texture.format;
3998 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3999 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4000 texture = (ID3D11Resource *)texture3d;
4003 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
4005 current_desc = NULL;
4007 else
4009 current_desc = &rtv_desc;
4010 get_rtv_desc(current_desc, &tests[i].rtv_desc);
4013 expected_refcount = get_refcount(texture);
4014 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
4015 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
4016 refcount = get_refcount(texture);
4017 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
4019 /* Not available on all Windows versions. */
4020 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
4022 memset(&rtv_desc, 0, sizeof(rtv_desc));
4023 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
4024 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
4026 ID3D11RenderTargetView_Release(rtview);
4027 ID3D11Resource_Release(texture);
4030 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
4032 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
4033 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
4035 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
4037 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4038 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
4039 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
4041 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4042 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4043 texture = (ID3D11Resource *)texture2d;
4045 else
4047 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4048 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
4049 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
4051 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4052 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4053 texture = (ID3D11Resource *)texture3d;
4056 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
4057 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
4058 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
4060 ID3D11Resource_Release(texture);
4063 refcount = ID3D11Device_Release(device);
4064 ok(!refcount, "Device has %u references left.\n", refcount);
4067 static void test_create_shader_resource_view(void)
4069 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
4070 D3D11_TEXTURE3D_DESC texture3d_desc;
4071 D3D11_TEXTURE2D_DESC texture2d_desc;
4072 ULONG refcount, expected_refcount;
4073 ID3D11ShaderResourceView *srview;
4074 D3D_FEATURE_LEVEL feature_level;
4075 D3D11_BUFFER_DESC buffer_desc;
4076 ID3D11Device *device, *tmp;
4077 ID3D11Texture3D *texture3d;
4078 ID3D11Texture2D *texture2d;
4079 ID3D11Resource *texture;
4080 ID3D11Buffer *buffer;
4081 unsigned int i;
4082 HRESULT hr;
4084 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
4085 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
4086 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
4087 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
4088 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
4089 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
4090 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
4091 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
4092 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
4093 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
4094 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
4095 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
4096 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
4097 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
4098 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
4099 static const struct
4101 struct
4103 unsigned int miplevel_count;
4104 unsigned int depth_or_array_size;
4105 DXGI_FORMAT format;
4106 } texture;
4107 struct srv_desc srv_desc;
4108 struct srv_desc expected_srv_desc;
4110 tests[] =
4112 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4113 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4114 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4115 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4116 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4117 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4118 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
4119 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
4120 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
4121 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
4122 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
4123 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
4124 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
4125 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
4126 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
4127 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4128 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4129 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4130 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4131 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4132 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4133 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4134 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4135 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
4136 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
4137 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4138 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4139 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4140 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
4141 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4142 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4143 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4144 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4145 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4146 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
4147 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
4148 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4149 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
4150 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4151 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4152 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4153 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4154 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4155 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4156 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4157 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
4158 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
4159 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
4161 static const struct
4163 struct
4165 D3D11_SRV_DIMENSION dimension;
4166 unsigned int miplevel_count;
4167 unsigned int depth_or_array_size;
4168 DXGI_FORMAT format;
4169 } texture;
4170 struct srv_desc srv_desc;
4172 invalid_desc_tests[] =
4174 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
4175 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
4176 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4177 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4178 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4179 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
4180 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
4181 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
4182 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
4183 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
4184 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
4185 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
4186 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
4187 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
4188 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
4189 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
4190 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
4191 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
4192 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
4193 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
4194 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
4195 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
4196 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4197 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
4198 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
4199 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
4200 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
4201 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
4202 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
4203 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
4204 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
4205 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
4206 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
4207 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
4208 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4209 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4210 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 1}},
4211 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4212 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 1}},
4213 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4214 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4215 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4216 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4217 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4218 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
4219 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4220 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4221 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4222 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4223 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
4224 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
4225 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
4226 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
4227 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
4228 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
4229 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
4231 #undef FMT_UNKNOWN
4232 #undef RGBA8_UNORM
4233 #undef RGBA8_SRGB
4234 #undef RGBA8_UINT
4235 #undef RGBA8_TL
4236 #undef DIM_UNKNOWN
4237 #undef TEX_1D
4238 #undef TEX_1D_ARRAY
4239 #undef TEX_2D
4240 #undef TEX_2D_ARRAY
4241 #undef TEX_2DMS
4242 #undef TEX_2DMS_ARR
4243 #undef TEX_3D
4244 #undef TEX_CUBE
4245 #undef CUBE_ARRAY
4247 if (!(device = create_device(NULL)))
4249 skip("Failed to create device.\n");
4250 return;
4252 feature_level = ID3D11Device_GetFeatureLevel(device);
4254 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
4256 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
4257 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4259 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
4260 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
4261 U1(U(srv_desc).Buffer).ElementOffset = 0;
4262 U2(U(srv_desc).Buffer).ElementWidth = 64;
4264 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
4265 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4267 expected_refcount = get_refcount(device) + 1;
4268 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
4269 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
4270 refcount = get_refcount(device);
4271 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4272 tmp = NULL;
4273 expected_refcount = refcount + 1;
4274 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
4275 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4276 refcount = get_refcount(device);
4277 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4278 ID3D11Device_Release(tmp);
4280 /* Not available on all Windows versions. */
4281 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
4282 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
4284 ID3D11ShaderResourceView_Release(srview);
4285 ID3D11Buffer_Release(buffer);
4287 /* Without D3D11_BIND_SHADER_RESOURCE. */
4288 buffer = create_buffer(device, 0, 1024, NULL);
4290 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
4291 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4293 ID3D11Buffer_Release(buffer);
4295 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
4297 buffer_desc.ByteWidth = 1024;
4298 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4299 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4300 buffer_desc.CPUAccessFlags = 0;
4301 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
4302 buffer_desc.StructureByteStride = 4;
4304 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
4305 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
4307 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
4308 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
4310 memset(&srv_desc, 0, sizeof(srv_desc));
4311 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
4313 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
4314 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
4315 srv_desc.ViewDimension);
4316 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
4317 U1(U(srv_desc).Buffer).FirstElement);
4318 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
4319 U2(U(srv_desc).Buffer).NumElements);
4321 ID3D11ShaderResourceView_Release(srview);
4322 ID3D11Buffer_Release(buffer);
4324 else
4326 skip("Structured buffers require feature level 11_0.\n");
4329 texture2d_desc.Width = 512;
4330 texture2d_desc.Height = 512;
4331 texture2d_desc.SampleDesc.Count = 1;
4332 texture2d_desc.SampleDesc.Quality = 0;
4333 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
4334 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4335 texture2d_desc.CPUAccessFlags = 0;
4337 texture3d_desc.Width = 64;
4338 texture3d_desc.Height = 64;
4339 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
4340 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4341 texture3d_desc.CPUAccessFlags = 0;
4342 texture3d_desc.MiscFlags = 0;
4344 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4346 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
4348 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
4350 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
4351 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
4352 texture2d_desc.Format = tests[i].texture.format;
4353 texture2d_desc.MiscFlags = 0;
4355 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
4356 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4357 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
4359 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
4360 && (texture2d_desc.ArraySize != 6
4361 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4362 && feature_level < D3D_FEATURE_LEVEL_10_1)
4364 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
4365 continue;
4368 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4369 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4370 texture = (ID3D11Resource *)texture2d;
4372 else
4374 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
4375 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
4376 texture3d_desc.Format = tests[i].texture.format;
4378 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4379 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4380 texture = (ID3D11Resource *)texture3d;
4383 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
4385 current_desc = NULL;
4387 else
4389 current_desc = &srv_desc;
4390 get_srv_desc(current_desc, &tests[i].srv_desc);
4393 expected_refcount = get_refcount(texture);
4394 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
4395 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
4396 refcount = get_refcount(texture);
4397 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
4399 /* Not available on all Windows versions. */
4400 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
4401 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
4403 memset(&srv_desc, 0, sizeof(srv_desc));
4404 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
4405 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
4407 ID3D11ShaderResourceView_Release(srview);
4408 ID3D11Resource_Release(texture);
4411 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
4413 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
4414 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
4416 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
4418 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4419 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
4420 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
4421 texture2d_desc.MiscFlags = 0;
4423 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
4424 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4425 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
4427 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
4428 && feature_level < D3D_FEATURE_LEVEL_10_1)
4430 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
4431 continue;
4434 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4435 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4436 texture = (ID3D11Resource *)texture2d;
4438 else
4440 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4441 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
4442 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
4444 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4445 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4446 texture = (ID3D11Resource *)texture3d;
4449 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
4450 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
4451 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
4453 ID3D11Resource_Release(texture);
4456 refcount = ID3D11Device_Release(device);
4457 ok(!refcount, "Device has %u references left.\n", refcount);
4460 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
4462 #if 0
4463 float4 light;
4464 float4x4 mat;
4466 struct input
4468 float4 position : POSITION;
4469 float3 normal : NORMAL;
4472 struct output
4474 float4 position : POSITION;
4475 float4 diffuse : COLOR;
4478 output main(const input v)
4480 output o;
4482 o.position = mul(v.position, mat);
4483 o.diffuse = dot((float3)light, v.normal);
4485 return o;
4487 #endif
4488 static const DWORD vs_4_1[] =
4490 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
4491 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
4492 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
4493 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
4494 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4495 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
4496 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
4497 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
4498 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
4499 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
4500 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
4501 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
4502 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
4503 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
4504 0x0100003e,
4506 static const DWORD vs_4_0[] =
4508 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
4509 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
4510 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
4511 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
4512 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
4513 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
4514 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
4515 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
4516 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
4517 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
4518 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
4519 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
4520 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
4521 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
4522 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
4523 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
4525 static const DWORD vs_3_0[] =
4527 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
4528 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
4529 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
4530 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
4531 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
4532 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
4533 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
4534 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
4535 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
4536 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
4537 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
4538 0x0000ffff,
4540 static const DWORD vs_2_0[] =
4542 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
4543 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
4544 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
4545 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
4546 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
4547 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
4548 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
4549 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
4550 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
4551 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
4552 0x90e40001, 0x0000ffff,
4555 #if 0
4556 float4 main(const float4 color : COLOR) : SV_TARGET
4558 float4 o;
4560 o = color;
4562 return o;
4564 #endif
4565 static const DWORD ps_4_1[] =
4567 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
4568 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4569 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4570 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4571 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
4572 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4573 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4575 static const DWORD ps_4_0[] =
4577 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
4578 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4579 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4580 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4581 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4582 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4583 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4585 static const DWORD ps_4_0_level_9_0[] =
4587 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
4588 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
4589 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
4590 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
4591 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
4592 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
4593 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
4594 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
4595 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4596 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
4597 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
4598 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4599 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
4600 0xabab0054,
4602 static const DWORD ps_4_0_level_9_1[] =
4604 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
4605 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
4606 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
4607 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
4608 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4609 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4610 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
4611 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4612 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
4613 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
4614 0x45475241, 0xabab0054,
4616 static const DWORD ps_4_0_level_9_3[] =
4618 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
4619 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
4620 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
4621 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
4622 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4623 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4624 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
4625 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4626 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
4627 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
4628 0x45475241, 0xabab0054,
4631 #if 0
4632 struct gs_out
4634 float4 pos : SV_POSITION;
4637 [maxvertexcount(4)]
4638 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
4640 float offset = 0.1 * vin[0].w;
4641 gs_out v;
4643 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
4644 vout.Append(v);
4645 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
4646 vout.Append(v);
4647 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
4648 vout.Append(v);
4649 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
4650 vout.Append(v);
4652 #endif
4653 static const DWORD gs_4_1[] =
4655 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
4656 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4657 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4658 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4659 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
4660 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
4661 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
4662 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
4663 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
4664 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
4665 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
4666 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4667 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
4668 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4669 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
4670 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
4671 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
4672 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4674 static const DWORD gs_4_0[] =
4676 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
4677 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4678 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4679 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4680 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
4681 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
4682 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
4683 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4684 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
4685 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4686 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
4687 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
4688 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
4689 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
4690 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
4691 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4692 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
4693 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4696 ULONG refcount, expected_refcount;
4697 struct device_desc device_desc;
4698 ID3D11Device *device, *tmp;
4699 ID3D11GeometryShader *gs;
4700 ID3D11VertexShader *vs;
4701 ID3D11PixelShader *ps;
4702 HRESULT hr;
4704 device_desc.feature_level = &feature_level;
4705 device_desc.flags = 0;
4706 if (!(device = create_device(&device_desc)))
4708 skip("Failed to create device for feature level %#x.\n", feature_level);
4709 return;
4712 /* level_9 shaders */
4713 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
4714 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4715 ID3D11PixelShader_Release(ps);
4717 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
4718 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4719 ID3D11PixelShader_Release(ps);
4721 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
4722 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4723 ID3D11PixelShader_Release(ps);
4725 /* vertex shader */
4726 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
4727 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4729 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
4730 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4732 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
4733 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
4734 hr, feature_level);
4736 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4737 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
4738 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4739 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4740 else
4741 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4743 refcount = get_refcount(device);
4744 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4745 refcount, expected_refcount);
4746 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4748 tmp = NULL;
4749 expected_refcount = refcount + 1;
4750 ID3D11VertexShader_GetDevice(vs, &tmp);
4751 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4752 refcount = get_refcount(device);
4753 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4754 refcount, expected_refcount);
4755 ID3D11Device_Release(tmp);
4757 /* Not available on all Windows versions. */
4758 check_interface(vs, &IID_ID3D10VertexShader, TRUE, TRUE);
4760 refcount = ID3D11VertexShader_Release(vs);
4761 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
4764 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
4765 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4767 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
4768 hr, feature_level);
4769 refcount = ID3D11VertexShader_Release(vs);
4770 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
4772 else
4774 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4775 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
4776 hr, feature_level);
4777 if (SUCCEEDED(hr))
4778 ID3D11VertexShader_Release(vs);
4781 /* pixel shader */
4782 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4783 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
4784 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4785 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4786 else
4787 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4789 refcount = get_refcount(device);
4790 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4791 refcount, expected_refcount);
4792 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4794 tmp = NULL;
4795 expected_refcount = refcount + 1;
4796 ID3D11PixelShader_GetDevice(ps, &tmp);
4797 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4798 refcount = get_refcount(device);
4799 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4800 refcount, expected_refcount);
4801 ID3D11Device_Release(tmp);
4803 /* Not available on all Windows versions. */
4804 check_interface(ps, &IID_ID3D10PixelShader, TRUE, TRUE);
4806 refcount = ID3D11PixelShader_Release(ps);
4807 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
4810 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
4811 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4813 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
4814 hr, feature_level);
4815 refcount = ID3D11PixelShader_Release(ps);
4816 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
4818 else
4820 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4821 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4822 if (SUCCEEDED(hr))
4823 ID3D11PixelShader_Release(ps);
4826 /* geometry shader */
4827 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4828 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
4829 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4830 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4831 else
4832 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4834 refcount = get_refcount(device);
4835 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4836 refcount, expected_refcount);
4837 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4839 tmp = NULL;
4840 expected_refcount = refcount + 1;
4841 ID3D11GeometryShader_GetDevice(gs, &tmp);
4842 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4843 refcount = get_refcount(device);
4844 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4845 refcount, expected_refcount);
4846 ID3D11Device_Release(tmp);
4848 /* Not available on all Windows versions. */
4849 check_interface(gs, &IID_ID3D10GeometryShader, TRUE, TRUE);
4851 refcount = ID3D11GeometryShader_Release(gs);
4852 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4855 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
4856 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4858 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4859 hr, feature_level);
4860 refcount = ID3D11GeometryShader_Release(gs);
4861 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4863 else
4865 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4866 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4867 hr, feature_level);
4868 if (SUCCEEDED(hr))
4869 ID3D11GeometryShader_Release(gs);
4872 refcount = ID3D11Device_Release(device);
4873 ok(!refcount, "Device has %u references left.\n", refcount);
4876 static void test_create_sampler_state(void)
4878 static const struct test
4880 D3D11_FILTER filter;
4881 D3D10_FILTER expected_filter;
4883 desc_conversion_tests[] =
4885 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
4886 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
4887 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
4888 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
4889 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
4890 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
4891 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
4892 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
4893 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
4894 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
4895 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
4897 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
4898 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
4900 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
4901 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
4903 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
4904 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
4906 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
4907 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
4908 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
4911 ID3D11SamplerState *sampler_state1, *sampler_state2;
4912 ID3D10SamplerState *d3d10_sampler_state;
4913 ULONG refcount, expected_refcount;
4914 ID3D11Device *device, *tmp;
4915 D3D11_SAMPLER_DESC desc;
4916 unsigned int i;
4917 HRESULT hr;
4919 if (!(device = create_device(NULL)))
4921 skip("Failed to create device.\n");
4922 return;
4925 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
4926 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4928 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
4929 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4930 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4931 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
4932 desc.MipLODBias = 0.0f;
4933 desc.MaxAnisotropy = 16;
4934 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4935 desc.BorderColor[0] = 0.0f;
4936 desc.BorderColor[1] = 1.0f;
4937 desc.BorderColor[2] = 0.0f;
4938 desc.BorderColor[3] = 1.0f;
4939 desc.MinLOD = 0.0f;
4940 desc.MaxLOD = 16.0f;
4942 expected_refcount = get_refcount(device) + 1;
4943 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4944 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4945 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
4946 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4947 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4948 refcount = get_refcount(device);
4949 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4950 tmp = NULL;
4951 expected_refcount = refcount + 1;
4952 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
4953 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4954 refcount = get_refcount(device);
4955 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4956 ID3D11Device_Release(tmp);
4958 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
4959 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4960 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4961 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4962 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4963 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4964 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4965 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4966 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4967 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4968 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4969 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4970 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4972 refcount = ID3D11SamplerState_Release(sampler_state2);
4973 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4974 refcount = ID3D11SamplerState_Release(sampler_state1);
4975 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4977 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4979 const struct test *current = &desc_conversion_tests[i];
4980 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4982 desc.Filter = current->filter;
4983 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4984 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4985 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4986 desc.MipLODBias = 0.0f;
4987 desc.MaxAnisotropy = 16;
4988 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4989 desc.BorderColor[0] = 0.0f;
4990 desc.BorderColor[1] = 1.0f;
4991 desc.BorderColor[2] = 0.0f;
4992 desc.BorderColor[3] = 1.0f;
4993 desc.MinLOD = 0.0f;
4994 desc.MaxLOD = 16.0f;
4996 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4997 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4999 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
5000 (void **)&d3d10_sampler_state);
5001 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5002 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
5003 if (FAILED(hr))
5005 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
5006 ID3D11SamplerState_Release(sampler_state1);
5007 break;
5010 memcpy(&expected_desc, &desc, sizeof(expected_desc));
5011 expected_desc.Filter = current->expected_filter;
5012 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
5013 expected_desc.MaxAnisotropy = 0;
5014 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
5015 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
5017 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
5018 ok(d3d10_desc.Filter == expected_desc.Filter,
5019 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
5020 ok(d3d10_desc.AddressU == expected_desc.AddressU,
5021 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
5022 ok(d3d10_desc.AddressV == expected_desc.AddressV,
5023 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
5024 ok(d3d10_desc.AddressW == expected_desc.AddressW,
5025 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
5026 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
5027 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
5028 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
5029 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
5030 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
5031 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
5032 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
5033 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
5034 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
5035 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
5036 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
5037 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
5038 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
5039 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
5040 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
5041 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
5042 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
5044 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
5045 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
5046 refcount = ID3D11SamplerState_Release(sampler_state1);
5047 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
5050 refcount = ID3D11Device_Release(device);
5051 ok(!refcount, "Device has %u references left.\n", refcount);
5054 static void test_create_blend_state(void)
5056 static const D3D11_BLEND_DESC desc_conversion_tests[] =
5059 FALSE, FALSE,
5062 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5063 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
5068 FALSE, TRUE,
5071 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5072 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5075 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5076 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
5079 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5080 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5083 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5084 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
5087 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5088 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5091 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5092 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5095 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5096 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5099 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5100 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5105 FALSE, TRUE,
5108 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5109 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5112 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
5113 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5116 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
5117 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5120 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5121 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5124 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
5125 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5128 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
5129 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5132 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5133 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5136 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5137 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5143 ID3D11BlendState *blend_state1, *blend_state2;
5144 D3D11_BLEND_DESC desc, obtained_desc;
5145 ID3D10BlendState *d3d10_blend_state;
5146 D3D10_BLEND_DESC d3d10_blend_desc;
5147 ULONG refcount, expected_refcount;
5148 ID3D11Device *device, *tmp;
5149 unsigned int i, j;
5150 HRESULT hr;
5152 if (!(device = create_device(NULL)))
5154 skip("Failed to create device.\n");
5155 return;
5158 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
5159 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5161 memset(&desc, 0, sizeof(desc));
5162 desc.AlphaToCoverageEnable = FALSE;
5163 desc.IndependentBlendEnable = FALSE;
5164 desc.RenderTarget[0].BlendEnable = FALSE;
5165 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5167 expected_refcount = get_refcount(device) + 1;
5168 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
5169 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5170 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
5171 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5172 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
5173 refcount = get_refcount(device);
5174 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5175 tmp = NULL;
5176 expected_refcount = refcount + 1;
5177 ID3D11BlendState_GetDevice(blend_state1, &tmp);
5178 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5179 refcount = get_refcount(device);
5180 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5181 ID3D11Device_Release(tmp);
5183 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
5184 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
5185 obtained_desc.AlphaToCoverageEnable);
5186 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
5187 obtained_desc.IndependentBlendEnable);
5188 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5190 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
5191 "Got unexpected blend enable %#x for render target %u.\n",
5192 obtained_desc.RenderTarget[i].BlendEnable, i);
5193 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
5194 "Got unexpected src blend %u for render target %u.\n",
5195 obtained_desc.RenderTarget[i].SrcBlend, i);
5196 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
5197 "Got unexpected dest blend %u for render target %u.\n",
5198 obtained_desc.RenderTarget[i].DestBlend, i);
5199 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
5200 "Got unexpected blend op %u for render target %u.\n",
5201 obtained_desc.RenderTarget[i].BlendOp, i);
5202 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
5203 "Got unexpected src blend alpha %u for render target %u.\n",
5204 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
5205 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
5206 "Got unexpected dest blend alpha %u for render target %u.\n",
5207 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
5208 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
5209 "Got unexpected blend op alpha %u for render target %u.\n",
5210 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
5211 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
5212 "Got unexpected render target write mask %#x for render target %u.\n",
5213 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
5216 /* Not available on all Windows versions. */
5217 check_interface(blend_state1, &IID_ID3D10BlendState, TRUE, TRUE);
5218 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
5220 refcount = ID3D11BlendState_Release(blend_state1);
5221 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5222 refcount = ID3D11BlendState_Release(blend_state2);
5223 ok(!refcount, "Blend state has %u references left.\n", refcount);
5225 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
5227 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
5229 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
5230 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5232 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
5233 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5234 "Blend state should implement ID3D10BlendState.\n");
5235 if (FAILED(hr))
5237 win_skip("Blend state does not implement ID3D10BlendState.\n");
5238 ID3D11BlendState_Release(blend_state1);
5239 break;
5242 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
5243 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
5244 "Got unexpected alpha to coverage enable %#x for test %u.\n",
5245 d3d10_blend_desc.AlphaToCoverageEnable, i);
5246 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
5247 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
5248 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
5249 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
5250 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
5251 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
5252 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
5253 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
5254 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
5255 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
5256 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
5257 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
5258 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
5260 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
5261 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
5262 "Got unexpected blend enable %#x for test %u, render target %u.\n",
5263 d3d10_blend_desc.BlendEnable[j], i, j);
5264 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
5265 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
5266 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
5269 ID3D10BlendState_Release(d3d10_blend_state);
5271 refcount = ID3D11BlendState_Release(blend_state1);
5272 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5275 refcount = ID3D11Device_Release(device);
5276 ok(!refcount, "Device has %u references left.\n", refcount);
5279 static void test_create_depthstencil_state(void)
5281 ID3D11DepthStencilState *ds_state1, *ds_state2;
5282 ULONG refcount, expected_refcount;
5283 D3D11_DEPTH_STENCIL_DESC ds_desc;
5284 ID3D11Device *device, *tmp;
5285 HRESULT hr;
5287 if (!(device = create_device(NULL)))
5289 skip("Failed to create device.\n");
5290 return;
5293 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
5294 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5296 ds_desc.DepthEnable = TRUE;
5297 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
5298 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
5299 ds_desc.StencilEnable = FALSE;
5300 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
5301 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
5302 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
5303 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
5304 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
5305 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
5306 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
5307 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
5308 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
5309 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
5311 expected_refcount = get_refcount(device) + 1;
5312 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
5313 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5314 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
5315 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5316 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
5317 refcount = get_refcount(device);
5318 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5319 tmp = NULL;
5320 expected_refcount = refcount + 1;
5321 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
5322 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5323 refcount = get_refcount(device);
5324 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5325 ID3D11Device_Release(tmp);
5327 /* Not available on all Windows versions. */
5328 check_interface(ds_state1, &IID_ID3D10DepthStencilState, TRUE, TRUE);
5330 refcount = ID3D11DepthStencilState_Release(ds_state2);
5331 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5332 refcount = ID3D11DepthStencilState_Release(ds_state1);
5333 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5335 ds_desc.DepthEnable = FALSE;
5336 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
5337 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
5338 ds_desc.StencilEnable = FALSE;
5339 ds_desc.StencilReadMask = 0;
5340 ds_desc.StencilWriteMask = 0;
5341 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
5342 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
5343 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
5344 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
5345 ds_desc.BackFace = ds_desc.FrontFace;
5347 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
5348 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5350 memset(&ds_desc, 0, sizeof(ds_desc));
5351 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
5352 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
5353 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
5354 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
5355 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
5356 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
5357 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
5358 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
5359 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
5360 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
5361 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
5362 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
5363 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
5364 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
5365 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
5366 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
5367 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
5368 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
5369 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
5370 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
5371 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
5372 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
5373 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
5374 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
5375 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
5376 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
5378 ID3D11DepthStencilState_Release(ds_state1);
5380 refcount = ID3D11Device_Release(device);
5381 ok(!refcount, "Device has %u references left.\n", refcount);
5384 static void test_create_rasterizer_state(void)
5386 ID3D11RasterizerState *rast_state1, *rast_state2;
5387 ID3D10RasterizerState *d3d10_rast_state;
5388 ULONG refcount, expected_refcount;
5389 D3D10_RASTERIZER_DESC d3d10_desc;
5390 D3D11_RASTERIZER_DESC desc;
5391 ID3D11Device *device, *tmp;
5392 HRESULT hr;
5394 if (!(device = create_device(NULL)))
5396 skip("Failed to create device.\n");
5397 return;
5400 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
5401 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5403 desc.FillMode = D3D11_FILL_SOLID;
5404 desc.CullMode = D3D11_CULL_BACK;
5405 desc.FrontCounterClockwise = FALSE;
5406 desc.DepthBias = 0;
5407 desc.DepthBiasClamp = 0.0f;
5408 desc.SlopeScaledDepthBias = 0.0f;
5409 desc.DepthClipEnable = TRUE;
5410 desc.ScissorEnable = FALSE;
5411 desc.MultisampleEnable = FALSE;
5412 desc.AntialiasedLineEnable = FALSE;
5414 expected_refcount = get_refcount(device) + 1;
5415 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
5416 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5417 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
5418 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5419 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
5420 refcount = get_refcount(device);
5421 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5422 tmp = NULL;
5423 expected_refcount = refcount + 1;
5424 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
5425 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5426 refcount = get_refcount(device);
5427 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5428 ID3D11Device_Release(tmp);
5430 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
5431 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5432 "Rasterizer state should implement ID3D10RasterizerState.\n");
5433 if (SUCCEEDED(hr))
5435 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
5436 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
5437 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
5438 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
5439 d3d10_desc.FrontCounterClockwise);
5440 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
5441 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
5442 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
5443 d3d10_desc.SlopeScaledDepthBias);
5444 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
5445 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
5446 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
5447 d3d10_desc.MultisampleEnable);
5448 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
5449 d3d10_desc.AntialiasedLineEnable);
5451 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
5452 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
5455 refcount = ID3D11RasterizerState_Release(rast_state2);
5456 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5457 refcount = ID3D11RasterizerState_Release(rast_state1);
5458 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5460 refcount = ID3D11Device_Release(device);
5461 ok(!refcount, "Device has %u references left.\n", refcount);
5464 static void test_create_query(void)
5466 static const struct
5468 D3D11_QUERY query;
5469 D3D_FEATURE_LEVEL required_feature_level;
5470 BOOL is_predicate;
5471 BOOL can_use_create_predicate;
5472 BOOL todo;
5474 tests[] =
5476 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5477 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5478 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5479 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5480 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5481 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
5482 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5483 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
5484 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5485 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5486 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5487 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5488 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5489 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5490 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5491 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5494 ULONG refcount, expected_refcount;
5495 D3D_FEATURE_LEVEL feature_level;
5496 D3D11_QUERY_DESC query_desc;
5497 ID3D11Predicate *predicate;
5498 ID3D11Device *device, *tmp;
5499 HRESULT hr, expected_hr;
5500 ID3D11Query *query;
5501 unsigned int i;
5503 if (!(device = create_device(NULL)))
5505 skip("Failed to create device.\n");
5506 return;
5508 feature_level = ID3D11Device_GetFeatureLevel(device);
5510 hr = ID3D11Device_CreateQuery(device, NULL, &query);
5511 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5512 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
5513 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5515 for (i = 0; i < ARRAY_SIZE(tests); ++i)
5517 if (tests[i].required_feature_level > feature_level)
5519 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
5520 continue;
5523 query_desc.Query = tests[i].query;
5524 query_desc.MiscFlags = 0;
5526 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
5527 todo_wine_if(tests[i].todo)
5528 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5530 query_desc.Query = tests[i].query;
5531 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
5532 todo_wine_if(tests[i].todo)
5533 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5534 if (FAILED(hr))
5535 continue;
5537 check_interface(query, &IID_ID3D11Predicate, tests[i].is_predicate, FALSE);
5538 ID3D11Query_Release(query);
5540 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
5541 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
5542 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5544 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
5545 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
5546 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5547 if (SUCCEEDED(hr))
5548 ID3D11Predicate_Release(predicate);
5551 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
5552 expected_refcount = get_refcount(device) + 1;
5553 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
5554 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5555 refcount = get_refcount(device);
5556 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5557 tmp = NULL;
5558 expected_refcount = refcount + 1;
5559 ID3D11Predicate_GetDevice(predicate, &tmp);
5560 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5561 refcount = get_refcount(device);
5562 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5563 ID3D11Device_Release(tmp);
5564 /* Not available on all Windows versions. */
5565 check_interface(predicate, &IID_ID3D10Predicate, TRUE, TRUE);
5566 ID3D11Predicate_Release(predicate);
5568 refcount = ID3D11Device_Release(device);
5569 ok(!refcount, "Device has %u references left.\n", refcount);
5572 #define get_query_data(a, b, c, d) get_query_data_(__LINE__, a, b, c, d)
5573 static void get_query_data_(unsigned int line, ID3D11DeviceContext *context,
5574 ID3D11Asynchronous *query, void *data, unsigned int data_size)
5576 unsigned int i;
5577 HRESULT hr;
5579 for (i = 0; i < 500; ++i)
5581 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
5582 break;
5583 Sleep(10);
5585 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5586 memset(data, 0xff, data_size);
5587 hr = ID3D11DeviceContext_GetData(context, query, data, data_size, 0);
5588 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5591 static void test_occlusion_query(void)
5593 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5594 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5596 struct d3d11_test_context test_context;
5597 D3D11_TEXTURE2D_DESC texture_desc;
5598 ID3D11DeviceContext *context;
5599 ID3D11RenderTargetView *rtv;
5600 D3D11_QUERY_DESC query_desc;
5601 ID3D11Asynchronous *query;
5602 unsigned int data_size, i;
5603 ID3D11Texture2D *texture;
5604 ID3D11Device *device;
5605 union
5607 UINT64 uint;
5608 DWORD dword[2];
5609 } data;
5610 HRESULT hr;
5612 if (!init_test_context(&test_context, NULL))
5613 return;
5615 device = test_context.device;
5616 context = test_context.immediate_context;
5618 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5620 query_desc.Query = D3D11_QUERY_OCCLUSION;
5621 query_desc.MiscFlags = 0;
5622 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5623 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5624 data_size = ID3D11Asynchronous_GetDataSize(query);
5625 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
5627 memset(&data, 0xff, sizeof(data));
5628 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5629 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5630 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5631 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5632 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5633 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5635 ID3D11DeviceContext_End(context, query);
5636 ID3D11DeviceContext_Begin(context, query);
5637 ID3D11DeviceContext_Begin(context, query);
5639 memset(&data, 0xff, sizeof(data));
5640 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5641 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5642 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5643 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5644 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5645 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5647 draw_color_quad(&test_context, &red);
5649 ID3D11DeviceContext_End(context, query);
5650 get_query_data(context, query, &data, sizeof(data));
5651 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5653 memset(&data, 0xff, sizeof(data));
5654 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
5655 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5656 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
5657 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5658 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
5659 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5660 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
5661 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5662 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5663 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5665 memset(&data, 0xff, sizeof(data));
5666 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
5667 ok(hr == S_OK, "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 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
5672 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5673 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
5674 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5676 ID3D11DeviceContext_Begin(context, query);
5677 ID3D11DeviceContext_End(context, query);
5678 ID3D11DeviceContext_End(context, query);
5680 get_query_data(context, query, &data, sizeof(data));
5681 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5682 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5683 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5685 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
5686 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
5687 texture_desc.MipLevels = 1;
5688 texture_desc.ArraySize = 1;
5689 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
5690 texture_desc.SampleDesc.Count = 1;
5691 texture_desc.SampleDesc.Quality = 0;
5692 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5693 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5694 texture_desc.CPUAccessFlags = 0;
5695 texture_desc.MiscFlags = 0;
5696 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5697 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5698 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
5699 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5701 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
5702 set_viewport(context, 0.0f, 0.0f, texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
5704 ID3D11DeviceContext_Begin(context, query);
5705 for (i = 0; i < 100; i++)
5706 draw_color_quad(&test_context, &red);
5707 ID3D11DeviceContext_End(context, query);
5709 get_query_data(context, query, &data, sizeof(data));
5710 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
5711 || (data.dword[0] == 0xffffffff && !data.dword[1])
5712 || broken(!data.uint),
5713 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5714 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5715 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5717 ID3D11Asynchronous_Release(query);
5719 /* The following test exercises a code path in wined3d. A wined3d context
5720 * associated with the query is destroyed when the swapchain is released. */
5721 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5722 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5724 set_viewport(context, 0.0f, 0.0f, 64.0f, 64.0f, 0.0f, 1.0f);
5725 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5726 ID3D11DeviceContext_Begin(context, query);
5727 draw_color_quad(&test_context, &red);
5728 ID3D11DeviceContext_End(context, query);
5730 ID3D11RenderTargetView_Release(test_context.backbuffer_rtv);
5731 ID3D11Texture2D_Release(test_context.backbuffer);
5732 IDXGISwapChain_Release(test_context.swapchain);
5733 test_context.swapchain = create_swapchain(device, test_context.window, NULL);
5734 hr = IDXGISwapChain_GetBuffer(test_context.swapchain, 0, &IID_ID3D11Texture2D,
5735 (void **)&test_context.backbuffer);
5736 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
5737 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer,
5738 NULL, &test_context.backbuffer_rtv);
5739 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5740 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
5741 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5743 get_query_data(context, query, &data, sizeof(data));
5744 /* This test occasionally succeeds with CSMT enabled because of a race condition. */
5745 if (0)
5746 todo_wine ok(data.dword[0] == 0x1000 && !data.dword[1],
5747 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5749 ID3D11Asynchronous_Release(query);
5750 ID3D11RenderTargetView_Release(rtv);
5751 ID3D11Texture2D_Release(texture);
5752 release_test_context(&test_context);
5755 static void test_pipeline_statistics_query(void)
5757 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5758 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5760 D3D11_QUERY_DATA_PIPELINE_STATISTICS data;
5761 struct d3d11_test_context test_context;
5762 ID3D11DeviceContext *context;
5763 D3D11_QUERY_DESC query_desc;
5764 ID3D11Asynchronous *query;
5765 unsigned int data_size;
5766 ID3D11Device *device;
5767 HRESULT hr;
5769 if (!init_test_context(&test_context, NULL))
5770 return;
5772 device = test_context.device;
5773 context = test_context.immediate_context;
5775 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5777 query_desc.Query = D3D11_QUERY_PIPELINE_STATISTICS;
5778 query_desc.MiscFlags = 0;
5779 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5780 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5781 data_size = ID3D11Asynchronous_GetDataSize(query);
5782 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
5784 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5785 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5786 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5787 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5789 ID3D11DeviceContext_End(context, query);
5790 ID3D11DeviceContext_Begin(context, query);
5791 ID3D11DeviceContext_Begin(context, query);
5793 memset(&data, 0xff, sizeof(data));
5794 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5795 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5796 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5797 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5798 ok(data.IAVertices == ~(UINT64)0, "Data was modified.\n");
5800 draw_quad(&test_context);
5802 ID3D11DeviceContext_End(context, query);
5803 get_query_data(context, query, &data, sizeof(data));
5804 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5805 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5806 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5807 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5808 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5809 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5810 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5811 todo_wine
5812 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5813 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5814 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5815 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5817 ID3D11DeviceContext_Begin(context, query);
5818 draw_color_quad(&test_context, &red);
5819 ID3D11DeviceContext_End(context, query);
5820 get_query_data(context, query, &data, sizeof(data));
5821 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5822 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5823 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5824 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5825 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5826 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5827 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5828 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5829 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5830 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5831 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5833 ID3D11Asynchronous_Release(query);
5834 release_test_context(&test_context);
5837 static void test_timestamp_query(void)
5839 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5841 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
5842 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
5843 struct d3d11_test_context test_context;
5844 ID3D11DeviceContext *context;
5845 D3D11_QUERY_DESC query_desc;
5846 unsigned int data_size;
5847 ID3D11Device *device;
5848 UINT64 timestamp;
5849 HRESULT hr;
5851 if (!init_test_context(&test_context, NULL))
5852 return;
5854 device = test_context.device;
5855 context = test_context.immediate_context;
5857 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5858 query_desc.MiscFlags = 0;
5859 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5860 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5861 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
5862 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
5864 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
5865 query_desc.MiscFlags = 0;
5866 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
5867 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5868 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
5869 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
5871 disjoint.Frequency = 0xdeadbeef;
5872 disjoint.Disjoint = 0xdeadbeef;
5873 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5874 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5875 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5876 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5877 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5878 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5880 /* Test a TIMESTAMP_DISJOINT query. */
5881 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5883 disjoint.Frequency = 0xdeadbeef;
5884 disjoint.Disjoint = 0xdeadbeef;
5885 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5886 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5887 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5888 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5889 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5890 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5892 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5893 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5894 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
5895 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5897 prev_disjoint = disjoint;
5899 disjoint.Frequency = 0xdeadbeef;
5900 disjoint.Disjoint = 0xff;
5901 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
5902 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5903 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
5904 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5905 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
5906 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5907 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
5908 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5909 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5910 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
5912 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5913 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5914 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
5915 D3D11_ASYNC_GETDATA_DONOTFLUSH);
5916 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5917 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
5918 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
5920 memset(&timestamp, 0xff, sizeof(timestamp));
5921 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
5922 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5923 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5924 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5925 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5927 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
5928 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5930 memset(&timestamp, 0xff, sizeof(timestamp));
5931 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5932 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5933 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5935 draw_color_quad(&test_context, &red);
5937 ID3D11DeviceContext_End(context, timestamp_query);
5938 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5940 timestamp = 0xdeadbeef;
5941 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5942 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5943 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5945 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5946 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5947 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
5949 timestamp = 0xdeadbeef;
5950 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
5951 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5952 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
5953 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5954 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5955 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5956 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
5957 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5958 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5960 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5961 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5962 disjoint.Frequency = 0xdeadbeef;
5963 disjoint.Disjoint = 0xff;
5964 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5965 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5966 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
5967 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5969 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
5970 ID3D11Asynchronous_Release(timestamp_query);
5971 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5972 query_desc.MiscFlags = 0;
5973 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5974 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5976 draw_color_quad(&test_context, &red);
5978 ID3D11DeviceContext_End(context, timestamp_query);
5979 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5981 ID3D11Asynchronous_Release(timestamp_query);
5982 ID3D11Asynchronous_Release(timestamp_disjoint_query);
5983 release_test_context(&test_context);
5986 static void test_so_statistics_query(void)
5988 struct d3d11_test_context test_context;
5989 D3D11_QUERY_DATA_SO_STATISTICS data;
5990 ID3D11DeviceContext *context;
5991 unsigned int vertex_count[4];
5992 D3D11_QUERY_DESC query_desc;
5993 ID3D11Buffer *so_buffer[4];
5994 ID3D11Asynchronous *query;
5995 ID3D11GeometryShader *gs;
5996 ID3D11VertexShader *vs;
5997 unsigned int data_size;
5998 ID3D11Device *device;
5999 ID3D11Buffer *cb;
6000 unsigned int i;
6001 HRESULT hr;
6003 static const DWORD vs_code[] =
6005 #if 0
6006 float4 main(uint id : SV_VertexID) : custom
6008 return (float4)id;
6010 #endif
6011 0x43425844, 0x8b0e47b9, 0x6efc9512, 0xd55ca6ff, 0x487c5ef2, 0x00000001, 0x000000d4, 0x00000003,
6012 0x0000002c, 0x00000060, 0x00000090, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6013 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
6014 0x4e47534f, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6015 0x00000000, 0x0000000f, 0x74737563, 0xab006d6f, 0x52444853, 0x0000003c, 0x00010040, 0x0000000f,
6016 0x04000060, 0x00101012, 0x00000000, 0x00000006, 0x03000065, 0x001020f2, 0x00000000, 0x05000056,
6017 0x001020f2, 0x00000000, 0x00101006, 0x00000000, 0x0100003e,
6019 static const DWORD gs_code[] =
6021 #if 0
6022 struct vertex
6024 float4 data : custom;
6027 uint4 vertex_count;
6029 [maxvertexcount(32)]
6030 void main(point vertex input[1], uint id : SV_PrimitiveID,
6031 inout PointStream<vertex> output0,
6032 inout PointStream<vertex> output1,
6033 inout PointStream<vertex> output2,
6034 inout PointStream<vertex> output3)
6036 if (id < vertex_count.x)
6037 output0.Append(input[0]);
6038 if (id < vertex_count.y)
6039 output1.Append(input[0]);
6040 if (id < vertex_count.z)
6041 output2.Append(input[0]);
6042 if (id < vertex_count.w)
6043 output3.Append(input[0]);
6045 #endif
6046 0x43425844, 0xd616829d, 0x4355ce2a, 0xd71909e5, 0xdc916d4c, 0x00000001, 0x000002bc, 0x00000003,
6047 0x0000002c, 0x00000084, 0x0000010c, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
6048 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000003f, 0x00000000, 0x00000007,
6049 0x00000001, 0xffffffff, 0x00000101, 0x74737563, 0x53006d6f, 0x72505f56, 0x74696d69, 0x49657669,
6050 0xabab0044, 0x3547534f, 0x00000080, 0x00000004, 0x00000008, 0x00000000, 0x00000078, 0x00000000,
6051 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000001, 0x00000078, 0x00000000, 0x00000000,
6052 0x00000003, 0x00000000, 0x0000000f, 0x00000002, 0x00000078, 0x00000000, 0x00000000, 0x00000003,
6053 0x00000000, 0x0000000f, 0x00000003, 0x00000078, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
6054 0x0000000f, 0x74737563, 0xab006d6f, 0x58454853, 0x000001a8, 0x00020050, 0x0000006a, 0x0100086a,
6055 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000,
6056 0x0200005f, 0x0000b000, 0x02000068, 0x00000001, 0x0100085d, 0x0300008f, 0x00110000, 0x00000000,
6057 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000001, 0x0100085c,
6058 0x03000065, 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000002, 0x0100085c, 0x03000065,
6059 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000003, 0x0100085c, 0x03000065, 0x001020f2,
6060 0x00000000, 0x0200005e, 0x00000020, 0x0700004f, 0x001000f2, 0x00000000, 0x0000b001, 0x00208e46,
6061 0x00000000, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000,
6062 0x00201e46, 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x01000015, 0x0304001f,
6063 0x0010001a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000, 0x00000000,
6064 0x03000075, 0x00110000, 0x00000001, 0x01000015, 0x0304001f, 0x0010002a, 0x00000000, 0x06000036,
6065 0x001020f2, 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000002,
6066 0x01000015, 0x0304001f, 0x0010003a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
6067 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000003, 0x01000015, 0x0100003e,
6069 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
6071 {0, "custom", 0, 0, 4, 0},
6072 {1, "custom", 0, 0, 4, 1},
6073 {2, "custom", 0, 0, 4, 2},
6074 {3, "custom", 0, 0, 4, 3},
6076 static const unsigned int offset[4] = {0};
6078 static const struct
6080 D3D11_QUERY query;
6081 D3D_FEATURE_LEVEL feature_level;
6083 tests[] =
6085 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0},
6086 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0},
6087 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0},
6088 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0},
6089 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0},
6092 if (!init_test_context(&test_context, NULL))
6093 return;
6095 device = test_context.device;
6096 context = test_context.immediate_context;
6098 for (i = 0; i < ARRAY_SIZE(tests); ++i)
6100 if (ID3D11Device_GetFeatureLevel(device) < tests[i].feature_level)
6102 skip("Feature level %#x is required.\n", tests[i].feature_level);
6103 continue;
6106 query_desc.Query = tests[i].query;
6107 query_desc.MiscFlags = 0;
6108 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
6109 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6110 data_size = ID3D11Asynchronous_GetDataSize(query);
6111 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
6113 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
6114 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6115 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
6116 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6118 ID3D11DeviceContext_End(context, query);
6119 ID3D11DeviceContext_Begin(context, query);
6120 ID3D11DeviceContext_Begin(context, query);
6122 memset(&data, 0xff, sizeof(data));
6123 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
6124 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6125 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
6126 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6127 ok(data.NumPrimitivesWritten == ~(UINT64)0, "Data was modified.\n");
6128 ok(data.PrimitivesStorageNeeded == ~(UINT64)0, "Data was modified.\n");
6130 draw_quad(&test_context);
6132 ID3D11DeviceContext_End(context, query);
6133 get_query_data(context, query, &data, sizeof(data));
6134 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
6135 (unsigned int)data.NumPrimitivesWritten);
6136 todo_wine_if(query_desc.Query == D3D11_QUERY_SO_STATISTICS || query_desc.Query == D3D11_QUERY_SO_STATISTICS_STREAM0)
6137 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
6138 (unsigned int)data.PrimitivesStorageNeeded);
6140 ID3D11DeviceContext_Begin(context, query);
6141 draw_quad(&test_context);
6142 ID3D11DeviceContext_End(context, query);
6143 get_query_data(context, query, &data, sizeof(data));
6144 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
6145 (unsigned int)data.NumPrimitivesWritten);
6146 todo_wine_if(query_desc.Query == D3D11_QUERY_SO_STATISTICS || query_desc.Query == D3D11_QUERY_SO_STATISTICS_STREAM0)
6147 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
6148 (unsigned int)data.PrimitivesStorageNeeded);
6150 ID3D11Asynchronous_Release(query);
6153 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
6155 skip("Vertex streams are not supported.\n");
6156 goto done;
6159 /* multiple vertex streams */
6160 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
6161 ok(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
6162 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
6164 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
6165 so_declaration, ARRAY_SIZE(so_declaration),
6166 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
6167 todo_wine
6168 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
6169 if (FAILED(hr))
6171 ID3D11VertexShader_Release(vs);
6172 goto done;
6174 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
6176 for (i = 0; i < ARRAY_SIZE(vertex_count); ++i)
6177 vertex_count[i] = 5;
6178 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(vertex_count), vertex_count);
6179 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
6181 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
6183 query_desc.Query = D3D11_QUERY_SO_STATISTICS;
6184 query_desc.MiscFlags = 0;
6185 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
6186 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6188 ID3D11DeviceContext_Begin(context, query);
6189 ID3D11DeviceContext_Draw(context, 5, 0);
6190 ID3D11DeviceContext_End(context, query);
6192 memset(&data, 0xff, sizeof(data));
6193 get_query_data(context, query, &data, sizeof(data));
6194 ok(!data.NumPrimitivesWritten, "Got unexpected primitives written %u.\n",
6195 (unsigned int)data.NumPrimitivesWritten);
6196 ok(data.PrimitivesStorageNeeded == 5, "Got unexpected primitives storage needed %u.\n",
6197 (unsigned int)data.PrimitivesStorageNeeded);
6199 for (i = 0; i < ARRAY_SIZE(so_buffer); ++i)
6200 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(struct vec4) * 10, NULL);
6202 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6203 ID3D11DeviceContext_Begin(context, query);
6204 ID3D11DeviceContext_Draw(context, 16, 0);
6205 ID3D11DeviceContext_End(context, query);
6206 memset(&data, 0xff, sizeof(data));
6207 get_query_data(context, query, &data, sizeof(data));
6208 ok(data.NumPrimitivesWritten == 5, "Got unexpected primitives written %u.\n",
6209 (unsigned int)data.NumPrimitivesWritten);
6210 ok(data.PrimitivesStorageNeeded == 5, "Got unexpected primitives storage needed %u.\n",
6211 (unsigned int)data.PrimitivesStorageNeeded);
6213 vertex_count[0] = 3;
6214 vertex_count[1] = 6;
6215 vertex_count[2] = 4;
6216 vertex_count[3] = 12;
6217 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, vertex_count, 0, 0);
6219 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6220 ID3D11DeviceContext_Begin(context, query);
6221 ID3D11DeviceContext_Draw(context, 32, 0);
6222 ID3D11DeviceContext_End(context, query);
6223 memset(&data, 0xff, sizeof(data));
6224 get_query_data(context, query, &data, sizeof(data));
6225 ok(data.NumPrimitivesWritten == 3, "Got unexpected primitives written %u.\n",
6226 (unsigned int)data.NumPrimitivesWritten);
6227 ok(data.PrimitivesStorageNeeded == 3, "Got unexpected primitives storage needed %u.\n",
6228 (unsigned int)data.PrimitivesStorageNeeded);
6230 vertex_count[0] = 16;
6231 vertex_count[1] = 6;
6232 vertex_count[2] = 4;
6233 vertex_count[3] = 12;
6234 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, vertex_count, 0, 0);
6236 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6237 ID3D11DeviceContext_Begin(context, query);
6238 ID3D11DeviceContext_Draw(context, 32, 0);
6239 ID3D11DeviceContext_End(context, query);
6240 memset(&data, 0xff, sizeof(data));
6241 get_query_data(context, query, &data, sizeof(data));
6242 ok(data.NumPrimitivesWritten == 10, "Got unexpected primitives written %u.\n",
6243 (unsigned int)data.NumPrimitivesWritten);
6244 ok(data.PrimitivesStorageNeeded == 16, "Got unexpected primitives storage needed %u.\n",
6245 (unsigned int)data.PrimitivesStorageNeeded);
6247 ID3D11Asynchronous_Release(query);
6249 for (i = 0; i < ARRAY_SIZE(so_buffer); ++i)
6250 ID3D11Buffer_Release(so_buffer[i]);
6251 ID3D11Buffer_Release(cb);
6252 ID3D11GeometryShader_Release(gs);
6253 ID3D11VertexShader_Release(vs);
6255 done:
6256 release_test_context(&test_context);
6259 static void test_device_removed_reason(void)
6261 ID3D11Device *device;
6262 ULONG refcount;
6263 HRESULT hr;
6265 if (!(device = create_device(NULL)))
6267 skip("Failed to create device.\n");
6268 return;
6271 hr = ID3D11Device_GetDeviceRemovedReason(device);
6272 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6273 hr = ID3D11Device_GetDeviceRemovedReason(device);
6274 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6276 refcount = ID3D11Device_Release(device);
6277 ok(!refcount, "Device has %u references left.\n", refcount);
6280 static void test_private_data(void)
6282 ULONG refcount, expected_refcount;
6283 D3D11_TEXTURE2D_DESC texture_desc;
6284 ID3D10Texture2D *d3d10_texture;
6285 ID3D11Device *test_object;
6286 ID3D11Texture2D *texture;
6287 IDXGIDevice *dxgi_device;
6288 IDXGISurface *surface;
6289 ID3D11Device *device;
6290 IUnknown *ptr;
6291 HRESULT hr;
6292 UINT size;
6294 static const GUID test_guid =
6295 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
6296 static const GUID test_guid2 =
6297 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
6298 static const DWORD data[] = {1, 2, 3, 4};
6300 if (!(device = create_device(NULL)))
6302 skip("Failed to create device.\n");
6303 return;
6306 test_object = create_device(NULL);
6308 texture_desc.Width = 512;
6309 texture_desc.Height = 512;
6310 texture_desc.MipLevels = 1;
6311 texture_desc.ArraySize = 1;
6312 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6313 texture_desc.SampleDesc.Count = 1;
6314 texture_desc.SampleDesc.Quality = 0;
6315 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6316 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6317 texture_desc.CPUAccessFlags = 0;
6318 texture_desc.MiscFlags = 0;
6320 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6321 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6322 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
6323 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
6325 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
6326 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6327 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6328 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6329 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6330 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6331 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6332 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6334 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6335 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6336 size = sizeof(ptr) * 2;
6337 ptr = (IUnknown *)0xdeadbeef;
6338 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6339 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6340 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6341 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6343 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
6344 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
6345 size = sizeof(ptr) * 2;
6346 ptr = (IUnknown *)0xdeadbeef;
6347 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
6348 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6349 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6350 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6351 IDXGIDevice_Release(dxgi_device);
6353 refcount = get_refcount(test_object);
6354 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6355 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6356 expected_refcount = refcount + 1;
6357 refcount = get_refcount(test_object);
6358 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6359 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6360 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6361 refcount = get_refcount(test_object);
6362 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6364 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6365 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6366 --expected_refcount;
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, (IUnknown *)test_object);
6371 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6372 size = sizeof(data);
6373 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
6374 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6375 refcount = get_refcount(test_object);
6376 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6377 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
6378 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6379 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
6380 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6382 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6383 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6384 ++expected_refcount;
6385 size = 2 * sizeof(ptr);
6386 ptr = NULL;
6387 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6388 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6389 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
6390 ++expected_refcount;
6391 refcount = get_refcount(test_object);
6392 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6393 IUnknown_Release(ptr);
6394 --expected_refcount;
6396 ptr = (IUnknown *)0xdeadbeef;
6397 size = 1;
6398 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
6399 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6400 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6401 size = 2 * sizeof(ptr);
6402 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
6403 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6404 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6405 refcount = get_refcount(test_object);
6406 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6408 size = 1;
6409 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6410 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
6411 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6412 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6413 if (!enable_debug_layer)
6415 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
6416 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6417 size = 0xdeadbabe;
6418 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
6419 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
6420 ok(size == 0, "Got unexpected size %u.\n", size);
6421 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6422 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
6423 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6424 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6427 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
6428 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6429 ptr = NULL;
6430 size = sizeof(ptr);
6431 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
6432 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6433 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6434 IUnknown_Release(ptr);
6436 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
6437 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
6438 "Texture should implement ID3D10Texture2D.\n");
6439 if (SUCCEEDED(hr))
6441 ptr = NULL;
6442 size = sizeof(ptr);
6443 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
6444 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6445 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6446 IUnknown_Release(ptr);
6447 ID3D10Texture2D_Release(d3d10_texture);
6450 IDXGISurface_Release(surface);
6451 ID3D11Texture2D_Release(texture);
6452 refcount = ID3D11Device_Release(device);
6453 ok(!refcount, "Device has %u references left.\n", refcount);
6454 refcount = ID3D11Device_Release(test_object);
6455 ok(!refcount, "Test object has %u references left.\n", refcount);
6458 static void test_state_refcounting(const D3D_FEATURE_LEVEL feature_level)
6460 ID3D11RasterizerState *rasterizer_state, *tmp_rasterizer_state;
6461 ID3D11Predicate *predicate, *tmp_predicate;
6462 ID3D11SamplerState *sampler, *tmp_sampler;
6463 ID3D11ShaderResourceView *srv, *tmp_srv;
6464 ID3D11RenderTargetView *rtv, *tmp_rtv;
6465 D3D11_RASTERIZER_DESC rasterizer_desc;
6466 D3D11_TEXTURE2D_DESC texture_desc;
6467 D3D11_QUERY_DESC predicate_desc;
6468 D3D11_SAMPLER_DESC sampler_desc;
6469 struct device_desc device_desc;
6470 ID3D11DeviceContext *context;
6471 ID3D11Texture2D *texture;
6472 ID3D11Device *device;
6473 ULONG refcount;
6474 HRESULT hr;
6476 device_desc.feature_level = &feature_level;
6477 device_desc.flags = 0;
6478 if (!(device = create_device(&device_desc)))
6480 skip("Failed to create device for feature level %#x.\n", feature_level);
6481 return;
6484 ID3D11Device_GetImmediateContext(device, &context);
6486 /* ID3D11SamplerState */
6487 memset(&sampler_desc, 0, sizeof(sampler_desc));
6488 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
6489 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
6490 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
6491 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
6492 sampler_desc.MaxLOD = FLT_MAX;
6493 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6494 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6496 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
6497 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6498 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6499 ID3D11SamplerState_Release(tmp_sampler);
6501 tmp_sampler = sampler;
6502 refcount = get_refcount(sampler);
6503 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
6504 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6505 refcount = ID3D11SamplerState_Release(sampler);
6506 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6507 sampler = NULL;
6508 ID3D11DeviceContext_PSGetSamplers(context, 0, 1, &sampler);
6509 ok(sampler == tmp_sampler, "Got sampler %p, expected %p.\n", sampler, tmp_sampler);
6510 refcount = ID3D11SamplerState_Release(sampler);
6511 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6513 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
6514 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6515 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6516 refcount = ID3D11SamplerState_Release(tmp_sampler);
6517 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6519 /* ID3D11RasterizerState */
6520 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
6521 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
6522 rasterizer_desc.CullMode = D3D11_CULL_BACK;
6523 rasterizer_desc.DepthClipEnable = TRUE;
6524 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
6525 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
6527 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
6528 refcount = ID3D11RasterizerState_Release(rasterizer_state);
6529 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6530 ID3D11DeviceContext_RSGetState(context, &tmp_rasterizer_state);
6531 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
6532 tmp_rasterizer_state, rasterizer_state);
6533 refcount = ID3D11RasterizerState_Release(tmp_rasterizer_state);
6534 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6536 /* ID3D11ShaderResourceView */
6537 memset(&texture_desc, 0, sizeof(texture_desc));
6538 texture_desc.Width = 32;
6539 texture_desc.Height = 32;
6540 texture_desc.MipLevels = 1;
6541 texture_desc.ArraySize = 1;
6542 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6543 texture_desc.SampleDesc.Count = 1;
6544 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6545 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6546 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6547 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6548 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6549 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
6550 ID3D11Texture2D_Release(texture);
6552 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6553 refcount = ID3D11ShaderResourceView_Release(srv);
6554 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6555 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &tmp_srv);
6556 ok(tmp_srv == srv, "Got SRV %p, expected %p.\n", tmp_srv, srv);
6557 refcount = ID3D11ShaderResourceView_Release(tmp_srv);
6558 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6560 /* ID3D11RenderTargetView */
6561 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6562 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6563 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6564 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
6565 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
6566 ID3D11Texture2D_Release(texture);
6568 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6569 refcount = ID3D11RenderTargetView_Release(rtv);
6570 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6571 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &tmp_rtv, NULL);
6572 ok(tmp_rtv == rtv, "Got RTV %p, expected %p.\n", tmp_rtv, rtv);
6573 refcount = ID3D11RenderTargetView_Release(tmp_rtv);
6574 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6576 /* ID3D11Predicate */
6577 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
6579 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
6580 predicate_desc.MiscFlags = 0;
6581 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
6582 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
6584 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
6585 refcount = ID3D11Predicate_Release(predicate);
6586 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6587 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, NULL);
6588 ok(tmp_predicate == predicate, "Got predicate %p, expected %p.\n", tmp_predicate, predicate);
6589 refcount = ID3D11Predicate_Release(tmp_predicate);
6590 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6593 ID3D11DeviceContext_Release(context);
6594 refcount = ID3D11Device_Release(device);
6595 ok(!refcount, "Device has %u references left.\n", refcount);
6598 static void test_device_context_state(void)
6600 ID3DDeviceContextState *context_state, *previous_context_state;
6601 ID3D11SamplerState *sampler, *tmp_sampler;
6602 D3D11_DEVICE_CONTEXT_TYPE context_type;
6603 ID3D11DeviceContext1 *context = NULL;
6604 D3D11_SAMPLER_DESC sampler_desc;
6605 D3D_FEATURE_LEVEL feature_level;
6606 ID3D11Device *d3d11_device;
6607 ID3D11Device1 *device;
6608 struct vec4 constant;
6609 ID3D11Buffer *cb, *tmp_cb;
6610 ULONG refcount;
6611 HRESULT hr;
6613 if (!(d3d11_device = create_device(NULL)))
6615 skip("Failed to create device.\n");
6616 return;
6619 hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11Device1, (void **)&device);
6620 ID3D11Device_Release(d3d11_device);
6621 if (FAILED(hr))
6623 skip("ID3D11Device1 is not available.\n");
6624 return;
6627 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
6628 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
6630 feature_level = ID3D11Device1_GetFeatureLevel(device);
6631 ID3D11Device1_GetImmediateContext1(device, &context);
6632 ok(!!context, "Failed to get immediate context.\n");
6634 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
6635 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
6636 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
6637 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
6638 sampler_desc.MipLODBias = 0.0f;
6639 sampler_desc.MaxAnisotropy = 0;
6640 sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
6641 sampler_desc.BorderColor[0] = 0.0f;
6642 sampler_desc.BorderColor[1] = 1.0f;
6643 sampler_desc.BorderColor[2] = 0.0f;
6644 sampler_desc.BorderColor[3] = 1.0f;
6645 sampler_desc.MinLOD = 0.0f;
6646 sampler_desc.MaxLOD = 16.0f;
6647 hr = ID3D11Device1_CreateSamplerState(device, &sampler_desc, &sampler);
6648 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6650 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
6651 tmp_sampler = NULL;
6652 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
6653 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6654 ID3D11SamplerState_Release(tmp_sampler);
6656 ID3D11DeviceContext1_CSSetSamplers(context, 0, 1, &sampler);
6657 tmp_sampler = NULL;
6658 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
6659 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6660 ID3D11SamplerState_Release(tmp_sampler);
6662 ID3D11DeviceContext1_DSSetSamplers(context, 0, 1, &sampler);
6663 tmp_sampler = NULL;
6664 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
6665 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6666 ID3D11SamplerState_Release(tmp_sampler);
6668 ID3D11DeviceContext1_GSSetSamplers(context, 0, 1, &sampler);
6669 tmp_sampler = NULL;
6670 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
6671 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6672 ID3D11SamplerState_Release(tmp_sampler);
6674 ID3D11DeviceContext1_HSSetSamplers(context, 0, 1, &sampler);
6675 tmp_sampler = NULL;
6676 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
6677 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6678 ID3D11SamplerState_Release(tmp_sampler);
6680 ID3D11DeviceContext1_VSSetSamplers(context, 0, 1, &sampler);
6681 tmp_sampler = NULL;
6682 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
6683 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6684 ID3D11SamplerState_Release(tmp_sampler);
6686 feature_level = min(feature_level, D3D_FEATURE_LEVEL_10_1);
6687 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
6688 &IID_ID3D10Device, NULL, &context_state);
6689 todo_wine
6690 ok(SUCCEEDED(hr), "Failed to create device context state, hr %#x.\n", hr);
6691 if (FAILED(hr))
6693 ID3D11SamplerState_Release(sampler);
6694 ID3D11Device1_Release(device);
6695 return;
6697 refcount = get_refcount(context_state);
6698 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
6700 context_type = ID3D11DeviceContext1_GetType(context);
6701 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
6703 cb = create_buffer((ID3D11Device *)device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), NULL);
6705 ID3D11DeviceContext1_CSSetConstantBuffers(context, 0, 1, &cb);
6706 tmp_cb = NULL;
6707 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
6708 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
6709 ID3D11Buffer_Release(tmp_cb);
6711 ID3D11DeviceContext1_PSSetConstantBuffers(context, 0, 1, &cb);
6712 tmp_cb = NULL;
6713 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
6714 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
6715 ID3D11Buffer_Release(tmp_cb);
6717 ID3D11DeviceContext1_VSSetConstantBuffers(context, 0, 1, &cb);
6718 tmp_cb = NULL;
6719 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
6720 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
6721 ID3D11Buffer_Release(tmp_cb);
6723 ID3D11DeviceContext1_DSSetConstantBuffers(context, 0, 1, &cb);
6724 tmp_cb = NULL;
6725 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
6726 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
6727 ID3D11Buffer_Release(tmp_cb);
6729 ID3D11DeviceContext1_GSSetConstantBuffers(context, 0, 1, &cb);
6730 tmp_cb = NULL;
6731 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
6732 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
6733 ID3D11Buffer_Release(tmp_cb);
6735 ID3D11DeviceContext1_HSSetConstantBuffers(context, 0, 1, &cb);
6736 tmp_cb = NULL;
6737 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
6738 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
6739 ID3D11Buffer_Release(tmp_cb);
6741 /* Enable ID3D10Device behavior. */
6742 previous_context_state = NULL;
6743 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
6744 refcount = ID3DDeviceContextState_Release(context_state);
6745 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6747 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
6748 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
6749 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
6750 ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler);
6751 if (!enable_debug_layer)
6752 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
6754 ID3D11DeviceContext1_CSSetSamplers(context, 0, 1, &sampler);
6755 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
6756 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
6757 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
6759 ID3D11DeviceContext1_DSSetSamplers(context, 0, 1, &sampler);
6760 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
6761 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
6762 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
6764 ID3D11DeviceContext1_GSSetSamplers(context, 0, 1, &sampler);
6765 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
6766 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
6767 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
6769 ID3D11DeviceContext1_HSSetSamplers(context, 0, 1, &sampler);
6770 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
6771 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
6772 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
6774 ID3D11DeviceContext1_VSSetSamplers(context, 0, 1, &sampler);
6775 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
6776 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
6777 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
6779 context_type = ID3D11DeviceContext1_GetType(context);
6780 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
6782 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
6783 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
6784 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
6786 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
6787 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
6788 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
6790 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
6791 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
6792 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
6794 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
6795 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
6796 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
6798 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
6799 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
6800 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
6802 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
6803 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
6804 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
6806 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
6807 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
6809 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
6810 refcount = ID3DDeviceContextState_Release(context_state);
6811 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6812 refcount = ID3DDeviceContextState_Release(previous_context_state);
6813 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6815 /* ID3DDeviceContextState retains the previous state. */
6816 tmp_sampler = NULL;
6817 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
6818 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6819 ID3D11SamplerState_Release(tmp_sampler);
6821 tmp_sampler = NULL;
6822 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
6823 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
6824 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
6825 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
6826 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
6827 tmp_sampler = NULL;
6828 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
6829 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6830 ID3D11SamplerState_Release(tmp_sampler);
6832 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
6833 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
6835 ID3D11Buffer_Release(cb);
6836 ID3D11SamplerState_Release(sampler);
6837 ID3D11DeviceContext1_Release(context);
6838 refcount = ID3D11Device1_Release(device);
6839 ok(!refcount, "Device has %u references left.\n", refcount);
6842 static void test_blend(void)
6844 ID3D11BlendState *src_blend, *dst_blend, *dst_blend_factor;
6845 struct d3d11_test_context test_context;
6846 ID3D11RenderTargetView *offscreen_rtv;
6847 D3D11_TEXTURE2D_DESC texture_desc;
6848 ID3D11InputLayout *input_layout;
6849 ID3D11DeviceContext *context;
6850 D3D11_BLEND_DESC blend_desc;
6851 unsigned int stride, offset;
6852 ID3D11Texture2D *offscreen;
6853 ID3D11VertexShader *vs;
6854 ID3D11PixelShader *ps;
6855 ID3D11Device *device;
6856 ID3D11Buffer *vb;
6857 DWORD color;
6858 HRESULT hr;
6860 static const DWORD vs_code[] =
6862 #if 0
6863 struct vs_out
6865 float4 position : SV_POSITION;
6866 float4 color : COLOR;
6869 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
6871 struct vs_out o;
6873 o.position = position;
6874 o.color = color;
6876 return o;
6878 #endif
6879 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
6880 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
6881 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
6882 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
6883 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
6884 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
6885 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
6886 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
6887 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
6888 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
6890 static const DWORD ps_code[] =
6892 #if 0
6893 struct vs_out
6895 float4 position : SV_POSITION;
6896 float4 color : COLOR;
6899 float4 main(struct vs_out i) : SV_TARGET
6901 return i.color;
6903 #endif
6904 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
6905 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
6906 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
6907 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
6908 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6909 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
6910 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
6911 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
6913 static const struct
6915 struct vec3 position;
6916 DWORD diffuse;
6918 quads[] =
6920 /* quad1 */
6921 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
6922 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
6923 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
6924 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
6925 /* quad2 */
6926 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
6927 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
6928 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
6929 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
6931 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
6933 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
6934 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
6936 static const float blend_factor[] = {0.3f, 0.4f, 0.8f, 0.9f};
6937 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6939 if (!init_test_context(&test_context, NULL))
6940 return;
6942 device = test_context.device;
6943 context = test_context.immediate_context;
6945 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
6946 vs_code, sizeof(vs_code), &input_layout);
6947 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6949 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
6951 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
6952 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6953 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
6954 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6956 memset(&blend_desc, 0, sizeof(blend_desc));
6957 blend_desc.RenderTarget[0].BlendEnable = TRUE;
6958 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
6959 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
6960 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
6961 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
6962 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
6963 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
6964 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
6966 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
6967 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6969 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
6970 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
6971 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
6972 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
6974 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
6975 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6977 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_BLEND_FACTOR;
6978 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_BLEND_FACTOR;
6979 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
6980 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
6982 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend_factor);
6983 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6985 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
6986 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6987 stride = sizeof(*quads);
6988 offset = 0;
6989 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
6990 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
6991 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6993 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6995 ID3D11DeviceContext_OMSetBlendState(context, src_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
6996 ID3D11DeviceContext_Draw(context, 4, 0);
6997 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
6998 ID3D11DeviceContext_Draw(context, 4, 4);
7000 color = get_texture_color(test_context.backbuffer, 320, 360);
7001 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
7002 color = get_texture_color(test_context.backbuffer, 320, 120);
7003 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
7005 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7007 ID3D11DeviceContext_OMSetBlendState(context, dst_blend_factor, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
7008 ID3D11DeviceContext_Draw(context, 4, 0);
7009 ID3D11DeviceContext_Draw(context, 4, 4);
7011 color = get_texture_color(test_context.backbuffer, 320, 360);
7012 ok(compare_color(color, 0x600066b3, 1), "Got unexpected color 0x%08x.\n", color);
7013 color = get_texture_color(test_context.backbuffer, 320, 120);
7014 ok(compare_color(color, 0xa0cc00b3, 1), "Got unexpected color 0x%08x.\n", color);
7016 texture_desc.Width = 128;
7017 texture_desc.Height = 128;
7018 texture_desc.MipLevels = 1;
7019 texture_desc.ArraySize = 1;
7020 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
7021 texture_desc.SampleDesc.Count = 1;
7022 texture_desc.SampleDesc.Quality = 0;
7023 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7024 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
7025 texture_desc.CPUAccessFlags = 0;
7026 texture_desc.MiscFlags = 0;
7028 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
7029 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
7031 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
7032 goto done;
7035 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
7036 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7038 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
7040 set_viewport(context, 0.0f, 0.0f, 128.0f, 128.0f, 0.0f, 1.0f);
7042 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
7044 ID3D11DeviceContext_OMSetBlendState(context, src_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
7045 ID3D11DeviceContext_Draw(context, 4, 0);
7046 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
7047 ID3D11DeviceContext_Draw(context, 4, 4);
7049 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
7050 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
7051 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
7052 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
7054 ID3D11RenderTargetView_Release(offscreen_rtv);
7055 ID3D11Texture2D_Release(offscreen);
7056 done:
7057 ID3D11BlendState_Release(dst_blend_factor);
7058 ID3D11BlendState_Release(dst_blend);
7059 ID3D11BlendState_Release(src_blend);
7060 ID3D11PixelShader_Release(ps);
7061 ID3D11VertexShader_Release(vs);
7062 ID3D11Buffer_Release(vb);
7063 ID3D11InputLayout_Release(input_layout);
7064 release_test_context(&test_context);
7067 static void test_texture1d(void)
7069 struct shader
7071 const DWORD *code;
7072 size_t size;
7074 struct texture
7076 UINT width;
7077 UINT miplevel_count;
7078 UINT array_size;
7079 DXGI_FORMAT format;
7080 D3D11_SUBRESOURCE_DATA data[3];
7083 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
7084 struct d3d11_test_context test_context;
7085 const struct texture *current_texture;
7086 D3D11_TEXTURE1D_DESC texture_desc;
7087 D3D11_SAMPLER_DESC sampler_desc;
7088 const struct shader *current_ps;
7089 D3D_FEATURE_LEVEL feature_level;
7090 ID3D11ShaderResourceView *srv;
7091 ID3D11DeviceContext *context;
7092 ID3D11SamplerState *sampler;
7093 struct resource_readback rb;
7094 ID3D11Texture1D *texture;
7095 struct vec4 ps_constant;
7096 ID3D11PixelShader *ps;
7097 ID3D11Device *device;
7098 unsigned int i, x;
7099 ID3D11Buffer *cb;
7100 DWORD color;
7101 HRESULT hr;
7103 static const DWORD ps_ld_code[] =
7105 #if 0
7106 Texture1D t;
7108 float miplevel;
7110 float4 main(float4 position : SV_POSITION) : SV_TARGET
7112 float2 p;
7113 t.GetDimensions(miplevel, p.x, p.y);
7114 p.y = miplevel;
7115 p *= float2(position.x / 640.0f, 1.0f);
7116 return t.Load(int2(p));
7118 #endif
7119 0x43425844, 0x7b0c6359, 0x598178f6, 0xef2ddbdb, 0x88fc794c, 0x00000001, 0x000001ac, 0x00000003,
7120 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7121 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
7122 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7123 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
7124 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001058, 0x00107000, 0x00000000,
7125 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
7126 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
7127 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
7128 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000e2,
7129 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
7130 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
7131 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
7132 0x00107e46, 0x00000000, 0x0100003e,
7134 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
7135 static const DWORD ps_ld_sint8_code[] =
7137 #if 0
7138 Texture1D<int4> t;
7140 float4 main(float4 position : SV_POSITION) : SV_TARGET
7142 float2 p, s;
7143 int4 c;
7145 p = float2(position.x / 640.0f, 0.0f);
7146 t.GetDimensions(0, s.x, s.y);
7147 p *= s;
7149 c = t.Load(int2(p));
7150 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
7152 #endif
7153 0x43425844, 0x65a13d1e, 0x8a0bfc92, 0xa2f2708a, 0x0bafafb6, 0x00000001, 0x00000234, 0x00000003,
7154 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7155 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
7156 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7157 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000198, 0x00000040,
7158 0x00000066, 0x04001058, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101012, 0x00000000,
7159 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
7160 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
7161 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
7162 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
7163 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7164 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0500002b,
7165 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
7166 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204, 0x3c010204, 0x0a000034, 0x001000f2,
7167 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000, 0xbf800000, 0xbf800000, 0xbf800000,
7168 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
7169 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002,
7170 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
7172 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
7173 static const DWORD ps_ld_uint8_code[] =
7175 #if 0
7176 Texture1D<uint4> t;
7178 float4 main(float4 position : SV_POSITION) : SV_TARGET
7180 float2 p, s;
7182 p = float2(position.x / 640.0f, 0.0f);
7183 t.GetDimensions(0, s.x, s.y);
7184 p *= s;
7186 return t.Load(int2(p)) / (float4)255;
7188 #endif
7189 0x43425844, 0x35186c1f, 0x55bad4fd, 0xb7c97a57, 0x99c060e7, 0x00000001, 0x000001bc, 0x00000003,
7190 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7191 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
7192 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7193 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000120, 0x00000040,
7194 0x00000048, 0x04001058, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101012, 0x00000000,
7195 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
7196 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
7197 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
7198 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
7199 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7200 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x05000056,
7201 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46,
7202 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081, 0x3b808081, 0x0100003e,
7204 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
7205 static DWORD ps_ld_array_code[] =
7207 #if 0
7208 Texture1DArray t;
7210 float miplevel;
7212 float4 main(float4 position : SV_POSITION) : SV_TARGET
7214 float3 p;
7215 t.GetDimensions(miplevel, p.x, p.y, p.z);
7216 p.y = 1;
7217 p.z = miplevel;
7218 p *= float3(position.x / 640.0f, 1.0f, 1.0f);
7219 return t.Load(int3(p));
7221 #endif
7222 0x43425844, 0xbfccadc4, 0xc00ff13d, 0x2ba75365, 0xf747cbee, 0x00000001, 0x000001c0, 0x00000003,
7223 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7224 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
7225 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7226 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000124, 0x00000040,
7227 0x00000049, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003858, 0x00107000, 0x00000000,
7228 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
7229 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
7230 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
7231 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000c2,
7232 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x00100072, 0x00000000, 0x00100386,
7233 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x00000000, 0x0500001b, 0x001000d2,
7234 0x00000000, 0x00100906, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000001,
7235 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
7237 static const struct shader ps_ld_array = {ps_ld_array_code, sizeof(ps_ld_array_code)};
7239 static const DWORD rgba_level_0[] =
7241 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7243 static const DWORD rgba_level_1[] =
7245 0xffffffff, 0xff0000ff,
7247 static const DWORD rgba_level_2[] =
7249 0xffff0000,
7251 static const DWORD srgb_data[] =
7253 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
7255 static const DWORD r32_uint[] =
7257 0, 1, 2, 3,
7259 static const DWORD r9g9b9e5_data[] =
7261 0x80000100, 0x80020000, 0x84000000, 0x84000100,
7263 static const DWORD array_data0[] =
7265 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7267 static const DWORD array_data1[] =
7269 0x00ffff00, 0xff000000, 0x00ff0000, 0x000000ff,
7271 static const DWORD array_data2[] =
7273 0x000000ff, 0xffff00ff, 0x0000ff00, 0xff000000,
7275 static const struct texture rgba_texture =
7277 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
7279 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
7280 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
7281 {rgba_level_2, sizeof(*rgba_level_2), 0},
7284 static const struct texture srgb_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
7285 {{srgb_data, 4 * sizeof(*srgb_data)}}};
7286 static const struct texture sint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
7287 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
7288 static const struct texture uint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
7289 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
7290 static const struct texture r32u_typeless = {4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
7291 {{r32_uint, 4 * sizeof(*r32_uint)}}};
7292 static const struct texture r9g9b9e5_texture = {4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
7293 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
7294 static const struct texture array_texture = {4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
7296 {array_data0, 4 * sizeof(*array_data0)},
7297 {array_data1, 4 * sizeof(*array_data1)},
7298 {array_data2, 4 * sizeof(*array_data2)},
7302 static const DWORD level_1_colors[] =
7304 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
7306 static const DWORD level_2_colors[] =
7308 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7310 static const DWORD srgb_colors[] =
7312 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
7314 static const DWORD sint8_colors[] =
7316 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
7318 static const DWORD r32u_colors[4] =
7320 0x01000000, 0x01000001, 0x01000002, 0x01000003,
7322 static const DWORD r9g9b9e5_colors[4] =
7324 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
7326 static const DWORD zero_colors[4] = {0};
7327 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7328 static const struct texture_test
7330 const struct shader *ps;
7331 const struct texture *texture;
7332 D3D11_FILTER filter;
7333 float lod_bias;
7334 float min_lod;
7335 float max_lod;
7336 float ps_constant;
7337 const DWORD *expected_colors;
7339 texture_tests[] =
7341 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
7342 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
7343 #define MIP_MAX D3D11_FLOAT32_MAX
7344 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7345 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
7346 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
7347 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
7348 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
7349 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
7350 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7351 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7352 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
7353 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7354 {&ps_ld_array, &array_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, array_data1},
7356 #undef POINT
7357 #undef POINT_LINEAR
7358 #undef MIP_MAX
7359 static const struct srv_test
7361 const struct shader *ps;
7362 const struct texture *texture;
7363 struct srv_desc srv_desc;
7364 float ps_constant;
7365 const DWORD *expected_colors;
7367 srv_tests[] =
7369 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
7370 #define R32_UINT DXGI_FORMAT_R32_UINT
7371 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_1D, 0, 1}, 0.0f, r32u_colors},
7372 #undef TEX_1D
7373 #undef R32_UINT
7374 #undef FMT_UNKNOWN
7377 if (!init_test_context(&test_context, NULL))
7378 return;
7380 device = test_context.device;
7381 context = test_context.immediate_context;
7382 feature_level = ID3D11Device_GetFeatureLevel(device);
7384 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
7386 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7388 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7389 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
7390 texture_desc.CPUAccessFlags = 0;
7391 texture_desc.MiscFlags = 0;
7393 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7394 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7395 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7396 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7397 sampler_desc.MipLODBias = 0.0f;
7398 sampler_desc.MaxAnisotropy = 0;
7399 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7400 sampler_desc.BorderColor[0] = 0.0f;
7401 sampler_desc.BorderColor[1] = 0.0f;
7402 sampler_desc.BorderColor[2] = 0.0f;
7403 sampler_desc.BorderColor[3] = 0.0f;
7404 sampler_desc.MinLOD = 0.0f;
7405 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
7407 ps = NULL;
7408 srv = NULL;
7409 sampler = NULL;
7410 texture = NULL;
7411 current_ps = NULL;
7412 current_texture = NULL;
7413 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
7415 const struct texture_test *test = &texture_tests[i];
7417 if (current_ps != test->ps)
7419 if (ps)
7420 ID3D11PixelShader_Release(ps);
7422 current_ps = test->ps;
7424 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
7425 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7427 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7430 if (current_texture != test->texture)
7432 if (texture)
7433 ID3D11Texture1D_Release(texture);
7434 if (srv)
7435 ID3D11ShaderResourceView_Release(srv);
7437 current_texture = test->texture;
7439 if (current_texture)
7441 texture_desc.Width = current_texture->width;
7442 texture_desc.MipLevels = current_texture->miplevel_count;
7443 texture_desc.ArraySize = current_texture->array_size;
7444 texture_desc.Format = current_texture->format;
7446 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
7447 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
7449 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
7450 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7452 else
7454 texture = NULL;
7455 srv = NULL;
7458 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7461 if (!sampler || (sampler_desc.Filter != test->filter
7462 || sampler_desc.MipLODBias != test->lod_bias
7463 || sampler_desc.MinLOD != test->min_lod
7464 || sampler_desc.MaxLOD != test->max_lod))
7466 if (sampler)
7467 ID3D11SamplerState_Release(sampler);
7469 sampler_desc.Filter = test->filter;
7470 sampler_desc.MipLODBias = test->lod_bias;
7471 sampler_desc.MinLOD = test->min_lod;
7472 sampler_desc.MaxLOD = test->max_lod;
7474 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
7475 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
7477 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7480 ps_constant.x = test->ps_constant;
7481 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
7483 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7485 draw_quad(&test_context);
7487 get_texture_readback(test_context.backbuffer, 0, &rb);
7488 for (x = 0; x < 4; ++x)
7490 color = get_readback_color(&rb, 80 + x * 160, 0, 0);
7491 ok(compare_color(color, test->expected_colors[x], 2),
7492 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
7494 release_resource_readback(&rb);
7496 if (srv)
7497 ID3D11ShaderResourceView_Release(srv);
7498 ID3D11SamplerState_Release(sampler);
7499 if (texture)
7500 ID3D11Texture1D_Release(texture);
7501 ID3D11PixelShader_Release(ps);
7503 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
7505 win_skip("SRV tests are broken on WARP.\n");
7506 ID3D11Buffer_Release(cb);
7507 release_test_context(&test_context);
7508 return;
7511 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7512 sampler_desc.MipLODBias = 0.0f;
7513 sampler_desc.MinLOD = 0.0f;
7514 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
7516 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
7517 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7519 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7521 ps = NULL;
7522 srv = NULL;
7523 texture = NULL;
7524 current_ps = NULL;
7525 current_texture = NULL;
7526 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
7528 const struct srv_test *test = &srv_tests[i];
7530 if (current_ps != test->ps)
7532 if (ps)
7533 ID3D11PixelShader_Release(ps);
7535 current_ps = test->ps;
7537 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
7538 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7540 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7543 if (current_texture != test->texture)
7545 if (texture)
7546 ID3D11Texture1D_Release(texture);
7548 current_texture = test->texture;
7550 texture_desc.Width = current_texture->width;
7551 texture_desc.MipLevels = current_texture->miplevel_count;
7552 texture_desc.ArraySize = current_texture->array_size;
7553 texture_desc.Format = current_texture->format;
7555 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
7556 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
7559 if (srv)
7560 ID3D11ShaderResourceView_Release(srv);
7562 get_srv_desc(&srv_desc, &test->srv_desc);
7563 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
7564 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7566 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7568 ps_constant.x = test->ps_constant;
7569 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
7571 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7573 draw_quad(&test_context);
7575 get_texture_readback(test_context.backbuffer, 0, &rb);
7576 for (x = 0; x < 4; ++x)
7578 color = get_readback_color(&rb, 80 + x * 160, 0, 0);
7579 ok(compare_color(color, test->expected_colors[x], 1),
7580 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
7582 release_resource_readback(&rb);
7584 ID3D11PixelShader_Release(ps);
7585 ID3D11Texture1D_Release(texture);
7586 ID3D11ShaderResourceView_Release(srv);
7587 ID3D11SamplerState_Release(sampler);
7589 ID3D11Buffer_Release(cb);
7590 release_test_context(&test_context);
7593 static void test_texture(void)
7595 struct shader
7597 const DWORD *code;
7598 size_t size;
7600 struct texture
7602 UINT width;
7603 UINT height;
7604 UINT miplevel_count;
7605 UINT array_size;
7606 DXGI_FORMAT format;
7607 D3D11_SUBRESOURCE_DATA data[3];
7610 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
7611 struct d3d11_test_context test_context;
7612 const struct texture *current_texture;
7613 D3D11_TEXTURE2D_DESC texture_desc;
7614 D3D11_SAMPLER_DESC sampler_desc;
7615 const struct shader *current_ps;
7616 D3D_FEATURE_LEVEL feature_level;
7617 ID3D11ShaderResourceView *srv;
7618 ID3D11DeviceContext *context;
7619 ID3D11SamplerState *sampler;
7620 struct resource_readback rb;
7621 ID3D11Texture2D *texture;
7622 struct vec4 ps_constant;
7623 ID3D11PixelShader *ps;
7624 ID3D11Device *device;
7625 unsigned int i, x, y;
7626 ID3D11Buffer *cb;
7627 DWORD color;
7628 HRESULT hr;
7630 static const DWORD ps_ld_code[] =
7632 #if 0
7633 Texture2D t;
7635 float miplevel;
7637 float4 main(float4 position : SV_POSITION) : SV_TARGET
7639 float3 p;
7640 t.GetDimensions(miplevel, p.x, p.y, p.z);
7641 p.z = miplevel;
7642 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
7643 return t.Load(int3(p));
7645 #endif
7646 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
7647 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7648 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7649 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7650 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
7651 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
7652 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
7653 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
7654 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
7655 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
7656 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
7657 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
7658 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
7659 0x00107e46, 0x00000000, 0x0100003e,
7661 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
7662 static const DWORD ps_ld_sint8_code[] =
7664 #if 0
7665 Texture2D<int4> t;
7667 float4 main(float4 position : SV_POSITION) : SV_TARGET
7669 float3 p, s;
7670 int4 c;
7672 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
7673 t.GetDimensions(0, s.x, s.y, s.z);
7674 p *= s;
7676 c = t.Load(int3(p));
7677 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
7679 #endif
7680 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
7681 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7682 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7683 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7684 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
7685 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
7686 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
7687 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
7688 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
7689 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
7690 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
7691 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7692 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
7693 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
7694 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
7695 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7696 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
7697 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
7699 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
7700 static const DWORD ps_ld_uint8_code[] =
7702 #if 0
7703 Texture2D<uint4> t;
7705 float4 main(float4 position : SV_POSITION) : SV_TARGET
7707 float3 p, s;
7709 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
7710 t.GetDimensions(0, s.x, s.y, s.z);
7711 p *= s;
7713 return t.Load(int3(p)) / (float4)255;
7715 #endif
7716 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
7717 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7718 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7719 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7720 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
7721 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
7722 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
7723 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
7724 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
7725 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
7726 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
7727 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7728 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
7729 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
7730 0x3b808081, 0x0100003e,
7732 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
7733 static const DWORD ps_sample_code[] =
7735 #if 0
7736 Texture2D t;
7737 SamplerState s;
7739 float4 main(float4 position : SV_POSITION) : SV_Target
7741 float2 p;
7743 p.x = position.x / 640.0f;
7744 p.y = position.y / 480.0f;
7745 return t.Sample(s, p);
7747 #endif
7748 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
7749 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7750 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7751 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7752 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7753 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7754 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7755 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7756 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7757 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7759 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
7760 static const DWORD ps_sample_b_code[] =
7762 #if 0
7763 Texture2D t;
7764 SamplerState s;
7766 float bias;
7768 float4 main(float4 position : SV_POSITION) : SV_Target
7770 float2 p;
7772 p.x = position.x / 640.0f;
7773 p.y = position.y / 480.0f;
7774 return t.SampleBias(s, p, bias);
7776 #endif
7777 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
7778 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7779 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7780 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7781 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
7782 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
7783 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7784 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
7785 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
7786 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
7787 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
7789 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
7790 static const DWORD ps_sample_l_code[] =
7792 #if 0
7793 Texture2D t;
7794 SamplerState s;
7796 float level;
7798 float4 main(float4 position : SV_POSITION) : SV_Target
7800 float2 p;
7802 p.x = position.x / 640.0f;
7803 p.y = position.y / 480.0f;
7804 return t.SampleLevel(s, p, level);
7806 #endif
7807 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
7808 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7809 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7810 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7811 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
7812 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
7813 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7814 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
7815 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
7816 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
7817 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
7819 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
7820 static const DWORD ps_sample_2d_array_code[] =
7822 #if 0
7823 Texture2DArray t;
7824 SamplerState s;
7826 float layer;
7828 float4 main(float4 position : SV_POSITION) : SV_TARGET
7830 float3 d;
7831 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
7832 t.GetDimensions(d.x, d.y, d.z);
7833 d.z = layer;
7834 return t.Sample(s, p * d);
7836 #endif
7837 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
7838 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7839 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7840 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7841 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
7842 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
7843 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7844 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
7845 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
7846 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
7847 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
7848 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
7849 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7851 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
7852 static const DWORD red_data[] =
7854 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
7855 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
7856 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
7857 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
7859 static const DWORD green_data[] =
7861 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
7862 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
7863 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
7864 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
7866 static const DWORD blue_data[] =
7868 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
7869 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
7870 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
7871 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
7873 static const DWORD rgba_level_0[] =
7875 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7876 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
7877 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
7878 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7880 static const DWORD rgba_level_1[] =
7882 0xffffffff, 0xff0000ff,
7883 0xff000000, 0xff00ff00,
7885 static const DWORD rgba_level_2[] =
7887 0xffff0000,
7889 static const DWORD srgb_data[] =
7891 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
7892 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
7893 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
7894 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
7896 static const WORD r8g8_data[] =
7898 0x0000, 0xffff, 0x0000, 0x7fff,
7899 0x0203, 0xff10, 0x0b0c, 0x8000,
7900 0xc4de, 0xfff0, 0xfdfe, 0x5a6f,
7901 0xff00, 0xffc8, 0x00aa, 0xdd5b,
7903 static const BYTE a8_data[] =
7905 0x00, 0x10, 0x20, 0x30,
7906 0x40, 0x50, 0x60, 0x70,
7907 0x80, 0x90, 0xa0, 0xb0,
7908 0xc0, 0xd0, 0xe0, 0xf0,
7910 static const BYTE bc1_data[] =
7912 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
7913 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
7914 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
7915 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
7917 static const BYTE bc2_data[] =
7919 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
7920 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
7921 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
7922 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
7924 static const BYTE bc3_data[] =
7926 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
7927 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
7928 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
7929 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
7931 static const BYTE bc4_data[] =
7933 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
7934 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
7935 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
7936 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
7938 static const BYTE bc5_data[] =
7940 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
7941 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
7942 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
7943 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
7945 static const BYTE bc6h_u_data[] =
7947 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7948 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7949 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7950 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7952 static const BYTE bc6h_s_data[] =
7954 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7955 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7956 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7957 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7959 static const BYTE bc7_data[] =
7961 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7962 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7963 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7964 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
7966 static const float r32_float[] =
7968 0.0f, 1.0f, 0.5f, 0.50f,
7969 1.0f, 0.0f, 0.0f, 0.75f,
7970 0.0f, 1.0f, 0.5f, 0.25f,
7971 1.0f, 0.0f, 0.0f, 0.75f,
7973 static const DWORD r32_uint[] =
7975 0, 1, 2, 3,
7976 100, 200, 255, 128,
7977 40, 30, 20, 10,
7978 250, 210, 155, 190,
7980 static const DWORD r9g9b9e5_data[] =
7982 0x80000100, 0x80020000, 0x84000000, 0x84000100,
7983 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
7984 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
7985 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
7987 static const struct texture rgba_texture =
7989 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
7991 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
7992 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
7993 {rgba_level_2, sizeof(*rgba_level_2), 0},
7996 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
7997 {{srgb_data, 4 * sizeof(*srgb_data)}}};
7998 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
7999 {{srgb_data, 4 * sizeof(*srgb_data)}}};
8000 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
8001 {{a8_data, 4 * sizeof(*a8_data)}}};
8002 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
8003 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
8004 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
8005 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
8006 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
8007 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
8008 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
8009 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
8010 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
8011 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
8012 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
8013 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
8014 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
8015 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
8016 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
8017 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
8018 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
8019 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
8020 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
8021 static const struct texture array_2d_texture =
8023 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
8025 {red_data, 6 * sizeof(*red_data)},
8026 {green_data, 4 * sizeof(*green_data)},
8027 {blue_data, 5 * sizeof(*blue_data)},
8030 static const struct texture r32f_float = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
8031 {{r32_float, 4 * sizeof(*r32_float)}}};
8032 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
8033 {{r32_float, 4 * sizeof(*r32_float)}}};
8034 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
8035 {{r32_uint, 4 * sizeof(*r32_uint)}}};
8036 static const struct texture r8g8_snorm = {4, 4, 1, 1, DXGI_FORMAT_R8G8_SNORM,
8037 {{r8g8_data, 4 * sizeof(*r8g8_data)}}};
8038 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
8039 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
8040 static const DWORD red_colors[] =
8042 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
8043 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
8044 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
8045 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
8047 static const DWORD blue_colors[] =
8049 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
8050 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
8051 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
8052 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
8054 static const DWORD level_1_colors[] =
8056 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
8057 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
8058 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
8059 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
8061 static const DWORD lerp_1_2_colors[] =
8063 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
8064 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
8065 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
8066 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
8068 static const DWORD level_2_colors[] =
8070 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
8071 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
8072 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
8073 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
8075 static const DWORD srgb_colors[] =
8077 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
8078 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
8079 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
8080 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
8082 static const DWORD a8_colors[] =
8084 0x00000000, 0x10000000, 0x20000000, 0x30000000,
8085 0x40000000, 0x50000000, 0x60000000, 0x70000000,
8086 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
8087 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
8089 static const DWORD bc_colors[] =
8091 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
8092 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
8093 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
8094 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
8096 static const DWORD bc4_colors[] =
8098 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
8099 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
8100 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
8101 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
8103 static const DWORD bc5_colors[] =
8105 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
8106 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
8107 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
8108 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
8110 static const DWORD bc7_colors[] =
8112 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
8113 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
8114 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
8115 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
8117 static const DWORD sint8_colors[] =
8119 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
8120 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
8121 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
8122 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
8124 static const DWORD snorm_colors[] =
8126 0xff000000, 0xff000000, 0xff000000, 0xff00ff00,
8127 0xff000406, 0xff000020, 0xff001618, 0xff000000,
8128 0xff000000, 0xff000000, 0xff000000, 0xff00b5df,
8129 0xff000000, 0xff000000, 0xff000000, 0xff0000b7,
8131 static const DWORD r32f_colors[] =
8133 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
8134 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
8135 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
8136 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
8138 static const DWORD r32u_colors[16] =
8140 0x01000000, 0x01000001, 0x01000002, 0x01000003,
8141 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
8142 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
8143 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
8145 static const DWORD r9g9b9e5_colors[16] =
8147 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
8148 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
8149 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
8150 0xff000033, 0xff003300, 0xff330000, 0xff333333,
8152 static const DWORD zero_colors[4 * 4] = {0};
8153 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8155 static const struct texture_test
8157 const struct shader *ps;
8158 const struct texture *texture;
8159 D3D11_FILTER filter;
8160 float lod_bias;
8161 float min_lod;
8162 float max_lod;
8163 float ps_constant;
8164 const DWORD *expected_colors;
8166 texture_tests[] =
8168 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
8169 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
8170 #define MIP_MAX D3D11_FLOAT32_MAX
8171 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
8172 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
8173 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
8174 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
8175 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
8176 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
8177 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
8178 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
8179 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
8180 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
8181 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
8182 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
8183 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
8184 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
8185 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
8186 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
8187 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
8188 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
8189 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
8190 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
8191 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
8192 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
8193 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
8194 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
8195 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
8196 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
8197 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
8198 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
8199 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
8200 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
8201 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
8202 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
8203 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
8204 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
8205 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
8206 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
8207 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
8208 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
8209 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
8210 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
8211 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
8212 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
8213 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
8214 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
8215 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
8216 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
8217 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
8218 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
8219 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
8220 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
8221 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
8222 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
8223 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
8224 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
8225 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
8226 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
8227 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
8228 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
8229 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
8230 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
8231 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
8232 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
8233 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
8234 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
8235 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
8236 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
8237 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
8238 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
8239 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
8240 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
8241 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
8242 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
8243 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
8244 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
8245 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
8246 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
8247 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
8248 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
8249 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
8250 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
8251 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
8252 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
8253 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
8254 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
8255 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
8256 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
8257 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
8258 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
8259 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
8260 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
8261 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
8262 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
8263 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
8264 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
8265 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
8266 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
8267 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
8268 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
8269 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
8270 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
8271 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
8272 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
8273 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
8274 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
8275 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
8276 #undef POINT
8277 #undef POINT_LINEAR
8278 #undef MIP_MAX
8280 static const struct srv_test
8282 const struct shader *ps;
8283 const struct texture *texture;
8284 struct srv_desc srv_desc;
8285 float ps_constant;
8286 const DWORD *expected_colors;
8288 srv_tests[] =
8290 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
8291 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
8292 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
8293 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
8294 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
8295 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
8296 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
8297 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
8298 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
8299 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
8300 #define R8G8_SNORM DXGI_FORMAT_R8G8_SNORM
8301 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
8302 #define R32_UINT DXGI_FORMAT_R32_UINT
8303 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
8304 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
8305 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
8306 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
8307 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
8308 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
8309 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
8310 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
8311 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
8312 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
8313 {&ps_sample, &r32f_float, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
8314 {&ps_sample, &r8g8_snorm, {R8G8_SNORM, TEX_2D, 0, 1}, 0.0f, snorm_colors},
8315 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
8316 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
8317 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
8318 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
8319 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
8320 #undef TEX_2D
8321 #undef TEX_2D_ARRAY
8322 #undef BC1_UNORM
8323 #undef BC1_UNORM_SRGB
8324 #undef BC2_UNORM
8325 #undef BC2_UNORM_SRGB
8326 #undef BC3_UNORM
8327 #undef BC3_UNORM_SRGB
8328 #undef R8G8B8A8_UNORM_SRGB
8329 #undef R8G8B8A8_UNORM
8330 #undef R8G8_SNORM
8331 #undef R32_FLOAT
8332 #undef R32_UINT
8333 #undef FMT_UNKNOWN
8336 if (!init_test_context(&test_context, NULL))
8337 return;
8339 device = test_context.device;
8340 context = test_context.immediate_context;
8341 feature_level = ID3D11Device_GetFeatureLevel(device);
8343 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
8345 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8347 texture_desc.SampleDesc.Count = 1;
8348 texture_desc.SampleDesc.Quality = 0;
8349 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8350 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
8351 texture_desc.CPUAccessFlags = 0;
8352 texture_desc.MiscFlags = 0;
8354 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8355 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8356 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8357 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8358 sampler_desc.MipLODBias = 0.0f;
8359 sampler_desc.MaxAnisotropy = 0;
8360 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8361 sampler_desc.BorderColor[0] = 0.0f;
8362 sampler_desc.BorderColor[1] = 0.0f;
8363 sampler_desc.BorderColor[2] = 0.0f;
8364 sampler_desc.BorderColor[3] = 0.0f;
8365 sampler_desc.MinLOD = 0.0f;
8366 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
8368 ps = NULL;
8369 srv = NULL;
8370 sampler = NULL;
8371 texture = NULL;
8372 current_ps = NULL;
8373 current_texture = NULL;
8374 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
8376 const struct texture_test *test = &texture_tests[i];
8378 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
8379 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
8380 && feature_level < D3D_FEATURE_LEVEL_11_0)
8382 skip("Feature level >= 11.0 is required for BC7 tests.\n");
8383 continue;
8386 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
8387 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
8388 && feature_level < D3D_FEATURE_LEVEL_11_0)
8390 skip("Feature level >= 11.0 is required for BC6H tests.\n");
8391 continue;
8394 if (current_ps != test->ps)
8396 if (ps)
8397 ID3D11PixelShader_Release(ps);
8399 current_ps = test->ps;
8401 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
8402 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
8404 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8407 if (current_texture != test->texture)
8409 if (texture)
8410 ID3D11Texture2D_Release(texture);
8411 if (srv)
8412 ID3D11ShaderResourceView_Release(srv);
8414 current_texture = test->texture;
8416 if (current_texture)
8418 texture_desc.Width = current_texture->width;
8419 texture_desc.Height = current_texture->height;
8420 texture_desc.MipLevels = current_texture->miplevel_count;
8421 texture_desc.ArraySize = current_texture->array_size;
8422 texture_desc.Format = current_texture->format;
8424 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
8425 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
8427 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
8428 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
8430 else
8432 texture = NULL;
8433 srv = NULL;
8436 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8439 if (!sampler || (sampler_desc.Filter != test->filter
8440 || sampler_desc.MipLODBias != test->lod_bias
8441 || sampler_desc.MinLOD != test->min_lod
8442 || sampler_desc.MaxLOD != test->max_lod))
8444 if (sampler)
8445 ID3D11SamplerState_Release(sampler);
8447 sampler_desc.Filter = test->filter;
8448 sampler_desc.MipLODBias = test->lod_bias;
8449 sampler_desc.MinLOD = test->min_lod;
8450 sampler_desc.MaxLOD = test->max_lod;
8452 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
8453 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
8455 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
8458 ps_constant.x = test->ps_constant;
8459 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
8461 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8463 draw_quad(&test_context);
8465 get_texture_readback(test_context.backbuffer, 0, &rb);
8466 for (y = 0; y < 4; ++y)
8468 for (x = 0; x < 4; ++x)
8470 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
8471 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
8472 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
8475 release_resource_readback(&rb);
8477 if (srv)
8478 ID3D11ShaderResourceView_Release(srv);
8479 ID3D11SamplerState_Release(sampler);
8480 if (texture)
8481 ID3D11Texture2D_Release(texture);
8482 ID3D11PixelShader_Release(ps);
8484 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
8486 win_skip("SRV tests are broken on WARP.\n");
8487 ID3D11Buffer_Release(cb);
8488 release_test_context(&test_context);
8489 return;
8492 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8493 sampler_desc.MipLODBias = 0.0f;
8494 sampler_desc.MinLOD = 0.0f;
8495 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
8497 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
8498 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8500 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
8502 ps = NULL;
8503 srv = NULL;
8504 texture = NULL;
8505 current_ps = NULL;
8506 current_texture = NULL;
8507 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
8509 const struct srv_test *test = &srv_tests[i];
8511 if (current_ps != test->ps)
8513 if (ps)
8514 ID3D11PixelShader_Release(ps);
8516 current_ps = test->ps;
8518 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
8519 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
8521 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8524 if (current_texture != test->texture)
8526 if (texture)
8527 ID3D11Texture2D_Release(texture);
8529 current_texture = test->texture;
8531 texture_desc.Width = current_texture->width;
8532 texture_desc.Height = current_texture->height;
8533 texture_desc.MipLevels = current_texture->miplevel_count;
8534 texture_desc.ArraySize = current_texture->array_size;
8535 texture_desc.Format = current_texture->format;
8537 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
8538 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
8541 if (srv)
8542 ID3D11ShaderResourceView_Release(srv);
8544 get_srv_desc(&srv_desc, &test->srv_desc);
8545 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
8546 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
8548 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8550 ps_constant.x = test->ps_constant;
8551 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
8553 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8555 draw_quad(&test_context);
8557 get_texture_readback(test_context.backbuffer, 0, &rb);
8558 for (y = 0; y < 4; ++y)
8560 for (x = 0; x < 4; ++x)
8562 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
8563 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
8564 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
8567 release_resource_readback(&rb);
8569 ID3D11PixelShader_Release(ps);
8570 ID3D11Texture2D_Release(texture);
8571 ID3D11ShaderResourceView_Release(srv);
8572 ID3D11SamplerState_Release(sampler);
8574 ID3D11Buffer_Release(cb);
8575 release_test_context(&test_context);
8578 static void test_cube_maps(void)
8580 struct shader
8582 const DWORD *code;
8583 size_t size;
8586 unsigned int i, j, sub_resource_idx, sub_resource_count;
8587 struct d3d11_test_context test_context;
8588 D3D11_TEXTURE2D_DESC texture_desc;
8589 const struct shader *current_ps;
8590 D3D_FEATURE_LEVEL feature_level;
8591 ID3D11ShaderResourceView *srv;
8592 ID3D11DeviceContext *context;
8593 ID3D11Texture2D *rtv_texture;
8594 ID3D11RenderTargetView *rtv;
8595 struct vec4 expected_result;
8596 ID3D11Resource *texture;
8597 ID3D11PixelShader *ps;
8598 ID3D11Device *device;
8599 float data[64 * 64];
8600 ID3D11Buffer *cb;
8601 HRESULT hr;
8602 RECT rect;
8603 struct
8605 unsigned int face;
8606 unsigned int level;
8607 unsigned int cube;
8608 unsigned int padding;
8609 } constant;
8611 static const DWORD ps_cube_code[] =
8613 #if 0
8614 TextureCube t;
8615 SamplerState s;
8617 uint face;
8618 uint level;
8620 float4 main(float4 position : SV_POSITION) : SV_Target
8622 float2 p;
8623 p.x = position.x / 640.0f;
8624 p.y = position.y / 480.0f;
8626 float3 coord;
8627 switch (face)
8629 case 0:
8630 coord = float3(1.0f, p.x, p.y);
8631 break;
8632 case 1:
8633 coord = float3(-1.0f, p.x, p.y);
8634 break;
8635 case 2:
8636 coord = float3(p.x, 1.0f, p.y);
8637 break;
8638 case 3:
8639 coord = float3(p.x, -1.0f, p.y);
8640 break;
8641 case 4:
8642 coord = float3(p.x, p.y, 1.0f);
8643 break;
8644 case 5:
8645 default:
8646 coord = float3(p.x, p.y, -1.0f);
8647 break;
8649 return t.SampleLevel(s, coord, level);
8651 #endif
8652 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
8653 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8654 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8655 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8656 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
8657 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
8658 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
8659 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
8660 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
8661 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
8662 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
8663 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
8664 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
8665 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
8666 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
8667 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
8668 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
8669 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
8670 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
8671 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
8672 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8673 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
8674 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
8675 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
8676 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
8678 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
8679 static const DWORD ps_cube_array_code[] =
8681 #if 0
8682 TextureCubeArray t;
8683 SamplerState s;
8685 uint face;
8686 uint level;
8687 uint cube;
8689 float4 main(float4 position : SV_POSITION) : SV_Target
8691 float2 p;
8692 p.x = position.x / 640.0f;
8693 p.y = position.y / 480.0f;
8695 float3 coord;
8696 switch (face)
8698 case 0:
8699 coord = float3(1.0f, p.x, p.y);
8700 break;
8701 case 1:
8702 coord = float3(-1.0f, p.x, p.y);
8703 break;
8704 case 2:
8705 coord = float3(p.x, 1.0f, p.y);
8706 break;
8707 case 3:
8708 coord = float3(p.x, -1.0f, p.y);
8709 break;
8710 case 4:
8711 coord = float3(p.x, p.y, 1.0f);
8712 break;
8713 case 5:
8714 default:
8715 coord = float3(p.x, p.y, -1.0f);
8716 break;
8718 return t.SampleLevel(s, float4(coord, cube), level);
8720 #endif
8721 0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
8722 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8723 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8724 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8725 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
8726 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
8727 0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
8728 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
8729 0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
8730 0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
8731 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
8732 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
8733 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
8734 0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
8735 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
8736 0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
8737 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
8738 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
8739 0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8740 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
8741 0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
8742 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
8743 0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
8744 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
8745 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
8746 0x00000001, 0x0100003e,
8748 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
8749 static const struct ps_test
8751 const struct shader *ps;
8752 unsigned int miplevel_count;
8753 unsigned int array_size;
8755 ps_tests[] =
8757 {&ps_cube, 1, 6},
8758 {&ps_cube, 2, 6},
8759 {&ps_cube, 3, 6},
8760 {&ps_cube, 0, 6},
8762 {&ps_cube_array, 1, 12},
8763 {&ps_cube_array, 2, 12},
8764 {&ps_cube_array, 3, 12},
8765 {&ps_cube_array, 0, 12},
8768 if (!init_test_context(&test_context, NULL))
8769 return;
8771 device = test_context.device;
8772 context = test_context.immediate_context;
8773 feature_level = ID3D11Device_GetFeatureLevel(device);
8775 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8776 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8777 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
8778 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8779 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
8780 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8782 memset(&constant, 0, sizeof(constant));
8783 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
8785 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8786 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8788 ps = NULL;
8789 current_ps = NULL;
8790 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
8792 const struct ps_test *test = &ps_tests[i];
8794 if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
8796 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
8797 continue;
8800 if (current_ps != test->ps)
8802 if (ps)
8803 ID3D11PixelShader_Release(ps);
8805 current_ps = test->ps;
8807 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
8808 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
8809 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8812 if (!test->miplevel_count)
8814 srv = NULL;
8815 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8817 memset(&expected_result, 0, sizeof(expected_result));
8819 memset(&constant, 0, sizeof(constant));
8820 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8821 draw_quad(&test_context);
8822 check_texture_vec4(rtv_texture, &expected_result, 0);
8823 constant.level = 1;
8824 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8825 draw_quad(&test_context);
8826 check_texture_vec4(rtv_texture, &expected_result, 0);
8827 continue;
8830 texture_desc.Width = 64;
8831 texture_desc.Height = 64;
8832 texture_desc.MipLevels = test->miplevel_count;
8833 texture_desc.ArraySize = test->array_size;
8834 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
8835 texture_desc.SampleDesc.Count = 1;
8836 texture_desc.SampleDesc.Quality = 0;
8837 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8838 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
8839 texture_desc.CPUAccessFlags = 0;
8840 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
8841 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
8842 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
8844 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
8845 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
8846 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8848 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
8849 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
8851 for (j = 0; j < ARRAY_SIZE(data); ++j)
8852 data[j] = sub_resource_idx;
8853 ID3D11DeviceContext_UpdateSubresource(context, texture, sub_resource_idx, NULL, data,
8854 texture_desc.Width * sizeof(*data), 0);
8857 expected_result.y = expected_result.z = 0.0f;
8858 expected_result.w = 1.0f;
8859 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
8861 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
8862 constant.level = sub_resource_idx % texture_desc.MipLevels;
8863 constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
8864 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8866 draw_quad(&test_context);
8867 expected_result.x = sub_resource_idx;
8868 /* Avoid testing values affected by seamless cube map filtering. */
8869 SetRect(&rect, 100, 100, 540, 380);
8870 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
8873 ID3D11Resource_Release(texture);
8874 ID3D11ShaderResourceView_Release(srv);
8876 ID3D11PixelShader_Release(ps);
8878 ID3D11Buffer_Release(cb);
8879 ID3D11RenderTargetView_Release(rtv);
8880 ID3D11Texture2D_Release(rtv_texture);
8881 release_test_context(&test_context);
8884 static void test_depth_stencil_sampling(void)
8886 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
8887 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
8888 ID3D11SamplerState *cmp_sampler, *sampler;
8889 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8890 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
8891 struct d3d11_test_context test_context;
8892 ID3D11Texture2D *texture, *rt_texture;
8893 D3D11_TEXTURE2D_DESC texture_desc;
8894 D3D11_SAMPLER_DESC sampler_desc;
8895 ID3D11DeviceContext *context;
8896 ID3D11DepthStencilView *dsv;
8897 ID3D11RenderTargetView *rtv;
8898 struct vec4 ps_constant;
8899 ID3D11Device *device;
8900 ID3D11Buffer *cb;
8901 unsigned int i;
8902 HRESULT hr;
8904 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
8905 static const DWORD ps_compare_code[] =
8907 #if 0
8908 Texture2D t;
8909 SamplerComparisonState s;
8911 float ref;
8913 float4 main(float4 position : SV_Position) : SV_Target
8915 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
8917 #endif
8918 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
8919 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8920 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
8921 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8922 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
8923 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
8924 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
8925 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
8926 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
8927 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
8928 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
8929 0x0100003e,
8931 static const DWORD ps_sample_code[] =
8933 #if 0
8934 Texture2D t;
8935 SamplerState s;
8937 float4 main(float4 position : SV_Position) : SV_Target
8939 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
8941 #endif
8942 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
8943 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8944 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
8945 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8946 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
8947 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
8948 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
8949 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8950 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
8951 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
8953 static const DWORD ps_stencil_code[] =
8955 #if 0
8956 Texture2D<uint4> t;
8958 float4 main(float4 position : SV_Position) : SV_Target
8960 float2 s;
8961 t.GetDimensions(s.x, s.y);
8962 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
8964 #endif
8965 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
8966 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8967 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
8968 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8969 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
8970 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
8971 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
8972 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
8973 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
8974 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
8975 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
8976 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8977 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
8979 static const DWORD ps_depth_stencil_code[] =
8981 #if 0
8982 SamplerState samp;
8983 Texture2D depth_tex;
8984 Texture2D<uint4> stencil_tex;
8986 float main(float4 position: SV_Position) : SV_Target
8988 float2 s, p;
8989 float depth, stencil;
8990 depth_tex.GetDimensions(s.x, s.y);
8991 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
8992 depth = depth_tex.Sample(samp, p).r;
8993 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
8994 return depth + stencil;
8996 #endif
8997 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
8998 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8999 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
9000 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9001 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
9002 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9003 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9004 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
9005 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
9006 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
9007 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
9008 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
9009 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
9010 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
9011 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
9012 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
9014 static const struct test
9016 DXGI_FORMAT typeless_format;
9017 DXGI_FORMAT dsv_format;
9018 DXGI_FORMAT depth_view_format;
9019 DXGI_FORMAT stencil_view_format;
9021 tests[] =
9023 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
9024 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
9025 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
9026 DXGI_FORMAT_R32_FLOAT},
9027 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
9028 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
9029 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
9030 DXGI_FORMAT_R16_UNORM},
9033 if (!init_test_context(&test_context, NULL))
9034 return;
9036 device = test_context.device;
9037 context = test_context.immediate_context;
9039 if (is_amd_device(device))
9041 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
9042 win_skip("Some AMD drivers have a bug affecting the test.\n");
9043 release_test_context(&test_context);
9044 return;
9047 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
9048 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
9049 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
9050 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
9051 sampler_desc.MipLODBias = 0.0f;
9052 sampler_desc.MaxAnisotropy = 0;
9053 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
9054 sampler_desc.BorderColor[0] = 0.0f;
9055 sampler_desc.BorderColor[1] = 0.0f;
9056 sampler_desc.BorderColor[2] = 0.0f;
9057 sampler_desc.BorderColor[3] = 0.0f;
9058 sampler_desc.MinLOD = 0.0f;
9059 sampler_desc.MaxLOD = 0.0f;
9060 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
9061 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9063 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
9064 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
9065 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
9066 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9068 texture_desc.Width = 640;
9069 texture_desc.Height = 480;
9070 texture_desc.MipLevels = 1;
9071 texture_desc.ArraySize = 1;
9072 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
9073 texture_desc.SampleDesc.Count = 1;
9074 texture_desc.SampleDesc.Quality = 0;
9075 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9076 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9077 texture_desc.CPUAccessFlags = 0;
9078 texture_desc.MiscFlags = 0;
9079 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
9080 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9081 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
9082 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
9083 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9085 memset(&ps_constant, 0, sizeof(ps_constant));
9086 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
9087 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9089 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
9090 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9091 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
9092 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9093 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
9094 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9095 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
9096 &ps_depth_stencil);
9097 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9099 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9101 texture_desc.Format = tests[i].typeless_format;
9102 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
9103 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9104 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
9105 texture_desc.Format, hr);
9107 dsv_desc.Format = tests[i].dsv_format;
9108 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
9109 dsv_desc.Flags = 0;
9110 U(dsv_desc).Texture2D.MipSlice = 0;
9111 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
9112 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
9113 dsv_desc.Format, hr);
9115 srv_desc.Format = tests[i].depth_view_format;
9116 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
9117 U(srv_desc).Texture2D.MostDetailedMip = 0;
9118 U(srv_desc).Texture2D.MipLevels = 1;
9119 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
9120 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
9121 srv_desc.Format, hr);
9123 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
9124 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
9125 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
9127 ps_constant.x = 0.5f;
9128 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
9129 NULL, &ps_constant, 0, 0);
9131 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
9132 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
9133 draw_quad(&test_context);
9134 check_texture_float(rt_texture, 0.0f, 2);
9136 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
9137 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
9138 draw_quad(&test_context);
9139 check_texture_float(rt_texture, 1.0f, 2);
9141 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
9142 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
9143 draw_quad(&test_context);
9144 check_texture_float(rt_texture, 0.0f, 2);
9146 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
9147 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
9148 draw_quad(&test_context);
9149 check_texture_float(rt_texture, 0.0f, 2);
9151 ps_constant.x = 0.7f;
9152 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
9153 NULL, &ps_constant, 0, 0);
9155 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
9156 draw_quad(&test_context);
9157 check_texture_float(rt_texture, 1.0f, 2);
9159 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
9160 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
9162 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
9163 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
9164 draw_quad(&test_context);
9165 check_texture_float(rt_texture, 1.0f, 2);
9167 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
9168 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
9169 draw_quad(&test_context);
9170 check_texture_float(rt_texture, 0.2f, 2);
9172 if (!tests[i].stencil_view_format)
9174 ID3D11DepthStencilView_Release(dsv);
9175 ID3D11ShaderResourceView_Release(depth_srv);
9176 ID3D11Texture2D_Release(texture);
9177 continue;
9180 srv_desc.Format = tests[i].stencil_view_format;
9181 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
9182 if (hr == E_OUTOFMEMORY)
9184 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
9185 ID3D11DepthStencilView_Release(dsv);
9186 ID3D11ShaderResourceView_Release(depth_srv);
9187 ID3D11Texture2D_Release(texture);
9188 continue;
9190 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
9191 srv_desc.Format, hr);
9193 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
9194 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
9196 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
9197 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
9198 draw_quad(&test_context);
9199 check_texture_float(rt_texture, 0.0f, 0);
9201 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
9202 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
9203 draw_quad(&test_context);
9204 check_texture_float(rt_texture, 100.0f, 0);
9206 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
9207 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
9208 draw_quad(&test_context);
9209 check_texture_float(rt_texture, 255.0f, 0);
9211 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
9212 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
9213 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
9215 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
9216 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
9217 draw_quad(&test_context);
9218 check_texture_float(rt_texture, 3.3f, 2);
9220 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
9221 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
9222 draw_quad(&test_context);
9223 check_texture_float(rt_texture, 4.0f, 2);
9225 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
9226 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
9227 draw_quad(&test_context);
9228 check_texture_float(rt_texture, 0.0f, 2);
9230 ID3D11DepthStencilView_Release(dsv);
9231 ID3D11ShaderResourceView_Release(depth_srv);
9232 ID3D11ShaderResourceView_Release(stencil_srv);
9233 ID3D11Texture2D_Release(texture);
9236 ID3D11Buffer_Release(cb);
9237 ID3D11PixelShader_Release(ps_cmp);
9238 ID3D11PixelShader_Release(ps_depth);
9239 ID3D11PixelShader_Release(ps_depth_stencil);
9240 ID3D11PixelShader_Release(ps_stencil);
9241 ID3D11RenderTargetView_Release(rtv);
9242 ID3D11SamplerState_Release(cmp_sampler);
9243 ID3D11SamplerState_Release(sampler);
9244 ID3D11Texture2D_Release(rt_texture);
9245 release_test_context(&test_context);
9248 static void test_sample_c_lz(void)
9250 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
9251 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
9252 struct d3d11_test_context test_context;
9253 ID3D11Texture2D *texture, *rt_texture;
9254 D3D11_TEXTURE2D_DESC texture_desc;
9255 D3D11_SAMPLER_DESC sampler_desc;
9256 ID3D11ShaderResourceView *srv;
9257 ID3D11DeviceContext *context;
9258 ID3D11DepthStencilView *dsv;
9259 ID3D11RenderTargetView *rtv;
9260 ID3D11SamplerState *sampler;
9261 struct vec4 ps_constant;
9262 ID3D11PixelShader *ps;
9263 ID3D11Device *device;
9264 ID3D11Buffer *cb;
9265 unsigned int i;
9266 HRESULT hr;
9267 RECT rect;
9269 static const float clear_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
9270 static const DWORD ps_array_code[] =
9272 #if 0
9273 Texture2DArray t;
9274 SamplerComparisonState s;
9276 float ref;
9277 float layer;
9279 float4 main(float4 position : SV_Position) : SV_Target
9281 return t.SampleCmpLevelZero(s, float3(position.x / 640.0f, position.y / 480.0f, layer), ref);
9283 #endif
9284 0x43425844, 0xfe28b3c3, 0xdd7ef404, 0x8d5874a1, 0x984ff182, 0x00000001, 0x00000180, 0x00000003,
9285 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9286 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
9287 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9288 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000e4, 0x00000041,
9289 0x00000039, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
9290 0x00000000, 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
9291 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
9292 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
9293 0x06000036, 0x00100042, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0c000047, 0x00100012,
9294 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000, 0x0020800a,
9295 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
9297 static const DWORD ps_cube_code[] =
9299 #if 0
9300 TextureCube t;
9301 SamplerComparisonState s;
9303 float ref;
9304 float face;
9306 float4 main(float4 position : SV_Position) : SV_Target
9308 float2 p;
9309 p.x = position.x / 640.0f;
9310 p.y = position.y / 480.0f;
9312 float3 coord;
9313 switch ((uint)face)
9315 case 0:
9316 coord = float3(1.0f, p.x, p.y);
9317 break;
9318 case 1:
9319 coord = float3(-1.0f, p.x, p.y);
9320 break;
9321 case 2:
9322 coord = float3(p.x, 1.0f, p.y);
9323 break;
9324 case 3:
9325 coord = float3(p.x, -1.0f, p.y);
9326 break;
9327 case 4:
9328 coord = float3(p.x, p.y, 1.0f);
9329 break;
9330 case 5:
9331 default:
9332 coord = float3(p.x, p.y, -1.0f);
9333 break;
9336 return t.SampleCmpLevelZero(s, coord, ref);
9338 #endif
9339 0x43425844, 0xde5655e5, 0x1b116fa1, 0xfce9e757, 0x41c28aac, 0x00000001, 0x00000328, 0x00000003,
9340 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9341 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
9342 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9343 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
9344 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
9345 0x00000000, 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
9346 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600001c, 0x00100012,
9347 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0300004c, 0x0010000a, 0x00000000, 0x03000006,
9348 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x3f800000, 0x0a000038,
9349 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889,
9350 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, 0x00100012, 0x00000000,
9351 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
9352 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000002,
9353 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000,
9354 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
9355 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
9356 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
9357 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, 0x0a000038, 0x00100032,
9358 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
9359 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x0100000a, 0x0a000038,
9360 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000,
9361 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x01000017,
9362 0x0c000047, 0x00100012, 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000,
9363 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006,
9364 0x00000000, 0x0100003e,
9366 static const float depth_values[] = {1.0f, 0.0f, 0.5f, 0.6f, 0.4f, 0.1f};
9367 static const struct
9369 unsigned int layer;
9370 float d_ref;
9371 float expected;
9373 tests[] =
9375 {0, 0.5f, 0.0f},
9376 {1, 0.5f, 1.0f},
9377 {2, 0.5f, 0.0f},
9378 {3, 0.5f, 0.0f},
9379 {4, 0.5f, 1.0f},
9380 {5, 0.5f, 1.0f},
9382 {0, 0.0f, 0.0f},
9383 {1, 0.0f, 0.0f},
9384 {2, 0.0f, 0.0f},
9385 {3, 0.0f, 0.0f},
9386 {4, 0.0f, 0.0f},
9387 {5, 0.0f, 0.0f},
9389 {0, 1.0f, 0.0f},
9390 {1, 1.0f, 1.0f},
9391 {2, 1.0f, 1.0f},
9392 {3, 1.0f, 1.0f},
9393 {4, 1.0f, 1.0f},
9394 {5, 1.0f, 1.0f},
9397 if (!init_test_context(&test_context, NULL))
9398 return;
9400 device = test_context.device;
9401 context = test_context.immediate_context;
9403 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
9404 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
9405 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
9406 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
9407 sampler_desc.MipLODBias = 0.0f;
9408 sampler_desc.MaxAnisotropy = 0;
9409 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
9410 sampler_desc.BorderColor[0] = 0.0f;
9411 sampler_desc.BorderColor[1] = 0.0f;
9412 sampler_desc.BorderColor[2] = 0.0f;
9413 sampler_desc.BorderColor[3] = 0.0f;
9414 sampler_desc.MinLOD = 0.0f;
9415 sampler_desc.MaxLOD = 10.0f;
9416 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
9417 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9419 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9420 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
9421 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
9422 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9423 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
9424 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9425 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9427 memset(&ps_constant, 0, sizeof(ps_constant));
9428 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
9430 /* 2D array texture */
9431 texture_desc.Width = 32;
9432 texture_desc.Height = 32;
9433 texture_desc.MipLevels = 2;
9434 texture_desc.ArraySize = ARRAY_SIZE(depth_values);
9435 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
9436 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
9437 texture_desc.MiscFlags = 0;
9438 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9439 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9441 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
9443 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
9444 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
9445 dsv_desc.Flags = 0;
9446 U(dsv_desc).Texture2DArray.MipSlice = 0;
9447 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
9448 U(dsv_desc).Texture2DArray.ArraySize = 1;
9450 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
9451 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
9452 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
9453 ID3D11DepthStencilView_Release(dsv);
9455 U(dsv_desc).Texture2DArray.MipSlice = 1;
9456 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
9457 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
9458 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
9459 ID3D11DepthStencilView_Release(dsv);
9462 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
9463 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
9464 U(srv_desc).Texture2DArray.MostDetailedMip = 0;
9465 U(srv_desc).Texture2DArray.MipLevels = ~0u;
9466 U(srv_desc).Texture2DArray.FirstArraySlice = 0;
9467 U(srv_desc).Texture2DArray.ArraySize = ~0u;
9468 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
9469 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9471 hr = ID3D11Device_CreatePixelShader(device, ps_array_code, sizeof(ps_array_code), NULL, &ps);
9472 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9474 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9475 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9476 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
9477 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
9479 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9481 ps_constant.x = tests[i].d_ref;
9482 ps_constant.y = tests[i].layer;
9483 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
9484 NULL, &ps_constant, 0, 0);
9485 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
9486 draw_quad(&test_context);
9487 check_texture_float(rt_texture, tests[i].expected, 2);
9490 ID3D11Texture2D_Release(texture);
9491 ID3D11ShaderResourceView_Release(srv);
9492 ID3D11PixelShader_Release(ps);
9494 /* cube texture */
9495 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
9496 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9497 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9499 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
9501 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
9502 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
9503 dsv_desc.Flags = 0;
9504 U(dsv_desc).Texture2DArray.MipSlice = 0;
9505 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
9506 U(dsv_desc).Texture2DArray.ArraySize = 1;
9508 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
9509 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
9510 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
9511 ID3D11DepthStencilView_Release(dsv);
9513 U(dsv_desc).Texture2DArray.MipSlice = 1;
9514 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
9515 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
9516 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
9517 ID3D11DepthStencilView_Release(dsv);
9520 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
9521 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
9522 U(srv_desc).TextureCube.MostDetailedMip = 0;
9523 U(srv_desc).TextureCube.MipLevels = ~0u;
9524 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
9525 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9527 hr = ID3D11Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), NULL, &ps);
9528 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9530 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9531 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9532 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
9533 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
9535 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9537 ps_constant.x = tests[i].d_ref;
9538 ps_constant.y = tests[i].layer;
9539 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
9540 NULL, &ps_constant, 0, 0);
9541 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
9542 draw_quad(&test_context);
9543 /* Avoid testing values affected by seamless cube map filtering. */
9544 SetRect(&rect, 100, 100, 540, 380);
9545 check_texture_sub_resource_float(rt_texture, 0, &rect, tests[i].expected, 2);
9548 ID3D11Texture2D_Release(texture);
9549 ID3D11ShaderResourceView_Release(srv);
9551 ID3D11Buffer_Release(cb);
9552 ID3D11PixelShader_Release(ps);
9553 ID3D11RenderTargetView_Release(rtv);
9554 ID3D11SamplerState_Release(sampler);
9555 ID3D11Texture2D_Release(rt_texture);
9556 release_test_context(&test_context);
9559 static void test_multiple_render_targets(void)
9561 ID3D11RenderTargetView *rtv[4], *tmp_rtv[4];
9562 D3D11_TEXTURE2D_DESC texture_desc;
9563 ID3D11InputLayout *input_layout;
9564 unsigned int stride, offset, i;
9565 ID3D11DeviceContext *context;
9566 ID3D11Texture2D *rt[4];
9567 ID3D11VertexShader *vs;
9568 ID3D11PixelShader *ps;
9569 ID3D11Device *device;
9570 ID3D11Buffer *vb;
9571 ULONG refcount;
9572 HRESULT hr;
9574 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9576 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
9578 static const DWORD vs_code[] =
9580 #if 0
9581 float4 main(float4 position : POSITION) : SV_POSITION
9583 return position;
9585 #endif
9586 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
9587 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9588 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
9589 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
9590 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
9591 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
9592 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
9594 static const DWORD ps_code[] =
9596 #if 0
9597 struct output
9599 float4 t1 : SV_TARGET0;
9600 float4 t2 : SV_Target1;
9601 float4 t3 : SV_TARGET2;
9602 float4 t4 : SV_Target3;
9605 output main(float4 position : SV_POSITION)
9607 struct output o;
9608 o.t1 = (float4)1.0f;
9609 o.t2 = (float4)0.5f;
9610 o.t3 = (float4)0.2f;
9611 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
9612 return o;
9614 #endif
9615 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
9616 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9617 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
9618 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
9619 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9620 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
9621 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
9622 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
9623 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
9624 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
9625 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
9626 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
9627 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
9628 0x3f800000, 0x0100003e,
9630 static const struct vec2 quad[] =
9632 {-1.0f, -1.0f},
9633 {-1.0f, 1.0f},
9634 { 1.0f, -1.0f},
9635 { 1.0f, 1.0f},
9637 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
9639 if (!(device = create_device(NULL)))
9641 skip("Failed to create device.\n");
9642 return;
9645 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9646 vs_code, sizeof(vs_code), &input_layout);
9647 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9649 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
9651 texture_desc.Width = 640;
9652 texture_desc.Height = 480;
9653 texture_desc.MipLevels = 1;
9654 texture_desc.ArraySize = 1;
9655 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9656 texture_desc.SampleDesc.Count = 1;
9657 texture_desc.SampleDesc.Quality = 0;
9658 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9659 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9660 texture_desc.CPUAccessFlags = 0;
9661 texture_desc.MiscFlags = 0;
9663 for (i = 0; i < ARRAY_SIZE(rt); ++i)
9665 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
9666 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
9668 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
9669 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
9672 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
9673 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9674 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9675 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9677 ID3D11Device_GetImmediateContext(device, &context);
9679 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
9680 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
9681 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9682 stride = sizeof(*quad);
9683 offset = 0;
9684 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
9685 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
9686 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9688 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
9690 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
9691 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
9692 ID3D11DeviceContext_Draw(context, 4, 0);
9693 check_texture_color(rt[0], 0xffffffff, 2);
9694 check_texture_color(rt[1], 0x7f7f7f7f, 2);
9695 check_texture_color(rt[2], 0x33333333, 2);
9696 check_texture_color(rt[3], 0xff7f3300, 2);
9698 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
9699 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
9700 for (i = 0; i < ARRAY_SIZE(tmp_rtv); ++i)
9702 memset(tmp_rtv, 0, sizeof(tmp_rtv));
9703 tmp_rtv[i] = rtv[i];
9704 ID3D11DeviceContext_OMSetRenderTargets(context, 4, tmp_rtv, NULL);
9705 ID3D11DeviceContext_Draw(context, 4, 0);
9707 check_texture_color(rt[0], 0xffffffff, 2);
9708 check_texture_color(rt[1], 0x7f7f7f7f, 2);
9709 check_texture_color(rt[2], 0x33333333, 2);
9710 check_texture_color(rt[3], 0xff7f3300, 2);
9712 ID3D11Buffer_Release(vb);
9713 ID3D11PixelShader_Release(ps);
9714 ID3D11VertexShader_Release(vs);
9715 ID3D11InputLayout_Release(input_layout);
9716 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
9718 ID3D11RenderTargetView_Release(rtv[i]);
9719 ID3D11Texture2D_Release(rt[i]);
9721 ID3D11DeviceContext_Release(context);
9722 refcount = ID3D11Device_Release(device);
9723 ok(!refcount, "Device has %u references left.\n", refcount);
9726 static void test_render_target_views(void)
9728 struct texture
9730 UINT miplevel_count;
9731 UINT array_size;
9734 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
9735 static struct test
9737 struct texture texture;
9738 struct rtv_desc rtv;
9739 DWORD expected_colors[4];
9741 tests[] =
9743 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
9744 {0xff0000ff, 0x00000000}},
9745 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
9746 {0x00000000, 0xff0000ff}},
9747 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
9748 {0xff0000ff, 0x00000000}},
9749 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
9750 {0x00000000, 0xff0000ff}},
9751 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
9752 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
9753 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
9754 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
9755 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
9756 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
9757 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
9758 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
9759 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
9760 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
9761 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
9762 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
9763 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
9764 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
9765 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
9766 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
9767 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
9768 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
9769 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
9770 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
9771 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
9772 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
9774 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
9775 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
9776 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
9777 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
9778 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
9779 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
9780 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
9781 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
9782 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
9783 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
9784 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
9785 static const struct
9787 struct
9789 D3D11_RTV_DIMENSION dimension;
9790 unsigned int miplevel_count;
9791 unsigned int depth_or_array_size;
9792 DXGI_FORMAT format;
9793 } texture;
9794 struct rtv_desc rtv_desc;
9796 invalid_desc_tests[] =
9798 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
9799 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
9800 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
9801 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
9802 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
9803 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
9804 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
9805 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
9806 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
9807 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
9808 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
9809 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
9810 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
9811 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
9812 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
9813 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}},
9814 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
9815 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
9816 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
9817 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
9818 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
9819 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
9820 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
9821 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
9822 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
9823 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
9824 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
9825 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
9826 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
9827 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
9828 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
9829 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
9830 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
9831 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
9832 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
9833 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
9834 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
9836 #undef FMT_UNKNOWN
9837 #undef RGBA8_UNORM
9838 #undef RGBA8_SRGB
9839 #undef RGBA8_UINT
9840 #undef RGBA8_TL
9841 #undef DIM_UNKNOWN
9842 #undef TEX_1D
9843 #undef TEX_1D_ARRAY
9844 #undef TEX_2D
9845 #undef TEX_2D_ARRAY
9846 #undef TEX_3D
9848 struct d3d11_test_context test_context;
9849 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
9850 D3D11_TEXTURE3D_DESC texture3d_desc;
9851 D3D11_TEXTURE2D_DESC texture_desc;
9852 ID3D11DeviceContext *context;
9853 ID3D11RenderTargetView *rtv;
9854 ID3D11Texture3D *texture3d;
9855 ID3D11Texture2D *texture;
9856 ID3D11Resource *resource;
9857 ID3D11Device *device;
9858 unsigned int i, j, k;
9859 void *data;
9860 HRESULT hr;
9862 if (!init_test_context(&test_context, NULL))
9863 return;
9865 device = test_context.device;
9866 context = test_context.immediate_context;
9868 texture_desc.Width = 32;
9869 texture_desc.Height = 32;
9870 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9871 texture_desc.SampleDesc.Count = 1;
9872 texture_desc.SampleDesc.Quality = 0;
9873 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9874 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9875 texture_desc.CPUAccessFlags = 0;
9876 texture_desc.MiscFlags = 0;
9878 data = heap_alloc_zero(texture_desc.Width * texture_desc.Height * 4);
9879 ok(!!data, "Failed to allocate memory.\n");
9881 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9883 const struct test *test = &tests[i];
9884 unsigned int sub_resource_count;
9886 texture_desc.MipLevels = test->texture.miplevel_count;
9887 texture_desc.ArraySize = test->texture.array_size;
9889 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9890 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
9892 get_rtv_desc(&rtv_desc, &test->rtv);
9893 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
9894 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
9896 for (j = 0; j < texture_desc.ArraySize; ++j)
9898 for (k = 0; k < texture_desc.MipLevels; ++k)
9900 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
9901 ID3D11DeviceContext_UpdateSubresource(context,
9902 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
9905 check_texture_color(texture, 0, 0);
9907 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9908 draw_color_quad(&test_context, &red);
9910 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
9911 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
9912 for (j = 0; j < sub_resource_count; ++j)
9913 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
9915 ID3D11RenderTargetView_Release(rtv);
9916 ID3D11Texture2D_Release(texture);
9919 texture3d_desc.Width = 32;
9920 texture3d_desc.Height = 32;
9921 texture3d_desc.Depth = 32;
9922 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9923 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
9924 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9925 texture3d_desc.CPUAccessFlags = 0;
9926 texture3d_desc.MiscFlags = 0;
9928 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
9930 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
9931 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
9933 if (invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
9935 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
9936 texture_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
9937 texture_desc.Format = invalid_desc_tests[i].texture.format;
9938 texture_desc.MiscFlags = 0;
9940 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9941 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
9942 resource = (ID3D11Resource *)texture;
9944 else
9946 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
9947 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
9948 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
9950 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
9951 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
9952 resource = (ID3D11Resource *)texture3d;
9955 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
9956 hr = ID3D11Device_CreateRenderTargetView(device, resource, &rtv_desc, &rtv);
9957 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
9959 ID3D11Resource_Release(resource);
9962 heap_free(data);
9963 release_test_context(&test_context);
9966 static void test_layered_rendering(void)
9968 struct
9970 unsigned int layer_offset;
9971 unsigned int draw_id;
9972 unsigned int padding[2];
9973 } constant;
9974 struct d3d11_test_context test_context;
9975 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
9976 unsigned int i, sub_resource_count;
9977 D3D11_TEXTURE2D_DESC texture_desc;
9978 ID3D11DeviceContext *context;
9979 ID3D11RenderTargetView *rtv;
9980 ID3D11Texture2D *texture;
9981 ID3D11GeometryShader *gs;
9982 ID3D11VertexShader *vs;
9983 ID3D11PixelShader *ps;
9984 ID3D11Device *device;
9985 ID3D11Buffer *cb;
9986 HRESULT hr;
9987 BOOL warp;
9989 static const DWORD vs_code[] =
9991 #if 0
9992 uint layer_offset;
9994 void main(float4 position : POSITION,
9995 out float4 out_position : SV_POSITION,
9996 out uint layer : SV_RenderTargetArrayIndex)
9998 out_position = position;
9999 layer = layer_offset;
10001 #endif
10002 0x43425844, 0x71f7b9cd, 0x2ab8c713, 0x53e77663, 0x54a9ba68, 0x00000001, 0x00000158, 0x00000004,
10003 0x00000030, 0x00000064, 0x000000cc, 0x00000148, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
10004 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954,
10005 0xababab00, 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
10006 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001,
10007 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567,
10008 0x79617272, 0x65646e49, 0xabab0078, 0x52444853, 0x00000074, 0x00010040, 0x0000001d, 0x04000059,
10009 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2,
10010 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x05000036, 0x001020f2,
10011 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020800a, 0x00000000,
10012 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00002000, 0x00000000,
10014 static const DWORD gs_5_code[] =
10016 #if 0
10017 uint layer_offset;
10019 struct gs_in
10021 float4 pos : SV_Position;
10024 struct gs_out
10026 float4 pos : SV_Position;
10027 uint layer : SV_RenderTargetArrayIndex;
10030 [instance(4)]
10031 [maxvertexcount(3)]
10032 void main(triangle gs_in vin[3], in uint instance_id : SV_GSInstanceID,
10033 inout TriangleStream<gs_out> vout)
10035 gs_out o;
10036 o.layer = layer_offset + instance_id;
10037 for (uint i = 0; i < 3; ++i)
10039 o.pos = vin[i].pos;
10040 vout.Append(o);
10043 #endif
10044 0x43425844, 0xb52da162, 0x9a13d8ee, 0xf7c30b50, 0xe80bc2e7, 0x00000001, 0x00000218, 0x00000003,
10045 0x0000002c, 0x00000060, 0x000000d0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10046 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
10047 0x3547534f, 0x00000068, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
10048 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000004, 0x00000001,
10049 0x00000001, 0x00000e01, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472,
10050 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x58454853, 0x00000140, 0x00020050, 0x00000050,
10051 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
10052 0x00000000, 0x00000001, 0x0200005f, 0x00025000, 0x02000068, 0x00000001, 0x020000ce, 0x00000004,
10053 0x0100185d, 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
10054 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x00000003, 0x0700001e,
10055 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0002500a, 0x05000036, 0x00100022,
10056 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a,
10057 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000, 0x07000036, 0x001020f2,
10058 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001,
10059 0x0010000a, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x0700001e, 0x00100022, 0x00000000,
10060 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
10062 static const DWORD gs_4_code[] =
10064 #if 0
10065 uint layer_offset;
10067 struct gs_in
10069 float4 pos : SV_Position;
10072 struct gs_out
10074 float4 pos : SV_Position;
10075 uint layer : SV_RenderTargetArrayIndex;
10078 [maxvertexcount(12)]
10079 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
10081 gs_out o;
10082 for (uint instance_id = 0; instance_id < 4; ++instance_id)
10084 o.layer = layer_offset + instance_id;
10085 for (uint i = 0; i < 3; ++i)
10087 o.pos = vin[i].pos;
10088 vout.Append(o);
10090 vout.RestartStrip();
10093 #endif
10094 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
10095 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10096 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
10097 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10098 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
10099 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
10100 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
10101 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
10102 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
10103 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
10104 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
10105 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
10106 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
10107 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
10108 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
10109 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
10110 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
10111 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
10112 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
10114 static const DWORD ps_code[] =
10116 #if 0
10117 uint layer_offset;
10118 uint draw_id;
10120 float4 main(in float4 pos : SV_Position,
10121 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
10123 return float4(layer, draw_id, 0, 0);
10125 #endif
10126 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
10127 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
10128 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
10129 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
10130 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
10131 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
10132 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
10133 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
10134 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
10135 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
10136 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
10138 static const struct vec4 expected_values[] =
10140 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
10141 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
10142 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
10143 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
10145 static const struct vec4 vs_expected_value = {1.0f, 42.0f};
10147 if (!init_test_context(&test_context, NULL))
10148 return;
10150 device = test_context.device;
10151 context = test_context.immediate_context;
10153 warp = is_warp_device(device);
10155 memset(&constant, 0, sizeof(constant));
10156 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
10157 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
10158 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
10159 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10161 /* Geometry shader instancing seems broken on WARP. */
10162 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0 || warp)
10164 hr = ID3D11Device_CreateGeometryShader(device, gs_4_code, sizeof(gs_4_code), NULL, &gs);
10165 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
10167 else
10169 hr = ID3D11Device_CreateGeometryShader(device, gs_5_code, sizeof(gs_5_code), NULL, &gs);
10170 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
10172 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
10174 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10175 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10176 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10178 texture_desc.Width = 32;
10179 texture_desc.Height = 32;
10180 texture_desc.MipLevels = 3;
10181 texture_desc.ArraySize = 8;
10182 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10183 texture_desc.SampleDesc.Count = 1;
10184 texture_desc.SampleDesc.Quality = 0;
10185 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10186 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10187 texture_desc.CPUAccessFlags = 0;
10188 texture_desc.MiscFlags = 0;
10189 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10190 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10192 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
10193 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10194 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10195 constant.layer_offset = 0;
10196 constant.draw_id = 0;
10197 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10198 draw_quad(&test_context);
10199 constant.layer_offset = 4;
10200 constant.draw_id = 1;
10201 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10202 draw_quad(&test_context);
10203 ID3D11RenderTargetView_Release(rtv);
10205 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
10206 rtv_desc.Format = texture_desc.Format;
10207 U(rtv_desc).Texture2DArray.MipSlice = 0;
10208 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
10209 U(rtv_desc).Texture2DArray.ArraySize = 1;
10210 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
10211 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10212 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10213 constant.layer_offset = 1;
10214 constant.draw_id = 2;
10215 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10216 draw_quad(&test_context);
10217 ID3D11RenderTargetView_Release(rtv);
10219 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
10220 U(rtv_desc).Texture2DArray.MipSlice = 1;
10221 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
10222 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
10223 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
10224 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10225 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10226 constant.layer_offset = 0;
10227 constant.draw_id = 3;
10228 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10229 draw_quad(&test_context);
10230 constant.layer_offset = 4;
10231 constant.draw_id = 3;
10232 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10233 draw_quad(&test_context);
10234 ID3D11RenderTargetView_Release(rtv);
10236 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
10237 U(rtv_desc).Texture2DArray.MipSlice = 2;
10238 U(rtv_desc).Texture2DArray.ArraySize = 1;
10239 for (i = 0; i < texture_desc.ArraySize; ++i)
10241 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
10242 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
10243 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10244 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10245 constant.layer_offset = 0;
10246 constant.draw_id = 4 + i;
10247 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10248 draw_quad(&test_context);
10249 ID3D11RenderTargetView_Release(rtv);
10252 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
10253 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
10254 for (i = 0; i < sub_resource_count; ++i)
10256 if (warp && (i == 3 || i == 4)) /* Broken on WARP. */
10257 continue;
10258 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
10261 /* layered rendering without GS */
10262 if (!check_viewport_array_index_from_any_shader_support(device))
10264 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
10265 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10266 if (SUCCEEDED(hr))
10267 ID3D11VertexShader_Release(vs);
10268 skip("Viewport array index not supported in vertex shaders.\n");
10269 goto done;
10272 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
10274 constant.layer_offset = 1;
10275 constant.draw_id = 42;
10276 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10277 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
10278 U(rtv_desc).Texture2DArray.MipSlice = 0;
10279 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
10280 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
10281 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
10282 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
10283 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10284 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
10285 check_texture_sub_resource_vec4(texture,
10286 constant.layer_offset * texture_desc.MipLevels, NULL, &vs_expected_value, 1);
10287 ID3D11RenderTargetView_Release(rtv);
10289 done:
10290 ID3D11Texture2D_Release(texture);
10292 ID3D11Buffer_Release(cb);
10293 ID3D11GeometryShader_Release(gs);
10294 ID3D11PixelShader_Release(ps);
10295 release_test_context(&test_context);
10298 static void test_scissor(void)
10300 struct d3d11_test_context test_context;
10301 ID3D11DeviceContext *immediate_context;
10302 D3D11_RASTERIZER_DESC rs_desc;
10303 ID3D11RasterizerState *rs;
10304 D3D11_RECT scissor_rect;
10305 ID3D11Device *device;
10306 DWORD color;
10307 HRESULT hr;
10309 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
10310 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
10312 if (!init_test_context(&test_context, NULL))
10313 return;
10315 device = test_context.device;
10316 immediate_context = test_context.immediate_context;
10318 rs_desc.FillMode = D3D11_FILL_SOLID;
10319 rs_desc.CullMode = D3D11_CULL_BACK;
10320 rs_desc.FrontCounterClockwise = FALSE;
10321 rs_desc.DepthBias = 0;
10322 rs_desc.DepthBiasClamp = 0.0f;
10323 rs_desc.SlopeScaledDepthBias = 0.0f;
10324 rs_desc.DepthClipEnable = TRUE;
10325 rs_desc.ScissorEnable = TRUE;
10326 rs_desc.MultisampleEnable = FALSE;
10327 rs_desc.AntialiasedLineEnable = FALSE;
10328 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
10329 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
10331 SetRect(&scissor_rect, 160, 120, 480, 360);
10332 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
10334 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
10335 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
10337 draw_color_quad(&test_context, &green);
10338 color = get_texture_color(test_context.backbuffer, 320, 60);
10339 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10340 color = get_texture_color(test_context.backbuffer, 80, 240);
10341 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10342 color = get_texture_color(test_context.backbuffer, 320, 240);
10343 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10344 color = get_texture_color(test_context.backbuffer, 560, 240);
10345 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10346 color = get_texture_color(test_context.backbuffer, 320, 420);
10347 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10349 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
10350 ID3D11DeviceContext_RSSetState(immediate_context, rs);
10351 draw_color_quad(&test_context, &green);
10352 color = get_texture_color(test_context.backbuffer, 320, 60);
10353 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10354 color = get_texture_color(test_context.backbuffer, 80, 240);
10355 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10356 color = get_texture_color(test_context.backbuffer, 320, 240);
10357 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10358 color = get_texture_color(test_context.backbuffer, 560, 240);
10359 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10360 color = get_texture_color(test_context.backbuffer, 320, 420);
10361 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10363 ID3D11RasterizerState_Release(rs);
10364 release_test_context(&test_context);
10367 static void test_clear_state(void)
10369 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
10370 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
10372 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10374 #if 0
10375 float4 main(float4 pos : POSITION) : POSITION
10377 return pos;
10379 #endif
10380 static const DWORD simple_vs[] =
10382 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
10383 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10384 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10385 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10386 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
10387 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
10388 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
10390 #if 0
10391 struct data
10393 float4 position : SV_Position;
10396 struct patch_constant_data
10398 float edges[3] : SV_TessFactor;
10399 float inside : SV_InsideTessFactor;
10402 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
10404 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
10405 output.inside = 1.0f;
10408 [domain("tri")]
10409 [outputcontrolpoints(3)]
10410 [partitioning("integer")]
10411 [outputtopology("triangle_ccw")]
10412 [patchconstantfunc("patch_constant")]
10413 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
10415 return input[i];
10418 [domain("tri")]
10419 void ds_main(patch_constant_data input,
10420 float3 tess_coord : SV_DomainLocation,
10421 const OutputPatch<data, 3> patch,
10422 out data output)
10424 output.position = tess_coord.x * patch[0].position
10425 + tess_coord.y * patch[1].position
10426 + tess_coord.z * patch[2].position;
10428 #endif
10429 static const DWORD simple_hs[] =
10431 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
10432 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
10433 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
10434 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
10435 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
10436 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
10437 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
10438 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
10439 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
10440 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
10441 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
10442 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
10443 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
10444 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
10445 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
10446 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
10447 0x00004001, 0x3f800000, 0x0100003e,
10449 static const DWORD simple_ds[] =
10451 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
10452 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
10453 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
10454 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
10455 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
10456 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
10457 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
10458 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
10459 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
10460 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
10461 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
10462 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
10463 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
10464 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
10465 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
10467 #if 0
10468 struct gs_out
10470 float4 pos : SV_POSITION;
10473 [maxvertexcount(4)]
10474 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
10476 float offset = 0.1 * vin[0].w;
10477 gs_out v;
10479 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
10480 vout.Append(v);
10481 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
10482 vout.Append(v);
10483 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
10484 vout.Append(v);
10485 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
10486 vout.Append(v);
10488 #endif
10489 static const DWORD simple_gs[] =
10491 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
10492 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10493 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10494 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
10495 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
10496 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
10497 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
10498 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
10499 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
10500 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
10501 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
10502 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
10503 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
10504 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
10505 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
10506 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
10507 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
10508 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
10510 #if 0
10511 float4 main(float4 color : COLOR) : SV_TARGET
10513 return color;
10515 #endif
10516 static const DWORD simple_ps[] =
10518 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
10519 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
10520 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
10521 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10522 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
10523 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
10524 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
10526 #if 0
10527 [numthreads(1, 1, 1)]
10528 void main() { }
10529 #endif
10530 static const DWORD simple_cs[] =
10532 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
10533 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10534 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
10535 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
10538 D3D11_VIEWPORT tmp_viewport[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
10539 ID3D11ShaderResourceView *tmp_srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
10540 ID3D11ShaderResourceView *srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
10541 ID3D11RenderTargetView *tmp_rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
10542 RECT tmp_rect[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
10543 ID3D11SamplerState *tmp_sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
10544 ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
10545 ID3D11Texture2D *rt_texture[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
10546 ID3D11Buffer *cb[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
10547 ID3D11Buffer *tmp_buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
10548 ID3D11SamplerState *sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
10549 ID3D11UnorderedAccessView *tmp_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
10550 ID3D11UnorderedAccessView *cs_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
10551 ID3D11Buffer *buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
10552 ID3D11Buffer *cs_uav_buffer[D3D11_PS_CS_UAV_REGISTER_COUNT];
10553 UINT offset[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
10554 UINT stride[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
10555 ID3D11Buffer *so_buffer[D3D11_SO_BUFFER_SLOT_COUNT];
10556 ID3D11InputLayout *tmp_input_layout, *input_layout;
10557 ID3D11DepthStencilState *tmp_ds_state, *ds_state;
10558 ID3D11BlendState *tmp_blend_state, *blend_state;
10559 ID3D11RasterizerState *tmp_rs_state, *rs_state;
10560 ID3D11Predicate *tmp_predicate, *predicate;
10561 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
10562 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10563 ID3D11DepthStencilView *tmp_dsv, *dsv;
10564 ID3D11UnorderedAccessView *ps_uav;
10565 D3D11_PRIMITIVE_TOPOLOGY topology;
10566 D3D11_TEXTURE2D_DESC texture_desc;
10567 ID3D11GeometryShader *tmp_gs, *gs;
10568 ID3D11ComputeShader *tmp_cs, *cs;
10569 D3D11_DEPTH_STENCIL_DESC ds_desc;
10570 ID3D11VertexShader *tmp_vs, *vs;
10571 ID3D11DomainShader *tmp_ds, *ds;
10572 D3D11_SAMPLER_DESC sampler_desc;
10573 D3D11_QUERY_DESC predicate_desc;
10574 struct device_desc device_desc;
10575 ID3D11PixelShader *tmp_ps, *ps;
10576 ID3D11HullShader *tmp_hs, *hs;
10577 D3D11_RASTERIZER_DESC rs_desc;
10578 ID3D11DeviceContext *context;
10579 D3D11_BLEND_DESC blend_desc;
10580 ID3D11Texture2D *ds_texture;
10581 ID3D11Buffer *ps_uav_buffer;
10582 float blend_factor[4];
10583 ID3D11Device *device;
10584 BOOL predicate_value;
10585 UINT instance_count;
10586 DXGI_FORMAT format;
10587 UINT sample_mask;
10588 UINT stencil_ref;
10589 ULONG refcount;
10590 UINT count, i;
10591 HRESULT hr;
10593 device_desc.feature_level = &feature_level;
10594 device_desc.flags = 0;
10595 if (!(device = create_device(&device_desc)))
10597 skip("Failed to create device.\n");
10598 return;
10601 ID3D11Device_GetImmediateContext(device, &context);
10603 /* Verify the initial state after device creation. */
10605 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10606 tmp_buffer);
10607 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10609 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
10611 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10612 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10614 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
10616 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10617 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10619 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
10621 instance_count = 100;
10622 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, &instance_count);
10623 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
10624 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
10626 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10627 tmp_buffer);
10628 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10630 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
10632 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10633 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10635 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
10637 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10638 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10640 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
10642 instance_count = 100;
10643 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, &instance_count);
10644 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
10645 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
10647 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10648 tmp_buffer);
10649 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10651 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
10653 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10654 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10656 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
10658 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10659 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10661 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
10663 instance_count = 100;
10664 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, &instance_count);
10665 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
10666 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
10668 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10669 tmp_buffer);
10670 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10672 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
10674 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10675 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10677 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
10679 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10680 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10682 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
10684 instance_count = 100;
10685 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, &instance_count);
10686 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
10687 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
10689 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10690 tmp_buffer);
10691 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10693 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
10695 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
10696 tmp_srv);
10697 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10699 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
10701 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10702 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10704 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
10706 instance_count = 100;
10707 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, &instance_count);
10708 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
10709 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
10711 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10712 tmp_buffer);
10713 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10715 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
10717 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
10718 tmp_srv);
10719 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10721 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
10723 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10724 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10726 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
10728 instance_count = 100;
10729 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, &instance_count);
10730 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
10731 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
10732 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
10733 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
10735 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
10738 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
10739 tmp_buffer, stride, offset);
10740 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
10742 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
10743 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
10744 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
10746 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
10747 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
10748 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
10749 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
10750 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
10751 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
10752 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
10753 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
10755 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
10756 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
10757 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
10758 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
10759 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
10760 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
10761 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
10762 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
10763 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
10764 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
10765 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
10766 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
10768 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
10770 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
10771 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
10772 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
10773 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
10774 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
10776 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
10778 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
10779 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
10781 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
10784 if (!enable_debug_layer)
10786 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
10787 ok(!count, "Got unexpected scissor rect count %u.\n", count);
10789 memset(tmp_rect, 0x55, sizeof(tmp_rect));
10790 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
10791 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
10792 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
10794 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
10795 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
10797 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
10798 ok(!count, "Got unexpected viewport count %u.\n", count);
10799 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
10800 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
10801 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
10802 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
10804 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
10805 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
10806 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
10807 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
10808 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
10810 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
10811 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
10813 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
10814 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
10816 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
10819 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
10820 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
10821 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
10823 /* Create resources. */
10825 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10826 cb[i] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 1024, NULL);
10828 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
10830 buffer[i] = create_buffer(device,
10831 D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_SHADER_RESOURCE,
10832 1024, NULL);
10834 stride[i] = (i + 1) * 4;
10835 offset[i] = (i + 1) * 16;
10838 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
10839 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
10841 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10842 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
10843 U(srv_desc).Buffer.ElementOffset = 0;
10844 U(srv_desc).Buffer.ElementWidth = 64;
10846 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10848 hr = ID3D11Device_CreateShaderResourceView(device,
10849 (ID3D11Resource *)buffer[i % D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
10850 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10853 uav_desc.Format = DXGI_FORMAT_R32_UINT;
10854 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
10855 U(uav_desc).Buffer.FirstElement = 0;
10856 U(uav_desc).Buffer.NumElements = 8;
10857 U(uav_desc).Buffer.Flags = 0;
10859 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
10861 cs_uav_buffer[i] = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
10862 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_uav_buffer[i],
10863 &uav_desc, &cs_uav[i]);
10864 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
10867 ps_uav_buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
10868 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_uav_buffer,
10869 &uav_desc, &ps_uav);
10870 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
10872 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
10873 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10874 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10875 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10876 sampler_desc.MipLODBias = 0.0f;
10877 sampler_desc.MaxAnisotropy = 16;
10878 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
10879 sampler_desc.BorderColor[0] = 0.0f;
10880 sampler_desc.BorderColor[1] = 0.0f;
10881 sampler_desc.BorderColor[2] = 0.0f;
10882 sampler_desc.BorderColor[3] = 0.0f;
10883 sampler_desc.MinLOD = 0.0f;
10884 sampler_desc.MaxLOD = 16.0f;
10886 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10888 sampler_desc.MinLOD = (float)i;
10890 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
10891 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10894 hr = ID3D11Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
10895 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10897 hr = ID3D11Device_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
10898 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
10900 hr = ID3D11Device_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
10901 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
10903 hr = ID3D11Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
10904 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
10906 hr = ID3D11Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
10907 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10909 hr = ID3D11Device_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
10910 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
10912 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10913 simple_vs, sizeof(simple_vs), &input_layout);
10914 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10916 memset(&blend_desc, 0, sizeof(blend_desc));
10917 blend_desc.AlphaToCoverageEnable = FALSE;
10918 blend_desc.IndependentBlendEnable = FALSE;
10919 blend_desc.RenderTarget[0].BlendEnable = TRUE;
10920 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
10921 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
10922 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
10923 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
10924 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
10925 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
10926 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
10928 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
10929 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
10931 ds_desc.DepthEnable = TRUE;
10932 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
10933 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
10934 ds_desc.StencilEnable = FALSE;
10935 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
10936 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
10937 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
10938 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
10939 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
10940 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
10941 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
10942 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
10943 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
10944 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
10946 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
10947 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
10949 texture_desc.Width = 512;
10950 texture_desc.Height = 512;
10951 texture_desc.MipLevels = 1;
10952 texture_desc.ArraySize = 1;
10953 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10954 texture_desc.SampleDesc.Count = 1;
10955 texture_desc.SampleDesc.Quality = 0;
10956 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10957 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10958 texture_desc.CPUAccessFlags = 0;
10959 texture_desc.MiscFlags = 0;
10961 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
10963 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
10964 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10967 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
10968 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
10970 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
10971 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10973 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
10975 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture[i], NULL, &rtv[i]);
10976 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10979 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)ds_texture, NULL, &dsv);
10980 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
10982 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
10984 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
10986 tmp_viewport[i].TopLeftX = i * 3;
10987 tmp_viewport[i].TopLeftY = i * 4;
10988 tmp_viewport[i].Width = 3;
10989 tmp_viewport[i].Height = 4;
10990 tmp_viewport[i].MinDepth = i * 0.01f;
10991 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
10994 rs_desc.FillMode = D3D11_FILL_SOLID;
10995 rs_desc.CullMode = D3D11_CULL_BACK;
10996 rs_desc.FrontCounterClockwise = FALSE;
10997 rs_desc.DepthBias = 0;
10998 rs_desc.DepthBiasClamp = 0.0f;
10999 rs_desc.SlopeScaledDepthBias = 0.0f;
11000 rs_desc.DepthClipEnable = TRUE;
11001 rs_desc.ScissorEnable = FALSE;
11002 rs_desc.MultisampleEnable = FALSE;
11003 rs_desc.AntialiasedLineEnable = FALSE;
11005 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs_state);
11006 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11008 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
11009 predicate_desc.MiscFlags = 0;
11011 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
11012 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
11014 /* Setup state. */
11016 /* Some versions of Windows AMD drivers hang while the device is being
11017 * released, if the total number of used resource slots exceeds some limit.
11018 * Do not use all constant buffers slots in order to not trigger this
11019 * driver bug. */
11020 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb[0]);
11021 ID3D11DeviceContext_VSSetConstantBuffers(context, 7, 1, &cb[7]);
11022 ID3D11DeviceContext_VSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
11023 ID3D11DeviceContext_VSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
11024 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11026 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb[0]);
11027 ID3D11DeviceContext_HSSetConstantBuffers(context, 7, 1, &cb[7]);
11028 ID3D11DeviceContext_HSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
11029 ID3D11DeviceContext_HSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
11030 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
11032 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
11033 ID3D11DeviceContext_DSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
11034 ID3D11DeviceContext_DSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
11035 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
11037 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
11038 ID3D11DeviceContext_GSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
11039 ID3D11DeviceContext_GSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
11040 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
11042 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
11043 ID3D11DeviceContext_PSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
11044 ID3D11DeviceContext_PSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
11045 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11047 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
11048 ID3D11DeviceContext_CSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
11049 ID3D11DeviceContext_CSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
11050 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
11051 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, cs_uav, NULL);
11053 ID3D11DeviceContext_IASetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
11054 buffer, stride, offset);
11055 ID3D11DeviceContext_IASetIndexBuffer(context, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
11056 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
11057 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11059 blend_factor[0] = 0.1f;
11060 blend_factor[1] = 0.2f;
11061 blend_factor[2] = 0.3f;
11062 blend_factor[3] = 0.4f;
11063 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, 0xff00ff00);
11064 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 3);
11065 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
11066 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, rtv, dsv,
11067 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, 1, &ps_uav, NULL);
11069 ID3D11DeviceContext_RSSetScissorRects(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
11070 tmp_rect);
11071 ID3D11DeviceContext_RSSetViewports(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
11072 tmp_viewport);
11073 ID3D11DeviceContext_RSSetState(context, rs_state);
11075 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
11077 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
11079 /* Verify the set state. */
11081 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11082 tmp_buffer);
11083 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11085 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
11086 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
11087 tmp_buffer[i], i, expected_cb);
11088 if (tmp_buffer[i])
11089 ID3D11Buffer_Release(tmp_buffer[i]);
11091 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11092 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11094 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
11095 tmp_srv[i], i, srv[i]);
11096 ID3D11ShaderResourceView_Release(tmp_srv[i]);
11098 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11099 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11101 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
11102 tmp_sampler[i], i, sampler[i]);
11103 ID3D11SamplerState_Release(tmp_sampler[i]);
11105 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
11106 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
11107 ID3D11VertexShader_Release(tmp_vs);
11109 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11110 tmp_buffer);
11111 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11113 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
11114 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
11115 tmp_buffer[i], i, expected_cb);
11116 if (tmp_buffer[i])
11117 ID3D11Buffer_Release(tmp_buffer[i]);
11119 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11120 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11122 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
11123 tmp_srv[i], i, srv[i]);
11124 ID3D11ShaderResourceView_Release(tmp_srv[i]);
11126 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11127 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11129 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
11130 tmp_sampler[i], i, sampler[i]);
11131 ID3D11SamplerState_Release(tmp_sampler[i]);
11133 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
11134 ok(tmp_hs == hs, "Got unexpected hull shader %p, expected %p.\n", tmp_hs, hs);
11135 ID3D11HullShader_Release(tmp_hs);
11137 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11138 tmp_buffer);
11139 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11141 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
11142 tmp_buffer[i], i, cb[i]);
11143 ID3D11Buffer_Release(tmp_buffer[i]);
11145 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11146 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11148 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
11149 tmp_srv[i], i, srv[i]);
11150 ID3D11ShaderResourceView_Release(tmp_srv[i]);
11152 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11153 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11155 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
11156 tmp_sampler[i], i, sampler[i]);
11157 ID3D11SamplerState_Release(tmp_sampler[i]);
11159 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
11160 ok(tmp_ds == ds, "Got unexpected domain shader %p, expected %p.\n", tmp_ds, ds);
11161 ID3D11DomainShader_Release(tmp_ds);
11163 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11164 tmp_buffer);
11165 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11167 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
11168 tmp_buffer[i], i, cb[i]);
11169 ID3D11Buffer_Release(tmp_buffer[i]);
11171 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11172 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11174 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
11175 tmp_srv[i], i, srv[i]);
11176 ID3D11ShaderResourceView_Release(tmp_srv[i]);
11178 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11179 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11181 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
11182 tmp_sampler[i], i, sampler[i]);
11183 ID3D11SamplerState_Release(tmp_sampler[i]);
11185 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
11186 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
11187 ID3D11GeometryShader_Release(tmp_gs);
11189 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11190 tmp_buffer);
11191 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11193 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
11194 tmp_buffer[i], i, cb[i]);
11195 ID3D11Buffer_Release(tmp_buffer[i]);
11197 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11198 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11200 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
11201 tmp_srv[i], i, srv[i]);
11202 ID3D11ShaderResourceView_Release(tmp_srv[i]);
11204 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11205 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11207 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
11208 tmp_sampler[i], i, sampler[i]);
11209 ID3D11SamplerState_Release(tmp_sampler[i]);
11211 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
11212 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
11213 ID3D11PixelShader_Release(tmp_ps);
11215 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11216 tmp_buffer);
11217 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11219 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
11220 tmp_buffer[i], i, cb[i]);
11221 ID3D11Buffer_Release(tmp_buffer[i]);
11223 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11224 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11226 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
11227 tmp_srv[i], i, srv[i]);
11228 ID3D11ShaderResourceView_Release(tmp_srv[i]);
11230 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11231 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11233 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
11234 tmp_sampler[i], i, sampler[i]);
11235 ID3D11SamplerState_Release(tmp_sampler[i]);
11237 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
11238 ok(tmp_cs == cs, "Got unexpected compute shader %p, expected %p.\n", tmp_cs, cs);
11239 ID3D11ComputeShader_Release(tmp_cs);
11240 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
11241 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
11243 ok(tmp_uav[i] == cs_uav[i], "Got unexpected unordered access view %p in slot %u, expected %p.\n",
11244 tmp_uav[i], i, cs_uav[i]);
11245 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
11248 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
11249 tmp_buffer, stride, offset);
11250 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
11252 todo_wine_if(i >= D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
11254 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
11255 tmp_buffer[i], i, buffer[i]);
11256 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
11257 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
11259 if (tmp_buffer[i])
11260 ID3D11Buffer_Release(tmp_buffer[i]);
11262 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
11263 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
11264 ID3D11Buffer_Release(tmp_buffer[0]);
11265 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
11266 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
11267 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
11268 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
11269 tmp_input_layout, input_layout);
11270 ID3D11InputLayout_Release(tmp_input_layout);
11271 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
11272 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
11274 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
11275 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
11276 ID3D11BlendState_Release(tmp_blend_state);
11277 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
11278 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
11279 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
11280 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
11281 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
11282 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
11283 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
11284 ID3D11DepthStencilState_Release(tmp_ds_state);
11285 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
11286 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
11287 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
11289 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
11290 tmp_rtv[i], i, rtv[i]);
11291 ID3D11RenderTargetView_Release(tmp_rtv[i]);
11293 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
11294 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
11295 ID3D11DepthStencilView_Release(tmp_dsv);
11296 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
11297 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
11298 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
11299 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
11301 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
11302 tmp_rtv[i], i, rtv[i]);
11303 ID3D11RenderTargetView_Release(tmp_rtv[i]);
11305 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
11306 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
11307 ID3D11DepthStencilView_Release(tmp_dsv);
11308 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT - 1; ++i)
11310 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
11312 ok(tmp_uav[i] == ps_uav, "Got unexpected unordered access view %p in slot %u, expected %p.\n",
11313 tmp_uav[i], i, ps_uav);
11314 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
11316 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
11317 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
11318 "Got unexpected scissor rect count %u.\n", count);
11319 memset(tmp_rect, 0x55, sizeof(tmp_rect));
11320 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
11321 for (i = 0; i < count; ++i)
11323 ok(tmp_rect[i].left == i
11324 && tmp_rect[i].top == i * 2
11325 && tmp_rect[i].right == i + 1
11326 && tmp_rect[i].bottom == (i + 1) * 2,
11327 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
11329 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
11330 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
11331 "Got unexpected viewport count %u.\n", count);
11332 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
11333 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
11334 for (i = 0; i < count; ++i)
11336 ok(tmp_viewport[i].TopLeftX == i * 3
11337 && tmp_viewport[i].TopLeftY == i * 4
11338 && tmp_viewport[i].Width == 3
11339 && tmp_viewport[i].Height == 4
11340 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
11341 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
11342 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
11343 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
11344 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
11346 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
11347 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
11348 ID3D11RasterizerState_Release(tmp_rs_state);
11350 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
11351 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
11353 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
11354 tmp_buffer[i], i, so_buffer[i]);
11355 ID3D11Buffer_Release(tmp_buffer[i]);
11358 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
11359 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
11360 ID3D11Predicate_Release(tmp_predicate);
11361 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
11363 /* Verify ClearState(). */
11365 ID3D11DeviceContext_ClearState(context);
11367 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11368 tmp_buffer);
11369 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11371 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11373 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11374 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11376 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11378 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11379 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11381 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11383 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
11384 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
11386 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11387 tmp_buffer);
11388 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11390 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11392 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11393 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11395 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11397 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11398 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11400 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11402 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
11403 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
11405 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11406 tmp_buffer);
11407 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11409 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11411 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11412 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11414 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11416 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11417 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11419 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11421 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
11422 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
11424 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11425 tmp_buffer);
11426 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11428 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11430 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11431 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11433 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11435 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11436 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11438 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11440 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
11441 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
11443 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11444 tmp_buffer);
11445 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11447 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11449 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11450 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11452 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11454 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11455 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11457 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11459 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
11460 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
11462 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11463 tmp_buffer);
11464 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11466 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11468 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
11469 tmp_srv);
11470 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11472 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11474 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11475 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11477 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11479 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
11480 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
11481 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
11482 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
11484 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
11487 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
11488 tmp_buffer, stride, offset);
11489 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
11491 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
11492 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
11493 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
11495 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
11496 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
11497 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
11498 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
11499 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
11500 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
11501 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
11502 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
11504 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
11505 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
11506 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
11507 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
11508 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
11509 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
11510 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
11511 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
11512 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
11513 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
11514 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
11515 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
11517 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
11519 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
11520 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
11521 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
11522 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
11523 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
11525 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
11527 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
11528 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
11530 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
11533 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
11534 ok(!count, "Got unexpected scissor rect count %u.\n", count);
11535 memset(tmp_rect, 0x55, sizeof(tmp_rect));
11536 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
11537 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
11538 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
11540 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
11541 "Got unexpected scissor rect %s in slot %u.\n",
11542 wine_dbgstr_rect(&tmp_rect[i]), i);
11544 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
11545 ok(!count, "Got unexpected viewport count %u.\n", count);
11546 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
11547 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
11548 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
11549 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
11551 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
11552 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
11553 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
11554 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
11555 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
11557 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
11558 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
11560 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
11561 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
11563 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
11566 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
11567 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
11568 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
11570 /* Cleanup. */
11572 ID3D11Predicate_Release(predicate);
11573 ID3D11RasterizerState_Release(rs_state);
11574 ID3D11DepthStencilView_Release(dsv);
11575 ID3D11Texture2D_Release(ds_texture);
11577 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
11579 ID3D11RenderTargetView_Release(rtv[i]);
11580 ID3D11Texture2D_Release(rt_texture[i]);
11583 ID3D11DepthStencilState_Release(ds_state);
11584 ID3D11BlendState_Release(blend_state);
11585 ID3D11InputLayout_Release(input_layout);
11586 ID3D11VertexShader_Release(vs);
11587 ID3D11HullShader_Release(hs);
11588 ID3D11DomainShader_Release(ds);
11589 ID3D11GeometryShader_Release(gs);
11590 ID3D11PixelShader_Release(ps);
11591 ID3D11ComputeShader_Release(cs);
11593 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11595 ID3D11SamplerState_Release(sampler[i]);
11598 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11600 ID3D11ShaderResourceView_Release(srv[i]);
11603 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
11605 ID3D11UnorderedAccessView_Release(cs_uav[i]);
11606 ID3D11Buffer_Release(cs_uav_buffer[i]);
11608 ID3D11UnorderedAccessView_Release(ps_uav);
11609 ID3D11Buffer_Release(ps_uav_buffer);
11611 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
11613 ID3D11Buffer_Release(so_buffer[i]);
11616 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
11618 ID3D11Buffer_Release(buffer[i]);
11621 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11623 ID3D11Buffer_Release(cb[i]);
11626 ID3D11DeviceContext_Release(context);
11627 refcount = ID3D11Device_Release(device);
11628 ok(!refcount, "Device has %u references left.\n", refcount);
11631 static void test_il_append_aligned(void)
11633 struct d3d11_test_context test_context;
11634 ID3D11InputLayout *input_layout;
11635 ID3D11DeviceContext *context;
11636 unsigned int stride, offset;
11637 ID3D11VertexShader *vs;
11638 ID3D11PixelShader *ps;
11639 ID3D11Device *device;
11640 ID3D11Buffer *vb[3];
11641 DWORD color;
11642 HRESULT hr;
11644 /* Semantic names are case-insensitive. */
11645 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11647 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
11648 D3D11_INPUT_PER_INSTANCE_DATA, 2},
11649 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
11650 D3D11_INPUT_PER_INSTANCE_DATA, 1},
11651 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
11652 D3D11_INPUT_PER_VERTEX_DATA, 0},
11653 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
11654 D3D11_INPUT_PER_INSTANCE_DATA, 1},
11655 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
11656 D3D11_INPUT_PER_INSTANCE_DATA, 2},
11658 static const DWORD vs_code[] =
11660 #if 0
11661 struct vs_in
11663 float4 position : POSITION;
11664 float2 color_xy : COLOR0;
11665 float2 color_zw : COLOR1;
11666 unsigned int instance_id : SV_INSTANCEID;
11669 struct vs_out
11671 float4 position : SV_POSITION;
11672 float2 color_xy : COLOR0;
11673 float2 color_zw : COLOR1;
11676 struct vs_out main(struct vs_in i)
11678 struct vs_out o;
11680 o.position = i.position;
11681 o.position.x += i.instance_id * 0.5;
11682 o.color_xy = i.color_xy;
11683 o.color_zw = i.color_zw;
11685 return o;
11687 #endif
11688 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
11689 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
11690 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
11691 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
11692 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
11693 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
11694 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
11695 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
11696 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
11697 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
11698 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
11699 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
11700 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
11701 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
11702 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
11703 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
11704 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
11706 static const DWORD ps_code[] =
11708 #if 0
11709 struct vs_out
11711 float4 position : SV_POSITION;
11712 float2 color_xy : COLOR0;
11713 float2 color_zw : COLOR1;
11716 float4 main(struct vs_out i) : SV_TARGET
11718 return float4(i.color_xy.xy, i.color_zw.xy);
11720 #endif
11721 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
11722 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
11723 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
11724 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
11725 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
11726 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
11727 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
11728 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11729 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
11731 static const struct
11733 struct vec4 position;
11735 stream0[] =
11737 {{-1.0f, -1.0f, 0.0f, 1.0f}},
11738 {{-1.0f, 1.0f, 0.0f, 1.0f}},
11739 {{-0.5f, -1.0f, 0.0f, 1.0f}},
11740 {{-0.5f, 1.0f, 0.0f, 1.0f}},
11742 static const struct
11744 struct vec2 color2;
11745 struct vec2 color1;
11747 stream1[] =
11749 {{0.5f, 0.5f}, {0.0f, 1.0f}},
11750 {{0.5f, 0.5f}, {1.0f, 1.0f}},
11752 static const struct
11754 struct vec2 color3;
11755 struct vec2 color0;
11757 stream2[] =
11759 {{0.5f, 0.5f}, {1.0f, 0.0f}},
11760 {{0.5f, 0.5f}, {0.0f, 1.0f}},
11761 {{0.5f, 0.5f}, {0.0f, 0.0f}},
11762 {{0.5f, 0.5f}, {1.0f, 0.0f}},
11764 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
11766 if (!init_test_context(&test_context, NULL))
11767 return;
11769 device = test_context.device;
11770 context = test_context.immediate_context;
11772 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11773 vs_code, sizeof(vs_code), &input_layout);
11774 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11776 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
11777 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
11778 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
11780 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11781 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11782 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11783 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11785 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
11786 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11787 offset = 0;
11788 stride = sizeof(*stream0);
11789 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
11790 stride = sizeof(*stream1);
11791 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
11792 stride = sizeof(*stream2);
11793 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
11794 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11795 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11797 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
11799 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
11801 color = get_texture_color(test_context.backbuffer, 80, 240);
11802 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11803 color = get_texture_color(test_context.backbuffer, 240, 240);
11804 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11805 color = get_texture_color(test_context.backbuffer, 400, 240);
11806 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
11807 color = get_texture_color(test_context.backbuffer, 560, 240);
11808 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
11810 ID3D11PixelShader_Release(ps);
11811 ID3D11VertexShader_Release(vs);
11812 ID3D11Buffer_Release(vb[2]);
11813 ID3D11Buffer_Release(vb[1]);
11814 ID3D11Buffer_Release(vb[0]);
11815 ID3D11InputLayout_Release(input_layout);
11816 release_test_context(&test_context);
11819 static void test_instance_id(void)
11821 struct d3d11_test_context test_context;
11822 D3D11_TEXTURE2D_DESC texture_desc;
11823 ID3D11InputLayout *input_layout;
11824 ID3D11RenderTargetView *rtvs[2];
11825 ID3D11Texture2D *render_target;
11826 ID3D11DeviceContext *context;
11827 struct resource_readback rb;
11828 unsigned int stride, offset;
11829 ID3D11Buffer *args_buffer;
11830 ID3D11VertexShader *vs;
11831 ID3D11PixelShader *ps;
11832 ID3D11Device *device;
11833 ID3D11Buffer *vb[2];
11834 unsigned int i;
11835 HRESULT hr;
11837 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11839 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
11840 D3D11_INPUT_PER_VERTEX_DATA, 0},
11841 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT,
11842 D3D11_INPUT_PER_INSTANCE_DATA, 1},
11843 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
11844 D3D11_INPUT_PER_INSTANCE_DATA, 1},
11846 static const DWORD vs_code[] =
11848 #if 0
11849 struct vs_in
11851 float4 position : Position;
11852 float color : Color;
11853 float v_offset : V_Offset;
11854 uint instance_id : SV_InstanceId;
11857 struct vs_out
11859 float4 position : SV_Position;
11860 float color : Color;
11861 uint instance_id : InstanceId;
11864 void main(vs_in i, out vs_out o)
11866 o.position = i.position;
11867 o.position.x += i.v_offset;
11868 o.color = i.color;
11869 o.instance_id = i.instance_id;
11871 #endif
11872 0x43425844, 0xcde3cfbf, 0xe2e3d090, 0xe2eb1038, 0x7e5ad1cf, 0x00000001, 0x00000204, 0x00000003,
11873 0x0000002c, 0x000000c4, 0x0000013c, 0x4e475349, 0x00000090, 0x00000004, 0x00000008, 0x00000068,
11874 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
11875 0x00000003, 0x00000001, 0x00000101, 0x00000077, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
11876 0x00000101, 0x00000080, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x69736f50,
11877 0x6e6f6974, 0x6c6f4300, 0x5600726f, 0x66664f5f, 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e,
11878 0xabab0064, 0x4e47534f, 0x00000070, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
11879 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
11880 0x00000e01, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
11881 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
11882 0x000000c0, 0x00010040, 0x00000030, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
11883 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x04000060, 0x00101012, 0x00000003, 0x00000008,
11884 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
11885 0x00102012, 0x00000002, 0x07000000, 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x0010100a,
11886 0x00000002, 0x05000036, 0x001020e2, 0x00000000, 0x00101e56, 0x00000000, 0x05000036, 0x00102012,
11887 0x00000001, 0x0010100a, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000003,
11888 0x0100003e,
11890 static const DWORD ps_code[] =
11892 #if 0
11893 struct vs_out
11895 float4 position : SV_Position;
11896 float color : Color;
11897 uint instance_id : InstanceId;
11900 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
11902 o0 = float4(i.color, i.color, i.color, 1.0f);
11903 o1 = i.instance_id;
11905 #endif
11906 0x43425844, 0xda0ad0bb, 0x4743f5f5, 0xfbc6d0b1, 0x7c8e7df5, 0x00000001, 0x00000170, 0x00000003,
11907 0x0000002c, 0x000000a4, 0x000000f0, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
11908 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
11909 0x00000003, 0x00000001, 0x00000101, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002,
11910 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563,
11911 0xababab00, 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000,
11912 0x00000003, 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
11913 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000078, 0x00000040, 0x0000001e,
11914 0x03001062, 0x00101012, 0x00000001, 0x03000862, 0x00101012, 0x00000002, 0x03000065, 0x001020f2,
11915 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072, 0x00000000, 0x00101006,
11916 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x05000036, 0x001020f2,
11917 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
11919 static const struct vec4 stream0[] =
11921 {-1.00f, 0.0f, 0.0f, 1.0f},
11922 {-1.00f, 1.0f, 0.0f, 1.0f},
11923 {-0.75f, 0.0f, 0.0f, 1.0f},
11924 {-0.75f, 1.0f, 0.0f, 1.0f},
11925 /* indirect draws data */
11926 {-1.00f, -1.0f, 0.0f, 1.0f},
11927 {-1.00f, 0.0f, 0.0f, 1.0f},
11928 {-0.75f, -1.0f, 0.0f, 1.0f},
11929 {-0.75f, 0.0f, 0.0f, 1.0f},
11931 static const struct
11933 BYTE color;
11934 float v_offset;
11936 stream1[] =
11938 {0xf0, 0.00f},
11939 {0x80, 0.25f},
11940 {0x10, 0.50f},
11941 {0x40, 0.75f},
11943 {0xaa, 1.00f},
11944 {0xbb, 1.25f},
11945 {0xcc, 1.50f},
11946 {0x90, 1.75f},
11948 static const D3D11_DRAW_INSTANCED_INDIRECT_ARGS argument_data[] =
11950 {4, 4, 4, 0},
11951 {4, 4, 4, 4},
11953 static const struct
11955 RECT rect;
11956 unsigned int color;
11957 unsigned int instance_id;
11959 expected_results[] =
11961 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
11962 {{ 80, 0, 160, 240}, 0xff808080, 1},
11963 {{160, 0, 240, 240}, 0xff101010, 2},
11964 {{240, 0, 320, 240}, 0xff404040, 3},
11965 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
11966 {{400, 0, 480, 240}, 0xffbbbbbb, 1},
11967 {{480, 0, 560, 240}, 0xffcccccc, 2},
11968 {{560, 0, 640, 240}, 0xff909090, 3},
11969 /* indirect draws results */
11970 {{ 0, 240, 80, 480}, 0xfff0f0f0, 0},
11971 {{ 80, 240, 160, 480}, 0xff808080, 1},
11972 {{160, 240, 240, 480}, 0xff101010, 2},
11973 {{240, 240, 320, 480}, 0xff404040, 3},
11974 {{320, 240, 400, 480}, 0xffaaaaaa, 0},
11975 {{400, 240, 480, 480}, 0xffbbbbbb, 1},
11976 {{480, 240, 560, 480}, 0xffcccccc, 2},
11977 {{560, 240, 640, 480}, 0xff909090, 3},
11979 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11980 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11982 if (!init_test_context(&test_context, &feature_level))
11983 return;
11984 device = test_context.device;
11985 context = test_context.immediate_context;
11987 rtvs[0] = test_context.backbuffer_rtv;
11989 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11990 texture_desc.Format = DXGI_FORMAT_R32_UINT;
11991 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
11992 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11993 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtvs[1]);
11994 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11996 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11997 vs_code, sizeof(vs_code), &input_layout);
11998 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12000 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12001 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12002 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12003 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12005 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
12006 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
12008 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12009 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12010 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12011 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12012 offset = 0;
12013 stride = sizeof(*stream0);
12014 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
12015 stride = sizeof(*stream1);
12016 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
12018 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
12019 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[1], white);
12021 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
12022 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
12023 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 4);
12025 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
12026 sizeof(argument_data), argument_data);
12028 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, 0);
12029 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, sizeof(*argument_data));
12031 get_texture_readback(test_context.backbuffer, 0, &rb);
12032 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
12033 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
12034 release_resource_readback(&rb);
12036 get_texture_readback(render_target, 0, &rb);
12037 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
12038 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
12039 release_resource_readback(&rb);
12041 ID3D11Buffer_Release(vb[0]);
12042 ID3D11Buffer_Release(vb[1]);
12043 ID3D11Buffer_Release(args_buffer);
12044 ID3D11RenderTargetView_Release(rtvs[1]);
12045 ID3D11Texture2D_Release(render_target);
12046 ID3D11VertexShader_Release(vs);
12047 ID3D11PixelShader_Release(ps);
12048 ID3D11InputLayout_Release(input_layout);
12049 release_test_context(&test_context);
12052 static void test_vertex_id(void)
12054 static const DWORD vs_code[] =
12056 #if 0
12057 uint4 main(uint id : ID, uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID) : OUTPUT
12059 return uint4(id, instance_id, vertex_id, 0);
12061 #endif
12062 0x43425844, 0x5625197b, 0x588ccf8f, 0x48694905, 0x961d19ca, 0x00000001, 0x00000170, 0x00000003,
12063 0x0000002c, 0x000000a4, 0x000000d4, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
12064 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000101, 0x00000053, 0x00000000, 0x00000008,
12065 0x00000001, 0x00000001, 0x00000101, 0x00000061, 0x00000000, 0x00000006, 0x00000001, 0x00000002,
12066 0x00000101, 0x53004449, 0x6e495f56, 0x6e617473, 0x44496563, 0x5f565300, 0x74726556, 0x44497865,
12067 0xababab00, 0x4e47534f, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
12068 0x00000001, 0x00000000, 0x0000000f, 0x5054554f, 0xab005455, 0x52444853, 0x00000094, 0x00010040,
12069 0x00000025, 0x0300005f, 0x00101012, 0x00000000, 0x04000060, 0x00101012, 0x00000001, 0x00000008,
12070 0x04000060, 0x00101012, 0x00000002, 0x00000006, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
12071 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010100a,
12072 0x00000001, 0x05000036, 0x00102042, 0x00000000, 0x0010100a, 0x00000002, 0x05000036, 0x00102082,
12073 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
12075 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12077 {"ID", 0, DXGI_FORMAT_R32_UINT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
12079 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
12081 {0, "OUTPUT", 0, 0, 4, 0},
12083 static const unsigned int vertices[] =
12101 static const unsigned int indices[] =
12103 6, 7, 8,
12105 0, 1, 2,
12107 struct uvec4 expected_values[] =
12109 {0, 0, 0},
12110 {1, 0, 1},
12111 {2, 0, 2},
12112 {0, 1, 0},
12113 {1, 1, 1},
12114 {2, 1, 2},
12116 {3, 0, 0},
12117 {4, 0, 1},
12118 {5, 0, 2},
12120 {6, 0, 6},
12121 {7, 0, 7},
12122 {8, 0, 8},
12123 {6, 1, 6},
12124 {7, 1, 7},
12125 {8, 1, 8},
12127 {5, 0, 0},
12128 {6, 0, 1},
12129 {7, 0, 2},
12132 BOOL found_values[ARRAY_SIZE(expected_values)] = {0};
12133 BOOL used_values[ARRAY_SIZE(expected_values)] = {0};
12134 struct d3d11_test_context test_context;
12135 D3D11_QUERY_DATA_SO_STATISTICS data;
12136 ID3D11Buffer *vb, *ib, *so_buffer;
12137 ID3D11InputLayout *input_layout;
12138 ID3D11DeviceContext *context;
12139 D3D11_QUERY_DESC query_desc;
12140 struct resource_readback rb;
12141 unsigned int stride, offset;
12142 ID3D11Asynchronous *query;
12143 ID3D11GeometryShader *gs;
12144 ID3D11VertexShader *vs;
12145 ID3D11Device *device;
12146 unsigned int count;
12147 unsigned int i, j;
12148 HRESULT hr;
12150 if (!init_test_context(&test_context, NULL))
12151 return;
12152 device = test_context.device;
12153 context = test_context.immediate_context;
12155 query_desc.Query = D3D11_QUERY_SO_STATISTICS;
12156 query_desc.MiscFlags = 0;
12157 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
12158 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
12160 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12161 vs_code, sizeof(vs_code), &input_layout);
12162 ok(hr == S_OK, "Failed to create input layout, hr %#x.\n", hr);
12164 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12165 ok(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
12167 stride = 16;
12168 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
12169 so_declaration, ARRAY_SIZE(so_declaration), &stride, 1, 0, NULL, &gs);
12170 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
12172 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
12173 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
12174 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
12176 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12177 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
12178 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12179 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
12180 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
12181 offset = 0;
12182 stride = sizeof(*vertices);
12183 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
12185 offset = 0;
12186 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
12188 ID3D11DeviceContext_Begin(context, query);
12190 ID3D11DeviceContext_DrawInstanced(context, 3, 2, 0, 0);
12191 ID3D11DeviceContext_DrawInstanced(context, 3, 1, 3, 16);
12193 ID3D11DeviceContext_DrawIndexedInstanced(context, 3, 2, 0, 0, 0);
12194 ID3D11DeviceContext_DrawIndexedInstanced(context, 3, 1, 3, 9, 7);
12196 ID3D11DeviceContext_End(context, query);
12198 get_query_data(context, query, &data, sizeof(data));
12199 count = data.NumPrimitivesWritten;
12200 ok(count == ARRAY_SIZE(expected_values), "Got unexpected value %u.\n", count);
12202 count = min(count, ARRAY_SIZE(used_values));
12203 get_buffer_readback(so_buffer, &rb);
12204 for (i = 0; i < ARRAY_SIZE(expected_values); ++i)
12206 for (j = 0; j < count; ++j)
12208 if (!used_values[j] && compare_uvec4(get_readback_uvec4(&rb, j, 0), &expected_values[i]))
12210 found_values[i] = TRUE;
12211 used_values[j] = TRUE;
12212 break;
12217 for (i = 0; i < count; ++i)
12219 const struct uvec4 *v = get_readback_uvec4(&rb, i, 0);
12220 ok(used_values[i], "Found unexpected value {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n", v->x, v->y, v->z, v->w);
12222 release_resource_readback(&rb);
12224 for (i = 0; i < ARRAY_SIZE(expected_values); ++i)
12226 ok(found_values[i], "Failed to find value {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n",
12227 expected_values[i].x, expected_values[i].y, expected_values[i].z, expected_values[i].w);
12230 ID3D11Asynchronous_Release(query);
12231 ID3D11Buffer_Release(so_buffer);
12232 ID3D11Buffer_Release(vb);
12233 ID3D11Buffer_Release(ib);
12234 ID3D11GeometryShader_Release(gs);
12235 ID3D11VertexShader_Release(vs);
12236 ID3D11InputLayout_Release(input_layout);
12237 release_test_context(&test_context);
12240 static void test_fragment_coords(void)
12242 struct d3d11_test_context test_context;
12243 ID3D11PixelShader *ps, *ps_frac;
12244 ID3D11DeviceContext *context;
12245 ID3D11Device *device;
12246 ID3D11Buffer *ps_cb;
12247 DWORD color;
12248 HRESULT hr;
12250 static const DWORD ps_code[] =
12252 #if 0
12253 float2 cutoff;
12255 float4 main(float4 position : SV_POSITION) : SV_TARGET
12257 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
12259 if (position.x > cutoff.x)
12260 ret.y = 1.0;
12261 if (position.y > cutoff.y)
12262 ret.z = 1.0;
12264 return ret;
12266 #endif
12267 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
12268 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12269 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
12270 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12271 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
12272 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
12273 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
12274 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
12275 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
12276 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
12277 0x0100003e,
12279 static const DWORD ps_frac_code[] =
12281 #if 0
12282 float4 main(float4 position : SV_POSITION) : SV_TARGET
12284 return float4(frac(position.xy), 0.0, 1.0);
12286 #endif
12287 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
12288 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12289 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
12290 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12291 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
12292 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
12293 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
12294 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12296 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
12297 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
12299 if (!init_test_context(&test_context, NULL))
12300 return;
12302 device = test_context.device;
12303 context = test_context.immediate_context;
12305 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
12307 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12308 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12309 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
12310 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12312 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
12313 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12315 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
12317 draw_quad(&test_context);
12319 color = get_texture_color(test_context.backbuffer, 319, 239);
12320 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
12321 color = get_texture_color(test_context.backbuffer, 320, 239);
12322 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
12323 color = get_texture_color(test_context.backbuffer, 319, 240);
12324 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
12325 color = get_texture_color(test_context.backbuffer, 320, 240);
12326 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
12328 ID3D11Buffer_Release(ps_cb);
12329 cutoff.x = 16.0f;
12330 cutoff.y = 16.0f;
12331 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
12332 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
12334 draw_quad(&test_context);
12336 color = get_texture_color(test_context.backbuffer, 14, 14);
12337 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
12338 color = get_texture_color(test_context.backbuffer, 18, 14);
12339 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
12340 color = get_texture_color(test_context.backbuffer, 14, 18);
12341 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
12342 color = get_texture_color(test_context.backbuffer, 18, 18);
12343 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
12345 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
12346 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
12348 ID3D11DeviceContext_Draw(context, 4, 0);
12350 color = get_texture_color(test_context.backbuffer, 14, 14);
12351 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
12353 ID3D11Buffer_Release(ps_cb);
12354 ID3D11PixelShader_Release(ps_frac);
12355 ID3D11PixelShader_Release(ps);
12356 release_test_context(&test_context);
12359 static void test_initial_texture_data(void)
12361 ID3D11Texture2D *texture, *staging_texture;
12362 struct d3d11_test_context test_context;
12363 D3D11_SUBRESOURCE_DATA resource_data;
12364 D3D11_TEXTURE2D_DESC texture_desc;
12365 ID3D11SamplerState *sampler_state;
12366 ID3D11ShaderResourceView *ps_srv;
12367 D3D11_SAMPLER_DESC sampler_desc;
12368 ID3D11DeviceContext *context;
12369 struct resource_readback rb;
12370 ID3D11PixelShader *ps;
12371 ID3D11Device *device;
12372 unsigned int i, j;
12373 DWORD color;
12374 HRESULT hr;
12376 static const DWORD ps_code[] =
12378 #if 0
12379 Texture2D t;
12380 SamplerState s;
12382 float4 main(float4 position : SV_POSITION) : SV_Target
12384 float2 p;
12386 p.x = position.x / 640.0f;
12387 p.y = position.y / 480.0f;
12388 return t.Sample(s, p);
12390 #endif
12391 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
12392 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12393 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
12394 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12395 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
12396 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
12397 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12398 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
12399 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
12400 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
12402 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
12403 static const DWORD bitmap_data[] =
12405 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
12406 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
12407 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
12408 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
12411 if (!init_test_context(&test_context, NULL))
12412 return;
12414 device = test_context.device;
12415 context = test_context.immediate_context;
12417 texture_desc.Width = 4;
12418 texture_desc.Height = 4;
12419 texture_desc.MipLevels = 1;
12420 texture_desc.ArraySize = 1;
12421 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12422 texture_desc.SampleDesc.Count = 1;
12423 texture_desc.SampleDesc.Quality = 0;
12424 texture_desc.Usage = D3D11_USAGE_STAGING;
12425 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
12426 texture_desc.BindFlags = 0;
12427 texture_desc.MiscFlags = 0;
12429 resource_data.pSysMem = bitmap_data;
12430 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
12431 resource_data.SysMemSlicePitch = 0;
12433 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &staging_texture);
12434 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
12436 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12437 texture_desc.CPUAccessFlags = 0;
12438 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
12439 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12440 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
12442 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)texture, (ID3D11Resource *)staging_texture);
12444 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
12445 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
12447 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
12448 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
12449 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
12450 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
12451 sampler_desc.MipLODBias = 0.0f;
12452 sampler_desc.MaxAnisotropy = 0;
12453 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
12454 sampler_desc.BorderColor[0] = 0.0f;
12455 sampler_desc.BorderColor[1] = 0.0f;
12456 sampler_desc.BorderColor[2] = 0.0f;
12457 sampler_desc.BorderColor[3] = 0.0f;
12458 sampler_desc.MinLOD = 0.0f;
12459 sampler_desc.MaxLOD = 0.0f;
12460 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
12461 ok(hr == S_OK, "Failed to create sampler state, hr %#x.\n", hr);
12463 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12464 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
12466 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
12467 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
12468 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12470 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
12471 draw_quad(&test_context);
12472 get_texture_readback(test_context.backbuffer, 0, &rb);
12473 for (i = 0; i < 4; ++i)
12475 for (j = 0; j < 4; ++j)
12477 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
12478 ok(compare_color(color, bitmap_data[j + i * 4], 1),
12479 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
12480 color, j, i, bitmap_data[j + i * 4]);
12483 release_resource_readback(&rb);
12485 ID3D11PixelShader_Release(ps);
12486 ID3D11SamplerState_Release(sampler_state);
12487 ID3D11ShaderResourceView_Release(ps_srv);
12488 ID3D11Texture2D_Release(staging_texture);
12489 ID3D11Texture2D_Release(texture);
12490 release_test_context(&test_context);
12493 static void test_update_subresource(void)
12495 struct d3d11_test_context test_context;
12496 D3D11_SUBRESOURCE_DATA resource_data;
12497 D3D11_TEXTURE2D_DESC texture_desc;
12498 ID3D11SamplerState *sampler_state;
12499 ID3D11ShaderResourceView *ps_srv;
12500 D3D11_SAMPLER_DESC sampler_desc;
12501 ID3D11DeviceContext *context;
12502 struct resource_readback rb;
12503 ID3D11Texture2D *texture;
12504 ID3D11PixelShader *ps;
12505 ID3D11Device *device;
12506 unsigned int i, j;
12507 D3D11_BOX box;
12508 DWORD color;
12509 HRESULT hr;
12511 static const DWORD ps_code[] =
12513 #if 0
12514 Texture2D t;
12515 SamplerState s;
12517 float4 main(float4 position : SV_POSITION) : SV_Target
12519 float2 p;
12521 p.x = position.x / 640.0f;
12522 p.y = position.y / 480.0f;
12523 return t.Sample(s, p);
12525 #endif
12526 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
12527 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12528 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
12529 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12530 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
12531 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
12532 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12533 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
12534 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
12535 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
12537 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
12538 static const DWORD initial_data[16] = {0};
12539 static const DWORD bitmap_data[] =
12541 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
12542 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
12543 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
12544 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
12546 static const DWORD expected_colors[] =
12548 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
12549 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
12550 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
12551 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
12554 if (!init_test_context(&test_context, NULL))
12555 return;
12557 device = test_context.device;
12558 context = test_context.immediate_context;
12560 texture_desc.Width = 4;
12561 texture_desc.Height = 4;
12562 texture_desc.MipLevels = 1;
12563 texture_desc.ArraySize = 1;
12564 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12565 texture_desc.SampleDesc.Count = 1;
12566 texture_desc.SampleDesc.Quality = 0;
12567 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12568 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
12569 texture_desc.CPUAccessFlags = 0;
12570 texture_desc.MiscFlags = 0;
12572 resource_data.pSysMem = initial_data;
12573 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
12574 resource_data.SysMemSlicePitch = 0;
12576 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
12577 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
12579 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
12580 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12582 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
12583 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
12584 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
12585 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
12586 sampler_desc.MipLODBias = 0.0f;
12587 sampler_desc.MaxAnisotropy = 0;
12588 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
12589 sampler_desc.BorderColor[0] = 0.0f;
12590 sampler_desc.BorderColor[1] = 0.0f;
12591 sampler_desc.BorderColor[2] = 0.0f;
12592 sampler_desc.BorderColor[3] = 0.0f;
12593 sampler_desc.MinLOD = 0.0f;
12594 sampler_desc.MaxLOD = 0.0f;
12596 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
12597 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
12599 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12600 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12602 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
12603 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
12604 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12606 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
12607 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
12609 draw_quad(&test_context);
12610 check_texture_color(test_context.backbuffer, 0x00000000, 0);
12612 set_box(&box, 1, 1, 0, 3, 3, 1);
12613 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
12614 bitmap_data, 4 * sizeof(*bitmap_data), 0);
12615 set_box(&box, 0, 3, 0, 3, 4, 1);
12616 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
12617 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
12618 set_box(&box, 0, 0, 0, 4, 1, 1);
12619 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
12620 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
12621 set_box(&box, 0, 1, 0, 1, 3, 1);
12622 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
12623 &bitmap_data[2], sizeof(*bitmap_data), 0);
12624 set_box(&box, 4, 4, 0, 3, 1, 1);
12625 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
12626 bitmap_data, sizeof(*bitmap_data), 0);
12627 set_box(&box, 0, 0, 0, 4, 4, 0);
12628 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
12629 bitmap_data, 4 * sizeof(*bitmap_data), 0);
12630 draw_quad(&test_context);
12631 get_texture_readback(test_context.backbuffer, 0, &rb);
12632 for (i = 0; i < 4; ++i)
12634 for (j = 0; j < 4; ++j)
12636 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
12637 ok(compare_color(color, expected_colors[j + i * 4], 1),
12638 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
12639 color, j, i, expected_colors[j + i * 4]);
12642 release_resource_readback(&rb);
12644 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
12645 bitmap_data, 4 * sizeof(*bitmap_data), 0);
12646 draw_quad(&test_context);
12647 get_texture_readback(test_context.backbuffer, 0, &rb);
12648 for (i = 0; i < 4; ++i)
12650 for (j = 0; j < 4; ++j)
12652 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
12653 ok(compare_color(color, bitmap_data[j + i * 4], 1),
12654 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
12655 color, j, i, bitmap_data[j + i * 4]);
12658 release_resource_readback(&rb);
12660 ID3D11PixelShader_Release(ps);
12661 ID3D11SamplerState_Release(sampler_state);
12662 ID3D11ShaderResourceView_Release(ps_srv);
12663 ID3D11Texture2D_Release(texture);
12664 release_test_context(&test_context);
12667 static void test_copy_subresource_region(void)
12669 ID3D11Texture2D *dst_texture, *src_texture;
12670 struct d3d11_test_context test_context;
12671 ID3D11Buffer *dst_buffer, *src_buffer;
12672 D3D11_SUBRESOURCE_DATA resource_data;
12673 D3D11_TEXTURE2D_DESC texture_desc;
12674 ID3D11SamplerState *sampler_state;
12675 ID3D11ShaderResourceView *ps_srv;
12676 D3D11_SAMPLER_DESC sampler_desc;
12677 ID3D11DeviceContext1 *context1;
12678 ID3D11DeviceContext *context;
12679 struct vec4 float_colors[16];
12680 struct resource_readback rb;
12681 ID3D11PixelShader *ps;
12682 ID3D11Device *device;
12683 unsigned int i, j;
12684 D3D11_BOX box;
12685 DWORD color;
12686 HRESULT hr;
12688 static const DWORD ps_code[] =
12690 #if 0
12691 Texture2D t;
12692 SamplerState s;
12694 float4 main(float4 position : SV_POSITION) : SV_Target
12696 float2 p;
12698 p.x = position.x / 640.0f;
12699 p.y = position.y / 480.0f;
12700 return t.Sample(s, p);
12702 #endif
12703 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
12704 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12705 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
12706 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12707 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
12708 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
12709 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12710 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
12711 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
12712 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
12714 static const DWORD ps_buffer_code[] =
12716 #if 0
12717 float4 buffer[16];
12719 float4 main(float4 position : SV_POSITION) : SV_TARGET
12721 float2 p = (float2)4;
12722 p *= float2(position.x / 640.0f, position.y / 480.0f);
12723 return buffer[(int)p.y * 4 + (int)p.x];
12725 #endif
12726 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
12727 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12728 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
12729 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12730 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
12731 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
12732 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
12733 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
12734 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
12735 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
12736 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
12737 0x0010000a, 0x00000000, 0x0100003e,
12739 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
12740 static const DWORD initial_data[16] = {0};
12741 static const DWORD bitmap_data[] =
12743 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
12744 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
12745 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
12746 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
12748 static const DWORD expected_colors[] =
12750 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
12751 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
12752 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
12753 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
12756 if (!init_test_context(&test_context, NULL))
12757 return;
12759 device = test_context.device;
12760 context = test_context.immediate_context;
12762 texture_desc.Width = 4;
12763 texture_desc.Height = 4;
12764 texture_desc.MipLevels = 1;
12765 texture_desc.ArraySize = 1;
12766 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12767 texture_desc.SampleDesc.Count = 1;
12768 texture_desc.SampleDesc.Quality = 0;
12769 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12770 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
12771 texture_desc.CPUAccessFlags = 0;
12772 texture_desc.MiscFlags = 0;
12774 resource_data.pSysMem = initial_data;
12775 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
12776 resource_data.SysMemSlicePitch = 0;
12778 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
12779 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
12781 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
12783 resource_data.pSysMem = bitmap_data;
12784 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
12785 resource_data.SysMemSlicePitch = 0;
12787 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
12788 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
12790 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
12791 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12793 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
12794 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
12795 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
12796 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
12797 sampler_desc.MipLODBias = 0.0f;
12798 sampler_desc.MaxAnisotropy = 0;
12799 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
12800 sampler_desc.BorderColor[0] = 0.0f;
12801 sampler_desc.BorderColor[1] = 0.0f;
12802 sampler_desc.BorderColor[2] = 0.0f;
12803 sampler_desc.BorderColor[3] = 0.0f;
12804 sampler_desc.MinLOD = 0.0f;
12805 sampler_desc.MaxLOD = 0.0f;
12807 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
12808 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
12810 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12811 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12813 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
12814 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
12815 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12817 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
12819 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
12820 1, 1, 0, NULL, 0, &box);
12821 ID3D11DeviceContext_CopySubresourceRegion(context, NULL, 0,
12822 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
12824 set_box(&box, 0, 0, 0, 2, 2, 1);
12825 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
12826 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
12827 set_box(&box, 1, 2, 0, 4, 3, 1);
12828 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
12829 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
12830 set_box(&box, 0, 3, 0, 4, 4, 1);
12831 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
12832 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
12833 set_box(&box, 3, 0, 0, 4, 2, 1);
12834 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
12835 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
12836 set_box(&box, 3, 1, 0, 4, 2, 1);
12837 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
12838 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
12839 set_box(&box, 0, 0, 0, 4, 4, 0);
12840 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
12841 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
12842 draw_quad(&test_context);
12843 get_texture_readback(test_context.backbuffer, 0, &rb);
12844 for (i = 0; i < 4; ++i)
12846 for (j = 0; j < 4; ++j)
12848 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
12849 ok(compare_color(color, expected_colors[j + i * 4], 1),
12850 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
12851 color, j, i, expected_colors[j + i * 4]);
12854 release_resource_readback(&rb);
12856 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
12857 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
12858 draw_quad(&test_context);
12859 get_texture_readback(test_context.backbuffer, 0, &rb);
12860 for (i = 0; i < 4; ++i)
12862 for (j = 0; j < 4; ++j)
12864 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
12865 ok(compare_color(color, bitmap_data[j + i * 4], 1),
12866 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
12867 color, j, i, bitmap_data[j + i * 4]);
12870 release_resource_readback(&rb);
12872 hr = ID3D11DeviceContext_QueryInterface(context, &IID_ID3D11DeviceContext1, (void **)&context1);
12873 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
12874 "Failed to query ID3D11DeviceContext1, hr %#x.\n", hr);
12876 if (SUCCEEDED(hr))
12878 ID3D11DeviceContext1_ClearRenderTargetView(context1, test_context.backbuffer_rtv, red);
12879 check_texture_color(test_context.backbuffer, 0x800000ff, 2);
12881 memset(float_colors, 0, sizeof(float_colors));
12882 for (i = 0; i < texture_desc.Width; ++i)
12883 ((unsigned int *)float_colors)[i] = 0x45454545;
12885 ID3D11DeviceContext1_UpdateSubresource1(context1, (ID3D11Resource *)dst_texture, 0, NULL,
12886 float_colors, 0, 0, 0);
12887 draw_quad(&test_context);
12888 check_texture_color(test_context.backbuffer, 0x45454545, 1);
12890 ID3D11DeviceContext1_CopySubresourceRegion1(context1, (ID3D11Resource *)dst_texture, 0,
12891 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL, 0);
12892 draw_quad(&test_context);
12894 get_texture_readback(test_context.backbuffer, 0, &rb);
12895 for (i = 0; i < 4; ++i)
12897 for (j = 0; j < 4; ++j)
12899 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
12900 ok(compare_color(color, bitmap_data[j + i * 4], 1),
12901 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
12902 color, j, i, bitmap_data[j + i * 4]);
12905 release_resource_readback(&rb);
12907 ID3D11DeviceContext1_Release(context1);
12911 ID3D11PixelShader_Release(ps);
12912 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
12913 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12915 ID3D11ShaderResourceView_Release(ps_srv);
12916 ps_srv = NULL;
12918 ID3D11SamplerState_Release(sampler_state);
12919 sampler_state = NULL;
12921 ID3D11Texture2D_Release(dst_texture);
12922 ID3D11Texture2D_Release(src_texture);
12924 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
12925 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
12926 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12928 memset(float_colors, 0, sizeof(float_colors));
12929 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
12930 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
12932 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
12934 for (i = 0; i < 4; ++i)
12936 for (j = 0; j < 4; ++j)
12938 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
12939 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
12940 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
12941 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
12944 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
12945 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
12947 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
12948 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
12949 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
12950 draw_quad(&test_context);
12951 check_texture_color(test_context.backbuffer, 0x00000000, 0);
12953 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
12954 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
12955 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
12956 draw_quad(&test_context);
12957 check_texture_color(test_context.backbuffer, 0x00000000, 0);
12959 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
12960 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
12961 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
12962 draw_quad(&test_context);
12963 check_texture_color(test_context.backbuffer, 0x00000000, 0);
12965 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
12966 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
12967 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
12968 draw_quad(&test_context);
12969 get_texture_readback(test_context.backbuffer, 0, &rb);
12970 for (i = 0; i < 4; ++i)
12972 for (j = 0; j < 4; ++j)
12974 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
12975 ok(compare_color(color, bitmap_data[j + i * 4], 1),
12976 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
12977 color, j, i, bitmap_data[j + i * 4]);
12980 release_resource_readback(&rb);
12982 ID3D11Buffer_Release(dst_buffer);
12983 ID3D11Buffer_Release(src_buffer);
12984 ID3D11PixelShader_Release(ps);
12985 release_test_context(&test_context);
12988 static void test_copy_subresource_region_1d(void)
12990 D3D11_SUBRESOURCE_DATA resource_data[4];
12991 struct d3d11_test_context test_context;
12992 D3D11_TEXTURE1D_DESC texture1d_desc;
12993 D3D11_TEXTURE2D_DESC texture2d_desc;
12994 ID3D11DeviceContext *context;
12995 struct resource_readback rb;
12996 ID3D11Texture1D *texture1d;
12997 ID3D11Texture2D *texture2d;
12998 ID3D11Device *device;
12999 unsigned int i, j;
13000 D3D11_BOX box;
13001 DWORD color;
13002 HRESULT hr;
13004 static const DWORD bitmap_data[] =
13006 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
13007 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
13008 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
13009 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
13012 if (!init_test_context(&test_context, NULL))
13013 return;
13014 device = test_context.device;
13015 context = test_context.immediate_context;
13017 texture1d_desc.Width = 4;
13018 texture1d_desc.MipLevels = 1;
13019 texture1d_desc.ArraySize = 4;
13020 texture1d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13021 texture1d_desc.Usage = D3D11_USAGE_DEFAULT;
13022 texture1d_desc.BindFlags = 0;
13023 texture1d_desc.CPUAccessFlags = 0;
13024 texture1d_desc.MiscFlags = 0;
13026 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
13028 resource_data[i].pSysMem = &bitmap_data[4 * i];
13029 resource_data[i].SysMemPitch = texture1d_desc.Width * sizeof(bitmap_data);
13030 resource_data[i].SysMemSlicePitch = 0;
13033 hr = ID3D11Device_CreateTexture1D(device, &texture1d_desc, resource_data, &texture1d);
13034 ok(hr == S_OK, "Failed to create 1d texture, hr %#x.\n", hr);
13036 texture2d_desc.Width = 4;
13037 texture2d_desc.Height = 4;
13038 texture2d_desc.MipLevels = 1;
13039 texture2d_desc.ArraySize = 1;
13040 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13041 texture2d_desc.SampleDesc.Count = 1;
13042 texture2d_desc.SampleDesc.Quality = 0;
13043 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
13044 texture2d_desc.BindFlags = 0;
13045 texture2d_desc.CPUAccessFlags = 0;
13046 texture2d_desc.MiscFlags = 0;
13048 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
13049 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
13051 set_box(&box, 0, 0, 0, 4, 1, 1);
13052 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
13054 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2d, 0,
13055 0, i, 0, (ID3D11Resource *)texture1d, i, &box);
13058 get_texture_readback(texture2d, 0, &rb);
13059 for (i = 0; i < 4; ++i)
13061 for (j = 0; j < 4; ++j)
13063 color = get_readback_color(&rb, j, i, 0);
13064 ok(compare_color(color, bitmap_data[j + i * 4], 1),
13065 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13066 color, j, i, bitmap_data[j + i * 4]);
13069 release_resource_readback(&rb);
13071 get_texture1d_readback(texture1d, 0, &rb);
13072 for (i = 0; i < texture1d_desc.Width; ++i)
13074 color = get_readback_color(&rb, i, 0, 0);
13075 ok(compare_color(color, bitmap_data[i], 1),
13076 "Got color 0x%08x at %u, expected 0x%08x.\n",
13077 color, i, bitmap_data[i]);
13079 release_resource_readback(&rb);
13081 ID3D11Texture1D_Release(texture1d);
13082 ID3D11Texture2D_Release(texture2d);
13083 release_test_context(&test_context);
13086 static void test_copy_subresource_region_3d(void)
13088 ID3D11ShaderResourceView *dst_srv, *src_srv;
13089 ID3D11Texture3D *dst_texture, *src_texture;
13090 D3D11_SUBRESOURCE_DATA resource_data[4];
13091 struct d3d11_test_context test_context;
13092 D3D11_TEXTURE2D_DESC texture2d_desc;
13093 D3D11_TEXTURE3D_DESC texture3d_desc;
13094 ID3D11SamplerState *sampler_state;
13095 D3D11_SAMPLER_DESC sampler_desc;
13096 ID3D11DeviceContext *context;
13097 struct resource_readback rb;
13098 ID3D11Texture2D *texture2d;
13099 ID3D11PixelShader *ps;
13100 ID3D11Device *device;
13101 unsigned int i, j;
13102 DWORD data[4][16];
13103 D3D11_BOX box;
13104 DWORD color;
13105 HRESULT hr;
13107 static const DWORD ps_code[] =
13109 #if 0
13110 Texture3D t;
13111 SamplerState s;
13113 float4 main(float4 position : SV_POSITION) : SV_Target
13115 return t.Sample(s, position.xyz / float3(640, 480, 1));
13117 #endif
13118 0x43425844, 0x27b15ae8, 0xbebf46f7, 0x6cd88d8d, 0x5118de51, 0x00000001, 0x00000134, 0x00000003,
13119 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13120 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000070f, 0x505f5653, 0x5449534f, 0x004e4f49,
13121 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13122 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13123 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
13124 0x04002064, 0x00101072, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13125 0x00000001, 0x0a000038, 0x00100072, 0x00000000, 0x00101246, 0x00000000, 0x00004002, 0x3acccccd,
13126 0x3b088889, 0x3f800000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
13127 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13129 static const DWORD bitmap_data[] =
13131 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
13132 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
13133 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
13134 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
13137 if (!init_test_context(&test_context, NULL))
13138 return;
13139 device = test_context.device;
13140 context = test_context.immediate_context;
13142 texture3d_desc.Width = 4;
13143 texture3d_desc.Height = 4;
13144 texture3d_desc.Depth = 4;
13145 texture3d_desc.MipLevels = 1;
13146 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13147 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
13148 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13149 texture3d_desc.CPUAccessFlags = 0;
13150 texture3d_desc.MiscFlags = 0;
13152 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &src_texture);
13153 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
13154 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &dst_texture);
13155 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
13157 texture2d_desc.Width = 4;
13158 texture2d_desc.Height = 4;
13159 texture2d_desc.MipLevels = 1;
13160 texture2d_desc.ArraySize = 4;
13161 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13162 texture2d_desc.SampleDesc.Count = 1;
13163 texture2d_desc.SampleDesc.Quality = 0;
13164 texture2d_desc.Usage = D3D11_USAGE_IMMUTABLE;
13165 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13166 texture2d_desc.CPUAccessFlags = 0;
13167 texture2d_desc.MiscFlags = 0;
13169 for (i = 0; i < ARRAY_SIZE(*data); ++i)
13171 data[0][i] = 0xff0000ff;
13172 data[1][i] = bitmap_data[i];
13173 data[2][i] = 0xff00ff00;
13174 data[3][i] = 0xffff00ff;
13177 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
13179 resource_data[i].pSysMem = data[i];
13180 resource_data[i].SysMemPitch = texture2d_desc.Width * sizeof(data[0][0]);
13181 resource_data[i].SysMemSlicePitch = 0;
13184 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, resource_data, &texture2d);
13185 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
13187 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)src_texture, NULL, &src_srv);
13188 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
13189 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &dst_srv);
13190 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
13192 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
13193 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
13194 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
13195 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
13196 sampler_desc.MipLODBias = 0.0f;
13197 sampler_desc.MaxAnisotropy = 0;
13198 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
13199 sampler_desc.BorderColor[0] = 0.0f;
13200 sampler_desc.BorderColor[1] = 0.0f;
13201 sampler_desc.BorderColor[2] = 0.0f;
13202 sampler_desc.BorderColor[3] = 0.0f;
13203 sampler_desc.MinLOD = 0.0f;
13204 sampler_desc.MaxLOD = 0.0f;
13206 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
13207 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
13209 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13210 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
13212 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &src_srv);
13213 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
13214 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13216 set_box(&box, 0, 0, 0, 4, 4, 1);
13217 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
13219 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
13220 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
13222 draw_quad(&test_context);
13223 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
13224 draw_quad_z(&test_context, 0.25f);
13225 get_texture_readback(test_context.backbuffer, 0, &rb);
13226 for (i = 0; i < 4; ++i)
13228 for (j = 0; j < 4; ++j)
13230 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
13231 ok(compare_color(color, bitmap_data[j + i * 4], 1),
13232 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13233 color, j, i, bitmap_data[j + i * 4]);
13236 release_resource_readback(&rb);
13237 draw_quad_z(&test_context, 0.5f);
13238 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
13239 draw_quad_z(&test_context, 1.0f);
13240 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
13242 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &dst_srv);
13244 set_box(&box, 0, 0, 0, 4, 4, 2);
13245 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
13246 0, 0, 2, (ID3D11Resource *)src_texture, 0, &box);
13247 set_box(&box, 0, 0, 2, 4, 4, 4);
13248 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
13249 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
13251 set_box(&box, 0, 0, 0, 4, 4, 1);
13252 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
13254 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
13255 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
13257 draw_quad(&test_context);
13258 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
13259 draw_quad_z(&test_context, 0.25f);
13260 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
13261 draw_quad_z(&test_context, 0.5f);
13262 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
13263 draw_quad_z(&test_context, 1.0f);
13264 get_texture_readback(test_context.backbuffer, 0, &rb);
13265 for (i = 0; i < 4; ++i)
13267 for (j = 0; j < 4; ++j)
13269 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
13270 ok(compare_color(color, bitmap_data[j + i * 4], 1),
13271 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13272 color, j, i, bitmap_data[j + i * 4]);
13275 release_resource_readback(&rb);
13277 ID3D11PixelShader_Release(ps);
13278 ID3D11SamplerState_Release(sampler_state);
13279 ID3D11ShaderResourceView_Release(dst_srv);
13280 ID3D11ShaderResourceView_Release(src_srv);
13281 ID3D11Texture2D_Release(texture2d);
13282 ID3D11Texture3D_Release(dst_texture);
13283 ID3D11Texture3D_Release(src_texture);
13284 release_test_context(&test_context);
13287 static void test_resource_map(void)
13289 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
13290 D3D11_TEXTURE3D_DESC texture3d_desc;
13291 D3D11_TEXTURE2D_DESC texture2d_desc;
13292 D3D11_BUFFER_DESC buffer_desc;
13293 ID3D11DeviceContext *context;
13294 ID3D11Texture3D *texture3d;
13295 ID3D11Texture2D *texture2d;
13296 ID3D11Buffer *buffer;
13297 ID3D11Device *device;
13298 ULONG refcount;
13299 HRESULT hr;
13300 DWORD data;
13302 if (!(device = create_device(NULL)))
13304 skip("Failed to create device.\n");
13305 return;
13308 ID3D11Device_GetImmediateContext(device, &context);
13310 buffer_desc.ByteWidth = 1024;
13311 buffer_desc.Usage = D3D11_USAGE_STAGING;
13312 buffer_desc.BindFlags = 0;
13313 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
13314 buffer_desc.MiscFlags = 0;
13315 buffer_desc.StructureByteStride = 0;
13317 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
13318 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
13320 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
13321 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13323 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
13324 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
13325 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
13326 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
13327 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
13328 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
13329 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
13331 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
13332 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
13333 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
13334 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
13335 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
13336 data = *((DWORD *)mapped_subresource.pData);
13337 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
13338 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
13340 refcount = ID3D11Buffer_Release(buffer);
13341 ok(!refcount, "Buffer has %u references left.\n", refcount);
13343 texture2d_desc.Width = 512;
13344 texture2d_desc.Height = 512;
13345 texture2d_desc.MipLevels = 1;
13346 texture2d_desc.ArraySize = 1;
13347 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13348 texture2d_desc.SampleDesc.Count = 1;
13349 texture2d_desc.SampleDesc.Quality = 0;
13350 texture2d_desc.Usage = D3D11_USAGE_STAGING;
13351 texture2d_desc.BindFlags = 0;
13352 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
13353 texture2d_desc.MiscFlags = 0;
13355 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
13356 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
13358 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
13359 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13361 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
13362 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
13363 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
13364 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
13365 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
13366 mapped_subresource.DepthPitch);
13367 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
13368 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
13370 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
13371 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
13372 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
13373 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
13374 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
13375 mapped_subresource.DepthPitch);
13376 data = *((DWORD *)mapped_subresource.pData);
13377 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
13378 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
13380 refcount = ID3D11Texture2D_Release(texture2d);
13381 ok(!refcount, "2D texture has %u references left.\n", refcount);
13383 texture3d_desc.Width = 64;
13384 texture3d_desc.Height = 64;
13385 texture3d_desc.Depth = 64;
13386 texture3d_desc.MipLevels = 1;
13387 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13388 texture3d_desc.Usage = D3D11_USAGE_STAGING;
13389 texture3d_desc.BindFlags = 0;
13390 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
13391 texture3d_desc.MiscFlags = 0;
13393 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
13394 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
13396 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
13397 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13399 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
13400 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
13401 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
13402 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
13403 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
13404 mapped_subresource.DepthPitch);
13405 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
13406 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
13408 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
13409 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
13410 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
13411 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
13412 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
13413 mapped_subresource.DepthPitch);
13414 data = *((DWORD *)mapped_subresource.pData);
13415 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
13416 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
13418 refcount = ID3D11Texture3D_Release(texture3d);
13419 ok(!refcount, "3D texture has %u references left.\n", refcount);
13421 ID3D11DeviceContext_Release(context);
13423 refcount = ID3D11Device_Release(device);
13424 ok(!refcount, "Device has %u references left.\n", refcount);
13427 #define check_resource_cpu_access(a, b, c, d, e) check_resource_cpu_access_(__LINE__, a, b, c, d, e)
13428 static void check_resource_cpu_access_(unsigned int line, ID3D11DeviceContext *context,
13429 ID3D11Resource *resource, D3D11_USAGE usage, UINT bind_flags, UINT cpu_access)
13431 BOOL cpu_write = cpu_access & D3D11_CPU_ACCESS_WRITE;
13432 BOOL cpu_read = cpu_access & D3D11_CPU_ACCESS_READ;
13433 BOOL dynamic = usage == D3D11_USAGE_DYNAMIC;
13434 D3D11_MAPPED_SUBRESOURCE map_desc;
13435 HRESULT hr, expected_hr;
13436 ID3D11Device *device;
13438 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
13439 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ, 0, &map_desc);
13440 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
13441 if (SUCCEEDED(hr))
13442 ID3D11DeviceContext_Unmap(context, resource, 0);
13444 /* WRITE_DISCARD and WRITE_NO_OVERWRITE are the only allowed options for dynamic resources. */
13445 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
13446 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE, 0, &map_desc);
13447 todo_wine_if(dynamic && cpu_write)
13448 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
13449 if (SUCCEEDED(hr))
13450 ID3D11DeviceContext_Unmap(context, resource, 0);
13452 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
13453 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
13454 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
13455 if (SUCCEEDED(hr))
13456 ID3D11DeviceContext_Unmap(context, resource, 0);
13458 expected_hr = dynamic ? S_OK : E_INVALIDARG;
13459 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
13460 todo_wine_if(!dynamic && cpu_write)
13461 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
13462 if (SUCCEEDED(hr))
13463 ID3D11DeviceContext_Unmap(context, resource, 0);
13465 if (!dynamic)
13466 return;
13468 ID3D11DeviceContext_GetDevice(context, &device);
13470 /* WRITE_NO_OVERWRITE is supported only for buffers. */
13471 expected_hr = is_buffer(resource) ? S_OK : E_INVALIDARG;
13472 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
13473 /* D3D11.1 is required for constant and shader buffers. */
13474 todo_wine_if(expected_hr != S_OK)
13475 ok_(__FILE__, line)(hr == expected_hr
13476 || broken(bind_flags & (D3D11_BIND_CONSTANT_BUFFER | D3D11_BIND_SHADER_RESOURCE)),
13477 "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
13478 if (SUCCEEDED(hr))
13479 ID3D11DeviceContext_Unmap(context, resource, 0);
13481 ID3D11Device_Release(device);
13484 static void test_resource_access(const D3D_FEATURE_LEVEL feature_level)
13486 D3D11_TEXTURE2D_DESC texture_desc;
13487 struct device_desc device_desc;
13488 D3D11_BUFFER_DESC buffer_desc;
13489 ID3D11DeviceContext *context;
13490 D3D11_SUBRESOURCE_DATA data;
13491 ID3D11Resource *resource;
13492 BOOL required_cpu_access;
13493 BOOL cpu_write, cpu_read;
13494 HRESULT hr, expected_hr;
13495 UINT allowed_cpu_access;
13496 BOOL broken_validation;
13497 ID3D11Device *device;
13498 unsigned int i;
13499 ULONG refcount;
13501 static const struct
13503 D3D11_USAGE usage;
13504 UINT bind_flags;
13505 BOOL is_valid;
13506 UINT allowed_cpu_access;
13508 tests[] =
13510 /* Default resources cannot be written by CPU. */
13511 {D3D11_USAGE_DEFAULT, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
13512 {D3D11_USAGE_DEFAULT, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
13513 {D3D11_USAGE_DEFAULT, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
13514 {D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
13515 {D3D11_USAGE_DEFAULT, D3D11_BIND_STREAM_OUTPUT, TRUE, 0},
13516 {D3D11_USAGE_DEFAULT, D3D11_BIND_RENDER_TARGET, TRUE, 0},
13517 {D3D11_USAGE_DEFAULT, D3D11_BIND_DEPTH_STENCIL, TRUE, 0},
13518 {D3D11_USAGE_DEFAULT, D3D11_BIND_UNORDERED_ACCESS, TRUE, 0},
13520 /* Immutable resources cannot be written by CPU and GPU. */
13521 {D3D11_USAGE_IMMUTABLE, 0, FALSE, 0},
13522 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
13523 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
13524 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
13525 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
13526 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
13527 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_RENDER_TARGET, FALSE, 0},
13528 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
13529 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
13531 /* Dynamic resources cannot be written by GPU. */
13532 {D3D11_USAGE_DYNAMIC, 0, FALSE, D3D11_CPU_ACCESS_WRITE},
13533 {D3D11_USAGE_DYNAMIC, D3D11_BIND_VERTEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
13534 {D3D11_USAGE_DYNAMIC, D3D11_BIND_INDEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
13535 {D3D11_USAGE_DYNAMIC, D3D11_BIND_CONSTANT_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
13536 {D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE, TRUE, D3D11_CPU_ACCESS_WRITE},
13537 {D3D11_USAGE_DYNAMIC, D3D11_BIND_STREAM_OUTPUT, FALSE, D3D11_CPU_ACCESS_WRITE},
13538 {D3D11_USAGE_DYNAMIC, D3D11_BIND_RENDER_TARGET, FALSE, D3D11_CPU_ACCESS_WRITE},
13539 {D3D11_USAGE_DYNAMIC, D3D11_BIND_DEPTH_STENCIL, FALSE, D3D11_CPU_ACCESS_WRITE},
13540 {D3D11_USAGE_DYNAMIC, D3D11_BIND_UNORDERED_ACCESS, FALSE, D3D11_CPU_ACCESS_WRITE},
13542 /* Staging resources support only data transfer. */
13543 {D3D11_USAGE_STAGING, 0, TRUE, D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ},
13544 {D3D11_USAGE_STAGING, D3D11_BIND_VERTEX_BUFFER, FALSE, 0},
13545 {D3D11_USAGE_STAGING, D3D11_BIND_INDEX_BUFFER, FALSE, 0},
13546 {D3D11_USAGE_STAGING, D3D11_BIND_CONSTANT_BUFFER, FALSE, 0},
13547 {D3D11_USAGE_STAGING, D3D11_BIND_SHADER_RESOURCE, FALSE, 0},
13548 {D3D11_USAGE_STAGING, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
13549 {D3D11_USAGE_STAGING, D3D11_BIND_RENDER_TARGET, FALSE, 0},
13550 {D3D11_USAGE_STAGING, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
13551 {D3D11_USAGE_STAGING, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
13554 device_desc.feature_level = &feature_level;
13555 device_desc.flags = 0;
13556 if (!(device = create_device(&device_desc)))
13558 skip("Failed to create device for feature level %#x.\n", feature_level);
13559 return;
13561 ID3D11Device_GetImmediateContext(device, &context);
13563 data.SysMemPitch = 0;
13564 data.SysMemSlicePitch = 0;
13565 data.pSysMem = heap_alloc(10240);
13566 ok(!!data.pSysMem, "Failed to allocate memory.\n");
13568 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13570 switch (tests[i].bind_flags)
13572 case D3D11_BIND_DEPTH_STENCIL:
13573 continue;
13575 case D3D11_BIND_SHADER_RESOURCE:
13576 case D3D11_BIND_STREAM_OUTPUT:
13577 case D3D11_BIND_RENDER_TARGET:
13578 if (feature_level < D3D_FEATURE_LEVEL_10_0)
13579 continue;
13580 break;
13582 case D3D11_BIND_UNORDERED_ACCESS:
13583 if (feature_level < D3D_FEATURE_LEVEL_11_0)
13584 continue;
13585 break;
13587 default:
13588 break;
13591 allowed_cpu_access = tests[i].allowed_cpu_access;
13592 if (feature_level >= D3D_FEATURE_LEVEL_11_0 && is_d3d11_2_runtime(device)
13593 && tests[i].usage == D3D11_USAGE_DEFAULT
13594 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
13595 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS))
13596 allowed_cpu_access |= D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
13598 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
13599 cpu_write = allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
13600 cpu_read = allowed_cpu_access & D3D11_CPU_ACCESS_READ;
13602 buffer_desc.ByteWidth = 1024;
13603 buffer_desc.Usage = tests[i].usage;
13604 buffer_desc.BindFlags = tests[i].bind_flags;
13605 buffer_desc.MiscFlags = 0;
13606 buffer_desc.StructureByteStride = 0;
13608 buffer_desc.CPUAccessFlags = 0;
13609 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
13610 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
13611 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
13612 if (SUCCEEDED(hr))
13614 check_resource_cpu_access(context, resource,
13615 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
13616 ID3D11Resource_Release(resource);
13619 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
13620 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
13621 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
13622 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
13623 if (SUCCEEDED(hr))
13625 check_resource_cpu_access(context, resource,
13626 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
13627 ID3D11Resource_Release(resource);
13630 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
13631 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
13632 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
13633 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
13634 if (SUCCEEDED(hr))
13636 check_resource_cpu_access(context, resource,
13637 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
13638 ID3D11Resource_Release(resource);
13641 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
13642 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
13643 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
13644 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
13645 if (SUCCEEDED(hr))
13647 check_resource_cpu_access(context, resource,
13648 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
13649 ID3D11Resource_Release(resource);
13653 data.SysMemPitch = 16;
13655 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13657 switch (tests[i].bind_flags)
13659 case D3D11_BIND_VERTEX_BUFFER:
13660 case D3D11_BIND_INDEX_BUFFER:
13661 case D3D11_BIND_CONSTANT_BUFFER:
13662 case D3D11_BIND_STREAM_OUTPUT:
13663 continue;
13665 case D3D11_BIND_UNORDERED_ACCESS:
13666 if (feature_level < D3D_FEATURE_LEVEL_11_0)
13667 continue;
13668 break;
13670 default:
13671 break;
13674 broken_validation = tests[i].usage == D3D11_USAGE_DEFAULT
13675 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
13676 || tests[i].bind_flags == D3D11_BIND_RENDER_TARGET
13677 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS);
13679 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
13680 cpu_write = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
13681 cpu_read = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_READ;
13683 texture_desc.Width = 4;
13684 texture_desc.Height = 4;
13685 texture_desc.MipLevels = 1;
13686 texture_desc.ArraySize = 1;
13687 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13688 texture_desc.SampleDesc.Count = 1;
13689 texture_desc.SampleDesc.Quality = 0;
13690 texture_desc.Usage = tests[i].usage;
13691 texture_desc.BindFlags = tests[i].bind_flags;
13692 texture_desc.MiscFlags = 0;
13693 if (tests[i].bind_flags == D3D11_BIND_DEPTH_STENCIL)
13694 texture_desc.Format = DXGI_FORMAT_D16_UNORM;
13696 texture_desc.CPUAccessFlags = 0;
13697 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
13698 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
13699 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
13700 if (SUCCEEDED(hr))
13702 check_resource_cpu_access(context, resource,
13703 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
13704 ID3D11Resource_Release(resource);
13707 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
13708 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
13709 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
13710 ok(hr == expected_hr || (hr == S_OK && broken_validation),
13711 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
13712 if (SUCCEEDED(hr))
13714 if (broken_validation)
13715 texture_desc.CPUAccessFlags = 0;
13716 check_resource_cpu_access(context, resource,
13717 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
13718 ID3D11Resource_Release(resource);
13721 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
13722 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
13723 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
13724 ok(hr == expected_hr || (hr == S_OK && broken_validation),
13725 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
13726 if (SUCCEEDED(hr))
13728 if (broken_validation)
13729 texture_desc.CPUAccessFlags = 0;
13730 check_resource_cpu_access(context, resource,
13731 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
13732 ID3D11Resource_Release(resource);
13735 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
13736 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
13737 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
13738 ok(hr == expected_hr || (hr == S_OK && broken_validation),
13739 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
13740 if (SUCCEEDED(hr))
13742 if (broken_validation)
13743 texture_desc.CPUAccessFlags = 0;
13744 check_resource_cpu_access(context, resource,
13745 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
13746 ID3D11Resource_Release(resource);
13750 heap_free((void *)data.pSysMem);
13752 ID3D11DeviceContext_Release(context);
13753 refcount = ID3D11Device_Release(device);
13754 ok(!refcount, "Device has %u references left.\n", refcount);
13757 static void test_check_multisample_quality_levels(void)
13759 ID3D11Device *device;
13760 UINT quality_levels;
13761 ULONG refcount;
13762 HRESULT hr;
13764 if (!(device = create_device(NULL)))
13766 skip("Failed to create device.\n");
13767 return;
13770 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
13771 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
13772 if (!quality_levels)
13774 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
13775 goto done;
13778 quality_levels = 0xdeadbeef;
13779 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
13780 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
13781 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
13782 quality_levels = 0xdeadbeef;
13783 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
13784 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13785 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
13787 if (!enable_debug_layer)
13789 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
13790 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13791 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
13792 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13793 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
13794 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13797 quality_levels = 0xdeadbeef;
13798 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
13799 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
13800 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
13802 quality_levels = 0xdeadbeef;
13803 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
13804 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
13805 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
13807 quality_levels = 0xdeadbeef;
13808 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
13809 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
13810 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
13812 /* We assume 15 samples multisampling is never supported in practice. */
13813 quality_levels = 0xdeadbeef;
13814 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
13815 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
13816 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
13817 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
13818 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
13819 quality_levels = 0xdeadbeef;
13820 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
13821 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
13822 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
13823 quality_levels = 0xdeadbeef;
13824 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
13825 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
13826 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
13828 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
13829 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
13830 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
13832 done:
13833 refcount = ID3D11Device_Release(device);
13834 ok(!refcount, "Device has %u references left.\n", refcount);
13837 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
13839 DXGI_SWAP_CHAIN_DESC swapchain_desc;
13840 struct device_desc device_desc;
13841 IDXGISwapChain *swapchain;
13842 IDXGIDevice *dxgi_device;
13843 HRESULT hr, expected_hr;
13844 IDXGIAdapter *adapter;
13845 IDXGIFactory *factory;
13846 ID3D11Device *device;
13847 unsigned int i;
13848 ULONG refcount;
13850 swapchain_desc.BufferDesc.Width = 800;
13851 swapchain_desc.BufferDesc.Height = 600;
13852 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
13853 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
13854 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
13855 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
13856 swapchain_desc.SampleDesc.Count = 1;
13857 swapchain_desc.SampleDesc.Quality = 0;
13858 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
13859 swapchain_desc.BufferCount = 1;
13860 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
13861 swapchain_desc.Windowed = TRUE;
13862 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
13863 swapchain_desc.Flags = 0;
13865 device_desc.feature_level = &feature_level;
13866 device_desc.flags = 0;
13867 if (!(device = create_device(&device_desc)))
13869 skip("Failed to create device for feature level %#x.\n", feature_level);
13870 return;
13873 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
13874 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
13875 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
13876 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
13877 IDXGIDevice_Release(dxgi_device);
13878 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
13879 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
13880 IDXGIAdapter_Release(adapter);
13882 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
13883 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
13884 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
13885 hr, feature_level);
13886 if (SUCCEEDED(hr))
13887 IDXGISwapChain_Release(swapchain);
13889 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
13891 DXGI_FORMAT format = display_format_support[i].format;
13892 BOOL todo = FALSE;
13894 if (display_format_support[i].fl_required <= feature_level)
13896 expected_hr = S_OK;
13897 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
13898 todo = TRUE;
13900 else if (!display_format_support[i].fl_optional
13901 || display_format_support[i].fl_optional > feature_level)
13903 expected_hr = E_INVALIDARG;
13904 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
13905 todo = TRUE;
13907 else
13909 continue;
13912 swapchain_desc.BufferDesc.Format = format;
13913 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
13914 todo_wine_if(todo)
13915 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
13916 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
13917 hr, expected_hr, feature_level, format);
13918 if (FAILED(hr))
13919 continue;
13920 refcount = IDXGISwapChain_Release(swapchain);
13921 ok(!refcount, "Swapchain has %u references left.\n", refcount);
13924 refcount = ID3D11Device_Release(device);
13925 ok(!refcount, "Device has %u references left.\n", refcount);
13926 refcount = IDXGIFactory_Release(factory);
13927 ok(!refcount, "Factory has %u references left.\n", refcount);
13928 DestroyWindow(swapchain_desc.OutputWindow);
13931 static void test_swapchain_views(void)
13933 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
13934 struct d3d11_test_context test_context;
13935 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
13936 ID3D11ShaderResourceView *srv;
13937 ID3D11DeviceContext *context;
13938 ID3D11RenderTargetView *rtv;
13939 ID3D11Device *device;
13940 ULONG refcount;
13941 HRESULT hr;
13943 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
13945 if (!init_test_context(&test_context, NULL))
13946 return;
13948 device = test_context.device;
13949 context = test_context.immediate_context;
13951 refcount = get_refcount(test_context.backbuffer);
13952 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
13954 draw_color_quad(&test_context, &color);
13955 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
13957 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
13958 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
13959 U(rtv_desc).Texture2D.MipSlice = 0;
13960 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
13961 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13962 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13964 refcount = get_refcount(test_context.backbuffer);
13965 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
13967 draw_color_quad(&test_context, &color);
13968 todo_wine check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
13970 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
13971 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
13972 U(srv_desc).Texture2D.MostDetailedMip = 0;
13973 U(srv_desc).Texture2D.MipLevels = 1;
13974 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
13975 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13976 if (SUCCEEDED(hr))
13977 ID3D11ShaderResourceView_Release(srv);
13979 ID3D11RenderTargetView_Release(rtv);
13980 release_test_context(&test_context);
13983 static void test_swapchain_flip(void)
13985 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
13986 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
13987 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
13988 D3D11_TEXTURE2D_DESC texture_desc;
13989 ID3D11InputLayout *input_layout;
13990 ID3D11DeviceContext *context;
13991 unsigned int stride, offset;
13992 struct swapchain_desc desc;
13993 IDXGISwapChain *swapchain;
13994 ID3D11VertexShader *vs;
13995 ID3D11PixelShader *ps;
13996 ID3D11Device *device;
13997 ID3D11Buffer *vb;
13998 ULONG refcount;
13999 DWORD color;
14000 HWND window;
14001 HRESULT hr;
14002 RECT rect;
14004 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
14006 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
14008 static const DWORD vs_code[] =
14010 #if 0
14011 float4 main(float4 position : POSITION) : SV_POSITION
14013 return position;
14015 #endif
14016 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
14017 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14018 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
14019 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
14020 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
14021 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
14022 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
14025 static const DWORD ps_code[] =
14027 #if 0
14028 Texture2D t0, t1;
14029 SamplerState s;
14031 float4 main(float4 position : SV_POSITION) : SV_Target
14033 float2 p;
14035 p.x = 0.5;
14036 p.y = 0.5;
14037 if (position.x < 320)
14038 return t0.Sample(s, p);
14039 return t1.Sample(s, p);
14041 #endif
14042 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
14043 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14044 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
14045 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14046 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
14047 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
14048 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
14049 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
14050 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
14051 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
14052 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
14053 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
14054 0x00000000, 0x0100003e,
14056 static const struct vec2 quad[] =
14058 {-1.0f, -1.0f},
14059 {-1.0f, 1.0f},
14060 { 1.0f, -1.0f},
14061 { 1.0f, 1.0f},
14063 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
14064 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
14065 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
14067 if (!(device = create_device(NULL)))
14069 skip("Failed to create device, skipping tests.\n");
14070 return;
14072 SetRect(&rect, 0, 0, 640, 480);
14073 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
14074 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
14075 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
14076 desc.buffer_count = 3;
14077 desc.width = desc.height = 0;
14078 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
14079 desc.windowed = TRUE;
14080 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
14081 swapchain = create_swapchain(device, window, &desc);
14083 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
14084 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
14085 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
14086 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
14087 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
14088 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
14090 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
14091 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
14092 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
14093 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14094 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
14095 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14097 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
14098 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
14099 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
14100 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
14101 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
14103 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
14104 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
14105 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
14106 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
14107 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
14109 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
14110 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14111 if (SUCCEEDED(hr))
14112 ID3D11RenderTargetView_Release(offscreen_rtv);
14114 ID3D11Device_GetImmediateContext(device, &context);
14116 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
14117 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
14119 texture_desc.Width = 640;
14120 texture_desc.Height = 480;
14121 texture_desc.MipLevels = 1;
14122 texture_desc.ArraySize = 1;
14123 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14124 texture_desc.SampleDesc.Count = 1;
14125 texture_desc.SampleDesc.Quality = 0;
14126 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14127 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
14128 texture_desc.CPUAccessFlags = 0;
14129 texture_desc.MiscFlags = 0;
14130 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
14131 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
14132 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
14133 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
14134 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
14135 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
14137 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
14139 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
14140 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
14141 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
14142 vs_code, sizeof(vs_code), &input_layout);
14143 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
14144 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
14145 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
14146 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
14147 stride = sizeof(*quad);
14148 offset = 0;
14149 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
14151 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14152 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14153 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14155 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
14157 ID3D11DeviceContext_Draw(context, 4, 0);
14158 color = get_texture_color(offscreen, 120, 240);
14159 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
14161 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
14162 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
14163 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
14165 * What is this good for? I don't know. Ad-hoc tests suggest that
14166 * Present() always waits for the next V-sync interval, even if there are
14167 * still untouched buffers. Buffer 0 is the buffer that is shown on the
14168 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
14169 * rendering finishes before the V-sync interval is over. I haven't found
14170 * any productive use for more than one buffer. */
14171 IDXGISwapChain_Present(swapchain, 0, 0);
14173 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
14175 ID3D11DeviceContext_Draw(context, 4, 0);
14176 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
14177 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
14178 /* Buffer 1 is still untouched. */
14180 color = get_texture_color(backbuffer_0, 320, 240); /* green */
14181 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
14182 color = get_texture_color(backbuffer_2, 320, 240); /* red */
14183 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
14185 IDXGISwapChain_Present(swapchain, 0, 0);
14187 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
14189 ID3D11DeviceContext_Draw(context, 4, 0);
14190 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
14191 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
14192 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
14193 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
14195 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
14196 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
14197 color = get_texture_color(backbuffer_1, 320, 240); /* red */
14198 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
14199 color = get_texture_color(backbuffer_2, 320, 240); /* green */
14200 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
14202 ID3D11VertexShader_Release(vs);
14203 ID3D11PixelShader_Release(ps);
14204 ID3D11Buffer_Release(vb);
14205 ID3D11InputLayout_Release(input_layout);
14206 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
14207 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
14208 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
14209 ID3D11RenderTargetView_Release(offscreen_rtv);
14210 ID3D11Texture2D_Release(offscreen);
14211 ID3D11Texture2D_Release(backbuffer_0);
14212 ID3D11Texture2D_Release(backbuffer_1);
14213 ID3D11Texture2D_Release(backbuffer_2);
14214 IDXGISwapChain_Release(swapchain);
14216 ID3D11DeviceContext_Release(context);
14217 refcount = ID3D11Device_Release(device);
14218 ok(!refcount, "Device has %u references left.\n", refcount);
14219 DestroyWindow(window);
14222 static void test_clear_render_target_view_1d(void)
14224 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
14225 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
14227 struct d3d11_test_context test_context;
14228 D3D11_TEXTURE1D_DESC texture_desc;
14229 ID3D11DeviceContext *context;
14230 ID3D11RenderTargetView *rtv;
14231 ID3D11Texture1D *texture;
14232 ID3D11Device *device;
14233 HRESULT hr;
14235 if (!init_test_context(&test_context, NULL))
14236 return;
14238 device = test_context.device;
14239 context = test_context.immediate_context;
14241 texture_desc.Width = 64;
14242 texture_desc.MipLevels = 1;
14243 texture_desc.ArraySize = 1;
14244 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14245 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14246 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
14247 texture_desc.CPUAccessFlags = 0;
14248 texture_desc.MiscFlags = 0;
14249 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, NULL, &texture);
14250 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14252 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14253 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14255 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
14256 check_texture1d_color(texture, 0xbf4c7f19, 1);
14258 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
14259 check_texture1d_color(texture, 0x8000ff00, 1);
14261 ID3D11RenderTargetView_Release(rtv);
14262 ID3D11Texture1D_Release(texture);
14263 release_test_context(&test_context);
14266 static void test_clear_render_target_view_2d(void)
14268 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
14269 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
14270 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
14272 ID3D11Texture2D *texture, *srgb_texture;
14273 struct d3d11_test_context test_context;
14274 ID3D11RenderTargetView *rtv, *srgb_rtv;
14275 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
14276 D3D11_TEXTURE2D_DESC texture_desc;
14277 ID3D11DeviceContext *context;
14278 struct resource_readback rb;
14279 ID3D11Device *device;
14280 unsigned int i, j;
14281 HRESULT hr;
14283 if (!init_test_context(&test_context, NULL))
14284 return;
14286 device = test_context.device;
14287 context = test_context.immediate_context;
14289 texture_desc.Width = 640;
14290 texture_desc.Height = 480;
14291 texture_desc.MipLevels = 1;
14292 texture_desc.ArraySize = 1;
14293 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14294 texture_desc.SampleDesc.Count = 1;
14295 texture_desc.SampleDesc.Quality = 0;
14296 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14297 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
14298 texture_desc.CPUAccessFlags = 0;
14299 texture_desc.MiscFlags = 0;
14300 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14301 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14303 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
14304 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
14305 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14307 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14308 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14310 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
14311 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14313 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
14314 check_texture_color(test_context.backbuffer, expected_color, 1);
14316 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
14317 check_texture_color(texture, expected_color, 1);
14319 if (!enable_debug_layer)
14320 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
14321 check_texture_color(texture, expected_color, 1);
14323 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
14324 check_texture_color(srgb_texture, expected_srgb_color, 1);
14326 ID3D11RenderTargetView_Release(srgb_rtv);
14327 ID3D11RenderTargetView_Release(rtv);
14328 ID3D11Texture2D_Release(srgb_texture);
14329 ID3D11Texture2D_Release(texture);
14331 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
14332 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14333 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14335 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
14336 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
14337 U(rtv_desc).Texture2D.MipSlice = 0;
14338 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
14339 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14341 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14342 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
14343 U(rtv_desc).Texture2D.MipSlice = 0;
14344 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
14345 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14347 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
14348 check_texture_color(texture, expected_color, 1);
14350 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
14351 get_texture_readback(texture, 0, &rb);
14352 for (i = 0; i < 4; ++i)
14354 for (j = 0; j < 4; ++j)
14356 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
14357 DWORD color = get_readback_color(&rb, 80 + i * 160, 60 + j * 120, 0);
14358 ok(compare_color(color, expected_srgb_color, 1)
14359 || broken(compare_color(color, expected_color, 1) && broken_device),
14360 "Got unexpected color 0x%08x.\n", color);
14363 release_resource_readback(&rb);
14365 ID3D11RenderTargetView_Release(srgb_rtv);
14366 ID3D11RenderTargetView_Release(rtv);
14367 ID3D11Texture2D_Release(texture);
14368 release_test_context(&test_context);
14371 static void test_clear_render_target_view_3d(void)
14373 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
14374 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
14376 struct d3d11_test_context test_context;
14377 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
14378 D3D11_TEXTURE3D_DESC texture_desc;
14379 ID3D11DeviceContext *context;
14380 ID3D11RenderTargetView *rtv;
14381 ID3D11Texture3D *texture;
14382 ID3D11Device *device;
14383 HRESULT hr;
14385 if (!init_test_context(&test_context, NULL))
14386 return;
14387 device = test_context.device;
14388 context = test_context.immediate_context;
14390 texture_desc.Width = 8;
14391 texture_desc.Height = 8;
14392 texture_desc.Depth = 4;
14393 texture_desc.MipLevels = 1;
14394 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14395 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14396 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
14397 texture_desc.CPUAccessFlags = 0;
14398 texture_desc.MiscFlags = 0;
14399 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
14400 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14402 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14403 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14405 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
14406 check_texture3d_color(texture, 0xbf4c7f19, 1);
14407 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
14408 check_texture3d_color(texture, 0x8000ff00, 1);
14410 ID3D11RenderTargetView_Release(rtv);
14411 ID3D11Texture3D_Release(texture);
14413 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
14414 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
14415 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14417 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
14418 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
14419 U(rtv_desc).Texture3D.MipSlice = 0;
14420 U(rtv_desc).Texture3D.FirstWSlice = 0;
14421 U(rtv_desc).Texture3D.WSize = ~0u;
14422 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
14423 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14425 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
14426 check_texture3d_color(texture, 0xbf95bc59, 1);
14427 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
14428 check_texture3d_color(texture, 0x8000ff00, 1);
14430 ID3D11RenderTargetView_Release(rtv);
14431 ID3D11Texture3D_Release(texture);
14432 release_test_context(&test_context);
14435 static void test_clear_depth_stencil_view(void)
14437 D3D11_TEXTURE2D_DESC texture_desc;
14438 ID3D11Texture2D *depth_texture;
14439 ID3D11DeviceContext *context;
14440 ID3D11DepthStencilView *dsv;
14441 ID3D11Device *device;
14442 ULONG refcount;
14443 HRESULT hr;
14445 if (!(device = create_device(NULL)))
14447 skip("Failed to create device.\n");
14448 return;
14451 ID3D11Device_GetImmediateContext(device, &context);
14453 texture_desc.Width = 640;
14454 texture_desc.Height = 480;
14455 texture_desc.MipLevels = 1;
14456 texture_desc.ArraySize = 1;
14457 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
14458 texture_desc.SampleDesc.Count = 1;
14459 texture_desc.SampleDesc.Quality = 0;
14460 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14461 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
14462 texture_desc.CPUAccessFlags = 0;
14463 texture_desc.MiscFlags = 0;
14464 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
14465 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
14467 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
14468 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
14470 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
14471 check_texture_float(depth_texture, 1.0f, 0);
14473 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
14474 check_texture_float(depth_texture, 0.25f, 0);
14476 if (!enable_debug_layer)
14477 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
14478 check_texture_float(depth_texture, 0.25f, 0);
14480 ID3D11Texture2D_Release(depth_texture);
14481 ID3D11DepthStencilView_Release(dsv);
14483 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
14484 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
14485 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
14487 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
14488 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
14490 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
14491 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
14493 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
14494 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
14496 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
14497 check_texture_color(depth_texture, 0xffffffff, 0);
14499 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
14500 check_texture_color(depth_texture, 0x00000000, 0);
14502 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
14503 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
14505 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
14506 check_texture_color(depth_texture, 0xffffffff, 0);
14508 ID3D11Texture2D_Release(depth_texture);
14509 ID3D11DepthStencilView_Release(dsv);
14511 ID3D11DeviceContext_Release(context);
14513 refcount = ID3D11Device_Release(device);
14514 ok(!refcount, "Device has %u references left.\n", refcount);
14517 static unsigned int to_sint8(unsigned int x)
14519 union
14521 signed int s;
14522 unsigned int u;
14523 } bits;
14524 bits.u = x;
14525 return min(max(bits.s, -128), 127) & 0xff;
14528 #define check_rgba_sint8(data, uvec) check_rgba_sint8_(__LINE__, data, uvec)
14529 static void check_rgba_sint8_(unsigned int line, DWORD data, const struct uvec4 *v)
14531 unsigned int x = to_sint8(v->x);
14532 unsigned int y = to_sint8(v->y);
14533 unsigned int z = to_sint8(v->z);
14534 unsigned int w = to_sint8(v->w);
14535 DWORD expected[] =
14537 /* Windows 7 - Nvidia, WARP */
14538 (v->x & 0xff) | (v->y & 0xff) << 8 | (v->z & 0xff) << 16 | (v->w & 0xff) << 24,
14539 /* Windows 10 - AMD */
14540 x | y << 8 | z << 16 | w << 24,
14541 /* Windows 10 - Intel */
14542 x | x << 8 | x << 16 | x << 24,
14545 ok_(__FILE__, line)(data == expected[0] || data == expected[1] || broken(data == expected[2]),
14546 "Got %#x, expected %#x or %#x at %u, uvec4 %#x, %#x, %#x, %#x.\n",
14547 data, expected[0], expected[1], x, v->x, v->y, v->z, v->w);
14550 static void test_clear_buffer_unordered_access_view(void)
14552 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
14553 ID3D11UnorderedAccessView *uav, *uav2;
14554 struct device_desc device_desc;
14555 D3D11_BUFFER_DESC buffer_desc;
14556 ID3D11DeviceContext *context;
14557 struct resource_readback rb;
14558 ID3D11Buffer *buffer;
14559 ID3D11Device *device;
14560 struct uvec4 uvec4;
14561 unsigned int i, x;
14562 ULONG refcount;
14563 HRESULT hr;
14564 RECT rect;
14566 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
14567 static const struct uvec4 fe_uvec4 = {0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe};
14568 static const struct uvec4 uvec4_data[] =
14570 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
14572 {0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
14573 {0xffffffff, 0x00000000, 0x00000000, 0x00000000},
14574 {0x00000000, 0xffffffff, 0x00000000, 0x00000000},
14575 {0x00000000, 0x00000000, 0xffffffff, 0x00000000},
14576 {0x00000000, 0x00000000, 0x00000000, 0xffffffff},
14578 {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff},
14579 {0x80000000, 0x80000000, 0x80000000, 0x80000000},
14580 {0x000000ff, 0x00000080, 0x80000080, 0x00000080},
14581 {0x000000ff, 0x0000007f, 0x000000ef, 0x000000fe},
14582 {0x800000ff, 0x8000007f, 0x800000ef, 0x800000fe},
14583 {0xfefefefe, 0xf0f0f0f0, 0xefefefef, 0x0f0f0f0f},
14584 {0xaaaaaaaa, 0xdeadbeef, 0xdeadbabe, 0xdeadf00d},
14586 {0x00000001, 0x00000002, 0x00000003, 0x00000004},
14587 {0x000000ff, 0x000000fe, 0x000000fd, 0x000000fc},
14588 {0x000000f2, 0x000000f1, 0x000000f0, 0x000000ef},
14589 {0x0000000a, 0x0000000d, 0x0000000e, 0x0000000f},
14590 {0x0000001a, 0x0000002d, 0x0000003e, 0x0000004f},
14591 {0x00000050, 0x00000060, 0x00000070, 0x00000080},
14592 {0x00000090, 0x000000a0, 0x000000b0, 0x000000c0},
14593 {0x000000d0, 0x000000e0, 0x000000f0, 0x000000ff},
14594 {0x00000073, 0x00000077, 0x0000007a, 0x0000007b},
14595 {0x0000007c, 0x0000007d, 0x0000007e, 0x0000007f},
14597 {0x80000001, 0x80000002, 0x80000003, 0x80000004},
14598 {0x800000ff, 0x800000fe, 0x800000fd, 0x800000fc},
14599 {0x800000f2, 0x800000f1, 0x800000f0, 0x800000ef},
14600 {0x8000000a, 0x0000000d, 0x8000000e, 0x8000000f},
14601 {0x8000001a, 0x8000002d, 0x8000003e, 0x8000004f},
14602 {0x80000050, 0x80000060, 0x80000070, 0x00000080},
14603 {0x80000090, 0x800000a0, 0x800000b0, 0x800000c0},
14604 {0x800000d0, 0x800000e0, 0x800000f0, 0x800000ff},
14605 {0x80000073, 0x80000077, 0x8000007a, 0x8000007b},
14606 {0x8000007c, 0x8000007d, 0x8000007e, 0x8000007f},
14608 {0x7fffff01, 0x7fffff02, 0x7fffff03, 0x7fffff04},
14609 {0x7fffffff, 0x7ffffffe, 0x7ffffffd, 0x7ffffffc},
14610 {0x7ffffff2, 0x7ffffff1, 0x7ffffff0, 0x7fffffef},
14611 {0x7fffff0a, 0x7fffff0d, 0x7fffff0e, 0x7fffff0f},
14612 {0x7fffff1a, 0x7fffff2d, 0x7fffff3e, 0x7fffff4f},
14613 {0x7fffff50, 0x7fffff60, 0x7fffff70, 0x7fffff80},
14614 {0x8fffff90, 0x7fffffa0, 0x7fffffb0, 0x7fffffc0},
14615 {0x7fffffd0, 0x7fffffe0, 0x7ffffff0, 0x7fffffff},
14616 {0x7fffff73, 0x7fffff77, 0x7fffff7a, 0x7fffff7b},
14617 {0x7fffff7c, 0x7fffff7d, 0x7fffff7e, 0x7fffff7f},
14619 {0xffffff01, 0xffffff02, 0xffffff03, 0xffffff04},
14620 {0xffffffff, 0xfffffffe, 0xfffffffd, 0xfffffffc},
14621 {0xfffffff2, 0xfffffff1, 0xfffffff0, 0xffffffef},
14622 {0xffffff0a, 0xffffff0d, 0xffffff0e, 0xffffff0f},
14623 {0xffffff1a, 0xffffff2d, 0xffffff3e, 0xffffff4f},
14624 {0xffffff50, 0xffffff60, 0xffffff70, 0xffffff80},
14625 {0xffffff90, 0xffffffa0, 0xffffffb0, 0xffffffc0},
14626 {0xffffffd0, 0xffffffe0, 0xfffffff0, 0xffffffff},
14627 {0xffffff73, 0xffffff77, 0xffffff7a, 0xffffff7b},
14628 {0xffffff7c, 0xffffff7d, 0xffffff7e, 0xffffff7f},
14631 device_desc.feature_level = &feature_level;
14632 device_desc.flags = 0;
14633 if (!(device = create_device(&device_desc)))
14635 skip("Failed to create device for feature level %#x.\n", feature_level);
14636 return;
14639 ID3D11Device_GetImmediateContext(device, &context);
14641 /* Structured buffer views */
14642 buffer_desc.ByteWidth = 64;
14643 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
14644 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14645 buffer_desc.CPUAccessFlags = 0;
14646 buffer_desc.MiscFlags = 0;
14647 buffer_desc.StructureByteStride = 0;
14648 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
14649 buffer_desc.StructureByteStride = 4;
14650 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14651 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
14653 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
14654 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
14656 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
14657 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
14658 U(uav_desc).Buffer.FirstElement = 0;
14659 U(uav_desc).Buffer.NumElements = 4;
14660 U(uav_desc).Buffer.Flags = 0;
14661 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
14662 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
14664 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
14666 uvec4 = uvec4_data[i];
14667 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
14668 get_buffer_readback(buffer, &rb);
14669 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
14670 check_readback_data_color(&rb, &rect, uvec4.x, 0);
14671 release_resource_readback(&rb);
14673 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
14674 get_buffer_readback(buffer, &rb);
14675 SetRect(&rect, 0, 0, U(uav_desc).Buffer.NumElements, 1);
14676 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
14677 SetRect(&rect, U(uav_desc).Buffer.NumElements, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
14678 check_readback_data_color(&rb, &rect, uvec4.x, 0);
14679 release_resource_readback(&rb);
14682 ID3D11Buffer_Release(buffer);
14683 ID3D11UnorderedAccessView_Release(uav);
14684 ID3D11UnorderedAccessView_Release(uav2);
14686 /* Raw buffer views */
14687 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
14688 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14689 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
14691 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
14692 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
14693 U(uav_desc).Buffer.FirstElement = 0;
14694 U(uav_desc).Buffer.NumElements = 16;
14695 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
14696 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
14697 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
14698 U(uav_desc).Buffer.FirstElement = 8;
14699 U(uav_desc).Buffer.NumElements = 8;
14700 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
14701 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
14703 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
14705 uvec4 = uvec4_data[i];
14706 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
14707 get_buffer_readback(buffer, &rb);
14708 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
14709 check_readback_data_color(&rb, &rect, uvec4.x, 0);
14710 release_resource_readback(&rb);
14712 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
14713 get_buffer_readback(buffer, &rb);
14714 SetRect(&rect, 0, 0, U(uav_desc).Buffer.FirstElement, 1);
14715 check_readback_data_color(&rb, &rect, uvec4.x, 0);
14716 SetRect(&rect, U(uav_desc).Buffer.FirstElement, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
14717 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
14718 release_resource_readback(&rb);
14721 ID3D11Buffer_Release(buffer);
14722 ID3D11UnorderedAccessView_Release(uav);
14723 ID3D11UnorderedAccessView_Release(uav2);
14725 /* Typed buffer views */
14726 buffer_desc.MiscFlags = 0;
14727 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14728 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
14730 uav_desc.Format = DXGI_FORMAT_R32_SINT;
14731 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
14732 U(uav_desc).Buffer.FirstElement = 0;
14733 U(uav_desc).Buffer.NumElements = 16;
14734 U(uav_desc).Buffer.Flags = 0;
14735 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
14736 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
14737 U(uav_desc).Buffer.FirstElement = 9;
14738 U(uav_desc).Buffer.NumElements = 7;
14739 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
14740 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
14742 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
14744 uvec4 = uvec4_data[i];
14745 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
14746 get_buffer_readback(buffer, &rb);
14747 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
14748 check_readback_data_color(&rb, &rect, uvec4.x, 0);
14749 release_resource_readback(&rb);
14751 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
14752 get_buffer_readback(buffer, &rb);
14753 SetRect(&rect, 0, 0, U(uav_desc).Buffer.FirstElement, 1);
14754 check_readback_data_color(&rb, &rect, uvec4.x, 0);
14755 SetRect(&rect, U(uav_desc).Buffer.FirstElement, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
14756 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
14757 release_resource_readback(&rb);
14760 ID3D11UnorderedAccessView_Release(uav);
14761 ID3D11UnorderedAccessView_Release(uav2);
14763 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
14764 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
14765 U(uav_desc).Buffer.FirstElement = 0;
14766 U(uav_desc).Buffer.NumElements = 4;
14767 U(uav_desc).Buffer.Flags = 0;
14768 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
14769 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
14770 U(uav_desc).Buffer.FirstElement = 2;
14771 U(uav_desc).Buffer.NumElements = 2;
14772 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
14773 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
14775 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
14777 const struct uvec4 *data = NULL;
14778 BOOL all_match;
14780 uvec4 = uvec4_data[i];
14781 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
14782 get_buffer_readback(buffer, &rb);
14783 for (x = 0, all_match = TRUE; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
14785 const struct uvec4 broken_result = {uvec4.x, uvec4.x, uvec4.x, uvec4.x}; /* Intel */
14786 data = get_readback_uvec4(&rb, x, 0);
14787 if (!(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result))))
14788 all_match = FALSE;
14790 ok(all_match, "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
14791 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, x);
14792 release_resource_readback(&rb);
14794 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
14795 get_buffer_readback(buffer, &rb);
14796 for (x = 0, all_match = TRUE; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
14798 struct uvec4 broken_result;
14799 data = get_readback_uvec4(&rb, x, 0);
14800 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
14801 broken_result.x = broken_result.y = broken_result.z = broken_result.w = uvec4.x;
14802 if (!(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result))))
14803 all_match = FALSE;
14805 ok(all_match, "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
14806 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, x);
14807 release_resource_readback(&rb);
14810 uvec4.x = uvec4.y = uvec4.z = uvec4.w = 0xdeadbeef;
14811 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
14812 ID3D11UnorderedAccessView_Release(uav);
14813 ID3D11UnorderedAccessView_Release(uav2);
14815 uav_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT;
14816 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
14817 U(uav_desc).Buffer.FirstElement = 0;
14818 U(uav_desc).Buffer.NumElements = 16;
14819 U(uav_desc).Buffer.Flags = 0;
14820 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
14821 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
14822 U(uav_desc).Buffer.FirstElement = 8;
14823 U(uav_desc).Buffer.NumElements = 8;
14824 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
14825 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
14827 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
14829 uvec4 = uvec4_data[i];
14830 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
14831 get_buffer_readback(buffer, &rb);
14832 todo_wine check_rgba_sint8(get_readback_color(&rb, 0, 0, 0), &uvec4);
14833 todo_wine check_rgba_sint8(get_readback_color(&rb, 7, 0, 0), &uvec4);
14834 todo_wine check_rgba_sint8(get_readback_color(&rb, 15, 0, 0), &uvec4);
14835 release_resource_readback(&rb);
14837 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
14838 get_buffer_readback(buffer, &rb);
14839 todo_wine check_rgba_sint8(get_readback_color(&rb, 0, 0, 0), &uvec4);
14840 todo_wine check_rgba_sint8(get_readback_color(&rb, U(uav_desc).Buffer.FirstElement - 1, 0, 0), &uvec4);
14841 todo_wine check_rgba_sint8(get_readback_color(&rb, U(uav_desc).Buffer.FirstElement, 0, 0), &fe_uvec4);
14842 release_resource_readback(&rb);
14845 ID3D11UnorderedAccessView_Release(uav);
14846 ID3D11UnorderedAccessView_Release(uav2);
14848 ID3D11Buffer_Release(buffer);
14850 ID3D11DeviceContext_Release(context);
14851 refcount = ID3D11Device_Release(device);
14852 ok(!refcount, "Device has %u references left.\n", refcount);
14855 static void test_initial_depth_stencil_state(void)
14857 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
14858 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
14859 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
14860 struct d3d11_test_context test_context;
14861 D3D11_TEXTURE2D_DESC texture_desc;
14862 ID3D11DeviceContext *context;
14863 ID3D11DepthStencilView *dsv;
14864 ID3D11Texture2D *texture;
14865 ID3D11Device *device;
14866 unsigned int count;
14867 D3D11_VIEWPORT vp;
14868 HRESULT hr;
14870 if (!init_test_context(&test_context, NULL))
14871 return;
14873 device = test_context.device;
14874 context = test_context.immediate_context;
14876 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14877 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
14878 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
14879 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14880 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14882 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
14883 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
14885 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
14887 count = 1;
14888 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
14890 /* check if depth function is D3D11_COMPARISON_LESS */
14891 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
14892 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
14893 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.4f);
14894 draw_color_quad(&test_context, &green);
14895 draw_color_quad(&test_context, &red);
14896 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.6f, 0.6f);
14897 draw_color_quad(&test_context, &red);
14898 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14899 check_texture_float(texture, 0.4f, 1);
14901 ID3D11DepthStencilView_Release(dsv);
14902 ID3D11Texture2D_Release(texture);
14903 release_test_context(&test_context);
14906 static void test_draw_depth_only(void)
14908 struct d3d11_test_context test_context;
14909 ID3D11PixelShader *ps_color, *ps_depth;
14910 D3D11_TEXTURE2D_DESC texture_desc;
14911 ID3D11DeviceContext *context;
14912 ID3D11DepthStencilView *dsv;
14913 struct resource_readback rb;
14914 ID3D11Texture2D *texture;
14915 ID3D11Device *device;
14916 unsigned int i, j;
14917 struct vec4 depth;
14918 ID3D11Buffer *cb;
14919 HRESULT hr;
14921 static const DWORD ps_color_code[] =
14923 #if 0
14924 float4 main(float4 position : SV_POSITION) : SV_Target
14926 return float4(0.0, 1.0, 0.0, 1.0);
14928 #endif
14929 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
14930 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14931 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
14932 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14933 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
14934 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
14935 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
14937 static const DWORD ps_depth_code[] =
14939 #if 0
14940 float depth;
14942 float main() : SV_Depth
14944 return depth;
14946 #endif
14947 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
14948 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14949 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
14950 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
14951 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
14952 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
14955 if (!init_test_context(&test_context, NULL))
14956 return;
14958 device = test_context.device;
14959 context = test_context.immediate_context;
14961 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
14963 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14964 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
14965 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
14966 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14967 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14969 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
14970 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
14972 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
14973 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14974 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
14975 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14977 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14978 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
14979 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
14981 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
14982 check_texture_float(texture, 1.0f, 1);
14983 draw_quad(&test_context);
14984 check_texture_float(texture, 0.0f, 1);
14986 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
14988 depth.x = 0.7f;
14989 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
14990 draw_quad(&test_context);
14991 check_texture_float(texture, 0.0f, 1);
14992 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
14993 check_texture_float(texture, 1.0f, 1);
14994 draw_quad(&test_context);
14995 check_texture_float(texture, 0.7f, 1);
14996 depth.x = 0.8f;
14997 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
14998 draw_quad(&test_context);
14999 check_texture_float(texture, 0.7f, 1);
15000 depth.x = 0.5f;
15001 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
15002 draw_quad(&test_context);
15003 check_texture_float(texture, 0.5f, 1);
15005 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
15006 for (i = 0; i < 4; ++i)
15008 for (j = 0; j < 4; ++j)
15010 depth.x = 1.0f / 16.0f * (j + 4 * i);
15011 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
15013 set_viewport(context, 160.0f * j, 120.0f * i, 160.0f, 120.0f, 0.0f, 1.0f);
15015 draw_quad(&test_context);
15018 get_texture_readback(texture, 0, &rb);
15019 for (i = 0; i < 4; ++i)
15021 for (j = 0; j < 4; ++j)
15023 float obtained_depth, expected_depth;
15025 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
15026 expected_depth = 1.0f / 16.0f * (j + 4 * i);
15027 ok(compare_float(obtained_depth, expected_depth, 1),
15028 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
15029 obtained_depth, j, i, expected_depth);
15032 release_resource_readback(&rb);
15034 ID3D11Buffer_Release(cb);
15035 ID3D11PixelShader_Release(ps_color);
15036 ID3D11PixelShader_Release(ps_depth);
15037 ID3D11DepthStencilView_Release(dsv);
15038 ID3D11Texture2D_Release(texture);
15039 release_test_context(&test_context);
15042 static void test_draw_uav_only(void)
15044 struct d3d11_test_context test_context;
15045 D3D11_TEXTURE2D_DESC texture_desc;
15046 ID3D11UnorderedAccessView *uav;
15047 ID3D11DeviceContext *context;
15048 ID3D11Texture2D *texture;
15049 ID3D11PixelShader *ps;
15050 ID3D11Device *device;
15051 HRESULT hr;
15053 static const DWORD ps_code[] =
15055 #if 0
15056 RWTexture2D<int> u;
15058 void main()
15060 InterlockedAdd(u[uint2(0, 0)], 1);
15062 #endif
15063 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
15064 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15065 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
15066 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
15067 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
15069 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15070 static const UINT values[4] = {0};
15072 if (!init_test_context(&test_context, &feature_level))
15073 return;
15075 device = test_context.device;
15076 context = test_context.immediate_context;
15078 texture_desc.Width = 1;
15079 texture_desc.Height = 1;
15080 texture_desc.MipLevels = 1;
15081 texture_desc.ArraySize = 1;
15082 texture_desc.Format = DXGI_FORMAT_R32_SINT;
15083 texture_desc.SampleDesc.Count = 1;
15084 texture_desc.SampleDesc.Quality = 0;
15085 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15086 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15087 texture_desc.CPUAccessFlags = 0;
15088 texture_desc.MiscFlags = 0;
15090 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15091 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15093 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
15094 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15096 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15097 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15099 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15100 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
15101 0, 1, &uav, NULL);
15103 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
15104 set_viewport(context, 0.0f, 0.0f, 10.0f, 10.0f, 0.0f, 0.0f);
15105 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
15106 draw_quad(&test_context);
15107 check_texture_color(texture, 100, 1);
15109 draw_quad(&test_context);
15110 draw_quad(&test_context);
15111 draw_quad(&test_context);
15112 draw_quad(&test_context);
15113 check_texture_color(texture, 500, 1);
15115 ID3D11PixelShader_Release(ps);
15116 ID3D11Texture2D_Release(texture);
15117 ID3D11UnorderedAccessView_Release(uav);
15118 release_test_context(&test_context);
15121 static void test_cb_relative_addressing(void)
15123 struct d3d11_test_context test_context;
15124 ID3D11Buffer *colors_cb, *index_cb;
15125 unsigned int i, index[4] = {0};
15126 ID3D11DeviceContext *context;
15127 ID3D11PixelShader *ps;
15128 ID3D11Device *device;
15129 HRESULT hr;
15131 static const DWORD vs_code[] =
15133 #if 0
15134 int color_index;
15136 cbuffer colors
15138 float4 colors[8];
15141 struct vs_in
15143 float4 position : POSITION;
15146 struct vs_out
15148 float4 position : SV_POSITION;
15149 float4 color : COLOR;
15152 vs_out main(const vs_in v)
15154 vs_out o;
15156 o.position = v.position;
15157 o.color = colors[color_index];
15159 return o;
15161 #endif
15162 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
15163 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15164 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
15165 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15166 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15167 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
15168 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
15169 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
15170 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
15171 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
15172 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
15173 0x0100003e,
15175 static const DWORD ps_code[] =
15177 #if 0
15178 struct ps_in
15180 float4 position : SV_POSITION;
15181 float4 color : COLOR;
15184 float4 main(const ps_in v) : SV_TARGET
15186 return v.color;
15188 #endif
15189 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
15190 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15191 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15192 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15193 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15194 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
15195 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
15196 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
15198 static const struct
15200 float color[4];
15202 colors[10] =
15204 {{0.0f, 0.0f, 0.0f, 1.0f}},
15205 {{0.0f, 0.0f, 1.0f, 0.0f}},
15206 {{0.0f, 0.0f, 1.0f, 1.0f}},
15207 {{0.0f, 1.0f, 0.0f, 0.0f}},
15208 {{0.0f, 1.0f, 0.0f, 1.0f}},
15209 {{0.0f, 1.0f, 1.0f, 0.0f}},
15210 {{0.0f, 1.0f, 1.0f, 1.0f}},
15211 {{1.0f, 0.0f, 0.0f, 0.0f}},
15212 {{1.0f, 0.0f, 0.0f, 1.0f}},
15213 {{1.0f, 0.0f, 1.0f, 0.0f}},
15215 static const struct
15217 unsigned int index;
15218 DWORD expected;
15220 test_data[] =
15222 {0, 0xff000000},
15223 {1, 0x00ff0000},
15224 {2, 0xffff0000},
15225 {3, 0x0000ff00},
15226 {4, 0xff00ff00},
15227 {5, 0x00ffff00},
15228 {6, 0xffffff00},
15229 {7, 0x000000ff},
15231 {8, 0xff0000ff},
15232 {9, 0x00ff00ff},
15234 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
15235 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15237 if (!init_test_context(&test_context, &feature_level))
15238 return;
15240 device = test_context.device;
15241 context = test_context.immediate_context;
15243 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
15244 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
15246 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15247 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15249 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
15250 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
15251 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15253 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
15255 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
15257 index[0] = test_data[i].index;
15258 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
15260 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
15261 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
15264 ID3D11Buffer_Release(index_cb);
15265 ID3D11Buffer_Release(colors_cb);
15266 ID3D11PixelShader_Release(ps);
15268 release_test_context(&test_context);
15271 static void test_vs_input_relative_addressing(void)
15273 struct d3d11_test_context test_context;
15274 ID3D11DeviceContext *context;
15275 unsigned int offset, stride;
15276 unsigned int index[4] = {0};
15277 ID3D11PixelShader *ps;
15278 ID3D11Buffer *vb, *cb;
15279 ID3D11Device *device;
15280 unsigned int i;
15281 HRESULT hr;
15283 static const DWORD vs_code[] =
15285 #if 0
15286 struct vertex
15288 float4 position : POSITION;
15289 float4 colors[4] : COLOR;
15292 uint index;
15294 void main(vertex vin, out float4 position : SV_Position,
15295 out float4 color : COLOR)
15297 position = vin.position;
15298 color = vin.colors[index];
15300 #endif
15301 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003,
15302 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080,
15303 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000,
15304 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
15305 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089,
15306 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300,
15307 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
15308 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
15309 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4,
15310 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2,
15311 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f,
15312 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000,
15313 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2,
15314 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036,
15315 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001,
15316 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
15318 static const DWORD ps_code[] =
15320 #if 0
15321 struct vs_out
15323 float4 position : SV_POSITION;
15324 float4 color : COLOR;
15327 float4 main(struct vs_out i) : SV_TARGET
15329 return i.color;
15331 #endif
15332 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
15333 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15334 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15335 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15336 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15337 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
15338 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
15339 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
15341 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
15343 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15344 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1},
15345 {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D11_INPUT_PER_INSTANCE_DATA, 1},
15346 {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D11_INPUT_PER_INSTANCE_DATA, 1},
15347 {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D11_INPUT_PER_INSTANCE_DATA, 1},
15349 static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f};
15350 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
15352 if (!init_test_context(&test_context, NULL))
15353 return;
15354 device = test_context.device;
15355 context = test_context.immediate_context;
15357 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15358 vs_code, sizeof(vs_code), &test_context.input_layout);
15359 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15361 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
15362 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
15364 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(colors), colors);
15365 stride = sizeof(colors);
15366 offset = 0;
15367 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
15369 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15370 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15371 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15373 for (i = 0; i < ARRAY_SIZE(colors); ++i)
15375 *index = i;
15376 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
15377 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
15378 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
15379 check_texture_color(test_context.backbuffer, colors[i], 1);
15382 ID3D11Buffer_Release(cb);
15383 ID3D11Buffer_Release(vb);
15384 ID3D11PixelShader_Release(ps);
15385 release_test_context(&test_context);
15388 static void test_getdc(void)
15390 static const struct
15392 const char *name;
15393 DXGI_FORMAT format;
15394 BOOL getdc_supported;
15396 testdata[] =
15398 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
15399 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
15400 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
15401 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
15402 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
15403 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
15405 struct device_desc device_desc;
15406 D3D11_TEXTURE2D_DESC desc;
15407 ID3D11Texture2D *texture;
15408 IDXGISurface1 *surface;
15409 ID3D11Device *device;
15410 unsigned int i;
15411 ULONG refcount;
15412 HRESULT hr;
15413 HDC dc;
15415 device_desc.feature_level = NULL;
15416 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
15417 if (!(device = create_device(&device_desc)))
15419 skip("Failed to create device.\n");
15420 return;
15423 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
15424 desc.Width = 512;
15425 desc.Height = 512;
15426 desc.MipLevels = 1;
15427 desc.ArraySize = 1;
15428 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
15429 desc.SampleDesc.Count = 1;
15430 desc.SampleDesc.Quality = 0;
15431 desc.Usage = D3D11_USAGE_DEFAULT;
15432 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15433 desc.CPUAccessFlags = 0;
15434 desc.MiscFlags = 0;
15435 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
15436 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15438 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
15439 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
15441 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
15442 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
15444 IDXGISurface1_Release(surface);
15445 ID3D11Texture2D_Release(texture);
15447 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
15448 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
15449 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15451 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
15452 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
15454 hr = IDXGISurface1_ReleaseDC(surface, NULL);
15455 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
15457 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
15458 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
15460 hr = IDXGISurface1_ReleaseDC(surface, NULL);
15461 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
15463 IDXGISurface1_Release(surface);
15464 ID3D11Texture2D_Release(texture);
15466 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
15468 static const unsigned int bit_count = 32;
15469 unsigned int width_bytes;
15470 DIBSECTION dib;
15471 HBITMAP bitmap;
15472 DWORD type;
15473 int size;
15475 desc.Width = 64;
15476 desc.Height = 64;
15477 desc.MipLevels = 1;
15478 desc.ArraySize = 1;
15479 desc.Format = testdata[i].format;
15480 desc.SampleDesc.Count = 1;
15481 desc.SampleDesc.Quality = 0;
15482 desc.Usage = D3D11_USAGE_STAGING;
15483 desc.BindFlags = 0;
15484 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
15485 desc.MiscFlags = 0;
15487 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
15488 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15489 ID3D11Texture2D_Release(texture);
15491 /* STAGING usage, requesting GDI compatibility mode. */
15492 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
15493 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
15494 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
15496 desc.Usage = D3D11_USAGE_DEFAULT;
15497 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15498 desc.CPUAccessFlags = 0;
15499 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
15500 if (testdata[i].getdc_supported)
15501 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
15502 else
15503 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
15505 if (FAILED(hr))
15506 continue;
15508 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
15509 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
15511 dc = (void *)0x1234;
15512 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
15513 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
15515 if (FAILED(hr))
15517 IDXGISurface1_Release(surface);
15518 ID3D11Texture2D_Release(texture);
15519 continue;
15522 type = GetObjectType(dc);
15523 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
15524 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
15525 type = GetObjectType(bitmap);
15526 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
15528 size = GetObjectA(bitmap, sizeof(dib), &dib);
15529 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
15530 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
15532 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
15533 dib.dsBm.bmType, testdata[i].name);
15534 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
15535 dib.dsBm.bmWidth, testdata[i].name);
15536 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
15537 dib.dsBm.bmHeight, testdata[i].name);
15538 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
15539 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
15540 dib.dsBm.bmWidthBytes, testdata[i].name);
15541 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
15542 dib.dsBm.bmPlanes, testdata[i].name);
15543 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
15544 dib.dsBm.bmBitsPixel, testdata[i].name);
15546 if (size == sizeof(dib))
15547 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
15548 dib.dsBm.bmBits, testdata[i].name);
15549 else
15550 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
15551 dib.dsBm.bmBits, testdata[i].name);
15553 if (size == sizeof(dib))
15555 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
15556 dib.dsBmih.biSize, testdata[i].name);
15557 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
15558 dib.dsBmih.biHeight, testdata[i].name);
15559 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
15560 dib.dsBmih.biHeight, testdata[i].name);
15561 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
15562 dib.dsBmih.biPlanes, testdata[i].name);
15563 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
15564 dib.dsBmih.biBitCount, testdata[i].name);
15565 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
15566 dib.dsBmih.biCompression, testdata[i].name);
15567 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
15568 dib.dsBmih.biSizeImage, testdata[i].name);
15569 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
15570 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
15571 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
15572 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
15573 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
15574 dib.dsBmih.biClrUsed, testdata[i].name);
15575 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
15576 dib.dsBmih.biClrImportant, testdata[i].name);
15577 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
15578 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
15579 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
15580 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
15581 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
15584 hr = IDXGISurface1_ReleaseDC(surface, NULL);
15585 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
15587 IDXGISurface1_Release(surface);
15588 ID3D11Texture2D_Release(texture);
15591 refcount = ID3D11Device_Release(device);
15592 ok(!refcount, "Device has %u references left.\n", refcount);
15595 static void test_shader_stage_input_output_matching(void)
15597 struct d3d11_test_context test_context;
15598 D3D11_TEXTURE2D_DESC texture_desc;
15599 ID3D11Texture2D *render_target;
15600 ID3D11RenderTargetView *rtv[2];
15601 ID3D11DeviceContext *context;
15602 ID3D11VertexShader *vs;
15603 ID3D11PixelShader *ps;
15604 ID3D11Device *device;
15605 HRESULT hr;
15607 static const DWORD vs_code[] =
15609 #if 0
15610 struct output
15612 float4 position : SV_PoSiTion;
15613 float4 color0 : COLOR0;
15614 float4 color1 : COLOR1;
15617 void main(uint id : SV_VertexID, out output o)
15619 float2 coords = float2((id << 1) & 2, id & 2);
15620 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
15621 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
15622 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
15624 #endif
15625 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
15626 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15627 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
15628 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
15629 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15630 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
15631 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
15632 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
15633 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
15634 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
15635 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
15636 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
15637 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
15638 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
15639 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
15640 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
15641 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
15642 0x0100003e,
15644 static const DWORD ps_code[] =
15646 #if 0
15647 struct input
15649 float4 position : SV_PoSiTiOn;
15650 float4 color1 : COLOR1;
15651 float4 color0 : COLOR0;
15654 struct output
15656 float4 target0 : SV_Target0;
15657 float4 target1 : SV_Target1;
15660 void main(const in input i, out output o)
15662 o.target0 = i.color0;
15663 o.target1 = i.color1;
15665 #endif
15666 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
15667 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
15668 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
15669 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
15670 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
15671 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
15672 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
15673 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
15674 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
15675 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
15676 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
15679 if (!init_test_context(&test_context, NULL))
15680 return;
15682 device = test_context.device;
15683 context = test_context.immediate_context;
15685 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15686 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15687 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15688 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15690 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
15691 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
15692 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15694 rtv[0] = test_context.backbuffer_rtv;
15695 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
15696 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15698 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15699 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15700 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
15701 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
15702 ID3D11DeviceContext_Draw(context, 3, 0);
15704 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15705 check_texture_color(render_target, 0xff0000ff, 0);
15707 ID3D11RenderTargetView_Release(rtv[1]);
15708 ID3D11Texture2D_Release(render_target);
15709 ID3D11PixelShader_Release(ps);
15710 ID3D11VertexShader_Release(vs);
15711 release_test_context(&test_context);
15714 static void test_shader_interstage_interface(void)
15716 struct d3d11_test_context test_context;
15717 D3D11_TEXTURE2D_DESC texture_desc;
15718 ID3D11InputLayout *input_layout;
15719 ID3D11Texture2D *render_target;
15720 ID3D11DeviceContext *context;
15721 ID3D11RenderTargetView *rtv;
15722 ID3D11VertexShader *vs;
15723 ID3D11PixelShader *ps;
15724 ID3D11Device *device;
15725 UINT stride, offset;
15726 ID3D11Buffer *vb;
15727 unsigned int i;
15728 HRESULT hr;
15730 static const DWORD vs_code[] =
15732 #if 0
15733 struct vertex
15735 float4 position : SV_Position;
15736 float2 t0 : TEXCOORD0;
15737 nointerpolation float t1 : TEXCOORD1;
15738 uint t2 : TEXCOORD2;
15739 uint t3 : TEXCOORD3;
15740 float t4 : TEXCOORD4;
15743 void main(in vertex vin, out vertex vout)
15745 vout = vin;
15747 #endif
15748 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
15749 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
15750 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
15751 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
15752 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
15753 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
15754 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
15755 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
15756 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
15757 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
15758 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
15759 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
15760 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
15761 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
15762 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
15763 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
15764 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
15765 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
15766 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
15767 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
15768 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
15769 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
15771 static const DWORD ps_code[] =
15773 #if 0
15774 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
15775 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
15776 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
15778 o.x = t0.y + t1;
15779 o.y = t2 + t3;
15780 o.z = t4;
15781 o.w = t0.x;
15783 #endif
15784 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
15785 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
15786 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
15787 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
15788 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
15789 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
15790 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
15791 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
15792 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
15793 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
15794 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
15795 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
15796 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
15797 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
15798 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
15800 static const DWORD ps_partial_input_code[] =
15802 #if 0
15803 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
15804 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
15805 uint t3 : TEXCOORD3, out float4 o : SV_Target)
15807 o.x = t0.y + t1;
15808 o.y = t2 + t3;
15809 o.z = 0.0f;
15810 o.w = t0.x;
15812 #endif
15813 0x43425844, 0x5b1db356, 0xaa5a5e9d, 0xb916a081, 0x61e6dcb1, 0x00000001, 0x000001cc, 0x00000003,
15814 0x0000002c, 0x000000cc, 0x00000100, 0x4e475349, 0x00000098, 0x00000005, 0x00000008, 0x00000080,
15815 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
15816 0x00000003, 0x00000001, 0x00000303, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
15817 0x00000101, 0x0000008c, 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x0000008c,
15818 0x00000003, 0x00000000, 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
15819 0x43584554, 0x44524f4f, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15820 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
15821 0x52444853, 0x000000c4, 0x00000040, 0x00000031, 0x03001062, 0x00101032, 0x00000001, 0x03000862,
15822 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042, 0x00000002,
15823 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012, 0x00000000,
15824 0x0010102a, 0x00000002, 0x0010101a, 0x00000002, 0x05000056, 0x00102022, 0x00000000, 0x0010000a,
15825 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a, 0x00000002,
15826 0x05000036, 0x00102042, 0x00000000, 0x00004001, 0x00000000, 0x05000036, 0x00102082, 0x00000000,
15827 0x0010100a, 0x00000001, 0x0100003e,
15829 static const DWORD ps_single_input_code[] =
15831 #if 0
15832 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0, out float4 o : SV_Target)
15834 o.x = t0.x;
15835 o.y = t0.y;
15836 o.z = 1.0f;
15837 o.w = 2.0f;
15839 #endif
15840 0x43425844, 0x7cc601b6, 0xc65b8bdb, 0x54d0f606, 0x9cc74d3d, 0x00000001, 0x00000118, 0x00000003,
15841 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
15842 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15843 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
15844 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
15845 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058,
15846 0x00000040, 0x00000016, 0x03001062, 0x00101032, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
15847 0x05000036, 0x00102032, 0x00000000, 0x00101046, 0x00000001, 0x08000036, 0x001020c2, 0x00000000,
15848 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x40000000, 0x0100003e,
15850 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
15852 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15853 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
15854 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
15855 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
15856 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
15857 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
15859 static const struct
15861 struct vec2 position;
15862 struct vec2 t0;
15863 float t1;
15864 unsigned int t2;
15865 unsigned int t3;
15866 float t4;
15868 quad[] =
15870 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
15871 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
15872 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
15873 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
15875 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
15876 static const struct
15878 const DWORD *ps_code;
15879 size_t ps_size;
15880 struct vec4 expected_result;
15882 tests[] =
15884 {ps_code, sizeof(ps_code), {10.0f, 8.0f, 7.0f, 3.0f}},
15885 {ps_partial_input_code, sizeof(ps_partial_input_code), {10.0f, 8.0f, 0.0f, 3.0f}},
15886 {ps_single_input_code, sizeof(ps_single_input_code), {3.0f, 5.0f, 1.0f, 2.0f}},
15889 if (!init_test_context(&test_context, NULL))
15890 return;
15892 device = test_context.device;
15893 context = test_context.immediate_context;
15895 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15896 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15898 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
15899 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
15900 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
15901 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15903 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
15904 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15906 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15907 vs_code, sizeof(vs_code), &input_layout);
15908 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15910 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
15912 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
15914 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15915 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15916 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
15917 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
15918 offset = 0;
15919 stride = sizeof(*quad);
15920 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
15922 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15924 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_size, NULL, &ps);
15925 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
15926 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15927 ID3D11DeviceContext_Draw(context, 4, 0);
15928 check_texture_vec4(render_target, &tests[i].expected_result, 0);
15929 ID3D11PixelShader_Release(ps);
15932 ID3D11InputLayout_Release(input_layout);
15933 ID3D11RenderTargetView_Release(rtv);
15934 ID3D11Texture2D_Release(render_target);
15935 ID3D11VertexShader_Release(vs);
15936 ID3D11Buffer_Release(vb);
15937 release_test_context(&test_context);
15940 static void test_sm4_if_instruction(void)
15942 struct d3d11_test_context test_context;
15943 ID3D11PixelShader *ps_if_nz, *ps_if_z;
15944 ID3D11DeviceContext *context;
15945 ID3D11Device *device;
15946 unsigned int bits[4];
15947 DWORD expected_color;
15948 ID3D11Buffer *cb;
15949 unsigned int i;
15950 HRESULT hr;
15952 static const DWORD ps_if_nz_code[] =
15954 #if 0
15955 uint bits;
15957 float4 main() : SV_TARGET
15959 if (bits)
15960 return float4(0.0f, 1.0f, 0.0f, 1.0f);
15961 else
15962 return float4(1.0f, 0.0f, 0.0f, 1.0f);
15964 #endif
15965 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
15966 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15967 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15968 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
15969 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
15970 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
15971 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
15972 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
15974 static const DWORD ps_if_z_code[] =
15976 #if 0
15977 uint bits;
15979 float4 main() : SV_TARGET
15981 if (!bits)
15982 return float4(0.0f, 1.0f, 0.0f, 1.0f);
15983 else
15984 return float4(1.0f, 0.0f, 0.0f, 1.0f);
15986 #endif
15987 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
15988 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15989 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15990 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
15991 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
15992 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
15993 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
15994 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
15996 static unsigned int bit_patterns[] =
15998 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
16001 if (!init_test_context(&test_context, NULL))
16002 return;
16004 device = test_context.device;
16005 context = test_context.immediate_context;
16007 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
16008 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
16009 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
16010 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
16012 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
16013 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16015 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
16017 *bits = bit_patterns[i];
16018 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
16020 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
16021 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
16022 draw_quad(&test_context);
16023 check_texture_color(test_context.backbuffer, expected_color, 0);
16025 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
16026 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
16027 draw_quad(&test_context);
16028 check_texture_color(test_context.backbuffer, expected_color, 0);
16031 ID3D11Buffer_Release(cb);
16032 ID3D11PixelShader_Release(ps_if_z);
16033 ID3D11PixelShader_Release(ps_if_nz);
16034 release_test_context(&test_context);
16037 static void test_sm4_breakc_instruction(void)
16039 struct d3d11_test_context test_context;
16040 ID3D11DeviceContext *context;
16041 ID3D11PixelShader *ps;
16042 ID3D11Device *device;
16043 HRESULT hr;
16045 static const DWORD ps_breakc_nz_code[] =
16047 #if 0
16048 float4 main() : SV_TARGET
16050 uint counter = 0;
16052 for (uint i = 0; i < 255; ++i)
16053 ++counter;
16055 if (counter == 255)
16056 return float4(0.0f, 1.0f, 0.0f, 1.0f);
16057 else
16058 return float4(1.0f, 0.0f, 0.0f, 1.0f);
16060 #endif
16061 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
16062 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16063 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16064 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
16065 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
16066 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
16067 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
16068 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
16069 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
16070 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
16071 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
16072 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
16073 0x01000015, 0x0100003e,
16075 static const DWORD ps_breakc_z_code[] =
16077 #if 0
16078 float4 main() : SV_TARGET
16080 uint counter = 0;
16082 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
16083 ++counter;
16085 if (counter == 255)
16086 return float4(0.0f, 1.0f, 0.0f, 1.0f);
16087 else
16088 return float4(1.0f, 0.0f, 0.0f, 1.0f);
16090 #endif
16091 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
16092 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16093 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16094 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
16095 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
16096 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
16097 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
16098 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
16099 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
16100 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
16101 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
16102 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
16103 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
16104 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
16107 if (!init_test_context(&test_context, NULL))
16108 return;
16110 device = test_context.device;
16111 context = test_context.immediate_context;
16113 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
16114 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
16115 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16116 draw_quad(&test_context);
16117 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
16118 ID3D11PixelShader_Release(ps);
16120 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
16121 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
16122 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16123 draw_quad(&test_context);
16124 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
16125 ID3D11PixelShader_Release(ps);
16127 release_test_context(&test_context);
16130 static void test_sm4_continuec_instruction(void)
16132 struct d3d11_test_context test_context;
16133 ID3D11DeviceContext *context;
16134 ID3D11PixelShader *ps;
16135 ID3D11Device *device;
16136 HRESULT hr;
16138 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
16139 * with a normal continue inside, the shaders have been compiled with
16140 * the /Gfa flag. */
16141 static const DWORD ps_continuec_nz_code[] =
16143 #if 0
16144 float4 main() : SV_TARGET
16146 uint counter = 0;
16147 int i = -1;
16149 while (i < 255) {
16150 ++i;
16152 if (i != 0)
16153 continue;
16155 ++counter;
16158 if (counter == 1)
16159 return float4(0.0f, 1.0f, 0.0f, 1.0f);
16160 else
16161 return float4(1.0f, 0.0f, 0.0f, 1.0f);
16163 #endif
16164 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
16165 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16166 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16167 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
16168 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
16169 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
16170 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
16171 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
16172 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
16173 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
16174 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
16175 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
16176 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
16177 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
16178 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
16179 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
16180 0x3f800000, 0x0100003e,
16183 static const DWORD ps_continuec_z_code[] =
16185 #if 0
16186 float4 main() : SV_TARGET
16188 uint counter = 0;
16189 int i = -1;
16191 while (i < 255) {
16192 ++i;
16194 if (i == 0)
16195 continue;
16197 ++counter;
16200 if (counter == 255)
16201 return float4(0.0f, 1.0f, 0.0f, 1.0f);
16202 else
16203 return float4(1.0f, 0.0f, 0.0f, 1.0f);
16205 #endif
16206 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
16207 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16208 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16209 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
16210 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
16211 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
16212 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
16213 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
16214 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
16215 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
16216 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
16217 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
16218 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
16219 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
16220 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
16223 if (!init_test_context(&test_context, NULL))
16224 return;
16226 device = test_context.device;
16227 context = test_context.immediate_context;
16229 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), NULL, &ps);
16230 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
16231 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16232 draw_quad(&test_context);
16233 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
16234 ID3D11PixelShader_Release(ps);
16236 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), NULL, &ps);
16237 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
16238 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16239 draw_quad(&test_context);
16240 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
16241 ID3D11PixelShader_Release(ps);
16243 release_test_context(&test_context);
16246 static void test_sm4_discard_instruction(void)
16248 ID3D11PixelShader *ps_discard_nz, *ps_discard_z;
16249 struct d3d11_test_context test_context;
16250 ID3D11DeviceContext *context;
16251 ID3D11Device *device;
16252 ID3D11Buffer *cb;
16253 unsigned int i;
16254 HRESULT hr;
16256 static const DWORD ps_discard_nz_code[] =
16258 #if 0
16259 uint data;
16261 float4 main() : SV_Target
16263 if (data)
16264 discard;
16265 return float4(0.0f, 0.5f, 0.0f, 1.0f);
16267 #endif
16268 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
16269 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16270 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16271 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
16272 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
16273 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
16274 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
16276 static const DWORD ps_discard_z_code[] =
16278 #if 0
16279 uint data;
16281 float4 main() : SV_Target
16283 if (!data)
16284 discard;
16285 return float4(0.0f, 1.0f, 0.0f, 1.0f);
16287 #endif
16288 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
16289 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16290 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16291 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
16292 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
16293 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
16294 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
16296 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16297 static const struct uvec4 values[] =
16299 {0x0000000},
16300 {0x0000001},
16301 {0x8000000},
16302 {0xfffffff},
16305 if (!init_test_context(&test_context, NULL))
16306 return;
16308 device = test_context.device;
16309 context = test_context.immediate_context;
16311 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
16312 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16314 hr = ID3D11Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code),
16315 NULL, &ps_discard_nz);
16316 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
16317 hr = ID3D11Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code),
16318 NULL, &ps_discard_z);
16319 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
16321 for (i = 0; i < ARRAY_SIZE(values); ++i)
16323 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &values[i], 0, 0);
16325 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16326 ID3D11DeviceContext_PSSetShader(context, ps_discard_nz, NULL, 0);
16327 draw_quad(&test_context);
16328 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
16330 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16331 ID3D11DeviceContext_PSSetShader(context, ps_discard_z, NULL, 0);
16332 draw_quad(&test_context);
16333 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
16336 ID3D11Buffer_Release(cb);
16337 ID3D11PixelShader_Release(ps_discard_nz);
16338 ID3D11PixelShader_Release(ps_discard_z);
16339 release_test_context(&test_context);
16342 static void test_sm5_swapc_instruction(void)
16344 struct input
16346 struct uvec4 src0;
16347 struct uvec4 src1;
16348 struct uvec4 src2;
16351 struct d3d11_test_context test_context;
16352 D3D11_TEXTURE2D_DESC texture_desc;
16353 ID3D11DeviceContext *context;
16354 ID3D11RenderTargetView *rtv;
16355 ID3D11Texture2D *texture;
16356 ID3D11PixelShader *ps[6];
16357 ID3D11Device *device;
16358 ID3D11Buffer *cb;
16359 unsigned int i;
16360 HRESULT hr;
16362 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16363 static const DWORD ps_swapc0_code[] =
16365 #if 0
16366 ps_5_0
16367 dcl_globalFlags refactoringAllowed
16368 dcl_constantbuffer cb0[3], immediateIndexed
16369 dcl_output o0.xyzw
16370 dcl_temps 2
16371 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
16372 mov o0.xyzw, r0.xyzw
16374 #endif
16375 0x43425844, 0x9e089246, 0x9f8b5cbe, 0xbac66faf, 0xaef23488, 0x00000001, 0x000000f8, 0x00000003,
16376 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16377 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16378 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
16379 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
16380 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
16381 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
16382 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
16384 static const DWORD ps_swapc1_code[] =
16386 #if 0
16387 ps_5_0
16388 dcl_globalFlags refactoringAllowed
16389 dcl_constantbuffer cb0[3], immediateIndexed
16390 dcl_output o0.xyzw
16391 dcl_temps 2
16392 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
16393 mov o0.xyzw, r1.xyzw
16395 #endif
16396 0x43425844, 0xf2daed61, 0xede211f7, 0x7300dbea, 0x573ed49f, 0x00000001, 0x000000f8, 0x00000003,
16397 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16398 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16399 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
16400 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
16401 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
16402 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
16403 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
16405 static const DWORD ps_swapc2_code[] =
16407 #if 0
16408 ps_5_0
16409 dcl_globalFlags refactoringAllowed
16410 dcl_constantbuffer cb0[3], immediateIndexed
16411 dcl_output o0.xyzw
16412 dcl_temps 2
16413 mov r0.xyzw, cb0[1].xyzw
16414 mov r1.xyzw, cb0[2].xyzw
16415 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
16416 mov o0.xyzw, r0.xyzw
16418 #endif
16419 0x43425844, 0x230fcb22, 0x70d99148, 0x65814d89, 0x97473498, 0x00000001, 0x00000120, 0x00000003,
16420 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16421 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16422 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
16423 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
16424 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
16425 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
16426 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
16427 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
16429 static const DWORD ps_swapc3_code[] =
16431 #if 0
16432 ps_5_0
16433 dcl_globalFlags refactoringAllowed
16434 dcl_constantbuffer cb0[3], immediateIndexed
16435 dcl_output o0.xyzw
16436 dcl_temps 2
16437 mov r0.xyzw, cb0[1].xyzw
16438 mov r1.xyzw, cb0[2].xyzw
16439 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
16440 mov o0.xyzw, r1.xyzw
16442 #endif
16443 0x43425844, 0xce595d62, 0x98305541, 0xb04e74c8, 0xfc010f3a, 0x00000001, 0x00000120, 0x00000003,
16444 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16445 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16446 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
16447 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
16448 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
16449 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
16450 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
16451 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
16453 static const DWORD ps_swapc4_code[] =
16455 #if 0
16456 ps_5_0
16457 dcl_globalFlags refactoringAllowed
16458 dcl_constantbuffer cb0[3], immediateIndexed
16459 dcl_output o0.xyzw
16460 dcl_temps 2
16461 mov r0.xyzw, cb0[0].xyzw
16462 swapc r0.xyzw, r1.xyzw, r0.xyzw, cb0[1].xyzw, cb0[2].xyzw
16463 mov o0.xyzw, r0.xyzw
16465 #endif
16466 0x43425844, 0x72067c48, 0xb53572a0, 0x9dd9e0fd, 0x903e37e3, 0x00000001, 0x0000010c, 0x00000003,
16467 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16468 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16469 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
16470 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
16471 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
16472 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000000, 0x00208e46,
16473 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
16474 0x00100e46, 0x00000000, 0x0100003e,
16476 static const DWORD ps_swapc5_code[] =
16478 #if 0
16479 ps_5_0
16480 dcl_globalFlags refactoringAllowed
16481 dcl_constantbuffer cb0[3], immediateIndexed
16482 dcl_output o0.xyzw
16483 dcl_temps 2
16484 mov r1.xyzw, cb0[0].xyzw
16485 swapc r0.xyzw, r1.xyzw, r1.xyzw, cb0[1].xyzw, cb0[2].xyzw
16486 mov o0.xyzw, r1.xyzw
16488 #endif
16489 0x43425844, 0x7078fb08, 0xdd24cd44, 0x469d3258, 0x9e33a0bc, 0x00000001, 0x0000010c, 0x00000003,
16490 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16491 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16492 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
16493 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
16494 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000,
16495 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001, 0x00208e46,
16496 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
16497 0x00100e46, 0x00000001, 0x0100003e,
16499 static const struct
16501 struct input input;
16502 struct uvec4 dst0;
16503 struct uvec4 dst1;
16505 tests[] =
16508 {{0, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
16509 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}
16512 {{1, 1, 1, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
16513 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
16516 {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
16517 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
16518 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
16521 {{1, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
16522 {0xaaaa, 0xc0de, 0xcccc, 0xeeee}, {0xdead, 0xbbbb, 0xffff, 0xdddd},
16525 {{1, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
16526 {0xaaaa, 0xc0de, 0xffff, 0xdddd}, {0xdead, 0xbbbb, 0xcccc, 0xeeee},
16529 {{1, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
16530 {0xaaaa, 0xc0de, 0xffff, 0xeeee}, {0xdead, 0xbbbb, 0xcccc, 0xdddd}
16533 {{0, 1, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
16534 {0xdead, 0xbbbb, 0xffff, 0xeeee}, {0xaaaa, 0xc0de, 0xcccc, 0xdddd}
16537 {{0, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
16538 {0xdead, 0xc0de, 0xcccc, 0xeeee}, {0xaaaa, 0xbbbb, 0xffff, 0xdddd}
16541 {{0, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
16542 {0xdead, 0xc0de, 0xffff, 0xdddd}, {0xaaaa, 0xbbbb, 0xcccc, 0xeeee},
16546 if (!init_test_context(&test_context, &feature_level))
16547 return;
16549 device = test_context.device;
16550 context = test_context.immediate_context;
16552 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16553 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
16554 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16555 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16557 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
16558 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
16560 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
16562 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct input), NULL);
16563 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16565 hr = ID3D11Device_CreatePixelShader(device, ps_swapc0_code, sizeof(ps_swapc0_code), NULL, &ps[0]);
16566 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16567 hr = ID3D11Device_CreatePixelShader(device, ps_swapc1_code, sizeof(ps_swapc1_code), NULL, &ps[1]);
16568 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16569 hr = ID3D11Device_CreatePixelShader(device, ps_swapc2_code, sizeof(ps_swapc2_code), NULL, &ps[2]);
16570 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16571 hr = ID3D11Device_CreatePixelShader(device, ps_swapc3_code, sizeof(ps_swapc3_code), NULL, &ps[3]);
16572 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16573 hr = ID3D11Device_CreatePixelShader(device, ps_swapc4_code, sizeof(ps_swapc4_code), NULL, &ps[4]);
16574 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16575 hr = ID3D11Device_CreatePixelShader(device, ps_swapc5_code, sizeof(ps_swapc5_code), NULL, &ps[5]);
16576 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16578 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16580 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &tests[i].input, 0, 0);
16582 ID3D11DeviceContext_PSSetShader(context, ps[0], NULL, 0);
16583 draw_quad(&test_context);
16584 check_texture_uvec4(texture, &tests[i].dst0);
16586 ID3D11DeviceContext_PSSetShader(context, ps[1], NULL, 0);
16587 draw_quad(&test_context);
16588 check_texture_uvec4(texture, &tests[i].dst1);
16590 ID3D11DeviceContext_PSSetShader(context, ps[2], NULL, 0);
16591 draw_quad(&test_context);
16592 check_texture_uvec4(texture, &tests[i].dst0);
16594 ID3D11DeviceContext_PSSetShader(context, ps[3], NULL, 0);
16595 draw_quad(&test_context);
16596 check_texture_uvec4(texture, &tests[i].dst1);
16598 ID3D11DeviceContext_PSSetShader(context, ps[4], NULL, 0);
16599 draw_quad(&test_context);
16600 check_texture_uvec4(texture, &tests[i].dst0);
16602 ID3D11DeviceContext_PSSetShader(context, ps[5], NULL, 0);
16603 draw_quad(&test_context);
16604 check_texture_uvec4(texture, &tests[i].dst1);
16607 for (i = 0; i < ARRAY_SIZE(ps); ++i)
16608 ID3D11PixelShader_Release(ps[i]);
16609 ID3D11RenderTargetView_Release(rtv);
16610 ID3D11Texture2D_Release(texture);
16611 ID3D11Buffer_Release(cb);
16612 release_test_context(&test_context);
16615 static void test_create_input_layout(void)
16617 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
16619 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
16621 ULONG refcount, expected_refcount;
16622 ID3D11InputLayout *input_layout;
16623 ID3D11Device *device;
16624 unsigned int i;
16625 HRESULT hr;
16627 static const DWORD vs_code[] =
16629 #if 0
16630 float4 main(float4 position : POSITION) : SV_POSITION
16632 return position;
16634 #endif
16635 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
16636 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16637 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
16638 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
16639 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
16640 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
16641 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
16643 static const DXGI_FORMAT vertex_formats[] =
16645 DXGI_FORMAT_R32G32_FLOAT,
16646 DXGI_FORMAT_R32G32_UINT,
16647 DXGI_FORMAT_R32G32_SINT,
16648 DXGI_FORMAT_R16G16_FLOAT,
16649 DXGI_FORMAT_R16G16_UINT,
16650 DXGI_FORMAT_R16G16_SINT,
16651 DXGI_FORMAT_R32_FLOAT,
16652 DXGI_FORMAT_R32_UINT,
16653 DXGI_FORMAT_R32_SINT,
16654 DXGI_FORMAT_R16_UINT,
16655 DXGI_FORMAT_R16_SINT,
16656 DXGI_FORMAT_R8G8_UNORM,
16657 DXGI_FORMAT_R8_UINT,
16658 DXGI_FORMAT_R8_SINT,
16661 if (!(device = create_device(NULL)))
16663 skip("Failed to create device.\n");
16664 return;
16667 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
16669 expected_refcount = get_refcount(device) + 1;
16670 layout_desc->Format = vertex_formats[i];
16671 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
16672 vs_code, sizeof(vs_code), &input_layout);
16673 ok(hr == S_OK, "Failed to create input layout for format %#x, hr %#x.\n",
16674 vertex_formats[i], hr);
16675 refcount = get_refcount(device);
16676 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
16677 refcount, expected_refcount);
16678 ID3D11InputLayout_Release(input_layout);
16681 refcount = ID3D11Device_Release(device);
16682 ok(!refcount, "Device has %u references left.\n", refcount);
16685 static void test_input_assembler(void)
16687 enum layout_id
16689 LAYOUT_FLOAT32,
16690 LAYOUT_UINT16,
16691 LAYOUT_SINT16,
16692 LAYOUT_UNORM16,
16693 LAYOUT_SNORM16,
16694 LAYOUT_UINT8,
16695 LAYOUT_SINT8,
16696 LAYOUT_UNORM8,
16697 LAYOUT_SNORM8,
16698 LAYOUT_UNORM10_2,
16699 LAYOUT_UINT10_2,
16701 LAYOUT_COUNT,
16704 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
16706 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
16707 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
16709 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
16710 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
16711 ID3D11Buffer *vb_position, *vb_attribute;
16712 struct d3d11_test_context test_context;
16713 D3D11_TEXTURE2D_DESC texture_desc;
16714 unsigned int i, j, stride, offset;
16715 ID3D11Texture2D *render_target;
16716 ID3D11DeviceContext *context;
16717 ID3D11RenderTargetView *rtv;
16718 ID3D11PixelShader *ps;
16719 ID3D11Device *device;
16720 HRESULT hr;
16722 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
16724 DXGI_FORMAT_R32G32B32A32_FLOAT,
16725 DXGI_FORMAT_R16G16B16A16_UINT,
16726 DXGI_FORMAT_R16G16B16A16_SINT,
16727 DXGI_FORMAT_R16G16B16A16_UNORM,
16728 DXGI_FORMAT_R16G16B16A16_SNORM,
16729 DXGI_FORMAT_R8G8B8A8_UINT,
16730 DXGI_FORMAT_R8G8B8A8_SINT,
16731 DXGI_FORMAT_R8G8B8A8_UNORM,
16732 DXGI_FORMAT_R8G8B8A8_SNORM,
16733 DXGI_FORMAT_R10G10B10A2_UNORM,
16734 DXGI_FORMAT_R10G10B10A2_UINT,
16736 static const struct vec2 quad[] =
16738 {-1.0f, -1.0f},
16739 {-1.0f, 1.0f},
16740 { 1.0f, -1.0f},
16741 { 1.0f, 1.0f},
16743 static const DWORD ps_code[] =
16745 #if 0
16746 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
16748 return color;
16750 #endif
16751 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
16752 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
16753 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
16754 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
16755 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16756 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
16757 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
16758 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
16760 static const DWORD vs_float_code[] =
16762 #if 0
16763 struct output
16765 float4 position : SV_Position;
16766 float4 color : COLOR;
16769 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
16771 o.position = position;
16772 o.color = color;
16774 #endif
16775 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
16776 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16777 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
16778 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
16779 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
16780 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
16781 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
16782 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
16783 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
16784 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
16785 0x0100003e,
16787 static const DWORD vs_uint_code[] =
16789 #if 0
16790 struct output
16792 float4 position : SV_Position;
16793 float4 color : COLOR;
16796 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
16798 o.position = position;
16799 o.color = color;
16801 #endif
16802 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
16803 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16804 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
16805 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
16806 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
16807 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
16808 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
16809 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
16810 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
16811 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
16812 0x0100003e,
16814 static const DWORD vs_sint_code[] =
16816 #if 0
16817 struct output
16819 float4 position : SV_Position;
16820 float4 color : COLOR;
16823 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
16825 o.position = position;
16826 o.color = color;
16828 #endif
16829 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
16830 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16831 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
16832 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
16833 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
16834 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
16835 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
16836 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
16837 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
16838 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
16839 0x0100003e,
16841 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
16842 static const unsigned short uint16_data[] = {6, 8, 55, 777};
16843 static const short sint16_data[] = {-1, 33, 8, -77};
16844 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
16845 static const short snorm16_data[] = {-32768, 0, 32767, 0};
16846 static const unsigned char uint8_data[] = {0, 64, 128, 255};
16847 static const signed char sint8_data[] = {-128, 0, 127, 64};
16848 static const unsigned int uint32_zero = 0;
16849 static const unsigned int uint32_max = 0xffffffff;
16850 static const unsigned int unorm10_2_data= 0xa00003ff;
16851 static const unsigned int g10_data = 0x000ffc00;
16852 static const unsigned int a2_data = 0xc0000000;
16853 static const struct
16855 enum layout_id layout_id;
16856 unsigned int stride;
16857 const void *data;
16858 struct vec4 expected_color;
16859 BOOL todo;
16861 tests[] =
16863 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
16864 {1.0f, 2.0f, 3.0f, 4.0f}},
16865 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
16866 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
16867 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
16868 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
16869 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
16870 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
16871 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
16872 {-1.0f, 0.0f, 1.0f, 0.0f}},
16873 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
16874 {0.0f, 0.0f, 0.0f, 0.0f}},
16875 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
16876 {255.0f, 255.0f, 255.0f, 255.0f}},
16877 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
16878 {0.0f, 64.0f, 128.0f, 255.0f}},
16879 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
16880 {0.0f, 0.0f, 0.0f, 0.0f}},
16881 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
16882 {-1.0f, -1.0f, -1.0f, -1.0f}},
16883 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
16884 {-128.0f, 0.0f, 127.0f, 64.0f}},
16885 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
16886 {0.0f, 0.0f, 0.0f, 0.0f}},
16887 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
16888 {1.0f, 1.0f, 1.0f, 1.0f}},
16889 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
16890 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
16891 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
16892 {0.0f, 0.0f, 0.0f, 0.0f}},
16893 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
16894 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
16895 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
16896 {0.0f, 0.0f, 0.0f, 0.0f}},
16897 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
16898 {1.0f, 1.0f, 1.0f, 1.0f}},
16899 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
16900 {0.0f, 1.0f, 0.0f, 0.0f}},
16901 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
16902 {0.0f, 0.0f, 0.0f, 1.0f}},
16903 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
16904 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
16905 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
16906 {0.0f, 0.0f, 0.0f, 0.0f}},
16907 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
16908 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
16909 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
16910 {0.0f, 1023.0f, 0.0f, 0.0f}},
16911 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
16912 {0.0f, 0.0f, 0.0f, 3.0f}},
16913 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
16914 {1023.0f, 0.0f, 512.0f, 2.0f}},
16917 if (!init_test_context(&test_context, NULL))
16918 return;
16920 device = test_context.device;
16921 context = test_context.immediate_context;
16923 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16924 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16926 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
16927 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
16928 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
16929 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
16930 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
16931 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
16933 for (i = 0; i < LAYOUT_COUNT; ++i)
16935 input_layout_desc[1].Format = layout_formats[i];
16936 input_layout[i] = NULL;
16937 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
16938 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
16939 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
16940 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
16943 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
16944 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
16946 texture_desc.Width = 640;
16947 texture_desc.Height = 480;
16948 texture_desc.MipLevels = 1;
16949 texture_desc.ArraySize = 1;
16950 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
16951 texture_desc.SampleDesc.Count = 1;
16952 texture_desc.SampleDesc.Quality = 0;
16953 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16954 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16955 texture_desc.CPUAccessFlags = 0;
16956 texture_desc.MiscFlags = 0;
16958 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
16959 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
16961 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
16962 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16964 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
16965 offset = 0;
16966 stride = sizeof(*quad);
16967 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
16968 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16969 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
16971 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16973 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
16975 if (tests[i].layout_id == LAYOUT_UINT10_2)
16976 continue;
16978 assert(tests[i].layout_id < LAYOUT_COUNT);
16979 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
16981 assert(4 * tests[i].stride <= 1024);
16982 box.right = tests[i].stride;
16983 for (j = 0; j < 4; ++j)
16985 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
16986 &box, tests[i].data, 0, 0);
16987 box.left += tests[i].stride;
16988 box.right += tests[i].stride;
16991 stride = tests[i].stride;
16992 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
16994 switch (layout_formats[tests[i].layout_id])
16996 case DXGI_FORMAT_R16G16B16A16_UINT:
16997 case DXGI_FORMAT_R10G10B10A2_UINT:
16998 case DXGI_FORMAT_R8G8B8A8_UINT:
16999 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
17000 break;
17001 case DXGI_FORMAT_R16G16B16A16_SINT:
17002 case DXGI_FORMAT_R8G8B8A8_SINT:
17003 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
17004 break;
17006 default:
17007 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
17008 /* Fall through. */
17009 case DXGI_FORMAT_R32G32B32A32_FLOAT:
17010 case DXGI_FORMAT_R16G16B16A16_UNORM:
17011 case DXGI_FORMAT_R16G16B16A16_SNORM:
17012 case DXGI_FORMAT_R10G10B10A2_UNORM:
17013 case DXGI_FORMAT_R8G8B8A8_UNORM:
17014 case DXGI_FORMAT_R8G8B8A8_SNORM:
17015 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
17016 break;
17019 ID3D11DeviceContext_Draw(context, 4, 0);
17020 check_texture_vec4(render_target, &tests[i].expected_color, 2);
17023 ID3D11Texture2D_Release(render_target);
17024 ID3D11RenderTargetView_Release(rtv);
17025 ID3D11Buffer_Release(vb_attribute);
17026 ID3D11Buffer_Release(vb_position);
17027 for (i = 0; i < LAYOUT_COUNT; ++i)
17029 if (input_layout[i])
17030 ID3D11InputLayout_Release(input_layout[i]);
17032 ID3D11PixelShader_Release(ps);
17033 ID3D11VertexShader_Release(vs_float);
17034 ID3D11VertexShader_Release(vs_uint);
17035 ID3D11VertexShader_Release(vs_sint);
17036 release_test_context(&test_context);
17039 static void test_null_sampler(void)
17041 struct d3d11_test_context test_context;
17042 D3D11_TEXTURE2D_DESC texture_desc;
17043 ID3D11ShaderResourceView *srv;
17044 ID3D11DeviceContext *context;
17045 ID3D11RenderTargetView *rtv;
17046 ID3D11SamplerState *sampler;
17047 ID3D11Texture2D *texture;
17048 ID3D11PixelShader *ps;
17049 ID3D11Device *device;
17050 HRESULT hr;
17052 static const DWORD ps_code[] =
17054 #if 0
17055 Texture2D t;
17056 SamplerState s;
17058 float4 main(float4 position : SV_POSITION) : SV_Target
17060 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
17062 #endif
17063 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
17064 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17065 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
17066 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17067 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
17068 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
17069 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
17070 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
17071 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
17072 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
17074 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
17076 if (!init_test_context(&test_context, NULL))
17077 return;
17079 device = test_context.device;
17080 context = test_context.immediate_context;
17082 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17083 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17085 texture_desc.Width = 64;
17086 texture_desc.Height = 64;
17087 texture_desc.MipLevels = 1;
17088 texture_desc.ArraySize = 1;
17089 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
17090 texture_desc.SampleDesc.Count = 1;
17091 texture_desc.SampleDesc.Quality = 0;
17092 texture_desc.Usage = D3D11_USAGE_DEFAULT;
17093 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
17094 texture_desc.CPUAccessFlags = 0;
17095 texture_desc.MiscFlags = 0;
17097 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17098 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17100 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
17101 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17103 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
17104 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
17106 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
17108 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17109 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
17110 sampler = NULL;
17111 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
17112 draw_quad(&test_context);
17113 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
17115 ID3D11ShaderResourceView_Release(srv);
17116 ID3D11RenderTargetView_Release(rtv);
17117 ID3D11Texture2D_Release(texture);
17118 ID3D11PixelShader_Release(ps);
17119 release_test_context(&test_context);
17122 static void test_check_feature_support(void)
17124 D3D11_FEATURE_DATA_THREADING threading[2];
17125 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
17126 D3D11_FEATURE_DATA_ARCHITECTURE_INFO archinfo;
17127 ID3D11Device *device;
17128 ULONG refcount;
17129 HRESULT hr;
17131 if (!(device = create_device(NULL)))
17133 skip("Failed to create device.\n");
17134 return;
17137 memset(threading, 0xef, sizeof(threading));
17139 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
17140 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17141 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
17142 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17143 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
17144 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17145 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
17146 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17147 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
17148 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17149 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
17150 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17152 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
17153 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
17154 ok(threading[0].DriverCommandLists == 0xefefefef,
17155 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
17156 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
17157 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
17158 ok(threading[1].DriverCommandLists == 0xefefefef,
17159 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
17161 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
17162 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
17163 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
17164 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
17165 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
17166 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
17168 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
17169 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17170 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
17171 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17172 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
17173 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17174 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
17175 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17176 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
17177 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17178 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
17179 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17181 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
17182 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
17183 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
17185 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo));
17186 ok(hr == S_OK || broken(hr == E_INVALIDARG) /* Not available on all Windows versions. */,
17187 "Got unexpected hr %#x.\n", hr);
17188 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo)*2);
17189 ok(hr == E_INVALIDARG /* Not available on all Windows versions but they will return E_INVALIDARG anyways. */,
17190 "Got unexpected hr %#x.\n", hr);
17192 refcount = ID3D11Device_Release(device);
17193 ok(!refcount, "Device has %u references left.\n", refcount);
17196 static void test_create_unordered_access_view(void)
17198 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17199 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
17200 D3D11_TEXTURE3D_DESC texture3d_desc;
17201 D3D11_TEXTURE2D_DESC texture2d_desc;
17202 ULONG refcount, expected_refcount;
17203 D3D11_SUBRESOURCE_DATA data = {0};
17204 ID3D11UnorderedAccessView *uav;
17205 struct device_desc device_desc;
17206 D3D11_BUFFER_DESC buffer_desc;
17207 ID3D11Device *device, *tmp;
17208 ID3D11Texture3D *texture3d;
17209 ID3D11Texture2D *texture2d;
17210 ID3D11Resource *texture;
17211 ID3D11Buffer *buffer;
17212 unsigned int i;
17213 HRESULT hr;
17215 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
17216 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
17217 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
17218 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
17219 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
17220 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
17221 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
17222 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
17223 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
17224 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
17225 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
17226 static const struct
17228 struct
17230 unsigned int miplevel_count;
17231 unsigned int depth_or_array_size;
17232 DXGI_FORMAT format;
17233 } texture;
17234 struct uav_desc uav_desc;
17235 struct uav_desc expected_uav_desc;
17237 tests[] =
17239 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
17240 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
17241 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
17242 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
17243 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
17244 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
17245 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
17246 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
17247 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
17248 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
17249 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
17250 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
17251 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
17252 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
17253 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
17254 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
17255 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
17256 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
17257 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
17258 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
17259 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
17260 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
17261 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
17262 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
17263 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
17264 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
17265 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
17266 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
17267 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
17268 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
17269 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
17270 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
17271 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
17272 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
17273 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
17274 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
17276 static const struct
17278 struct
17280 D3D11_UAV_DIMENSION dimension;
17281 unsigned int miplevel_count;
17282 unsigned int depth_or_array_size;
17283 DXGI_FORMAT format;
17284 } texture;
17285 struct uav_desc uav_desc;
17287 invalid_desc_tests[] =
17289 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
17290 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
17291 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
17292 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
17293 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
17294 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
17295 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
17296 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
17297 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
17298 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
17299 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
17300 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
17301 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
17302 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
17303 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
17304 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}},
17305 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
17306 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
17307 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
17308 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
17309 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
17310 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
17311 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
17312 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
17313 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
17314 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
17315 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
17316 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
17317 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
17318 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
17319 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
17320 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
17321 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
17322 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
17323 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
17324 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
17325 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
17327 #undef FMT_UNKNOWN
17328 #undef RGBA8_UNORM
17329 #undef RGBA8_SRGB
17330 #undef RGBA8_UINT
17331 #undef RGBA8_TL
17332 #undef DIM_UNKNOWN
17333 #undef TEX_1D
17334 #undef TEX_1D_ARRAY
17335 #undef TEX_2D
17336 #undef TEX_2D_ARRAY
17337 #undef TEX_3D
17339 device_desc.feature_level = &feature_level;
17340 device_desc.flags = 0;
17341 if (!(device = create_device(&device_desc)))
17343 skip("Failed to create device.\n");
17344 return;
17347 buffer_desc.ByteWidth = 1024;
17348 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17349 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17350 buffer_desc.CPUAccessFlags = 0;
17351 buffer_desc.MiscFlags = 0;
17352 buffer_desc.StructureByteStride = 0;
17354 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
17355 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17357 expected_refcount = get_refcount(device) + 1;
17358 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
17359 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
17360 refcount = get_refcount(device);
17361 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
17362 tmp = NULL;
17363 expected_refcount = refcount + 1;
17364 ID3D11Buffer_GetDevice(buffer, &tmp);
17365 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
17366 refcount = get_refcount(device);
17367 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
17368 ID3D11Device_Release(tmp);
17370 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17371 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
17372 U(uav_desc).Buffer.FirstElement = 0;
17373 U(uav_desc).Buffer.NumElements = 64;
17374 U(uav_desc).Buffer.Flags = 0;
17376 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
17377 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17379 expected_refcount = get_refcount(device) + 1;
17380 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
17381 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17382 refcount = get_refcount(device);
17383 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
17384 tmp = NULL;
17385 expected_refcount = refcount + 1;
17386 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
17387 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
17388 refcount = get_refcount(device);
17389 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
17390 ID3D11Device_Release(tmp);
17392 ID3D11UnorderedAccessView_Release(uav);
17393 ID3D11Buffer_Release(buffer);
17395 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
17396 buffer_desc.StructureByteStride = 4;
17398 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
17399 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
17401 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
17402 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17404 memset(&uav_desc, 0, sizeof(uav_desc));
17405 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
17407 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
17408 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
17409 uav_desc.ViewDimension);
17410 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
17411 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
17412 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
17414 ID3D11UnorderedAccessView_Release(uav);
17415 ID3D11Buffer_Release(buffer);
17417 /* Without D3D11_BIND_UNORDERED_ACCESS. */
17418 buffer = create_buffer(device, 0, 1024, NULL);
17420 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17421 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
17422 U(uav_desc).Buffer.FirstElement = 0;
17423 U(uav_desc).Buffer.NumElements = 64;
17424 U(uav_desc).Buffer.Flags = 0;
17426 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
17427 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17429 ID3D11Buffer_Release(buffer);
17431 texture2d_desc.Width = 512;
17432 texture2d_desc.Height = 512;
17433 texture2d_desc.SampleDesc.Count = 1;
17434 texture2d_desc.SampleDesc.Quality = 0;
17435 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
17436 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17437 texture2d_desc.CPUAccessFlags = 0;
17438 texture2d_desc.MiscFlags = 0;
17440 texture3d_desc.Width = 64;
17441 texture3d_desc.Height = 64;
17442 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
17443 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17444 texture3d_desc.CPUAccessFlags = 0;
17445 texture3d_desc.MiscFlags = 0;
17447 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17449 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
17451 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
17453 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
17454 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
17455 texture2d_desc.Format = tests[i].texture.format;
17457 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
17458 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
17459 texture = (ID3D11Resource *)texture2d;
17461 else
17463 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
17464 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
17465 texture3d_desc.Format = tests[i].texture.format;
17467 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
17468 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
17469 texture = (ID3D11Resource *)texture3d;
17472 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
17474 current_desc = NULL;
17476 else
17478 current_desc = &uav_desc;
17479 get_uav_desc(current_desc, &tests[i].uav_desc);
17482 expected_refcount = get_refcount(texture);
17483 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
17484 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
17485 refcount = get_refcount(texture);
17486 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
17488 memset(&uav_desc, 0, sizeof(uav_desc));
17489 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
17490 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
17492 ID3D11UnorderedAccessView_Release(uav);
17493 ID3D11Resource_Release(texture);
17496 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
17498 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
17499 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
17501 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
17503 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
17504 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
17505 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
17507 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
17508 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
17509 texture = (ID3D11Resource *)texture2d;
17511 else
17513 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
17514 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
17515 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
17517 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
17518 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
17519 texture = (ID3D11Resource *)texture3d;
17522 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
17523 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
17524 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
17526 ID3D11Resource_Release(texture);
17529 refcount = ID3D11Device_Release(device);
17530 ok(!refcount, "Device has %u references left.\n", refcount);
17533 static void test_immediate_constant_buffer(void)
17535 struct d3d11_test_context test_context;
17536 D3D11_TEXTURE2D_DESC texture_desc;
17537 ID3D11DeviceContext *context;
17538 ID3D11RenderTargetView *rtv;
17539 unsigned int index[4] = {0};
17540 ID3D11Texture2D *texture;
17541 ID3D11PixelShader *ps;
17542 ID3D11Device *device;
17543 ID3D11Buffer *cb;
17544 unsigned int i;
17545 HRESULT hr;
17547 static const DWORD ps_code[] =
17549 #if 0
17550 uint index;
17552 static const int int_array[6] =
17554 310, 111, 212, -513, -318, 0,
17557 static const uint uint_array[6] =
17559 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
17562 static const float float_array[6] =
17564 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
17567 float4 main() : SV_Target
17569 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
17571 #endif
17572 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
17573 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17574 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17575 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
17576 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
17577 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
17578 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
17579 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
17580 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
17581 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
17582 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
17583 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
17584 0x0100003e,
17586 static struct vec4 expected_result[] =
17588 { 310.0f, 2.0f, 76.00f, 1.0f},
17589 { 111.0f, 7.0f, 83.50f, 1.0f},
17590 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
17591 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
17592 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
17593 { 0.0f, 0.0f, 0.0f, 1.0f},
17596 if (!init_test_context(&test_context, NULL))
17597 return;
17599 device = test_context.device;
17600 context = test_context.immediate_context;
17602 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17603 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17604 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17606 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
17607 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17609 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17610 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17611 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17612 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17614 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
17615 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17616 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17618 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
17620 *index = i;
17621 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
17623 draw_quad(&test_context);
17624 check_texture_vec4(texture, &expected_result[i], 0);
17627 ID3D11Buffer_Release(cb);
17628 ID3D11PixelShader_Release(ps);
17629 ID3D11Texture2D_Release(texture);
17630 ID3D11RenderTargetView_Release(rtv);
17631 release_test_context(&test_context);
17634 static void test_fp_specials(void)
17636 struct d3d11_test_context test_context;
17637 D3D11_TEXTURE2D_DESC texture_desc;
17638 ID3D11DeviceContext *context;
17639 ID3D11RenderTargetView *rtv;
17640 ID3D11Texture2D *texture;
17641 ID3D11PixelShader *ps;
17642 ID3D11Device *device;
17643 HRESULT hr;
17645 static const DWORD ps_code[] =
17647 #if 0
17648 float4 main() : SV_Target
17650 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
17652 #endif
17653 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
17654 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17655 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17656 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
17657 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
17658 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
17660 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
17662 if (!init_test_context(&test_context, NULL))
17663 return;
17665 device = test_context.device;
17666 context = test_context.immediate_context;
17668 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17669 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17670 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17672 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17673 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17674 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17675 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17677 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
17678 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17680 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17682 draw_quad(&test_context);
17683 check_texture_uvec4(texture, &expected_result);
17685 ID3D11PixelShader_Release(ps);
17686 ID3D11Texture2D_Release(texture);
17687 ID3D11RenderTargetView_Release(rtv);
17688 release_test_context(&test_context);
17691 static void test_uint_shader_instructions(void)
17693 struct shader
17695 const DWORD *code;
17696 size_t size;
17697 D3D_FEATURE_LEVEL required_feature_level;
17700 struct d3d11_test_context test_context;
17701 D3D11_TEXTURE2D_DESC texture_desc;
17702 D3D_FEATURE_LEVEL feature_level;
17703 ID3D11DeviceContext *context;
17704 ID3D11RenderTargetView *rtv;
17705 ID3D11Texture2D *texture;
17706 ID3D11PixelShader *ps;
17707 ID3D11Device *device;
17708 ID3D11Buffer *cb;
17709 unsigned int i;
17710 HRESULT hr;
17712 static const DWORD ps_bfi_code[] =
17714 #if 0
17715 uint bits, offset, insert, base;
17717 uint4 main() : SV_Target
17719 uint mask = ((1 << bits) - 1) << offset;
17720 return ((insert << offset) & mask) | (base & ~mask);
17722 #endif
17723 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
17724 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17725 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17726 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
17727 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17728 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
17729 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
17731 static const DWORD ps_bfi2_code[] =
17733 #if 0
17734 ps_5_0
17735 dcl_globalFlags refactoringAllowed
17736 dcl_constantbuffer cb0[1], immediateIndexed
17737 dcl_output o0.xyzw
17738 dcl_temps 1
17739 mov r0.xyzw, cb0[0].xyzw
17740 bfi r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz, r0.wwww
17741 mov o0.xyzw, r0.xyzw
17743 #endif
17744 0x43425844, 0x900f86b6, 0x73f4dabf, 0xea1b1106, 0x591ac790, 0x00000001, 0x00000104, 0x00000003,
17745 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17746 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17747 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000008c, 0x00000050, 0x00000023,
17748 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17749 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
17750 0x0b00008c, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
17751 0x00000000, 0x00100ff6, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
17752 0x0100003e,
17754 static const DWORD ps_ibfe_code[] =
17756 #if 0
17757 ps_5_0
17758 dcl_globalFlags refactoringAllowed
17759 dcl_constantbuffer cb0[1], immediateIndexed
17760 dcl_output o0.xyzw
17761 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
17763 #endif
17764 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
17765 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17766 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17767 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
17768 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17769 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
17770 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
17772 static const DWORD ps_ibfe2_code[] =
17774 #if 0
17775 ps_5_0
17776 dcl_globalFlags refactoringAllowed
17777 dcl_constantbuffer cb0[1], immediateIndexed
17778 dcl_output o0.xyzw
17779 dcl_temps 1
17780 mov r0.xyzw, cb0[0].xyzw
17781 ibfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
17782 mov o0.xyzw, r0.xyzw
17784 #endif
17785 0x43425844, 0x347a9c0e, 0x3eff39a4, 0x3dd41cc5, 0xff87ec8d, 0x00000001, 0x000000fc, 0x00000003,
17786 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17787 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17788 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
17789 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17790 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
17791 0x0900008b, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
17792 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
17794 static const DWORD ps_ubfe_code[] =
17796 #if 0
17797 uint u;
17799 uint4 main() : SV_Target
17801 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
17803 #endif
17804 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
17805 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17806 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17807 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
17808 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17809 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
17810 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
17811 0x0100003e,
17813 static const DWORD ps_ubfe2_code[] =
17815 #if 0
17816 ps_5_0
17817 dcl_globalFlags refactoringAllowed
17818 dcl_constantbuffer cb0[1], immediateIndexed
17819 dcl_output o0.xyzw
17820 dcl_temps 1
17821 mov r0.xyzw, cb0[0].xyzw
17822 ubfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
17823 mov o0.xyzw, r0.xyzw
17825 #endif
17826 0x43425844, 0xf377b7fc, 0x1e4cb9e7, 0xb9b1020d, 0xde484388, 0x00000001, 0x000000fc, 0x00000003,
17827 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17828 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17829 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
17830 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17831 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
17832 0x0900008a, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
17833 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
17835 static const DWORD ps_bfrev_code[] =
17837 #if 0
17838 uint bits;
17840 uint4 main() : SV_Target
17842 return uint4(reversebits(bits), reversebits(reversebits(bits)),
17843 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
17845 #endif
17846 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
17847 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17848 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17849 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
17850 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17851 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
17852 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
17853 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
17854 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
17855 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
17856 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
17858 static const DWORD ps_bits_code[] =
17860 #if 0
17861 uint u;
17862 int i;
17864 uint4 main() : SV_Target
17866 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
17868 #endif
17869 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
17870 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17871 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17872 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
17873 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17874 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
17875 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
17876 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
17877 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
17878 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
17879 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
17880 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
17881 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
17882 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
17884 static const DWORD ps_ftou_code[] =
17886 #if 0
17887 float f;
17889 uint4 main() : SV_Target
17891 return uint4(f, -f, 0, 0);
17893 #endif
17894 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
17895 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17896 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17897 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
17898 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
17899 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
17900 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
17901 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
17903 static const DWORD ps_f16tof32_code[] =
17905 #if 0
17906 uint4 hf;
17908 uint4 main() : SV_Target
17910 return f16tof32(hf);
17912 #endif
17913 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
17914 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17915 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17916 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
17917 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17918 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
17919 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
17921 static const DWORD ps_f32tof16_code[] =
17923 #if 0
17924 float4 f;
17926 uint4 main() : SV_Target
17928 return f32tof16(f);
17930 #endif
17931 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
17932 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17933 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17934 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
17935 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17936 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
17938 static const DWORD ps_not_code[] =
17940 #if 0
17941 uint2 bits;
17943 uint4 main() : SV_Target
17945 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
17947 #endif
17948 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
17949 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17950 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17951 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
17952 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
17953 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
17954 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
17955 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
17957 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
17958 static const struct shader ps_bfi2 = {ps_bfi2_code, sizeof(ps_bfi2_code), D3D_FEATURE_LEVEL_11_0};
17959 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
17960 static const struct shader ps_ibfe2 = {ps_ibfe2_code, sizeof(ps_ibfe2_code), D3D_FEATURE_LEVEL_11_0};
17961 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
17962 static const struct shader ps_ubfe2 = {ps_ubfe2_code, sizeof(ps_ubfe2_code), D3D_FEATURE_LEVEL_11_0};
17963 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
17964 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
17965 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
17966 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
17967 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
17968 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
17969 static const struct
17971 const struct shader *ps;
17972 unsigned int bits[4];
17973 struct uvec4 expected_result;
17975 tests[] =
17977 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
17978 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
17979 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
17980 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
17981 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
17982 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
17983 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
17984 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
17985 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
17986 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
17987 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
17988 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
17989 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
17990 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
17991 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
17992 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
17993 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
17994 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
17995 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
17997 {&ps_bfi2, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
17998 {&ps_bfi2, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
17999 {&ps_bfi2, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
18000 {&ps_bfi2, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
18002 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
18003 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
18004 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
18005 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
18006 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
18007 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
18008 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
18009 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
18010 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
18011 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
18012 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
18013 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
18014 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
18015 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
18016 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
18017 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
18018 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
18019 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
18020 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
18021 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
18022 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
18023 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
18024 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
18025 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
18026 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
18027 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
18029 {&ps_ibfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
18031 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
18032 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
18033 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
18034 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
18035 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
18036 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
18037 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
18039 {&ps_ubfe2, { 4, 4, 0x7fffffff}, {0x0000000f, 0x0000000f, 0x0000000f, 0x0000000f}},
18040 {&ps_ubfe2, {23, 8, 0xffffffff}, {0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff}},
18041 {&ps_ubfe2, {30, 1, 0xffffffff}, {0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff}},
18042 {&ps_ubfe2, {15, 15, 0x7fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
18043 {&ps_ubfe2, {15, 15, 0xffff00ff}, {0x00007ffe, 0x00007ffe, 0x00007ffe, 0x00007ffe}},
18044 {&ps_ubfe2, {16, 15, 0xffffffff}, {0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff}},
18045 {&ps_ubfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
18046 {&ps_ubfe2, {20, 15, 0xffffffff}, {0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff}},
18047 {&ps_ubfe2, {31, 31, 0xffffffff}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
18048 {&ps_ubfe2, {31, 31, 0x80000000}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
18049 {&ps_ubfe2, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
18051 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
18052 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
18053 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
18055 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
18056 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
18057 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
18058 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
18059 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
18060 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
18061 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
18062 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
18063 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
18064 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
18065 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
18066 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
18068 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
18069 {&ps_ftou, {BITS_NAN}, { 0, 0}},
18070 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
18071 {&ps_ftou, {BITS_INF}, {~0u, 0}},
18072 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
18073 {&ps_ftou, {BITS_1_0}, { 1, 0}},
18075 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
18076 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
18077 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
18078 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
18080 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
18082 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
18083 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
18086 if (!init_test_context(&test_context, NULL))
18087 return;
18089 device = test_context.device;
18090 context = test_context.immediate_context;
18091 feature_level = ID3D11Device_GetFeatureLevel(device);
18093 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
18094 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18096 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18097 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
18098 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18099 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18101 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18102 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
18104 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18106 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18108 if (feature_level < tests[i].ps->required_feature_level)
18109 continue;
18111 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
18112 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18113 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18115 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
18117 draw_quad(&test_context);
18118 check_texture_uvec4(texture, &tests[i].expected_result);
18120 ID3D11PixelShader_Release(ps);
18123 ID3D11Buffer_Release(cb);
18124 ID3D11Texture2D_Release(texture);
18125 ID3D11RenderTargetView_Release(rtv);
18126 release_test_context(&test_context);
18129 static void test_index_buffer_offset(void)
18131 ID3D11Buffer *vb, *ib, *so_buffer, *args_buffer;
18132 struct d3d11_test_context test_context;
18133 ID3D11InputLayout *input_layout;
18134 ID3D11DeviceContext *context;
18135 struct resource_readback rb;
18136 ID3D11GeometryShader *gs;
18137 const struct vec4 *data;
18138 ID3D11VertexShader *vs;
18139 ID3D11Device *device;
18140 UINT stride, offset;
18141 unsigned int i;
18142 HRESULT hr;
18144 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18145 static const DWORD vs_code[] =
18147 #if 0
18148 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
18149 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
18151 out_position = position;
18152 out_attrib = attrib;
18154 #endif
18155 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
18156 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18157 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
18158 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
18159 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18160 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18161 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
18162 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18163 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18164 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18165 0x0100003e,
18167 static const DWORD gs_code[] =
18169 #if 0
18170 struct vertex
18172 float4 position : SV_POSITION;
18173 float4 attrib : ATTRIB;
18176 [maxvertexcount(1)]
18177 void main(point vertex input[1], inout PointStream<vertex> output)
18179 output.Append(input[0]);
18180 output.RestartStrip();
18182 #endif
18183 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
18184 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18185 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
18186 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
18187 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18188 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18189 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
18190 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
18191 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18192 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
18193 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
18194 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
18196 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
18198 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18199 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
18201 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
18203 {0, "SV_Position", 0, 0, 4, 0},
18204 {0, "ATTRIB", 0, 0, 4, 0},
18206 static const struct
18208 struct vec4 position;
18209 struct vec4 attrib;
18211 vertices[] =
18213 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
18214 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
18215 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
18216 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
18218 static const unsigned int indices[] =
18220 0, 1, 2, 3,
18221 3, 2, 1, 0,
18222 1, 3, 2, 0,
18224 static const struct vec4 expected_data[] =
18226 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
18227 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
18228 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
18229 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
18231 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
18232 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
18233 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
18234 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
18236 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
18237 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
18238 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
18239 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
18241 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
18242 static const D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS argument_data[] =
18244 {4, 1, 0, 0, 0},
18247 if (!init_test_context(&test_context, &feature_level))
18248 return;
18250 device = test_context.device;
18251 context = test_context.immediate_context;
18253 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
18254 vs_code, sizeof(vs_code), &input_layout);
18255 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
18257 stride = 32;
18258 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
18259 so_declaration, ARRAY_SIZE(so_declaration),
18260 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
18261 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
18263 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
18264 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
18266 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
18267 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
18268 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
18270 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
18271 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
18273 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
18274 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
18275 stride = sizeof(*vertices);
18276 offset = 0;
18277 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
18279 offset = 0;
18280 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
18282 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
18283 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
18285 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
18286 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
18288 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
18289 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
18291 get_buffer_readback(so_buffer, &rb);
18292 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
18294 data = get_readback_vec4(&rb, i, 0);
18295 ok(compare_vec4(data, &expected_data[i], 0)
18296 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
18297 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
18298 data->x, data->y, data->z, data->w, i);
18300 release_resource_readback(&rb);
18302 /* indirect draws */
18303 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
18304 sizeof(argument_data), argument_data);
18306 offset = 0;
18307 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
18309 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
18310 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
18312 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
18313 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
18315 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
18316 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
18318 get_buffer_readback(so_buffer, &rb);
18319 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
18321 data = get_readback_vec4(&rb, i, 0);
18322 todo_wine_if(i >= 8 && i != 20 && i != 21)
18323 ok(compare_vec4(data, &expected_data[i], 0)
18324 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
18325 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
18326 data->x, data->y, data->z, data->w, i);
18328 release_resource_readback(&rb);
18330 ID3D11Buffer_Release(so_buffer);
18331 ID3D11Buffer_Release(args_buffer);
18332 ID3D11Buffer_Release(ib);
18333 ID3D11Buffer_Release(vb);
18334 ID3D11VertexShader_Release(vs);
18335 ID3D11GeometryShader_Release(gs);
18336 ID3D11InputLayout_Release(input_layout);
18337 release_test_context(&test_context);
18340 static void test_face_culling(void)
18342 struct d3d11_test_context test_context;
18343 D3D11_RASTERIZER_DESC rasterizer_desc;
18344 ID3D11RasterizerState *state;
18345 ID3D11DeviceContext *context;
18346 ID3D11Buffer *cw_vb, *ccw_vb;
18347 ID3D11Device *device;
18348 BOOL broken_warp;
18349 unsigned int i;
18350 HRESULT hr;
18352 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
18353 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
18354 static const DWORD ps_code[] =
18356 #if 0
18357 float4 main(uint front : SV_IsFrontFace) : SV_Target
18359 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
18361 #endif
18362 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
18363 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
18364 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
18365 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
18366 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
18367 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
18368 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
18369 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
18370 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
18371 0x3f800000, 0x0100003e,
18373 static const struct vec3 ccw_quad[] =
18375 {-1.0f, 1.0f, 0.0f},
18376 {-1.0f, -1.0f, 0.0f},
18377 { 1.0f, 1.0f, 0.0f},
18378 { 1.0f, -1.0f, 0.0f},
18380 static const struct
18382 D3D11_CULL_MODE cull_mode;
18383 BOOL front_ccw;
18384 BOOL expected_cw;
18385 BOOL expected_ccw;
18387 tests[] =
18389 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
18390 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
18391 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
18392 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
18393 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
18394 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
18397 if (!init_test_context(&test_context, NULL))
18398 return;
18400 device = test_context.device;
18401 context = test_context.immediate_context;
18403 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
18404 draw_color_quad(&test_context, &green);
18405 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
18407 cw_vb = test_context.vb;
18408 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
18410 test_context.vb = ccw_vb;
18411 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
18412 draw_color_quad(&test_context, &green);
18413 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
18415 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
18416 rasterizer_desc.CullMode = D3D11_CULL_BACK;
18417 rasterizer_desc.FrontCounterClockwise = FALSE;
18418 rasterizer_desc.DepthBias = 0;
18419 rasterizer_desc.DepthBiasClamp = 0.0f;
18420 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
18421 rasterizer_desc.DepthClipEnable = TRUE;
18422 rasterizer_desc.ScissorEnable = FALSE;
18423 rasterizer_desc.MultisampleEnable = FALSE;
18424 rasterizer_desc.AntialiasedLineEnable = FALSE;
18426 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18428 rasterizer_desc.CullMode = tests[i].cull_mode;
18429 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
18430 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
18431 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
18433 ID3D11DeviceContext_RSSetState(context, state);
18435 test_context.vb = cw_vb;
18436 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
18437 draw_color_quad(&test_context, &green);
18438 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
18440 test_context.vb = ccw_vb;
18441 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
18442 draw_color_quad(&test_context, &green);
18443 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
18445 ID3D11RasterizerState_Release(state);
18448 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0;
18450 /* Test SV_IsFrontFace. */
18451 ID3D11PixelShader_Release(test_context.ps);
18452 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
18453 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18455 rasterizer_desc.CullMode = D3D11_CULL_NONE;
18456 rasterizer_desc.FrontCounterClockwise = FALSE;
18457 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
18458 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
18459 ID3D11DeviceContext_RSSetState(context, state);
18461 test_context.vb = cw_vb;
18462 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
18463 draw_color_quad(&test_context, &green);
18464 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
18465 test_context.vb = ccw_vb;
18466 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
18467 draw_color_quad(&test_context, &green);
18468 if (!broken_warp)
18469 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
18470 else
18471 win_skip("Broken WARP.\n");
18473 ID3D11RasterizerState_Release(state);
18475 rasterizer_desc.CullMode = D3D11_CULL_NONE;
18476 rasterizer_desc.FrontCounterClockwise = TRUE;
18477 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
18478 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
18479 ID3D11DeviceContext_RSSetState(context, state);
18481 test_context.vb = cw_vb;
18482 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
18483 draw_color_quad(&test_context, &green);
18484 if (!broken_warp)
18485 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
18486 else
18487 win_skip("Broken WARP.\n");
18488 test_context.vb = ccw_vb;
18489 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
18490 draw_color_quad(&test_context, &green);
18491 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
18493 ID3D11RasterizerState_Release(state);
18495 test_context.vb = cw_vb;
18496 ID3D11Buffer_Release(ccw_vb);
18497 release_test_context(&test_context);
18500 static void test_line_antialiasing_blending(void)
18502 ID3D11RasterizerState *rasterizer_state;
18503 struct d3d11_test_context test_context;
18504 D3D11_RASTERIZER_DESC rasterizer_desc;
18505 ID3D11BlendState *blend_state;
18506 ID3D11DeviceContext *context;
18507 D3D11_BLEND_DESC blend_desc;
18508 ID3D11Device *device;
18509 HRESULT hr;
18511 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
18512 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
18514 if (!init_test_context(&test_context, NULL))
18515 return;
18517 device = test_context.device;
18518 context = test_context.immediate_context;
18520 memset(&blend_desc, 0, sizeof(blend_desc));
18521 blend_desc.AlphaToCoverageEnable = FALSE;
18522 blend_desc.IndependentBlendEnable = FALSE;
18523 blend_desc.RenderTarget[0].BlendEnable = TRUE;
18524 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
18525 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
18526 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
18527 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
18528 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
18529 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
18530 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
18532 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
18533 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
18534 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
18536 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
18537 draw_color_quad(&test_context, &green);
18538 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
18540 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
18541 draw_color_quad(&test_context, &red);
18542 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
18544 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
18545 ID3D11BlendState_Release(blend_state);
18547 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
18548 draw_color_quad(&test_context, &green);
18549 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
18551 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
18552 draw_color_quad(&test_context, &red);
18553 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
18555 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
18556 rasterizer_desc.CullMode = D3D11_CULL_BACK;
18557 rasterizer_desc.FrontCounterClockwise = FALSE;
18558 rasterizer_desc.DepthBias = 0;
18559 rasterizer_desc.DepthBiasClamp = 0.0f;
18560 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
18561 rasterizer_desc.DepthClipEnable = TRUE;
18562 rasterizer_desc.ScissorEnable = FALSE;
18563 rasterizer_desc.MultisampleEnable = FALSE;
18564 rasterizer_desc.AntialiasedLineEnable = TRUE;
18566 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
18567 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
18568 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
18570 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
18571 draw_color_quad(&test_context, &green);
18572 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
18574 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
18575 draw_color_quad(&test_context, &red);
18576 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
18578 ID3D11RasterizerState_Release(rasterizer_state);
18579 release_test_context(&test_context);
18582 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
18583 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
18584 const char *feature_name)
18586 unsigned int i;
18588 for (i = 0; i < format_count; ++i)
18590 DXGI_FORMAT format = formats[i].format;
18591 unsigned int supported = format_support[format] & feature_flag;
18593 if (formats[i].fl_required <= feature_level)
18595 todo_wine ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
18596 format, feature_name, feature_level, format_support[format]);
18597 continue;
18600 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
18602 if (supported)
18603 trace("Optional format %#x - %s supported, feature level %#x.\n",
18604 format, feature_name, feature_level);
18605 continue;
18608 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
18609 format, feature_name, feature_level, format_support[format]);
18613 static void test_format_support(const D3D_FEATURE_LEVEL feature_level)
18615 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
18616 struct device_desc device_desc;
18617 ID3D11Device *device;
18618 DXGI_FORMAT format;
18619 ULONG refcount;
18620 UINT support;
18621 HRESULT hr;
18623 static const struct format_support index_buffers[] =
18625 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
18626 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
18629 device_desc.feature_level = &feature_level;
18630 device_desc.flags = 0;
18631 if (!(device = create_device(&device_desc)))
18633 skip("Failed to create device for feature level %#x.\n", feature_level);
18634 return;
18637 support = 0xdeadbeef;
18638 hr = ID3D11Device_CheckFormatSupport(device, ~0u, &support);
18639 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
18640 ok(!support, "Got unexpected format support %#x.\n", support);
18642 memset(format_support, 0, sizeof(format_support));
18643 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
18645 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
18646 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
18647 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
18648 format, hr, format_support[format]);
18649 if (format_support[format] & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN)
18651 ok(format_support[format] & D3D11_FORMAT_SUPPORT_TEXTURE2D,
18652 "Got unexpected format support %#x for format %#x", format_support[format], format);
18656 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
18658 if (feature_level < D3D_FEATURE_LEVEL_10_0)
18660 /* SHADER_SAMPLE_COMPARISON is never advertised as supported on feature level 9. */
18661 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON),
18662 "Unexpected SHADER_SAMPLE_COMPARISON for format %#x, feature level %#x.\n",
18663 format, feature_level);
18665 if (feature_level < D3D_FEATURE_LEVEL_10_1)
18667 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER),
18668 "Unexpected SHADER_GATHER for format %#x, feature level %#x.\n",
18669 format, feature_level);
18670 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON),
18671 "Unexpected SHADER_GATHER_COMPARISON for format %#x, feature level %#x.\n",
18672 format, feature_level);
18676 ok(format_support[DXGI_FORMAT_R8G8B8A8_UNORM] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE,
18677 "SHADER_SAMPLE is not supported for R8G8B8A8_UNORM.\n");
18678 todo_wine
18679 ok(!(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE),
18680 "SHADER_SAMPLE is supported for R32G32B32A32_UINT.\n");
18681 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
18683 ok(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_LOAD,
18684 "SHADER_LOAD is not supported for R32G32B32A32_UINT.\n");
18687 check_format_support(format_support, feature_level,
18688 index_buffers, ARRAY_SIZE(index_buffers),
18689 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
18691 check_format_support(format_support, feature_level,
18692 display_format_support, ARRAY_SIZE(display_format_support),
18693 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
18695 refcount = ID3D11Device_Release(device);
18696 ok(!refcount, "Device has %u references left.\n", refcount);
18699 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
18701 struct d3d11_test_context test_context;
18702 D3D11_SUBRESOURCE_DATA resource_data;
18703 D3D11_TEXTURE2D_DESC texture_desc;
18704 ID3D11ShaderResourceView *srv;
18705 ID3D11DeviceContext *context;
18706 ID3D11Texture2D *texture;
18707 ID3D11PixelShader *ps;
18708 ID3D11Device *device;
18709 HRESULT hr;
18711 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
18712 static const DWORD ps_code[] =
18714 #if 0
18715 float4 main() : SV_TARGET
18717 return float4(1.0f, 0.0f, 0.0f, 0.5f);
18719 #endif
18720 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
18721 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
18722 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
18723 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
18724 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
18725 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
18726 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
18727 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
18728 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
18729 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
18730 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
18731 0x45475241, 0xabab0054,
18733 static const DWORD ps_texture_code[] =
18735 #if 0
18736 Texture2D t;
18737 SamplerState s;
18739 float4 main() : SV_TARGET
18741 return t.Sample(s, (float2)0);
18743 #endif
18744 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
18745 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
18746 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
18747 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
18748 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
18749 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
18750 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
18751 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
18752 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
18753 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
18754 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
18755 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
18756 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
18757 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18758 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
18760 static const DWORD texture_data[] = {0xffffff00};
18762 if (!init_test_context(&test_context, &feature_level))
18763 return;
18765 device = test_context.device;
18766 context = test_context.immediate_context;
18768 texture_desc.Width = 1;
18769 texture_desc.Height = 1;
18770 texture_desc.MipLevels = 0;
18771 texture_desc.ArraySize = 1;
18772 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
18773 texture_desc.SampleDesc.Count = 1;
18774 texture_desc.SampleDesc.Quality = 0;
18775 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18776 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18777 texture_desc.CPUAccessFlags = 0;
18778 texture_desc.MiscFlags = 0;
18779 resource_data.pSysMem = texture_data;
18780 resource_data.SysMemPitch = sizeof(texture_data);
18781 resource_data.SysMemSlicePitch = 0;
18782 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
18783 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
18784 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
18785 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
18787 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18788 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
18789 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18790 draw_quad(&test_context);
18791 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
18792 ID3D11PixelShader_Release(ps);
18794 draw_color_quad(&test_context, &color);
18795 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
18797 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
18798 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
18799 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18800 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18801 draw_quad(&test_context);
18802 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
18803 ID3D11PixelShader_Release(ps);
18805 ID3D11ShaderResourceView_Release(srv);
18806 ID3D11Texture2D_Release(texture);
18807 release_test_context(&test_context);
18810 static void queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
18811 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
18813 static const D3D_FEATURE_LEVEL feature_levels[] =
18815 D3D_FEATURE_LEVEL_11_1,
18816 D3D_FEATURE_LEVEL_11_0,
18817 D3D_FEATURE_LEVEL_10_1,
18818 D3D_FEATURE_LEVEL_10_0,
18819 D3D_FEATURE_LEVEL_9_3,
18820 D3D_FEATURE_LEVEL_9_2,
18821 D3D_FEATURE_LEVEL_9_1
18823 unsigned int i;
18825 assert(begin <= end);
18826 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
18828 if (begin <= feature_levels[i] && feature_levels[i] <= end)
18829 queue_test_fl(test_func, feature_levels[i]);
18833 static void queue_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
18835 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
18836 D3D_FEATURE_LEVEL_11_1, test_func);
18839 static void queue_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
18841 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
18842 D3D_FEATURE_LEVEL_9_3, test_func);
18845 static void test_ddy(void)
18847 static const struct
18849 struct vec4 position;
18850 unsigned int color;
18852 quad[] =
18854 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
18855 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
18856 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
18857 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
18859 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
18861 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18862 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
18864 #if 0
18865 struct vs_data
18867 float4 pos : SV_POSITION;
18868 float4 color : COLOR;
18871 void main(in struct vs_data vs_input, out struct vs_data vs_output)
18873 vs_output.pos = vs_input.pos;
18874 vs_output.color = vs_input.color;
18876 #endif
18877 static const DWORD vs_code[] =
18879 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
18880 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18881 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
18882 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
18883 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18884 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18885 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18886 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18887 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18888 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18889 0x0100003e,
18891 #if 0
18892 struct ps_data
18894 float4 pos : SV_POSITION;
18895 float4 color : COLOR;
18898 float4 main(struct ps_data ps_input) : SV_Target
18900 return ddy(ps_input.color) * 240.0 + 0.5;
18902 #endif
18903 static const DWORD ps_code_ddy[] =
18905 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
18906 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18907 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
18908 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
18909 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18910 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
18911 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
18912 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
18913 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
18914 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
18916 #if 0
18917 struct ps_data
18919 float4 pos : SV_POSITION;
18920 float4 color : COLOR;
18923 float4 main(struct ps_data ps_input) : SV_Target
18925 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
18927 #endif
18928 static const DWORD ps_code_ddy_coarse[] =
18930 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
18931 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18932 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
18933 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
18934 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18935 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
18936 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
18937 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
18938 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
18939 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
18941 #if 0
18942 struct ps_data
18944 float4 pos : SV_POSITION;
18945 float4 color : COLOR;
18948 float4 main(struct ps_data ps_input) : SV_Target
18950 return ddy_fine(ps_input.color) * 240.0 + 0.5;
18952 #endif
18953 static const DWORD ps_code_ddy_fine[] =
18955 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
18956 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18957 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
18958 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
18959 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18960 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
18961 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
18962 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
18963 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
18964 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
18966 static const struct
18968 D3D_FEATURE_LEVEL min_feature_level;
18969 const DWORD *ps_code;
18970 unsigned int ps_code_size;
18972 tests[] =
18974 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
18975 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
18976 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
18978 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
18979 struct d3d11_test_context test_context;
18980 D3D11_TEXTURE2D_DESC texture_desc;
18981 D3D_FEATURE_LEVEL feature_level;
18982 ID3D11InputLayout *input_layout;
18983 ID3D11DeviceContext *context;
18984 unsigned int stride, offset;
18985 struct resource_readback rb;
18986 ID3D11RenderTargetView *rtv;
18987 ID3D11Texture2D *texture;
18988 ID3D11VertexShader *vs;
18989 ID3D11PixelShader *ps;
18990 ID3D11Device *device;
18991 ID3D11Buffer *vb;
18992 unsigned int i;
18993 DWORD color;
18994 HRESULT hr;
18996 if (!init_test_context(&test_context, NULL))
18997 return;
18999 device = test_context.device;
19000 context = test_context.immediate_context;
19001 feature_level = ID3D11Device_GetFeatureLevel(device);
19003 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19004 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19005 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19007 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19008 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19010 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
19011 vs_code, sizeof(vs_code), &input_layout);
19012 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
19014 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
19016 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
19017 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
19019 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
19020 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
19021 stride = sizeof(*quad);
19022 offset = 0;
19023 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
19024 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
19026 for (i = 0; i < ARRAY_SIZE(tests); ++i)
19028 if (feature_level < tests[i].min_feature_level)
19030 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
19031 feature_level, tests[i].min_feature_level);
19032 continue;
19035 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
19036 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19038 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19040 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19041 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
19042 ID3D11DeviceContext_Draw(context, 4, 0);
19044 get_texture_readback(texture, 0, &rb);
19045 color = get_readback_color(&rb, 320, 190, 0);
19046 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
19047 color = get_readback_color(&rb, 255, 240, 0);
19048 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
19049 color = get_readback_color(&rb, 320, 240, 0);
19050 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
19051 color = get_readback_color(&rb, 385, 240, 0);
19052 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
19053 color = get_readback_color(&rb, 320, 290, 0);
19054 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
19055 release_resource_readback(&rb);
19057 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
19058 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
19059 ID3D11DeviceContext_Draw(context, 4, 0);
19061 get_texture_readback(test_context.backbuffer, 0, &rb);
19062 color = get_readback_color(&rb, 320, 190, 0);
19063 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
19064 color = get_readback_color(&rb, 255, 240, 0);
19065 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
19066 color = get_readback_color(&rb, 320, 240, 0);
19067 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
19068 color = get_readback_color(&rb, 385, 240, 0);
19069 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
19070 color = get_readback_color(&rb, 320, 290, 0);
19071 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
19072 release_resource_readback(&rb);
19074 ID3D11PixelShader_Release(ps);
19077 ID3D11VertexShader_Release(vs);
19078 ID3D11Buffer_Release(vb);
19079 ID3D11InputLayout_Release(input_layout);
19080 ID3D11Texture2D_Release(texture);
19081 ID3D11RenderTargetView_Release(rtv);
19082 release_test_context(&test_context);
19085 static void test_shader_input_registers_limits(void)
19087 struct d3d11_test_context test_context;
19088 D3D11_SUBRESOURCE_DATA resource_data;
19089 D3D11_TEXTURE2D_DESC texture_desc;
19090 D3D11_SAMPLER_DESC sampler_desc;
19091 ID3D11ShaderResourceView *srv;
19092 ID3D11DeviceContext *context;
19093 ID3D11SamplerState *sampler;
19094 ID3D11Texture2D *texture;
19095 ID3D11PixelShader *ps;
19096 ID3D11Device *device;
19097 HRESULT hr;
19099 static const DWORD ps_last_register_code[] =
19101 #if 0
19102 Texture2D t : register(t127);
19103 SamplerState s : register(s15);
19105 void main(out float4 target : SV_Target)
19107 target = t.Sample(s, float2(0, 0));
19109 #endif
19110 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
19111 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19112 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19113 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
19114 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
19115 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
19116 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
19118 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
19119 static const DWORD texture_data[] = {0xff00ff00};
19121 if (!init_test_context(&test_context, NULL))
19122 return;
19124 device = test_context.device;
19125 context = test_context.immediate_context;
19127 texture_desc.Width = 1;
19128 texture_desc.Height = 1;
19129 texture_desc.MipLevels = 0;
19130 texture_desc.ArraySize = 1;
19131 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
19132 texture_desc.SampleDesc.Count = 1;
19133 texture_desc.SampleDesc.Quality = 0;
19134 texture_desc.Usage = D3D11_USAGE_DEFAULT;
19135 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
19136 texture_desc.CPUAccessFlags = 0;
19137 texture_desc.MiscFlags = 0;
19139 resource_data.pSysMem = texture_data;
19140 resource_data.SysMemPitch = sizeof(texture_data);
19141 resource_data.SysMemSlicePitch = 0;
19143 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
19144 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
19146 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
19147 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
19149 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
19150 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
19151 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
19152 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
19153 sampler_desc.MipLODBias = 0.0f;
19154 sampler_desc.MaxAnisotropy = 0;
19155 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
19156 sampler_desc.BorderColor[0] = 0.0f;
19157 sampler_desc.BorderColor[1] = 0.0f;
19158 sampler_desc.BorderColor[2] = 0.0f;
19159 sampler_desc.BorderColor[3] = 0.0f;
19160 sampler_desc.MinLOD = 0.0f;
19161 sampler_desc.MaxLOD = 0.0f;
19163 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
19164 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
19166 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
19167 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19168 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19170 ID3D11DeviceContext_PSSetShaderResources(context,
19171 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
19172 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
19173 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
19174 draw_quad(&test_context);
19175 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
19177 ID3D11PixelShader_Release(ps);
19178 ID3D11SamplerState_Release(sampler);
19179 ID3D11ShaderResourceView_Release(srv);
19180 ID3D11Texture2D_Release(texture);
19181 release_test_context(&test_context);
19184 static void test_unbind_shader_resource_view(void)
19186 struct d3d11_test_context test_context;
19187 D3D11_SUBRESOURCE_DATA resource_data;
19188 ID3D11ShaderResourceView *srv, *srv2;
19189 D3D11_TEXTURE2D_DESC texture_desc;
19190 ID3D11DeviceContext *context;
19191 ID3D11Texture2D *texture;
19192 ID3D11PixelShader *ps;
19193 ID3D11Device *device;
19194 HRESULT hr;
19196 static const DWORD ps_code[] =
19198 #if 0
19199 Texture2D t0;
19200 Texture2D t1;
19201 SamplerState s;
19203 float4 main() : SV_Target
19205 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
19207 #endif
19208 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
19209 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19210 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19211 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
19212 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
19213 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
19214 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
19215 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
19216 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
19217 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
19218 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
19219 0x3f800000, 0x0100003e,
19221 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
19222 static const DWORD texture_data[] = {0xff00ff00};
19224 if (!init_test_context(&test_context, NULL))
19225 return;
19227 device = test_context.device;
19228 context = test_context.immediate_context;
19230 texture_desc.Width = 1;
19231 texture_desc.Height = 1;
19232 texture_desc.MipLevels = 0;
19233 texture_desc.ArraySize = 1;
19234 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
19235 texture_desc.SampleDesc.Count = 1;
19236 texture_desc.SampleDesc.Quality = 0;
19237 texture_desc.Usage = D3D11_USAGE_DEFAULT;
19238 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
19239 texture_desc.CPUAccessFlags = 0;
19240 texture_desc.MiscFlags = 0;
19242 resource_data.pSysMem = texture_data;
19243 resource_data.SysMemPitch = sizeof(texture_data);
19244 resource_data.SysMemSlicePitch = 0;
19246 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
19247 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
19248 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
19249 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
19250 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19251 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19252 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19254 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
19255 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
19256 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
19257 draw_quad(&test_context);
19258 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
19260 srv2 = NULL;
19261 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
19262 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
19263 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
19264 draw_quad(&test_context);
19265 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
19267 ID3D11PixelShader_Release(ps);
19268 ID3D11ShaderResourceView_Release(srv);
19269 ID3D11Texture2D_Release(texture);
19270 release_test_context(&test_context);
19273 static void test_stencil_separate(void)
19275 struct d3d11_test_context test_context;
19276 D3D11_TEXTURE2D_DESC texture_desc;
19277 D3D11_DEPTH_STENCIL_DESC ds_desc;
19278 ID3D11DepthStencilState *ds_state;
19279 ID3D11DepthStencilView *ds_view;
19280 D3D11_RASTERIZER_DESC rs_desc;
19281 ID3D11DeviceContext *context;
19282 ID3D11RasterizerState *rs;
19283 ID3D11Texture2D *texture;
19284 ID3D11Device *device;
19285 HRESULT hr;
19287 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
19288 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
19289 static const struct vec3 ccw_quad[] =
19291 {-1.0f, -1.0f, 0.0f},
19292 { 1.0f, -1.0f, 0.0f},
19293 {-1.0f, 1.0f, 0.0f},
19294 { 1.0f, 1.0f, 0.0f},
19297 if (!init_test_context(&test_context, NULL))
19298 return;
19300 device = test_context.device;
19301 context = test_context.immediate_context;
19303 texture_desc.Width = 640;
19304 texture_desc.Height = 480;
19305 texture_desc.MipLevels = 1;
19306 texture_desc.ArraySize = 1;
19307 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
19308 texture_desc.SampleDesc.Count = 1;
19309 texture_desc.SampleDesc.Quality = 0;
19310 texture_desc.Usage = D3D11_USAGE_DEFAULT;
19311 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
19312 texture_desc.CPUAccessFlags = 0;
19313 texture_desc.MiscFlags = 0;
19314 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19315 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19316 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
19317 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
19319 ds_desc.DepthEnable = TRUE;
19320 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
19321 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
19322 ds_desc.StencilEnable = TRUE;
19323 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
19324 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
19325 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
19326 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
19327 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
19328 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
19329 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
19330 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
19331 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
19332 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
19333 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
19334 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
19336 rs_desc.FillMode = D3D11_FILL_SOLID;
19337 rs_desc.CullMode = D3D11_CULL_NONE;
19338 rs_desc.FrontCounterClockwise = FALSE;
19339 rs_desc.DepthBias = 0;
19340 rs_desc.DepthBiasClamp = 0.0f;
19341 rs_desc.SlopeScaledDepthBias = 0.0f;
19342 rs_desc.DepthClipEnable = TRUE;
19343 rs_desc.ScissorEnable = FALSE;
19344 rs_desc.MultisampleEnable = FALSE;
19345 rs_desc.AntialiasedLineEnable = FALSE;
19346 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
19347 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
19349 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
19350 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
19351 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
19352 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
19353 ID3D11DeviceContext_RSSetState(context, rs);
19355 draw_color_quad(&test_context, &green);
19356 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
19358 ID3D11Buffer_Release(test_context.vb);
19359 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
19361 draw_color_quad(&test_context, &green);
19362 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
19364 ID3D11RasterizerState_Release(rs);
19365 rs_desc.FrontCounterClockwise = TRUE;
19366 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
19367 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
19368 ID3D11DeviceContext_RSSetState(context, rs);
19370 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
19371 draw_color_quad(&test_context, &green);
19372 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
19374 ID3D11DepthStencilState_Release(ds_state);
19375 ID3D11DepthStencilView_Release(ds_view);
19376 ID3D11RasterizerState_Release(rs);
19377 ID3D11Texture2D_Release(texture);
19378 release_test_context(&test_context);
19381 static void test_uav_load(void)
19383 struct shader
19385 const DWORD *code;
19386 size_t size;
19388 struct texture
19390 UINT width;
19391 UINT height;
19392 UINT miplevel_count;
19393 UINT array_size;
19394 DXGI_FORMAT format;
19395 D3D11_SUBRESOURCE_DATA data[3];
19398 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
19399 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19400 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
19401 struct d3d11_test_context test_context;
19402 const struct texture *current_texture;
19403 ID3D11Texture2D *texture, *rt_texture;
19404 D3D11_TEXTURE2D_DESC texture_desc;
19405 const struct shader *current_ps;
19406 ID3D11UnorderedAccessView *uav;
19407 ID3D11DeviceContext *context;
19408 struct resource_readback rb;
19409 ID3D11PixelShader *ps;
19410 ID3D11Device *device;
19411 unsigned int i, x, y;
19412 ID3D11Buffer *cb;
19413 HRESULT hr;
19415 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
19416 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19417 static const DWORD ps_ld_2d_float_code[] =
19419 #if 0
19420 RWTexture2D<float> u;
19422 float main(float4 position : SV_Position) : SV_Target
19424 float2 s;
19425 u.GetDimensions(s.x, s.y);
19426 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
19428 #endif
19429 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
19430 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19431 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19432 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19433 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
19434 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
19435 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
19436 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
19437 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
19438 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
19439 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
19440 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
19441 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
19443 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
19444 static const DWORD ps_ld_2d_uint_code[] =
19446 #if 0
19447 RWTexture2D<uint> u;
19449 uint main(float4 position : SV_Position) : SV_Target
19451 float2 s;
19452 u.GetDimensions(s.x, s.y);
19453 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
19455 #endif
19456 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
19457 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19458 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19459 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
19460 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
19461 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
19462 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
19463 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
19464 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
19465 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
19466 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
19467 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
19468 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
19470 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
19471 static const DWORD ps_ld_2d_int_code[] =
19473 #if 0
19474 RWTexture2D<int> u;
19476 int main(float4 position : SV_Position) : SV_Target
19478 float2 s;
19479 u.GetDimensions(s.x, s.y);
19480 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
19482 #endif
19483 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
19484 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19485 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19486 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
19487 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
19488 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
19489 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
19490 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
19491 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
19492 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
19493 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
19494 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
19495 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
19497 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
19498 static const DWORD ps_ld_2d_uint_arr_code[] =
19500 #if 0
19501 RWTexture2DArray<uint> u;
19503 uint layer;
19505 uint main(float4 position : SV_Position) : SV_Target
19507 float3 s;
19508 u.GetDimensions(s.x, s.y, s.z);
19509 s.z = layer;
19510 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
19512 #endif
19513 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
19514 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19515 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19516 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
19517 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
19518 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
19519 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
19520 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
19521 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
19522 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
19523 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
19524 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
19525 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
19526 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
19528 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
19529 static const float float_data[] =
19531 0.50f, 0.25f, 1.00f, 0.00f,
19532 -1.00f, -2.00f, -3.00f, -4.00f,
19533 -0.50f, -0.25f, -1.00f, -0.00f,
19534 1.00f, 2.00f, 3.00f, 4.00f,
19536 static const unsigned int uint_data[] =
19538 0x00, 0x10, 0x20, 0x30,
19539 0x40, 0x50, 0x60, 0x70,
19540 0x80, 0x90, 0xa0, 0xb0,
19541 0xc0, 0xd0, 0xe0, 0xf0,
19543 static const unsigned int uint_data2[] =
19545 0xffff, 0xffff, 0xffff, 0xffff,
19546 0xffff, 0xc000, 0xc000, 0xffff,
19547 0xffff, 0xc000, 0xc000, 0xffff,
19548 0xffff, 0xffff, 0xffff, 0xffff,
19550 static const unsigned int uint_data3[] =
19552 0xaa, 0xaa, 0xcc, 0xcc,
19553 0xaa, 0xaa, 0xdd, 0xdd,
19554 0xbb, 0xbb, 0xee, 0xee,
19555 0xbb, 0xbb, 0xff, 0xff,
19557 static const int int_data[] =
19559 -1, 0x10, 0x20, 0x30,
19560 0x40, 0x50, 0x60, -777,
19561 -666, 0x90, -555, 0xb0,
19562 0xc0, 0xd0, 0xe0, -101,
19564 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
19565 {{float_data, 4 * sizeof(*float_data), 0}}};
19566 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
19567 {{uint_data, 4 * sizeof(*uint_data), 0}}};
19568 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
19569 {{uint_data, 4 * sizeof(*uint_data), 0},
19570 {uint_data2, 4 * sizeof(*uint_data2), 0},
19571 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
19572 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
19573 {{int_data, 4 * sizeof(*int_data), 0}}};
19575 static const struct test
19577 const struct shader *ps;
19578 const struct texture *texture;
19579 struct uav_desc uav_desc;
19580 struct uvec4 constant;
19581 const DWORD *expected_colors;
19583 tests[] =
19585 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
19586 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
19587 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
19588 #define R32_UINT DXGI_FORMAT_R32_UINT
19589 #define R32_SINT DXGI_FORMAT_R32_SINT
19590 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {0}, (const DWORD *)float_data},
19591 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {0}, (const DWORD *)uint_data},
19592 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {0}, (const DWORD *)int_data},
19593 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
19594 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
19595 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
19596 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
19597 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
19598 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
19599 #undef TEX_2D
19600 #undef TEX_2D_ARRAY
19601 #undef R32_FLOAT
19602 #undef R32_UINT
19603 #undef R32_SINT
19606 if (!init_test_context(&test_context, &feature_level))
19607 return;
19609 device = test_context.device;
19610 context = test_context.immediate_context;
19612 texture_desc.Width = 640;
19613 texture_desc.Height = 480;
19614 texture_desc.MipLevels = 1;
19615 texture_desc.ArraySize = 1;
19616 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
19617 texture_desc.SampleDesc.Count = 1;
19618 texture_desc.SampleDesc.Quality = 0;
19619 texture_desc.Usage = D3D11_USAGE_DEFAULT;
19620 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
19621 texture_desc.CPUAccessFlags = 0;
19622 texture_desc.MiscFlags = 0;
19623 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
19624 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19626 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
19627 U(rtv_desc).Texture2D.MipSlice = 0;
19629 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
19630 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
19631 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
19633 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
19634 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
19635 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
19637 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
19638 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
19639 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
19641 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19643 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
19644 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
19646 ps = NULL;
19647 uav = NULL;
19648 texture = NULL;
19649 current_ps = NULL;
19650 current_texture = NULL;
19651 for (i = 0; i < ARRAY_SIZE(tests); ++i)
19653 const struct test *test = &tests[i];
19654 ID3D11RenderTargetView *current_rtv;
19656 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
19657 NULL, &test->constant, 0, 0);
19659 if (current_ps != test->ps)
19661 if (ps)
19662 ID3D11PixelShader_Release(ps);
19664 current_ps = test->ps;
19666 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
19667 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
19669 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19672 if (current_texture != test->texture)
19674 if (texture)
19675 ID3D11Texture2D_Release(texture);
19677 current_texture = test->texture;
19679 texture_desc.Width = current_texture->width;
19680 texture_desc.Height = current_texture->height;
19681 texture_desc.MipLevels = current_texture->miplevel_count;
19682 texture_desc.ArraySize = current_texture->array_size;
19683 texture_desc.Format = current_texture->format;
19685 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
19686 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
19689 if (uav)
19690 ID3D11UnorderedAccessView_Release(uav);
19692 get_uav_desc(&uav_desc, &test->uav_desc);
19693 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
19694 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
19696 switch (uav_desc.Format)
19698 case DXGI_FORMAT_R32_FLOAT:
19699 current_rtv = rtv_float;
19700 break;
19701 case DXGI_FORMAT_R32_UINT:
19702 current_rtv = rtv_uint;
19703 break;
19704 case DXGI_FORMAT_R32_SINT:
19705 current_rtv = rtv_sint;
19706 break;
19707 default:
19708 trace("Unhandled format %#x.\n", uav_desc.Format);
19709 current_rtv = NULL;
19710 break;
19713 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
19715 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
19716 1, 1, &uav, NULL);
19718 draw_quad(&test_context);
19720 get_texture_readback(rt_texture, 0, &rb);
19721 for (y = 0; y < 4; ++y)
19723 for (x = 0; x < 4; ++x)
19725 DWORD expected = test->expected_colors[y * 4 + x];
19726 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
19727 ok(compare_color(color, expected, 0),
19728 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
19729 i, color, expected, x, y);
19732 release_resource_readback(&rb);
19734 ID3D11PixelShader_Release(ps);
19735 ID3D11Texture2D_Release(texture);
19736 ID3D11UnorderedAccessView_Release(uav);
19738 ID3D11Buffer_Release(cb);
19739 ID3D11RenderTargetView_Release(rtv_float);
19740 ID3D11RenderTargetView_Release(rtv_sint);
19741 ID3D11RenderTargetView_Release(rtv_uint);
19742 ID3D11Texture2D_Release(rt_texture);
19743 release_test_context(&test_context);
19746 static void test_cs_uav_store(void)
19748 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19749 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19750 static const float zero[4] = {0.0f};
19751 D3D11_TEXTURE2D_DESC texture_desc;
19752 ID3D11UnorderedAccessView *uav;
19753 struct device_desc device_desc;
19754 ID3D11DeviceContext *context;
19755 struct vec4 input = {1.0f};
19756 ID3D11Texture2D *texture;
19757 ID3D11ComputeShader *cs;
19758 ID3D11Device *device;
19759 ID3D11Buffer *cb;
19760 ULONG refcount;
19761 HRESULT hr;
19762 RECT rect;
19764 static const DWORD cs_1_thread_code[] =
19766 #if 0
19767 RWTexture2D<float> u;
19769 float value;
19771 [numthreads(1, 1, 1)]
19772 void main()
19774 uint x, y, width, height;
19775 u.GetDimensions(width, height);
19776 for (y = 0; y < height; ++y)
19778 for (x = 0; x < width; ++x)
19779 u[uint2(x, y)] = value;
19782 #endif
19783 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
19784 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19785 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
19786 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
19787 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
19788 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
19789 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
19790 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
19791 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
19792 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
19793 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
19794 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
19795 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
19796 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
19797 0x01000016, 0x0100003e,
19799 static const DWORD cs_1_group_code[] =
19801 #if 0
19802 RWTexture2D<float> u;
19804 float value;
19806 [numthreads(16, 16, 1)]
19807 void main(uint3 threadID : SV_GroupThreadID)
19809 uint2 count, size ;
19810 u.GetDimensions(size.x, size.y);
19811 count = size / (uint2)16;
19812 for (uint y = 0; y < count.y; ++y)
19813 for (uint x = 0; x < count.x; ++x)
19814 u[count * threadID.xy + uint2(x, y)] = value;
19816 #endif
19817 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
19818 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19819 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
19820 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
19821 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
19822 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
19823 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
19824 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
19825 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
19826 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
19827 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
19828 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
19829 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
19830 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
19831 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
19832 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
19833 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
19835 static const DWORD cs_1_store_code[] =
19837 #if 0
19838 RWTexture2D<float> u;
19840 float value;
19842 [numthreads(1, 1, 1)]
19843 void main(uint3 groupID : SV_GroupID)
19845 u[groupID.xy] = value;
19847 #endif
19848 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
19849 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19850 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
19851 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
19852 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
19853 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
19855 static const DWORD cs_dispatch_id_code[] =
19857 #if 0
19858 RWTexture2D<float> u;
19860 float value;
19862 [numthreads(4, 4, 1)]
19863 void main(uint3 id : SV_DispatchThreadID)
19865 u[id.xy] = value;
19867 #endif
19868 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
19869 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19870 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
19871 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
19872 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
19873 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
19875 static const DWORD cs_group_index_code[] =
19877 #if 0
19878 RWTexture2D<float> u;
19880 float value;
19882 [numthreads(32, 1, 1)]
19883 void main(uint index : SV_GroupIndex)
19885 uint2 size;
19886 u.GetDimensions(size.x, size.y);
19887 uint count = size.x * size.y / 32;
19888 index *= count;
19889 for (uint i = 0; i < count; ++i, ++index)
19890 u[uint2(index % size.x, index / size.x)] = value;
19892 #endif
19893 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
19894 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19895 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
19896 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
19897 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
19898 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
19899 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
19900 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
19901 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
19902 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
19903 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
19904 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
19905 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
19906 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
19907 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
19908 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
19911 device_desc.feature_level = &feature_level;
19912 device_desc.flags = 0;
19913 if (!(device = create_device(&device_desc)))
19915 skip("Failed to create device for feature level %#x.\n", feature_level);
19916 return;
19919 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
19921 texture_desc.Width = 64;
19922 texture_desc.Height = 64;
19923 texture_desc.MipLevels = 1;
19924 texture_desc.ArraySize = 1;
19925 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
19926 texture_desc.SampleDesc.Count = 1;
19927 texture_desc.SampleDesc.Quality = 0;
19928 texture_desc.Usage = D3D11_USAGE_DEFAULT;
19929 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19930 texture_desc.CPUAccessFlags = 0;
19931 texture_desc.MiscFlags = 0;
19933 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19934 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19936 uav_desc.Format = texture_desc.Format;
19937 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
19938 U(uav_desc).Texture2D.MipSlice = 0;
19940 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
19941 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19943 ID3D11Device_GetImmediateContext(device, &context);
19945 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
19946 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19948 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
19949 check_texture_float(texture, 0.0f, 2);
19951 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
19952 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19953 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19955 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19956 check_texture_float(texture, 1.0f, 2);
19958 input.x = 0.5f;
19959 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
19960 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19961 check_texture_float(texture, 0.5f, 2);
19963 ID3D11ComputeShader_Release(cs);
19965 input.x = 2.0f;
19966 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
19967 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
19968 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19969 check_texture_float(texture, 0.5f, 2);
19971 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
19972 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19973 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19975 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19976 check_texture_float(texture, 2.0f, 2);
19978 input.x = 4.0f;
19979 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
19980 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19981 check_texture_float(texture, 4.0f, 2);
19983 ID3D11ComputeShader_Release(cs);
19985 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
19986 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19987 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19989 input.x = 1.0f;
19990 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
19991 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
19992 check_texture_float(texture, 1.0f, 2);
19994 input.x = 0.5f;
19995 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
19996 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
19997 SetRect(&rect, 0, 0, 16, 32);
19998 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
19999 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
20000 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
20001 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
20002 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
20004 ID3D11ComputeShader_Release(cs);
20006 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
20007 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
20008 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
20010 input.x = 0.6f;
20011 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
20012 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
20013 SetRect(&rect, 0, 0, 60, 60);
20014 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
20015 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
20016 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
20017 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
20018 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
20020 input.x = 0.7f;
20021 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
20022 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
20023 check_texture_float(texture, 0.7f, 2);
20025 ID3D11ComputeShader_Release(cs);
20027 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
20028 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
20029 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
20031 input.x = 0.3f;
20032 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
20033 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
20034 check_texture_float(texture, 0.3f, 2);
20036 input.x = 0.1f;
20037 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
20038 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
20039 check_texture_float(texture, 0.1f, 2);
20041 ID3D11ComputeShader_Release(cs);
20043 ID3D11Buffer_Release(cb);
20044 ID3D11Texture2D_Release(texture);
20045 ID3D11UnorderedAccessView_Release(uav);
20046 ID3D11DeviceContext_Release(context);
20047 refcount = ID3D11Device_Release(device);
20048 ok(!refcount, "Device has %u references left.\n", refcount);
20051 static void test_uav_store_immediate_constant(void)
20053 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
20054 struct d3d11_test_context test_context;
20055 D3D11_TEXTURE2D_DESC texture_desc;
20056 ID3D11UnorderedAccessView *uav;
20057 ID3D11DeviceContext *context;
20058 struct resource_readback rb;
20059 ID3D11Texture2D *texture;
20060 ID3D11ComputeShader *cs;
20061 unsigned int uint_data;
20062 ID3D11Device *device;
20063 ID3D11Buffer *buffer;
20064 float float_data;
20065 int int_data;
20066 HRESULT hr;
20068 static const DWORD cs_store_int_code[] =
20070 #if 0
20071 RWBuffer<int> u;
20073 [numthreads(1, 1, 1)]
20074 void main()
20076 u[0] = 42;
20078 #endif
20079 0x43425844, 0x7246d785, 0x3f4ccbd6, 0x6a7cdbc0, 0xe2b58c72, 0x00000001, 0x000000b8, 0x00000003,
20080 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20081 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
20082 0x0400089c, 0x0011e000, 0x00000000, 0x00003333, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
20083 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
20084 0x00004002, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, 0x0100003e,
20086 static const DWORD cs_store_float_code[] =
20088 #if 0
20089 RWBuffer<float> u;
20091 [numthreads(1, 1, 1)]
20092 void main()
20094 u[0] = 1.0;
20096 #endif
20097 0x43425844, 0x525eea68, 0xc4cd5716, 0xc588f9c4, 0x0da27c5a, 0x00000001, 0x000000b8, 0x00000003,
20098 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20099 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
20100 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
20101 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
20102 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e,
20104 static const DWORD cs_store_unorm_code[] =
20106 #if 0
20107 RWTexture2D<unorm float> u;
20109 [numthreads(1, 1, 1)]
20110 void main()
20112 u[uint2(0, 0)] = 0.5f;
20114 #endif
20115 0x43425844, 0x3623f1de, 0xe847109e, 0x8e3da13f, 0xb6787b06, 0x00000001, 0x000000b8, 0x00000003,
20116 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20117 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
20118 0x0400189c, 0x0011e000, 0x00000000, 0x00001111, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
20119 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
20120 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20122 static const DWORD cs_store_snorm_code[] =
20124 #if 0
20125 RWTexture2D<snorm float> u;
20127 [numthreads(1, 1, 1)]
20128 void main()
20130 u[uint2(0, 0)] = -0.5f;
20132 #endif
20133 0x43425844, 0xce5397fc, 0x7464bc06, 0xc79aa56c, 0x881bd7ef, 0x00000001, 0x000000b8, 0x00000003,
20134 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20135 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
20136 0x0400189c, 0x0011e000, 0x00000000, 0x00002222, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
20137 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
20138 0x00004002, 0xbf000000, 0xbf000000, 0xbf000000, 0xbf000000, 0x0100003e,
20140 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20141 static const unsigned int zero[4] = {0};
20143 if (!init_test_context(&test_context, &feature_level))
20144 return;
20146 device = test_context.device;
20147 context = test_context.immediate_context;
20149 buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
20151 uav_desc.Format = DXGI_FORMAT_R32_SINT;
20152 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
20153 U(uav_desc).Buffer.FirstElement = 0;
20154 U(uav_desc).Buffer.NumElements = 1;
20155 U(uav_desc).Buffer.Flags = 0;
20156 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
20157 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
20158 hr = ID3D11Device_CreateComputeShader(device, cs_store_int_code, sizeof(cs_store_int_code), NULL, &cs);
20159 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
20161 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
20162 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
20163 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
20164 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
20165 get_buffer_readback(buffer, &rb);
20166 int_data = get_readback_color(&rb, 0, 0, 0);
20167 ok(int_data == 42, "Got unexpected value %u.\n", int_data);
20168 release_resource_readback(&rb);
20170 ID3D11ComputeShader_Release(cs);
20171 ID3D11UnorderedAccessView_Release(uav);
20172 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
20173 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
20174 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
20175 hr = ID3D11Device_CreateComputeShader(device, cs_store_float_code, sizeof(cs_store_float_code), NULL, &cs);
20176 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
20178 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
20179 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
20180 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
20181 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
20182 get_buffer_readback(buffer, &rb);
20183 float_data = get_readback_float(&rb, 0, 0);
20184 ok(float_data == 1.0f, "Got unexpected value %.8e.\n", float_data);
20185 release_resource_readback(&rb);
20187 texture_desc.Width = 64;
20188 texture_desc.Height = 64;
20189 texture_desc.MipLevels = 1;
20190 texture_desc.ArraySize = 1;
20191 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
20192 texture_desc.SampleDesc.Count = 1;
20193 texture_desc.SampleDesc.Quality = 0;
20194 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20195 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
20196 texture_desc.CPUAccessFlags = 0;
20197 texture_desc.MiscFlags = 0;
20198 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
20199 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
20200 ID3D11UnorderedAccessView_Release(uav);
20201 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
20202 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
20204 ID3D11ComputeShader_Release(cs);
20205 hr = ID3D11Device_CreateComputeShader(device, cs_store_unorm_code, sizeof(cs_store_unorm_code), NULL, &cs);
20206 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
20207 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
20208 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
20209 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
20210 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
20211 get_texture_readback(texture, 0, &rb);
20212 uint_data = get_readback_color(&rb, 0, 0, 0);
20213 ok(compare_color(uint_data, 0x80808080, 1), "Got unexpected color 0x%08x.\n", uint_data);
20214 release_resource_readback(&rb);
20216 ID3D11Texture2D_Release(texture);
20217 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_SNORM;
20218 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
20219 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
20220 ID3D11UnorderedAccessView_Release(uav);
20221 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
20222 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
20224 ID3D11ComputeShader_Release(cs);
20225 hr = ID3D11Device_CreateComputeShader(device, cs_store_snorm_code, sizeof(cs_store_snorm_code), NULL, &cs);
20226 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
20227 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
20228 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
20229 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
20230 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
20231 get_texture_readback(texture, 0, &rb);
20232 uint_data = get_readback_color(&rb, 0, 0, 0);
20233 ok(compare_color(uint_data, 0xc0c0c0c0, 1), "Got unexpected color 0x%08x.\n", uint_data);
20234 release_resource_readback(&rb);
20236 ID3D11Buffer_Release(buffer);
20237 ID3D11Texture2D_Release(texture);
20238 ID3D11ComputeShader_Release(cs);
20239 ID3D11UnorderedAccessView_Release(uav);
20240 release_test_context(&test_context);
20243 static void test_ps_cs_uav_binding(void)
20245 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20246 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
20247 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
20248 ID3D11Texture2D *cs_texture, *ps_texture;
20249 struct d3d11_test_context test_context;
20250 static const float zero[4] = {0.0f};
20251 D3D11_TEXTURE2D_DESC texture_desc;
20252 ID3D11DeviceContext *context;
20253 ID3D11Buffer *cs_cb, *ps_cb;
20254 struct vec4 input = {1.0f};
20255 ID3D11ComputeShader *cs;
20256 ID3D11PixelShader *ps;
20257 ID3D11Device *device;
20258 HRESULT hr;
20260 static const DWORD cs_code[] =
20262 #if 0
20263 RWTexture2D<float> u;
20265 float value;
20267 [numthreads(1, 1, 1)]
20268 void main()
20270 uint x, y, width, height;
20271 u.GetDimensions(width, height);
20272 for (y = 0; y < height; ++y)
20274 for (x = 0; x < width; ++x)
20275 u[uint2(x, y)] = value;
20278 #endif
20279 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
20280 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20281 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
20282 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
20283 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
20284 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
20285 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
20286 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
20287 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
20288 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
20289 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
20290 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
20291 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
20292 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
20293 0x01000016, 0x0100003e,
20295 static const DWORD ps_code[] =
20297 #if 0
20298 RWTexture2D<float> u : register(u1);
20300 float value;
20302 void main()
20304 uint x, y, width, height;
20305 u.GetDimensions(width, height);
20306 for (y = 0; y < height; ++y)
20308 for (x = 0; x < width; ++x)
20309 u[uint2(x, y)] = value;
20312 #endif
20313 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
20314 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20315 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
20316 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
20317 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
20318 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
20319 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
20320 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
20321 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
20322 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
20323 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
20324 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
20325 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
20326 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
20329 if (!init_test_context(&test_context, &feature_level))
20330 return;
20332 device = test_context.device;
20333 context = test_context.immediate_context;
20335 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
20336 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
20338 texture_desc.Width = 64;
20339 texture_desc.Height = 64;
20340 texture_desc.MipLevels = 1;
20341 texture_desc.ArraySize = 1;
20342 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
20343 texture_desc.SampleDesc.Count = 1;
20344 texture_desc.SampleDesc.Quality = 0;
20345 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20346 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
20347 texture_desc.CPUAccessFlags = 0;
20348 texture_desc.MiscFlags = 0;
20349 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
20350 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20351 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
20352 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20354 uav_desc.Format = texture_desc.Format;
20355 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
20356 U(uav_desc).Texture2D.MipSlice = 0;
20357 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
20358 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
20359 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
20360 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
20362 ID3D11Device_GetImmediateContext(device, &context);
20364 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
20365 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
20366 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
20367 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
20368 0, NULL, NULL, 1, 1, &ps_uav, NULL);
20370 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
20371 check_texture_float(cs_texture, 0.0f, 2);
20372 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
20373 check_texture_float(ps_texture, 0.0f, 2);
20375 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
20376 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
20377 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
20378 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20379 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20380 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20382 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
20383 check_texture_float(cs_texture, 1.0f, 2);
20384 check_texture_float(ps_texture, 0.0f, 2);
20385 draw_quad(&test_context);
20386 check_texture_float(cs_texture, 1.0f, 2);
20387 check_texture_float(ps_texture, 1.0f, 2);
20389 input.x = 0.5f;
20390 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
20391 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
20392 check_texture_float(cs_texture, 0.5f, 2);
20393 check_texture_float(ps_texture, 1.0f, 2);
20394 input.x = 2.0f;
20395 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
20396 draw_quad(&test_context);
20397 check_texture_float(cs_texture, 0.5f, 2);
20398 check_texture_float(ps_texture, 2.0f, 2);
20400 input.x = 8.0f;
20401 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
20402 input.x = 4.0f;
20403 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
20404 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
20405 check_texture_float(cs_texture, 8.0f, 2);
20406 check_texture_float(ps_texture, 2.0f, 2);
20407 draw_quad(&test_context);
20408 check_texture_float(cs_texture, 8.0f, 2);
20409 check_texture_float(ps_texture, 4.0f, 2);
20411 ID3D11ComputeShader_Release(cs);
20412 ID3D11PixelShader_Release(ps);
20413 ID3D11Buffer_Release(cs_cb);
20414 ID3D11Buffer_Release(ps_cb);
20415 ID3D11Texture2D_Release(cs_texture);
20416 ID3D11Texture2D_Release(ps_texture);
20417 ID3D11UnorderedAccessView_Release(cs_uav);
20418 ID3D11UnorderedAccessView_Release(ps_uav);
20419 ID3D11DeviceContext_Release(context);
20420 release_test_context(&test_context);
20423 static void test_atomic_instructions(void)
20425 ID3D11UnorderedAccessView *in_uav, *out_uav;
20426 ID3D11Buffer *cb, *in_buffer, *out_buffer;
20427 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
20428 struct d3d11_test_context test_context;
20429 struct resource_readback rb, out_rb;
20430 D3D11_BUFFER_DESC buffer_desc;
20431 ID3D11DeviceContext *context;
20432 ID3D11ComputeShader *cs;
20433 ID3D11PixelShader *ps;
20434 ID3D11Device *device;
20435 unsigned int i, j;
20436 HRESULT hr;
20438 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20439 static const unsigned int zero[4] = {0, 0, 0, 0};
20440 static const DWORD ps_atomics_code[] =
20442 #if 0
20443 RWByteAddressBuffer u;
20445 uint4 v;
20446 int4 i;
20448 void main()
20450 u.InterlockedAnd(0 * 4, v.x);
20451 u.InterlockedCompareStore(1 * 4, v.y, v.x);
20452 u.InterlockedAdd(2 * 4, v.x);
20453 u.InterlockedOr(3 * 4, v.x);
20454 u.InterlockedMax(4 * 4, i.x);
20455 u.InterlockedMin(5 * 4, i.x);
20456 u.InterlockedMax(6 * 4, v.x);
20457 u.InterlockedMin(7 * 4, v.x);
20458 u.InterlockedXor(8 * 4, v.x);
20460 #endif
20461 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
20462 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20463 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
20464 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
20465 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
20466 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
20467 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
20468 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
20469 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
20470 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
20471 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
20472 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
20473 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
20474 0x00000000, 0x00000000, 0x0100003e,
20476 static const DWORD cs_atomics_code[] =
20478 #if 0
20479 RWByteAddressBuffer u;
20480 RWByteAddressBuffer u2;
20482 uint4 v;
20483 int4 i;
20485 [numthreads(1, 1, 1)]
20486 void main()
20488 uint r;
20489 u.InterlockedAnd(0 * 4, v.x, r);
20490 u2.Store(0 * 4, r);
20491 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
20492 u2.Store(1 * 4, r);
20493 u.InterlockedAdd(2 * 4, v.x, r);
20494 u2.Store(2 * 4, r);
20495 u.InterlockedOr(3 * 4, v.x, r);
20496 u2.Store(3 * 4, r);
20497 u.InterlockedMax(4 * 4, i.x, r);
20498 u2.Store(4 * 4, r);
20499 u.InterlockedMin(5 * 4, i.x, r);
20500 u2.Store(5 * 4, r);
20501 u.InterlockedMax(6 * 4, v.x, r);
20502 u2.Store(6 * 4, r);
20503 u.InterlockedMin(7 * 4, v.x, r);
20504 u2.Store(7 * 4, r);
20505 u.InterlockedXor(8 * 4, v.x, r);
20506 u2.Store(8 * 4, r);
20508 #endif
20509 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
20510 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20511 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
20512 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
20513 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
20514 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
20515 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
20516 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
20517 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
20518 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
20519 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
20520 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
20521 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
20522 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
20523 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
20524 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
20525 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
20526 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
20527 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
20528 0x0010000a, 0x00000000, 0x0100003e,
20531 static const char * const instructions[] =
20533 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
20534 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
20536 static const char * const imm_instructions[] =
20538 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
20539 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
20541 static const struct test
20543 struct uvec4 v;
20544 struct ivec4 i;
20545 unsigned int input[ARRAY_SIZE(instructions)];
20546 unsigned int expected_result[ARRAY_SIZE(instructions)];
20548 tests[] =
20550 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
20551 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
20554 if (!init_test_context(&test_context, &feature_level))
20555 return;
20557 device = test_context.device;
20558 context = test_context.immediate_context;
20560 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
20561 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
20562 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
20564 buffer_desc.ByteWidth = sizeof(tests->input);
20565 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
20566 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
20567 buffer_desc.CPUAccessFlags = 0;
20568 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
20569 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
20570 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
20571 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
20572 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
20574 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
20575 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
20576 U(uav_desc).Buffer.FirstElement = 0;
20577 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
20578 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
20579 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
20580 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
20581 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
20582 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
20584 set_viewport(context, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f);
20586 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
20587 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20588 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20590 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
20591 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
20592 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
20594 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20596 const struct test *test = &tests[i];
20598 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
20599 NULL, &test->v, 0, 0);
20601 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
20602 NULL, test->input, 0, 0);
20604 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
20605 0, 1, &in_uav, NULL);
20607 draw_quad(&test_context);
20608 get_buffer_readback(in_buffer, &rb);
20609 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
20611 unsigned int value = get_readback_color(&rb, j, 0, 0);
20612 unsigned int expected = test->expected_result[j];
20614 todo_wine_if(expected != test->input[j]
20615 && (!strcmp(instructions[j], "atomic_imax")
20616 || !strcmp(instructions[j], "atomic_imin")))
20617 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
20618 "with inputs (%u, %u), (%d), %#x (%d).\n",
20619 i, value, value, expected, expected, instructions[j],
20620 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
20622 release_resource_readback(&rb);
20624 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
20625 NULL, test->input, 0, 0);
20626 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
20628 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
20629 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
20631 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
20632 get_buffer_readback(in_buffer, &rb);
20633 get_buffer_readback(out_buffer, &out_rb);
20634 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
20636 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
20637 || !strcmp(imm_instructions[j], "imm_atomic_imin");
20638 unsigned int out_value = get_readback_color(&out_rb, j, 0, 0);
20639 unsigned int value = get_readback_color(&rb, j, 0, 0);
20640 unsigned int expected = test->expected_result[j];
20642 todo_wine_if(expected != test->input[j] && todo_instruction)
20643 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
20644 "with inputs (%u, %u), (%d), %#x (%d).\n",
20645 i, value, value, expected, expected, imm_instructions[j],
20646 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
20648 todo_wine_if(todo_instruction && out_value != test->input[j])
20649 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
20650 out_value, test->input[j], imm_instructions[j]);
20652 release_resource_readback(&out_rb);
20653 release_resource_readback(&rb);
20656 ID3D11Buffer_Release(cb);
20657 ID3D11Buffer_Release(in_buffer);
20658 ID3D11Buffer_Release(out_buffer);
20659 ID3D11ComputeShader_Release(cs);
20660 ID3D11PixelShader_Release(ps);
20661 ID3D11UnorderedAccessView_Release(in_uav);
20662 ID3D11UnorderedAccessView_Release(out_uav);
20663 release_test_context(&test_context);
20666 static void test_sm4_ret_instruction(void)
20668 struct d3d11_test_context test_context;
20669 ID3D11DeviceContext *context;
20670 ID3D11PixelShader *ps;
20671 struct uvec4 constant;
20672 ID3D11Device *device;
20673 ID3D11Buffer *cb;
20674 HRESULT hr;
20676 static const DWORD ps_code[] =
20678 #if 0
20679 uint c;
20681 float4 main() : SV_TARGET
20683 if (c == 1)
20684 return float4(1, 0, 0, 1);
20685 if (c == 2)
20686 return float4(0, 1, 0, 1);
20687 if (c == 3)
20688 return float4(0, 0, 1, 1);
20689 return float4(1, 1, 1, 1);
20691 #endif
20692 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
20693 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20694 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
20695 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
20696 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
20697 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
20698 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
20699 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
20700 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
20701 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
20702 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
20703 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
20704 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
20705 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
20706 0x0100003e,
20709 if (!init_test_context(&test_context, NULL))
20710 return;
20712 device = test_context.device;
20713 context = test_context.immediate_context;
20715 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20716 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
20717 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20718 memset(&constant, 0, sizeof(constant));
20719 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
20720 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
20722 draw_quad(&test_context);
20723 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20725 constant.x = 1;
20726 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20727 draw_quad(&test_context);
20728 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
20730 constant.x = 2;
20731 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20732 draw_quad(&test_context);
20733 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20735 constant.x = 3;
20736 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20737 draw_quad(&test_context);
20738 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
20740 constant.x = 4;
20741 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20742 draw_quad(&test_context);
20743 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20745 ID3D11Buffer_Release(cb);
20746 ID3D11PixelShader_Release(ps);
20747 release_test_context(&test_context);
20750 static void test_primitive_restart(void)
20752 struct d3d11_test_context test_context;
20753 ID3D11Buffer *ib32, *ib16, *vb;
20754 ID3D11DeviceContext *context;
20755 unsigned int stride, offset;
20756 ID3D11InputLayout *layout;
20757 ID3D11VertexShader *vs;
20758 ID3D11PixelShader *ps;
20759 ID3D11Device *device;
20760 unsigned int i;
20761 HRESULT hr;
20762 RECT rect;
20764 static const DWORD ps_code[] =
20766 #if 0
20767 struct vs_out
20769 float4 position : SV_Position;
20770 float4 color : color;
20773 float4 main(vs_out input) : SV_TARGET
20775 return input.color;
20777 #endif
20778 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
20779 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20780 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20781 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
20782 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20783 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
20784 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
20785 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
20787 static const DWORD vs_code[] =
20789 #if 0
20790 struct vs_out
20792 float4 position : SV_Position;
20793 float4 color : color;
20796 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
20798 output.position = position;
20799 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
20801 #endif
20802 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
20803 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
20804 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
20805 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
20806 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
20807 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
20808 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
20809 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
20810 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
20811 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
20812 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
20813 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
20814 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
20816 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
20818 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
20820 static const struct vec2 vertices[] =
20822 {-1.00f, -1.0f},
20823 {-1.00f, 1.0f},
20824 {-0.25f, -1.0f},
20825 {-0.25f, 1.0f},
20826 { 0.25f, -1.0f},
20827 { 0.25f, 1.0f},
20828 { 1.00f, -1.0f},
20829 { 1.00f, 1.0f},
20831 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
20832 static const unsigned short indices16[] =
20834 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
20836 static const unsigned int indices32[] =
20838 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
20841 if (!init_test_context(&test_context, NULL))
20842 return;
20844 device = test_context.device;
20845 context = test_context.immediate_context;
20847 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
20848 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
20849 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20850 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
20852 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
20853 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
20855 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
20856 vs_code, sizeof(vs_code), &layout);
20857 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
20859 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
20861 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
20862 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20864 ID3D11DeviceContext_IASetInputLayout(context, layout);
20865 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
20866 stride = sizeof(*vertices);
20867 offset = 0;
20868 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
20870 for (i = 0; i < 2; ++i)
20872 if (!i)
20873 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
20874 else
20875 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
20877 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
20878 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
20879 SetRect(&rect, 0, 0, 240, 480);
20880 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
20881 SetRect(&rect, 240, 0, 400, 480);
20882 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
20883 SetRect(&rect, 400, 0, 640, 480);
20884 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
20887 ID3D11Buffer_Release(ib16);
20888 ID3D11Buffer_Release(ib32);
20889 ID3D11Buffer_Release(vb);
20890 ID3D11InputLayout_Release(layout);
20891 ID3D11PixelShader_Release(ps);
20892 ID3D11VertexShader_Release(vs);
20893 release_test_context(&test_context);
20896 static void test_resinfo_instruction(void)
20898 struct shader
20900 const DWORD *code;
20901 size_t size;
20904 struct d3d11_test_context test_context;
20905 D3D11_TEXTURE3D_DESC texture3d_desc;
20906 D3D11_TEXTURE2D_DESC texture_desc;
20907 const struct shader *current_ps;
20908 D3D_FEATURE_LEVEL feature_level;
20909 ID3D11ShaderResourceView *srv;
20910 ID3D11DeviceContext *context;
20911 ID3D11Texture2D *rtv_texture;
20912 ID3D11RenderTargetView *rtv;
20913 ID3D11Resource *texture;
20914 struct uvec4 constant;
20915 ID3D11PixelShader *ps;
20916 ID3D11Device *device;
20917 unsigned int i, type;
20918 ID3D11Buffer *cb;
20919 HRESULT hr;
20921 static const DWORD ps_2d_code[] =
20923 #if 0
20924 Texture2D t;
20926 uint type;
20927 uint level;
20929 float4 main() : SV_TARGET
20931 if (!type)
20933 float width, height, miplevels;
20934 t.GetDimensions(level, width, height, miplevels);
20935 return float4(width, height, miplevels, 0);
20937 else
20939 uint width, height, miplevels;
20940 t.GetDimensions(level, width, height, miplevels);
20941 return float4(width, height, miplevels, 0);
20944 #endif
20945 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
20946 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20947 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
20948 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
20949 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
20950 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
20951 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
20952 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
20953 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
20954 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
20955 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
20956 0x01000015, 0x0100003e,
20958 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
20959 static const DWORD ps_2d_array_code[] =
20961 #if 0
20962 Texture2DArray t;
20964 uint type;
20965 uint level;
20967 float4 main() : SV_TARGET
20969 if (!type)
20971 float width, height, elements, miplevels;
20972 t.GetDimensions(level, width, height, elements, miplevels);
20973 return float4(width, height, elements, miplevels);
20975 else
20977 uint width, height, elements, miplevels;
20978 t.GetDimensions(level, width, height, elements, miplevels);
20979 return float4(width, height, elements, miplevels);
20982 #endif
20983 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
20984 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20985 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
20986 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
20987 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
20988 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
20989 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
20990 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
20991 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
20992 0x0100003e, 0x01000015, 0x0100003e,
20994 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
20995 static const DWORD ps_3d_code[] =
20997 #if 0
20998 Texture3D t;
21000 uint type;
21001 uint level;
21003 float4 main() : SV_TARGET
21005 if (!type)
21007 float width, height, depth, miplevels;
21008 t.GetDimensions(level, width, height, depth, miplevels);
21009 return float4(width, height, depth, miplevels);
21011 else
21013 uint width, height, depth, miplevels;
21014 t.GetDimensions(level, width, height, depth, miplevels);
21015 return float4(width, height, depth, miplevels);
21018 #endif
21019 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
21020 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21021 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
21022 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
21023 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
21024 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
21025 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
21026 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
21027 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
21028 0x0100003e, 0x01000015, 0x0100003e,
21030 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
21031 static const DWORD ps_cube_code[] =
21033 #if 0
21034 TextureCube t;
21036 uint type;
21037 uint level;
21039 float4 main() : SV_TARGET
21041 if (!type)
21043 float width, height, miplevels;
21044 t.GetDimensions(level, width, height, miplevels);
21045 return float4(width, height, miplevels, 0);
21047 else
21049 uint width, height, miplevels;
21050 t.GetDimensions(level, width, height, miplevels);
21051 return float4(width, height, miplevels, 0);
21054 #endif
21055 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
21056 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21057 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
21058 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
21059 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
21060 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
21061 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
21062 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
21063 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
21064 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
21065 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
21066 0x01000015, 0x0100003e,
21068 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
21069 static const DWORD ps_cube_array_code[] =
21071 #if 0
21072 TextureCubeArray t;
21074 uint type;
21075 uint level;
21077 float4 main() : SV_TARGET
21079 if (!type)
21081 float width, height, elements, miplevels;
21082 t.GetDimensions(level, width, height, elements, miplevels);
21083 return float4(width, height, miplevels, 0);
21085 else
21087 uint width, height, elements, miplevels;
21088 t.GetDimensions(level, width, height, elements, miplevels);
21089 return float4(width, height, miplevels, 0);
21092 #endif
21093 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
21094 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21095 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
21096 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
21097 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
21098 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
21099 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
21100 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
21101 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
21102 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
21103 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
21104 0x0100003e, 0x01000015, 0x0100003e,
21106 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
21107 static const struct ps_test
21109 const struct shader *ps;
21110 struct
21112 unsigned int width;
21113 unsigned int height;
21114 unsigned int depth;
21115 unsigned int miplevel_count;
21116 unsigned int array_size;
21117 unsigned int cube_count;
21118 } texture_desc;
21119 unsigned int miplevel;
21120 struct vec4 expected_result;
21122 ps_tests[] =
21124 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
21125 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
21126 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
21127 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
21129 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
21130 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
21131 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
21132 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
21134 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
21135 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
21136 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
21137 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
21138 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
21139 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
21140 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
21141 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
21142 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
21144 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
21145 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
21146 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
21147 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
21148 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
21150 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
21151 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
21152 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
21155 if (!init_test_context(&test_context, NULL))
21156 return;
21158 device = test_context.device;
21159 context = test_context.immediate_context;
21160 feature_level = ID3D11Device_GetFeatureLevel(device);
21162 texture_desc.Width = 64;
21163 texture_desc.Height = 64;
21164 texture_desc.MipLevels = 1;
21165 texture_desc.ArraySize = 1;
21166 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
21167 texture_desc.SampleDesc.Count = 1;
21168 texture_desc.SampleDesc.Quality = 0;
21169 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21170 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21171 texture_desc.CPUAccessFlags = 0;
21172 texture_desc.MiscFlags = 0;
21173 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
21174 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21175 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
21176 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21178 memset(&constant, 0, sizeof(constant));
21179 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
21181 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
21182 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
21184 ps = NULL;
21185 current_ps = NULL;
21186 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
21188 const struct ps_test *test = &ps_tests[i];
21190 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
21192 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
21193 continue;
21196 if (current_ps != test->ps)
21198 if (ps)
21199 ID3D11PixelShader_Release(ps);
21201 current_ps = test->ps;
21203 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
21204 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
21205 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21208 if (test->texture_desc.depth != 1)
21210 texture3d_desc.Width = test->texture_desc.width;
21211 texture3d_desc.Height = test->texture_desc.height;
21212 texture3d_desc.Depth = test->texture_desc.depth;
21213 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
21214 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
21215 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
21216 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
21217 texture3d_desc.CPUAccessFlags = 0;
21218 texture3d_desc.MiscFlags = 0;
21219 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
21220 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
21222 else
21224 texture_desc.Width = test->texture_desc.width;
21225 texture_desc.Height = test->texture_desc.height;
21226 texture_desc.MipLevels = test->texture_desc.miplevel_count;
21227 texture_desc.ArraySize = test->texture_desc.array_size;
21228 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
21229 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
21230 texture_desc.MiscFlags = 0;
21231 if (test->texture_desc.cube_count)
21232 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
21233 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
21234 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
21237 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
21238 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
21239 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
21241 for (type = 0; type < 2; ++type)
21243 constant.x = type;
21244 constant.y = test->miplevel;
21245 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
21247 draw_quad(&test_context);
21248 check_texture_vec4(rtv_texture, &test->expected_result, 0);
21251 ID3D11Resource_Release(texture);
21252 ID3D11ShaderResourceView_Release(srv);
21254 ID3D11PixelShader_Release(ps);
21256 ID3D11Buffer_Release(cb);
21257 ID3D11RenderTargetView_Release(rtv);
21258 ID3D11Texture2D_Release(rtv_texture);
21259 release_test_context(&test_context);
21262 static void test_sm5_bufinfo_instruction(void)
21264 struct shader
21266 const DWORD *code;
21267 size_t size;
21270 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21271 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
21272 struct d3d11_test_context test_context;
21273 D3D11_TEXTURE2D_DESC texture_desc;
21274 const struct shader *current_ps;
21275 ID3D11UnorderedAccessView *uav;
21276 ID3D11ShaderResourceView *srv;
21277 D3D11_BUFFER_DESC buffer_desc;
21278 ID3D11DeviceContext *context;
21279 ID3D11RenderTargetView *rtv;
21280 ID3D11Texture2D *texture;
21281 ID3D11PixelShader *ps;
21282 ID3D11Buffer *buffer;
21283 ID3D11Device *device;
21284 unsigned int i;
21285 HRESULT hr;
21287 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21288 static const DWORD ps_uav_structured_code[] =
21290 #if 0
21291 struct s
21293 uint4 u;
21294 bool b;
21297 RWStructuredBuffer<s> b;
21299 uint4 main(void) : SV_Target
21301 uint count, stride;
21302 b.GetDimensions(count, stride);
21303 return uint4(count, stride, 0, 1);
21305 #endif
21306 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
21307 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21308 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
21309 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
21310 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
21311 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
21312 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
21313 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
21315 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
21316 static const DWORD ps_uav_structured32_code[] =
21318 #if 0
21319 struct s
21321 uint4 u;
21322 bool4 b;
21325 RWStructuredBuffer<s> b;
21327 uint4 main(void) : SV_Target
21329 uint count, stride;
21330 b.GetDimensions(count, stride);
21331 return uint4(count, stride, 0, 1);
21333 #endif
21334 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
21335 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21336 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
21337 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
21338 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
21339 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
21340 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
21341 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
21343 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
21344 static const DWORD ps_srv_structured_code[] =
21346 #if 0
21347 StructuredBuffer<bool> b;
21349 uint4 main(void) : SV_Target
21351 uint count, stride;
21352 b.GetDimensions(count, stride);
21353 return uint4(count, stride, 0, 1);
21355 #endif
21356 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
21357 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21358 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
21359 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
21360 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
21361 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
21362 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
21363 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
21365 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
21366 static const DWORD ps_uav_raw_code[] =
21368 #if 0
21369 RWByteAddressBuffer b;
21371 uint4 main(void) : SV_Target
21373 uint width;
21374 b.GetDimensions(width);
21375 return width;
21377 #endif
21378 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
21379 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21380 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
21381 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
21382 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
21383 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
21384 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
21386 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
21387 static const DWORD ps_srv_raw_code[] =
21389 #if 0
21390 ByteAddressBuffer b;
21392 uint4 main(void) : SV_Target
21394 uint width;
21395 b.GetDimensions(width);
21396 return width;
21398 #endif
21399 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
21400 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21401 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
21402 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
21403 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
21404 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
21405 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
21407 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
21408 static const DWORD ps_uav_typed_code[] =
21410 #if 0
21411 RWBuffer<float> b;
21413 uint4 main(void) : SV_Target
21415 uint width;
21416 b.GetDimensions(width);
21417 return width;
21419 #endif
21420 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
21421 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21422 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
21423 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
21424 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
21425 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
21426 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
21428 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
21429 static const DWORD ps_srv_typed_code[] =
21431 #if 0
21432 Buffer<float> b;
21434 uint4 main(void) : SV_Target
21436 uint width;
21437 b.GetDimensions(width);
21438 return width;
21440 #endif
21441 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
21442 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21443 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
21444 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
21445 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
21446 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
21447 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
21449 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
21450 static const struct test
21452 const struct shader *ps;
21453 BOOL uav;
21454 unsigned int buffer_size;
21455 unsigned int buffer_misc_flags;
21456 unsigned int buffer_structure_byte_stride;
21457 DXGI_FORMAT view_format;
21458 unsigned int view_element_idx;
21459 unsigned int view_element_count;
21460 struct uvec4 expected_result;
21462 tests[] =
21464 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
21465 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
21466 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
21467 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
21468 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
21469 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
21470 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
21471 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
21472 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
21473 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
21474 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
21475 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
21476 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
21477 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
21478 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
21479 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
21480 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
21481 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
21482 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
21483 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
21484 #undef RAW
21485 #undef STRUCTURED
21488 if (!init_test_context(&test_context, &feature_level))
21489 return;
21491 device = test_context.device;
21492 context = test_context.immediate_context;
21494 texture_desc.Width = 64;
21495 texture_desc.Height = 64;
21496 texture_desc.MipLevels = 1;
21497 texture_desc.ArraySize = 1;
21498 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
21499 texture_desc.SampleDesc.Count = 1;
21500 texture_desc.SampleDesc.Quality = 0;
21501 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21502 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21503 texture_desc.CPUAccessFlags = 0;
21504 texture_desc.MiscFlags = 0;
21505 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21506 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21507 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
21508 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21510 ps = NULL;
21511 current_ps = NULL;
21512 for (i = 0; i < ARRAY_SIZE(tests); ++i)
21514 const struct test *test = &tests[i];
21516 if (current_ps != test->ps)
21518 if (ps)
21519 ID3D11PixelShader_Release(ps);
21521 current_ps = test->ps;
21523 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
21524 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
21525 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21528 buffer_desc.ByteWidth = test->buffer_size;
21529 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
21530 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
21531 buffer_desc.CPUAccessFlags = 0;
21532 buffer_desc.MiscFlags = test->buffer_misc_flags;
21533 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
21534 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
21535 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
21537 if (test->uav)
21539 uav_desc.Format = test->view_format;
21540 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
21541 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
21542 U(uav_desc).Buffer.NumElements = test->view_element_count;
21543 U(uav_desc).Buffer.Flags = 0;
21544 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
21545 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
21546 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
21547 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
21548 srv = NULL;
21550 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
21551 1, 1, &uav, NULL);
21553 else
21555 srv_desc.Format = test->view_format;
21556 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
21557 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
21558 U(srv_desc).BufferEx.NumElements = test->view_element_count;
21559 U(srv_desc).BufferEx.Flags = 0;
21560 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
21561 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
21562 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
21563 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
21564 uav = NULL;
21566 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
21567 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
21570 draw_quad(&test_context);
21571 check_texture_uvec4(texture, &test->expected_result);
21573 if (srv)
21574 ID3D11ShaderResourceView_Release(srv);
21575 if (uav)
21576 ID3D11UnorderedAccessView_Release(uav);
21577 ID3D11Buffer_Release(buffer);
21579 ID3D11PixelShader_Release(ps);
21581 ID3D11RenderTargetView_Release(rtv);
21582 ID3D11Texture2D_Release(texture);
21583 release_test_context(&test_context);
21586 static void test_sampleinfo_instruction(void)
21588 ID3D11Texture2D *float_rt_texture, *uint_rt_texture;
21589 ID3D11RenderTargetView *float_rtv, *uint_rtv, *rtv;
21590 ID3D11PixelShader *ps_float, *ps_uint, *ps_rt;
21591 ID3D11Texture2D *texture, *readback_texture;
21592 struct d3d11_test_context test_context;
21593 unsigned int sample_count, quality;
21594 D3D11_TEXTURE2D_DESC texture_desc;
21595 ID3D11RenderTargetView *rtvs[2];
21596 ID3D11ShaderResourceView *srv;
21597 ID3D11DeviceContext *context;
21598 struct uvec4 expected_uint;
21599 struct vec4 expected_float;
21600 ID3D11Device *device;
21601 HRESULT hr;
21603 static const DWORD ps_uint_code[] =
21605 #if 0
21606 Texture2DMS<float> t;
21608 uint4 main() : SV_Target1
21610 uint width, height, sample_count;
21611 t.GetDimensions(width, height, sample_count);
21612 return sample_count;
21614 #endif
21615 0x43425844, 0x4342ad12, 0x19addd8c, 0x5cb87c48, 0xe604a242, 0x00000001, 0x000000d4, 0x00000003,
21616 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21617 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
21618 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
21619 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000001,
21620 0x02000068, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a, 0x00000000, 0x05000036,
21621 0x001020f2, 0x00000001, 0x00100006, 0x00000000, 0x0100003e,
21623 static const DWORD ps_float_code[] =
21625 #if 0
21626 Texture2DMS<float> t;
21628 float4 main() : SV_Target
21630 uint width, height, sample_count;
21631 t.GetDimensions(width, height, sample_count);
21632 return sample_count;
21634 #endif
21635 0x43425844, 0x2b8aea46, 0x34ceda6f, 0xf98d222b, 0x235ebc0b, 0x00000001, 0x000000b8, 0x00000003,
21636 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21637 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
21638 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000040, 0x00000050, 0x00000010,
21639 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
21640 0x0500006f, 0x001020f2, 0x00000000, 0x0010700a, 0x00000000, 0x0100003e,
21642 static const DWORD ps_rt_code[] =
21644 #if 0
21645 float4 main() : SV_Target
21647 return GetRenderTargetSampleCount();
21649 #endif
21650 0x43425844, 0x74404d37, 0xad6f88e4, 0xb006ea57, 0xf07d9e2a, 0x00000001, 0x000000a4, 0x00000003,
21651 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21652 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
21653 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000002c, 0x00000050, 0x0000000b,
21654 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x0400006f, 0x001020f2, 0x00000000, 0x0000e00a,
21655 0x0100003e,
21657 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21659 if (!init_test_context(&test_context, &feature_level))
21660 return;
21662 device = test_context.device;
21663 context = test_context.immediate_context;
21665 texture_desc.Width = 64;
21666 texture_desc.Height = 64;
21667 texture_desc.MipLevels = 1;
21668 texture_desc.ArraySize = 1;
21669 texture_desc.SampleDesc.Count = 1;
21670 texture_desc.SampleDesc.Quality = 0;
21671 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21672 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21673 texture_desc.CPUAccessFlags = 0;
21674 texture_desc.MiscFlags = 0;
21676 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
21677 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &float_rt_texture);
21678 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
21679 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)float_rt_texture, NULL, &float_rtv);
21680 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
21681 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
21682 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &uint_rt_texture);
21683 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
21684 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)uint_rt_texture, NULL, &uint_rtv);
21685 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
21687 rtvs[0] = float_rtv;
21688 rtvs[1] = uint_rtv;
21689 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
21691 hr = ID3D11Device_CreatePixelShader(device, ps_float_code, sizeof(ps_float_code), NULL, &ps_float);
21692 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
21693 hr = ID3D11Device_CreatePixelShader(device, ps_uint_code, sizeof(ps_uint_code), NULL, &ps_uint);
21694 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
21696 for (sample_count = 2; sample_count <= 8; sample_count *= 2)
21698 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
21699 texture_desc.SampleDesc.Count = sample_count;
21700 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
21702 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
21703 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
21704 if (!quality)
21706 skip("Sample count %u not supported.\n", sample_count);
21707 continue;
21710 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21711 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
21712 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
21713 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
21714 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
21716 ID3D11DeviceContext_PSSetShader(context, ps_float, NULL, 0);
21717 draw_quad(&test_context);
21718 ID3D11DeviceContext_PSSetShader(context, ps_uint, NULL, 0);
21719 draw_quad(&test_context);
21721 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
21722 check_texture_vec4(float_rt_texture, &expected_float, 0);
21723 expected_uint.x = expected_uint.y = expected_uint.z = expected_uint.w = sample_count;
21724 check_texture_uvec4(uint_rt_texture, &expected_uint);
21726 ID3D11Texture2D_Release(texture);
21727 ID3D11ShaderResourceView_Release(srv);
21730 hr = ID3D11Device_CreatePixelShader(device, ps_rt_code, sizeof(ps_rt_code), NULL, &ps_rt);
21731 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
21732 for (sample_count = 1; sample_count <= 8; sample_count *= 2)
21734 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
21735 texture_desc.SampleDesc.Count = sample_count;
21736 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21738 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
21739 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
21740 if (!quality)
21742 skip("Sample count %u not supported.\n", sample_count);
21743 continue;
21746 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21747 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
21748 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
21749 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
21750 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
21752 /* Some drivers (AMD Radeon HD 6310) return stale sample counts if we
21753 * don't rebind the pixel shader between runs with different sample
21754 * counts. */
21755 ID3D11DeviceContext_PSSetShader(context, NULL, NULL, 0);
21756 ID3D11DeviceContext_PSSetShader(context, ps_rt, NULL, 0);
21757 draw_quad(&test_context);
21759 if (sample_count != 1)
21761 texture_desc.SampleDesc.Count = 1;
21762 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
21763 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
21764 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
21765 (ID3D11Resource *)texture, 0, texture_desc.Format);
21767 else
21769 readback_texture = texture;
21770 ID3D11Texture2D_AddRef(readback_texture);
21773 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
21774 check_texture_vec4(readback_texture, &expected_float, 0);
21776 ID3D11Texture2D_Release(readback_texture);
21777 ID3D11Texture2D_Release(texture);
21778 ID3D11RenderTargetView_Release(rtv);
21781 ID3D11RenderTargetView_Release(float_rtv);
21782 ID3D11RenderTargetView_Release(uint_rtv);
21783 ID3D11Texture2D_Release(float_rt_texture);
21784 ID3D11Texture2D_Release(uint_rt_texture);
21785 ID3D11PixelShader_Release(ps_float);
21786 ID3D11PixelShader_Release(ps_uint);
21787 ID3D11PixelShader_Release(ps_rt);
21788 release_test_context(&test_context);
21791 static void test_render_target_device_mismatch(void)
21793 struct d3d11_test_context test_context;
21794 struct device_desc device_desc = {0};
21795 ID3D11DeviceContext *context;
21796 ID3D11RenderTargetView *rtv;
21797 ID3D11Device *device;
21798 ULONG refcount;
21800 if (!init_test_context(&test_context, NULL))
21801 return;
21803 device = create_device(&device_desc);
21804 ok(!!device, "Failed to create device.\n");
21806 ID3D11Device_GetImmediateContext(device, &context);
21808 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
21809 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
21810 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
21811 if (!enable_debug_layer)
21813 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
21814 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
21815 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
21816 ID3D11RenderTargetView_Release(rtv);
21819 rtv = NULL;
21820 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
21822 ID3D11DeviceContext_Release(context);
21823 refcount = ID3D11Device_Release(device);
21824 ok(!refcount, "Device has %u references left.\n", refcount);
21825 release_test_context(&test_context);
21828 static void test_buffer_srv(void)
21830 struct shader
21832 const DWORD *code;
21833 size_t size;
21834 BOOL requires_raw_and_structured_buffers;
21836 struct buffer
21838 unsigned int byte_count;
21839 unsigned int data_offset;
21840 const void *data;
21841 unsigned int structure_byte_stride;
21844 BOOL raw_and_structured_buffers_supported;
21845 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
21846 struct d3d11_test_context test_context;
21847 D3D11_SUBRESOURCE_DATA resource_data;
21848 const struct buffer *current_buffer;
21849 const struct shader *current_shader;
21850 ID3D11ShaderResourceView *srv;
21851 D3D11_BUFFER_DESC buffer_desc;
21852 ID3D11DeviceContext *context;
21853 DWORD color, expected_color;
21854 struct resource_readback rb;
21855 ID3D11Buffer *cb, *buffer;
21856 ID3D11PixelShader *ps;
21857 ID3D11Device *device;
21858 unsigned int i, x, y;
21859 struct vec4 cb_size;
21860 HRESULT hr;
21862 static const DWORD ps_float4_code[] =
21864 #if 0
21865 Buffer<float4> b;
21867 float2 size;
21869 float4 main(float4 position : SV_POSITION) : SV_Target
21871 float2 p;
21872 int2 coords;
21873 p.x = position.x / 640.0f;
21874 p.y = position.y / 480.0f;
21875 coords = int2(p.x * size.x, p.y * size.y);
21876 return b.Load(coords.y * size.x + coords.x);
21878 #endif
21879 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
21880 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21881 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
21882 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21883 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
21884 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
21885 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
21886 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
21887 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
21888 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
21889 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
21890 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
21891 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
21893 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
21894 static const DWORD ps_structured_code[] =
21896 #if 0
21897 StructuredBuffer<float4> b;
21899 float2 size;
21901 float4 main(float4 position : SV_POSITION) : SV_Target
21903 float2 p;
21904 int2 coords;
21905 p.x = position.x / 640.0f;
21906 p.y = position.y / 480.0f;
21907 coords = int2(p.x * size.x, p.y * size.y);
21908 return b[coords.y * size.x + coords.x];
21910 #endif
21911 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
21912 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
21913 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
21914 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
21915 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
21916 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
21917 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
21918 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
21919 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
21920 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
21921 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
21922 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
21923 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
21924 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
21926 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
21927 static const DWORD rgba16[] =
21929 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
21930 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
21931 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
21932 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
21934 static const DWORD rgba4[] =
21936 0xffffffff, 0xff0000ff,
21937 0xff000000, 0xff00ff00,
21939 static const BYTE r4[] =
21941 0xde, 0xad,
21942 0xba, 0xbe,
21944 static const struct vec4 rgba_float[] =
21946 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
21947 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
21949 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
21950 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
21951 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
21952 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
21953 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
21954 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
21955 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
21956 &rgba_float, sizeof(*rgba_float)};
21957 static const DWORD rgba16_colors2x2[] =
21959 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
21960 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
21961 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
21962 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
21964 static const DWORD rgba16_colors1x1[] =
21966 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
21967 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
21968 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
21969 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
21971 static const DWORD rgba4_colors[] =
21973 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
21974 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
21975 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
21976 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
21978 static const DWORD r4_colors[] =
21980 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
21981 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
21982 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
21983 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
21985 static const DWORD zero_colors[16] = {0};
21986 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
21988 static const struct test
21990 const struct shader *shader;
21991 const struct buffer *buffer;
21992 DXGI_FORMAT srv_format;
21993 unsigned int srv_first_element;
21994 unsigned int srv_element_count;
21995 struct vec2 size;
21996 const DWORD *expected_colors;
21998 tests[] =
22000 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
22001 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
22002 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
22003 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
22004 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
22005 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
22006 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
22007 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
22008 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
22009 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
22010 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
22013 if (!init_test_context(&test_context, NULL))
22014 return;
22016 device = test_context.device;
22017 context = test_context.immediate_context;
22018 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
22019 || check_compute_shaders_via_sm4_support(device);
22021 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
22022 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22024 buffer_desc.ByteWidth = 256;
22025 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
22026 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
22027 buffer_desc.CPUAccessFlags = 0;
22028 buffer_desc.MiscFlags = 0;
22029 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
22030 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22031 srv_desc.Format = DXGI_FORMAT_R8_UNORM;
22032 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
22033 U(srv_desc).Buffer.FirstElement = 0;
22034 U(srv_desc).Buffer.NumElements = 0;
22035 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
22036 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
22037 ID3D11Buffer_Release(buffer);
22039 ps = NULL;
22040 srv = NULL;
22041 buffer = NULL;
22042 current_shader = NULL;
22043 current_buffer = NULL;
22044 for (i = 0; i < ARRAY_SIZE(tests); ++i)
22046 const struct test *test = &tests[i];
22048 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
22050 skip("Test %u: Raw and structured buffers are not supported.\n", i);
22051 continue;
22053 /* Structured buffer views with an offset don't seem to work on WARP. */
22054 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
22055 && is_warp_device(device))
22057 skip("Test %u: Broken WARP.\n", i);
22058 continue;
22061 if (current_shader != test->shader)
22063 if (ps)
22064 ID3D11PixelShader_Release(ps);
22066 current_shader = test->shader;
22068 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
22069 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
22070 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22073 if (current_buffer != test->buffer)
22075 if (buffer)
22076 ID3D11Buffer_Release(buffer);
22078 current_buffer = test->buffer;
22079 if (current_buffer)
22081 BYTE *data = NULL;
22083 buffer_desc.ByteWidth = current_buffer->byte_count;
22084 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
22085 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
22086 buffer_desc.CPUAccessFlags = 0;
22087 buffer_desc.MiscFlags = 0;
22088 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
22089 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
22090 resource_data.SysMemPitch = 0;
22091 resource_data.SysMemSlicePitch = 0;
22092 if (current_buffer->data_offset)
22094 data = heap_alloc_zero(current_buffer->byte_count);
22095 ok(!!data, "Failed to allocate memory.\n");
22096 memcpy(data + current_buffer->data_offset, current_buffer->data,
22097 current_buffer->byte_count - current_buffer->data_offset);
22098 resource_data.pSysMem = data;
22100 else
22102 resource_data.pSysMem = current_buffer->data;
22104 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
22105 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
22106 heap_free(data);
22108 else
22110 buffer = NULL;
22114 if (srv)
22115 ID3D11ShaderResourceView_Release(srv);
22116 if (current_buffer)
22118 srv_desc.Format = test->srv_format;
22119 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
22120 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
22121 U(srv_desc).Buffer.NumElements = test->srv_element_count;
22122 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
22123 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
22125 else
22127 srv = NULL;
22129 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
22131 cb_size.x = test->size.x;
22132 cb_size.y = test->size.y;
22133 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
22135 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
22136 draw_quad(&test_context);
22138 get_texture_readback(test_context.backbuffer, 0, &rb);
22139 for (y = 0; y < 4; ++y)
22141 for (x = 0; x < 4; ++x)
22143 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
22144 expected_color = test->expected_colors[y * 4 + x];
22145 ok(compare_color(color, expected_color, 1),
22146 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
22147 i, color, expected_color, x, y);
22150 release_resource_readback(&rb);
22152 if (srv)
22153 ID3D11ShaderResourceView_Release(srv);
22154 if (buffer)
22155 ID3D11Buffer_Release(buffer);
22157 ID3D11Buffer_Release(cb);
22158 ID3D11PixelShader_Release(ps);
22159 release_test_context(&test_context);
22162 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
22164 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22165 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
22166 struct d3d11_test_context test_context;
22167 D3D11_SUBRESOURCE_DATA resource_data;
22168 D3D11_TEXTURE2D_DESC texture_desc;
22169 ID3D11UnorderedAccessView *uav;
22170 ID3D11ShaderResourceView *srv;
22171 D3D11_BUFFER_DESC buffer_desc;
22172 ID3D11Buffer *cb, *raw_buffer;
22173 ID3D11DeviceContext *context;
22174 struct resource_readback rb;
22175 ID3D11RenderTargetView *rtv;
22176 ID3D11Texture2D *texture;
22177 ID3D11ComputeShader *cs;
22178 ID3D11PixelShader *ps;
22179 ID3D11Device *device;
22180 unsigned int i, data;
22181 struct uvec4 offset;
22182 HRESULT hr;
22184 static const unsigned int buffer_data[] =
22186 0xffffffff, 0x00000000,
22188 static const DWORD ps_code[] =
22190 #if 0
22191 ByteAddressBuffer buffer;
22193 uint offset;
22195 uint main() : SV_Target0
22197 return buffer.Load(offset);
22199 #endif
22200 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
22201 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
22202 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
22203 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
22204 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
22205 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
22206 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
22207 0x00000000,
22209 static const DWORD cs_code[] =
22211 #if 0
22212 RWByteAddressBuffer buffer;
22214 uint2 input;
22216 [numthreads(1, 1, 1)]
22217 void main()
22219 buffer.Store(input.x, input.y);
22221 #endif
22222 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
22223 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22224 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
22225 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
22226 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
22227 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
22229 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
22231 if (!init_test_context(&test_context, &feature_level))
22232 return;
22234 device = test_context.device;
22235 context = test_context.immediate_context;
22237 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
22239 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22240 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
22241 if (SUCCEEDED(hr))
22242 ID3D11PixelShader_Release(ps);
22243 skip("Raw buffers are not supported.\n");
22244 release_test_context(&test_context);
22245 return;
22248 if (is_intel_device(device))
22250 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
22251 * This test checks what happens when offsets are not properly aligned.
22252 * The behavior seems to be undefined on Intel hardware. */
22253 win_skip("Skipping the test on Intel hardware.\n");
22254 release_test_context(&test_context);
22255 return;
22258 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22259 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22261 memset(&offset, 0, sizeof(offset));
22262 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
22264 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
22265 texture_desc.Format = DXGI_FORMAT_R32_UINT;
22266 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22267 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22268 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
22269 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
22271 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
22273 buffer_desc.ByteWidth = sizeof(buffer_data);
22274 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
22275 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
22276 buffer_desc.CPUAccessFlags = 0;
22277 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
22278 resource_data.pSysMem = buffer_data;
22279 resource_data.SysMemPitch = 0;
22280 resource_data.SysMemSlicePitch = 0;
22281 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
22282 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22284 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
22285 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
22286 U(srv_desc).BufferEx.FirstElement = 0;
22287 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
22288 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
22289 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
22290 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
22292 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22293 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22294 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
22296 offset.x = 0;
22297 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22298 NULL, &offset, 0, 0);
22299 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
22300 draw_quad(&test_context);
22301 check_texture_color(texture, buffer_data[0], 0);
22302 offset.x = 1;
22303 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22304 NULL, &offset, 0, 0);
22305 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
22306 draw_quad(&test_context);
22307 check_texture_color(texture, buffer_data[0], 0);
22308 offset.x = 2;
22309 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22310 NULL, &offset, 0, 0);
22311 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
22312 draw_quad(&test_context);
22313 check_texture_color(texture, buffer_data[0], 0);
22314 offset.x = 3;
22315 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22316 NULL, &offset, 0, 0);
22317 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
22318 draw_quad(&test_context);
22319 check_texture_color(texture, buffer_data[0], 0);
22321 offset.x = 4;
22322 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22323 NULL, &offset, 0, 0);
22324 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
22325 draw_quad(&test_context);
22326 check_texture_color(texture, buffer_data[1], 0);
22327 offset.x = 7;
22328 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22329 NULL, &offset, 0, 0);
22330 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
22331 draw_quad(&test_context);
22332 check_texture_color(texture, buffer_data[1], 0);
22334 if (feature_level < D3D_FEATURE_LEVEL_11_0)
22336 skip("Feature level 11_0 required for unaligned UAV test.\n");
22337 goto done;
22340 ID3D11Buffer_Release(raw_buffer);
22341 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22342 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
22343 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22345 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
22346 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
22347 U(uav_desc).Buffer.FirstElement = 0;
22348 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
22349 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
22350 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
22351 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22353 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
22354 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22356 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22357 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
22358 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22360 offset.x = 0;
22361 offset.y = 0xffffffff;
22362 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22363 NULL, &offset, 0, 0);
22364 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
22365 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22366 get_buffer_readback(raw_buffer, &rb);
22367 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
22369 data = get_readback_color(&rb, i, 0, 0);
22370 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
22372 release_resource_readback(&rb);
22374 offset.x = 1;
22375 offset.y = 0xffffffff;
22376 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22377 NULL, &offset, 0, 0);
22378 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
22379 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22380 get_buffer_readback(raw_buffer, &rb);
22381 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
22383 data = get_readback_color(&rb, i, 0, 0);
22384 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
22386 release_resource_readback(&rb);
22388 offset.x = 2;
22389 offset.y = 0xffffffff;
22390 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22391 NULL, &offset, 0, 0);
22392 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
22393 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22394 get_buffer_readback(raw_buffer, &rb);
22395 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
22397 data = get_readback_color(&rb, i, 0, 0);
22398 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
22400 release_resource_readback(&rb);
22402 offset.x = 3;
22403 offset.y = 0xffffffff;
22404 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22405 NULL, &offset, 0, 0);
22406 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
22407 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22408 get_buffer_readback(raw_buffer, &rb);
22409 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
22411 data = get_readback_color(&rb, i, 0, 0);
22412 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
22414 release_resource_readback(&rb);
22416 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
22417 offset.x = 3;
22418 offset.y = 0xffff;
22419 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22420 NULL, &offset, 0, 0);
22421 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22422 offset.x = 4;
22423 offset.y = 0xa;
22424 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22425 NULL, &offset, 0, 0);
22426 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22427 get_buffer_readback(raw_buffer, &rb);
22428 data = get_readback_color(&rb, 0, 0, 0);
22429 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
22430 data = get_readback_color(&rb, 1, 0, 0);
22431 ok(data == 0xa, "Got unexpected result %#x.\n", data);
22432 release_resource_readback(&rb);
22434 ID3D11ComputeShader_Release(cs);
22435 ID3D11UnorderedAccessView_Release(uav);
22437 done:
22438 ID3D11Buffer_Release(cb);
22439 ID3D11Buffer_Release(raw_buffer);
22440 ID3D11PixelShader_Release(ps);
22441 ID3D11RenderTargetView_Release(rtv);
22442 ID3D11ShaderResourceView_Release(srv);
22443 ID3D11Texture2D_Release(texture);
22444 release_test_context(&test_context);
22447 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
22448 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
22450 D3D11_MAPPED_SUBRESOURCE map_desc;
22451 unsigned int counter;
22453 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
22455 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
22456 D3D11_MAP_READ, 0, &map_desc)))
22457 return 0xdeadbeef;
22458 counter = *(unsigned int *)map_desc.pData;
22459 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
22460 return counter;
22463 static int compare_id(const void *a, const void *b)
22465 return *(int *)a - *(int *)b;
22468 static void test_uav_counters(void)
22470 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
22471 ID3D11ComputeShader *cs_producer, *cs_consumer;
22472 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22473 struct d3d11_test_context test_context;
22474 ID3D11UnorderedAccessView *uav, *uav2;
22475 unsigned int data, id[128], i;
22476 D3D11_BUFFER_DESC buffer_desc;
22477 ID3D11DeviceContext *context;
22478 struct resource_readback rb;
22479 ID3D11Device *device;
22480 D3D11_BOX box;
22481 HRESULT hr;
22483 static const DWORD cs_producer_code[] =
22485 #if 0
22486 RWStructuredBuffer<uint> u;
22488 [numthreads(4, 1, 1)]
22489 void main(uint3 dispatch_id : SV_DispatchThreadID)
22491 uint counter = u.IncrementCounter();
22492 u[counter] = dispatch_id.x;
22494 #endif
22495 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
22496 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22497 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
22498 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
22499 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
22500 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
22501 0x0002000a, 0x0100003e,
22503 static const DWORD cs_consumer_code[] =
22505 #if 0
22506 RWStructuredBuffer<uint> u;
22507 RWStructuredBuffer<uint> u2;
22509 [numthreads(4, 1, 1)]
22510 void main()
22512 uint counter = u.DecrementCounter();
22513 u2[counter] = u[counter];
22515 #endif
22516 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
22517 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22518 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
22519 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
22520 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
22521 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
22522 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
22523 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
22525 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22527 if (!init_test_context(&test_context, &feature_level))
22528 return;
22530 device = test_context.device;
22531 context = test_context.immediate_context;
22533 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
22534 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22535 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
22536 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22538 memset(&buffer_desc, 0, sizeof(buffer_desc));
22539 buffer_desc.ByteWidth = sizeof(unsigned int);
22540 buffer_desc.Usage = D3D11_USAGE_STAGING;
22541 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
22542 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
22543 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
22545 buffer_desc.ByteWidth = 1024;
22546 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
22547 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22548 buffer_desc.CPUAccessFlags = 0;
22549 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
22550 buffer_desc.StructureByteStride = sizeof(unsigned int);
22551 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
22552 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
22553 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
22554 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
22555 U(uav_desc).Buffer.FirstElement = 0;
22556 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
22557 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
22558 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
22559 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22560 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
22561 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
22562 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
22563 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22565 data = read_uav_counter(context, staging_buffer, uav);
22566 ok(!data, "Got unexpected initial value %u.\n", data);
22567 data = 8;
22568 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
22569 data = read_uav_counter(context, staging_buffer, uav);
22570 ok(data == 8, "Got unexpected value %u.\n", data);
22571 data = ~0u;
22572 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
22573 data = read_uav_counter(context, staging_buffer, uav);
22574 ok(data == 8, "Got unexpected value %u.\n", data);
22575 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22576 data = read_uav_counter(context, staging_buffer, uav);
22577 ok(data == 8, "Got unexpected value %u.\n", data);
22579 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
22580 data = 0;
22581 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
22582 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
22583 data = read_uav_counter(context, staging_buffer, uav);
22584 ok(!data, "Got unexpected value %u.\n", data);
22586 /* produce */
22587 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
22588 data = read_uav_counter(context, staging_buffer, uav);
22589 ok(data == 64, "Got unexpected value %u.\n", data);
22590 get_buffer_readback(buffer, &rb);
22591 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
22592 release_resource_readback(&rb);
22593 qsort(id, 64, sizeof(*id), compare_id);
22594 for (i = 0; i < 64; ++i)
22596 if (id[i] != i)
22597 break;
22599 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
22601 /* consume */
22602 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
22603 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
22604 data = read_uav_counter(context, staging_buffer, uav);
22605 ok(!data, "Got unexpected value %u.\n", data);
22606 get_buffer_readback(buffer2, &rb);
22607 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
22608 release_resource_readback(&rb);
22609 qsort(id, 64, sizeof(*id), compare_id);
22610 for (i = 0; i < 64; ++i)
22612 if (id[i] != i)
22613 break;
22615 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
22617 /* produce on CPU */
22618 for (i = 0; i < 8; ++i)
22619 id[i] = 0xdeadbeef;
22620 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
22621 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
22622 data = 8;
22623 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
22624 data = read_uav_counter(context, staging_buffer, uav);
22625 ok(data == 8, "Got unexpected value %u.\n", data);
22627 /* consume */
22628 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22629 data = read_uav_counter(context, staging_buffer, uav);
22630 ok(data == 4, "Got unexpected value %u.\n", data);
22631 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22632 data = read_uav_counter(context, staging_buffer, uav);
22633 ok(!data, "Got unexpected value %u.\n", data);
22634 get_buffer_readback(buffer2, &rb);
22635 for (i = 0; i < 8; ++i)
22637 data = get_readback_color(&rb, i, 0, 0);
22638 ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
22640 release_resource_readback(&rb);
22642 ID3D11Buffer_Release(buffer);
22643 ID3D11Buffer_Release(buffer2);
22644 ID3D11Buffer_Release(staging_buffer);
22645 ID3D11ComputeShader_Release(cs_producer);
22646 ID3D11ComputeShader_Release(cs_consumer);
22647 ID3D11UnorderedAccessView_Release(uav);
22648 ID3D11UnorderedAccessView_Release(uav2);
22649 release_test_context(&test_context);
22652 static void test_dispatch_indirect(void)
22654 struct stats
22656 unsigned int dispatch_count;
22657 unsigned int thread_count;
22658 unsigned int max_x;
22659 unsigned int max_y;
22660 unsigned int max_z;
22663 ID3D11Buffer *append_buffer, *stats_buffer, *args_buffer, *staging_buffer;
22664 ID3D11UnorderedAccessView *uav, *stats_uav;
22665 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22666 ID3D11ComputeShader *cs_append, *cs_stats;
22667 struct d3d11_test_context test_context;
22668 D3D11_BUFFER_DESC buffer_desc;
22669 ID3D11DeviceContext *context;
22670 struct resource_readback rb;
22671 ID3D11Device *device;
22672 unsigned int data, i;
22673 struct stats *stats;
22674 HRESULT hr;
22676 static const DWORD cs_append_code[] =
22678 #if 0
22679 struct dispatch_args
22681 uint x, y, z;
22684 AppendStructuredBuffer<dispatch_args> u;
22686 [numthreads(1, 1, 1)]
22687 void main()
22689 dispatch_args args = {4, 2, 1};
22690 u.Append(args);
22691 args.y = 1;
22692 u.Append(args);
22693 args.x = 3;
22694 u.Append(args);
22696 #endif
22697 0x43425844, 0x954de75a, 0x8bb1b78b, 0x84ded464, 0x9d9532b7, 0x00000001, 0x00000158, 0x00000003,
22698 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22699 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000104, 0x00050050, 0x00000041, 0x0100086a,
22700 0x0400009e, 0x0011e000, 0x00000000, 0x0000000c, 0x02000068, 0x00000001, 0x0400009b, 0x00000001,
22701 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x0c0000a8,
22702 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002, 0x00000004,
22703 0x00000002, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000,
22704 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002,
22705 0x00000004, 0x00000001, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
22706 0x00000000, 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
22707 0x00004002, 0x00000003, 0x00000001, 0x00000001, 0x00000000, 0x0100003e,
22709 static const DWORD cs_stats_code[] =
22711 #if 0
22712 struct stats
22714 uint dispatch_count;
22715 uint thread_count;
22716 uint max_x;
22717 uint max_y;
22718 uint max_z;
22721 RWStructuredBuffer<stats> u;
22723 [numthreads(1, 1, 1)]
22724 void main(uint3 id : SV_DispatchThreadID)
22726 if (all(!id))
22727 InterlockedAdd(u[0].dispatch_count, 1);
22728 InterlockedAdd(u[0].thread_count, 1);
22729 InterlockedMax(u[0].max_x, id.x);
22730 InterlockedMax(u[0].max_y, id.y);
22731 InterlockedMax(u[0].max_z, id.z);
22733 #endif
22734 0x43425844, 0xbd3f2e4e, 0xb0f61ff7, 0xa8e10584, 0x2f61aec9, 0x00000001, 0x000001bc, 0x00000003,
22735 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22736 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000168, 0x00050050, 0x0000005a, 0x0100086a,
22737 0x0400009e, 0x0011e000, 0x00000000, 0x00000014, 0x0200005f, 0x00020072, 0x02000068, 0x00000001,
22738 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x09000020, 0x00100072, 0x00000000, 0x00020246,
22739 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000001, 0x00100012, 0x00000000,
22740 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00100012, 0x00000000, 0x0010002a,
22741 0x00000000, 0x0010000a, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x0a0000ad, 0x0011e000,
22742 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001,
22743 0x01000015, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000,
22744 0x00000000, 0x00004001, 0x00000001, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002, 0x00000000,
22745 0x00000008, 0x00000000, 0x00000000, 0x0002000a, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002,
22746 0x00000000, 0x0000000c, 0x00000000, 0x00000000, 0x0002001a, 0x090000b0, 0x0011e000, 0x00000000,
22747 0x00004002, 0x00000000, 0x00000010, 0x00000000, 0x00000000, 0x0002002a, 0x0100003e,
22749 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22750 static const unsigned int zero[4] = {0, 0, 0, 0};
22752 if (!init_test_context(&test_context, &feature_level))
22753 return;
22755 device = test_context.device;
22756 context = test_context.immediate_context;
22758 hr = ID3D11Device_CreateComputeShader(device, cs_append_code, sizeof(cs_append_code), NULL, &cs_append);
22759 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22760 hr = ID3D11Device_CreateComputeShader(device, cs_stats_code, sizeof(cs_stats_code), NULL, &cs_stats);
22761 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22763 memset(&buffer_desc, 0, sizeof(buffer_desc));
22764 buffer_desc.ByteWidth = sizeof(unsigned int);
22765 buffer_desc.Usage = D3D11_USAGE_STAGING;
22766 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
22767 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
22768 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
22770 buffer_desc.ByteWidth = 60;
22771 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
22772 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22773 buffer_desc.CPUAccessFlags = 0;
22774 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
22775 buffer_desc.StructureByteStride = 3 * sizeof(unsigned int);
22776 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &append_buffer);
22777 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
22778 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
22779 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
22780 U(uav_desc).Buffer.FirstElement = 0;
22781 U(uav_desc).Buffer.NumElements = 5;
22782 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
22783 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)append_buffer, &uav_desc, &uav);
22784 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22786 /* We use a separate buffer because D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
22787 * and D3D11_RESOURCE_MISC_BUFFER_STRUCTURED are mutually exclusive flags.
22789 buffer_desc.BindFlags = 0;
22790 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
22791 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &args_buffer);
22792 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
22794 buffer_desc.ByteWidth = sizeof(*stats);
22795 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22796 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
22797 buffer_desc.StructureByteStride = sizeof(*stats);
22798 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &stats_buffer);
22799 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
22800 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)stats_buffer, NULL, &stats_uav);
22801 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22803 data = read_uav_counter(context, staging_buffer, uav);
22804 ok(!data, "Got unexpected initial value %u.\n", data);
22805 data = 8;
22806 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
22807 data = read_uav_counter(context, staging_buffer, uav);
22808 ok(data == 8, "Got unexpected value %u.\n", data);
22810 ID3D11DeviceContext_CSSetShader(context, cs_append, NULL, 0);
22811 data = 0;
22812 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
22813 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22814 data = read_uav_counter(context, staging_buffer, uav);
22815 ok(data == 3, "Got unexpected value %u.\n", data);
22816 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)args_buffer, (ID3D11Resource *)append_buffer);
22818 ID3D11DeviceContext_CSSetShader(context, cs_stats, NULL, 0);
22819 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, stats_uav, zero);
22820 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &stats_uav, NULL);
22821 data = read_uav_counter(context, staging_buffer, uav);
22822 for (i = 0; i < data; ++i)
22823 ID3D11DeviceContext_DispatchIndirect(context, args_buffer, i * 3 * sizeof(unsigned int));
22824 get_buffer_readback(stats_buffer, &rb);
22825 stats = rb.map_desc.pData;
22826 ok(stats->dispatch_count == 3, "Got unexpected dispatch count %u.\n", stats->dispatch_count);
22827 ok(stats->thread_count == 15, "Got unexpected thread count %u.\n", stats->thread_count);
22828 ok(stats->max_x == 3, "Got unexpected max x %u.\n", stats->max_x);
22829 ok(stats->max_y == 1, "Got unexpected max y %u.\n", stats->max_y);
22830 ok(stats->max_z == 0, "Got unexpected max z %u.\n", stats->max_z);
22831 release_resource_readback(&rb);
22833 ID3D11Buffer_Release(append_buffer);
22834 ID3D11Buffer_Release(args_buffer);
22835 ID3D11Buffer_Release(staging_buffer);
22836 ID3D11Buffer_Release(stats_buffer);
22837 ID3D11ComputeShader_Release(cs_append);
22838 ID3D11ComputeShader_Release(cs_stats);
22839 ID3D11UnorderedAccessView_Release(uav);
22840 ID3D11UnorderedAccessView_Release(stats_uav);
22841 release_test_context(&test_context);
22844 static void test_compute_shader_registers(void)
22846 struct data
22848 unsigned int group_id[3];
22849 unsigned int group_index;
22850 unsigned int dispatch_id[3];
22851 unsigned int thread_id[3];
22854 struct d3d11_test_context test_context;
22855 unsigned int i, x, y, group_x, group_y;
22856 ID3D11UnorderedAccessView *uav;
22857 D3D11_BUFFER_DESC buffer_desc;
22858 ID3D11DeviceContext *context;
22859 struct resource_readback rb;
22860 ID3D11Buffer *cb, *buffer;
22861 struct uvec4 dimensions;
22862 ID3D11ComputeShader *cs;
22863 const struct data *data;
22864 ID3D11Device *device;
22865 HRESULT hr;
22867 static const DWORD cs_code[] =
22869 #if 0
22870 struct data
22872 uint3 group_id;
22873 uint group_index;
22874 uint3 dispatch_id;
22875 uint3 group_thread_id;
22878 RWStructuredBuffer<data> u;
22880 uint2 dim;
22882 [numthreads(3, 2, 1)]
22883 void main(uint3 group_id : SV_GroupID,
22884 uint group_index : SV_GroupIndex,
22885 uint3 dispatch_id : SV_DispatchThreadID,
22886 uint3 group_thread_id : SV_GroupThreadID)
22888 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
22889 u[i].group_id = group_id;
22890 u[i].group_index = group_index;
22891 u[i].dispatch_id = dispatch_id;
22892 u[i].group_thread_id = group_thread_id;
22894 #endif
22895 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
22896 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22897 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
22898 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
22899 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
22900 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
22901 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
22902 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
22903 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
22904 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
22905 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
22906 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
22907 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
22908 0x0100003e,
22910 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22912 if (!init_test_context(&test_context, &feature_level))
22913 return;
22915 device = test_context.device;
22916 context = test_context.immediate_context;
22918 buffer_desc.ByteWidth = 10240;
22919 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
22920 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22921 buffer_desc.CPUAccessFlags = 0;
22922 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
22923 buffer_desc.StructureByteStride = 40;
22924 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
22925 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
22926 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
22927 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
22928 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22930 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
22932 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
22933 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22935 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22936 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
22937 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22939 dimensions.x = 2;
22940 dimensions.y = 3;
22941 dimensions.z = 1;
22942 dimensions.w = 0;
22943 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22944 NULL, &dimensions, 0, 0);
22945 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
22947 get_buffer_readback(buffer, &rb);
22948 i = 0;
22949 data = rb.map_desc.pData;
22950 for (y = 0; y < dimensions.y; ++y)
22952 for (group_y = 0; group_y < 2; ++group_y)
22954 for (x = 0; x < dimensions.x; ++x)
22956 for (group_x = 0; group_x < 3; ++group_x)
22958 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
22959 const unsigned int group_index = group_y * 3 + group_x;
22960 const struct data *d = &data[i];
22962 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
22963 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
22964 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
22965 i, x, y, group_x, group_y);
22966 ok(d->group_index == group_index,
22967 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
22968 d->group_index, group_index, i, x, y, group_x, group_y);
22969 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
22970 && !d->dispatch_id[2],
22971 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
22972 "at %u (%u, %u, %u, %u).\n",
22973 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
22974 dispatch_id[0], dispatch_id[1], 0,
22975 i, x, y, group_x, group_y);
22976 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
22977 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
22978 "at %u (%u, %u, %u, %u).\n",
22979 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
22980 i, x, y, group_x, group_y);
22981 ++i;
22986 release_resource_readback(&rb);
22988 ID3D11Buffer_Release(cb);
22989 ID3D11Buffer_Release(buffer);
22990 ID3D11ComputeShader_Release(cs);
22991 ID3D11UnorderedAccessView_Release(uav);
22992 release_test_context(&test_context);
22995 static void test_tgsm(void)
22997 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22998 struct d3d11_test_context test_context;
22999 ID3D11UnorderedAccessView *uav, *uav2;
23000 struct resource_readback rb, rb2;
23001 unsigned int i, data, expected;
23002 ID3D11Buffer *buffer, *buffer2;
23003 D3D11_BUFFER_DESC buffer_desc;
23004 ID3D11DeviceContext *context;
23005 ID3D11ComputeShader *cs;
23006 ID3D11Device *device;
23007 float float_data;
23008 HRESULT hr;
23010 static const DWORD raw_tgsm_code[] =
23012 #if 0
23013 RWByteAddressBuffer u;
23014 groupshared uint m;
23016 [numthreads(32, 1, 1)]
23017 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
23019 if (!local_idx)
23020 m = group_id.x;
23021 GroupMemoryBarrierWithGroupSync();
23022 InterlockedAdd(m, group_id.x);
23023 GroupMemoryBarrierWithGroupSync();
23024 if (!local_idx)
23025 u.Store(4 * group_id.x, m);
23027 #endif
23028 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
23029 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23030 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
23031 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
23032 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
23033 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
23034 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
23035 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
23036 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
23037 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
23038 0x01000015, 0x0100003e,
23040 static const DWORD structured_tgsm_code[] =
23042 #if 0
23043 #define GROUP_SIZE 32
23045 RWByteAddressBuffer u;
23046 RWByteAddressBuffer u2;
23047 groupshared uint m[GROUP_SIZE];
23049 [numthreads(GROUP_SIZE, 1, 1)]
23050 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
23052 uint sum, original, i;
23054 if (!local_idx)
23056 for (i = 0; i < GROUP_SIZE; ++i)
23057 m[i] = 2 * group_id.x;
23059 GroupMemoryBarrierWithGroupSync();
23060 InterlockedAdd(m[local_idx], 1);
23061 GroupMemoryBarrierWithGroupSync();
23062 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
23063 u.InterlockedExchange(4 * group_id.x, sum, original);
23064 u2.Store(4 * group_id.x, original);
23066 #endif
23067 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
23068 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23069 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
23070 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
23071 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
23072 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
23073 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
23074 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
23075 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
23076 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
23077 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
23078 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
23079 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
23080 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
23081 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
23082 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
23083 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
23084 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
23085 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
23086 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
23087 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
23088 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
23090 static const DWORD structured_tgsm_float_code[] =
23092 #if 0
23093 #define GROUP_SIZE 32
23095 struct data
23097 float f;
23098 uint u;
23101 RWBuffer<float> u;
23102 RWBuffer<uint> u2;
23103 groupshared data m[GROUP_SIZE];
23105 [numthreads(GROUP_SIZE, 1, 1)]
23106 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
23107 uint thread_id : SV_DispatchThreadID)
23109 uint i;
23110 if (!local_idx)
23112 for (i = 0; i < GROUP_SIZE; ++i)
23114 m[i].f = group_id.x;
23115 m[i].u = group_id.x;
23118 GroupMemoryBarrierWithGroupSync();
23119 for (i = 0; i < local_idx; ++i)
23121 m[local_idx].f += group_id.x;
23122 m[local_idx].u += group_id.x;
23124 u[thread_id.x] = m[local_idx].f;
23125 u2[thread_id.x] = m[local_idx].u;
23127 #endif
23128 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
23129 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23130 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
23131 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
23132 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
23133 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
23134 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
23135 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
23136 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
23137 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
23138 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
23139 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
23140 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
23141 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
23142 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
23143 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
23144 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
23145 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
23146 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
23147 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
23148 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
23149 0x00100556, 0x00000000, 0x0100003e,
23151 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
23152 static const unsigned int zero[4] = {0};
23154 if (!init_test_context(&test_context, &feature_level))
23155 return;
23157 device = test_context.device;
23158 context = test_context.immediate_context;
23160 buffer_desc.ByteWidth = 1024;
23161 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23162 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
23163 buffer_desc.CPUAccessFlags = 0;
23164 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
23165 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
23166 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23168 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
23169 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
23170 U(uav_desc).Buffer.FirstElement = 0;
23171 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
23172 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
23173 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
23174 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
23176 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
23177 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
23179 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
23180 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
23182 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
23183 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
23184 get_buffer_readback(buffer, &rb);
23185 for (i = 0; i < 64; ++i)
23187 data = get_readback_color(&rb, i, 0, 0);
23188 expected = 33 * i;
23189 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
23191 release_resource_readback(&rb);
23193 ID3D11Buffer_Release(buffer);
23194 ID3D11ComputeShader_Release(cs);
23195 ID3D11UnorderedAccessView_Release(uav);
23197 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
23198 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23199 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
23200 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
23201 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
23202 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23203 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
23204 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
23205 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
23206 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
23208 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
23209 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
23210 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
23212 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
23213 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
23214 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
23215 get_buffer_readback(buffer, &rb);
23216 get_buffer_readback(buffer2, &rb2);
23217 for (i = 0; i < 32; ++i)
23219 expected = 64 * i + 32;
23220 data = get_readback_color(&rb, i, 0, 0);
23221 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
23222 data = get_readback_color(&rb2, i, 0, 0);
23223 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
23225 release_resource_readback(&rb);
23226 release_resource_readback(&rb2);
23228 ID3D11Buffer_Release(buffer);
23229 ID3D11Buffer_Release(buffer2);
23230 ID3D11ComputeShader_Release(cs);
23231 ID3D11UnorderedAccessView_Release(uav);
23232 ID3D11UnorderedAccessView_Release(uav2);
23234 buffer_desc.MiscFlags = 0;
23235 U(uav_desc).Buffer.Flags = 0;
23236 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
23237 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23238 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
23239 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
23240 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
23241 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
23242 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23243 uav_desc.Format = DXGI_FORMAT_R32_UINT;
23244 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
23245 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
23246 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
23247 sizeof(structured_tgsm_float_code), NULL, &cs);
23248 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
23250 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
23251 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
23252 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
23254 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
23255 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
23256 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
23257 get_buffer_readback(buffer, &rb);
23258 get_buffer_readback(buffer2, &rb2);
23259 for (i = 0; i < 96; ++i)
23261 expected = (i % 32 + 1) * (i / 32);
23262 float_data = get_readback_float(&rb, i, 0);
23263 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
23264 data = get_readback_color(&rb2, i, 0, 0);
23265 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
23267 release_resource_readback(&rb);
23268 release_resource_readback(&rb2);
23270 ID3D11Buffer_Release(buffer);
23271 ID3D11Buffer_Release(buffer2);
23272 ID3D11ComputeShader_Release(cs);
23273 ID3D11UnorderedAccessView_Release(uav);
23274 ID3D11UnorderedAccessView_Release(uav2);
23275 release_test_context(&test_context);
23278 static void test_geometry_shader(void)
23280 static const struct
23282 struct vec4 position;
23283 unsigned int color;
23285 vertex[] =
23287 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
23289 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
23291 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
23292 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
23294 #if 0
23295 struct vs_data
23297 float4 pos : SV_POSITION;
23298 float4 color : COLOR;
23301 void main(in struct vs_data vs_input, out struct vs_data vs_output)
23303 vs_output.pos = vs_input.pos;
23304 vs_output.color = vs_input.color;
23306 #endif
23307 static const DWORD vs_code[] =
23309 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
23310 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
23311 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
23312 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
23313 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
23314 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
23315 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
23316 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
23317 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
23318 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
23319 0x0100003e,
23321 #if 0
23322 struct gs_data
23324 float4 pos : SV_POSITION;
23325 float4 color : COLOR;
23328 [maxvertexcount(4)]
23329 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
23331 float offset = 0.2 * vin[0].pos.w;
23332 gs_data v;
23334 v.color = vin[0].color;
23336 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
23337 vout.Append(v);
23338 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
23339 vout.Append(v);
23340 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
23341 vout.Append(v);
23342 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
23343 vout.Append(v);
23345 #endif
23346 static const DWORD gs_code[] =
23348 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
23349 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
23350 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
23351 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
23352 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
23353 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
23354 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
23355 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
23356 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
23357 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
23358 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
23359 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
23360 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
23361 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
23362 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
23363 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
23364 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
23365 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
23366 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
23367 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
23368 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
23369 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
23370 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
23371 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
23372 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
23373 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
23374 0x00000001, 0x01000013, 0x0100003e,
23376 static const DWORD gs_5_0_code[] =
23378 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
23379 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
23380 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
23381 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
23382 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
23383 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
23384 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
23385 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
23386 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
23387 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
23388 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
23389 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
23390 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
23391 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
23392 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
23393 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
23394 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
23395 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
23396 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
23397 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
23398 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
23399 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
23400 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
23401 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
23402 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
23403 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
23404 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
23405 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
23406 0x0100003e,
23408 #if 0
23409 struct ps_data
23411 float4 pos : SV_POSITION;
23412 float4 color : COLOR;
23415 float4 main(struct ps_data ps_input) : SV_Target
23417 return ps_input.color;
23419 #endif
23420 static const DWORD ps_code[] =
23422 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
23423 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
23424 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
23425 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
23426 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
23427 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
23428 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
23429 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
23431 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
23432 struct d3d11_test_context test_context;
23433 ID3D11InputLayout *input_layout;
23434 ID3D11DeviceContext *context;
23435 unsigned int stride, offset;
23436 struct resource_readback rb;
23437 ID3D11GeometryShader *gs;
23438 ID3D11VertexShader *vs;
23439 ID3D11PixelShader *ps;
23440 ID3D11Device *device;
23441 ID3D11Buffer *vb;
23442 DWORD color;
23443 HRESULT hr;
23445 if (!init_test_context(&test_context, NULL))
23446 return;
23448 device = test_context.device;
23449 context = test_context.immediate_context;
23451 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
23452 vs_code, sizeof(vs_code), &input_layout);
23453 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
23455 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
23457 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
23458 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
23459 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
23460 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
23461 else
23462 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
23463 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
23464 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
23465 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
23467 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
23468 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
23469 stride = sizeof(*vertex);
23470 offset = 0;
23471 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
23472 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
23473 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
23474 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23476 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
23477 ID3D11DeviceContext_Draw(context, 1, 0);
23479 get_texture_readback(test_context.backbuffer, 0, &rb);
23480 color = get_readback_color(&rb, 320, 190, 0);
23481 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
23482 color = get_readback_color(&rb, 255, 240, 0);
23483 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
23484 color = get_readback_color(&rb, 320, 240, 0);
23485 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
23486 color = get_readback_color(&rb, 385, 240, 0);
23487 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
23488 color = get_readback_color(&rb, 320, 290, 0);
23489 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
23490 release_resource_readback(&rb);
23492 ID3D11PixelShader_Release(ps);
23493 ID3D11GeometryShader_Release(gs);
23494 ID3D11VertexShader_Release(vs);
23495 ID3D11Buffer_Release(vb);
23496 ID3D11InputLayout_Release(input_layout);
23497 release_test_context(&test_context);
23500 struct triangle
23502 struct vec4 v[3];
23505 #define check_triangles(buffer, triangles, count) check_triangles_(__LINE__, buffer, triangles, count)
23506 static void check_triangles_(unsigned int line, ID3D11Buffer *buffer,
23507 const struct triangle *triangles, unsigned int triangle_count)
23509 const struct triangle *current, *expected;
23510 struct resource_readback rb;
23511 unsigned int i, j, offset;
23512 BOOL all_match = TRUE;
23514 get_buffer_readback(buffer, &rb);
23516 for (i = 0; i < triangle_count; ++i)
23518 current = get_readback_data(&rb, i, 0, 0, sizeof(*current));
23519 expected = &triangles[i];
23521 offset = ~0u;
23522 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
23524 if (compare_vec4(&current->v[0], &expected->v[j], 0))
23526 offset = j;
23527 break;
23531 if (offset == ~0u)
23533 all_match = FALSE;
23534 break;
23537 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
23539 if (!compare_vec4(&current->v[j], &expected->v[(j + offset) % 3], 0))
23541 all_match = FALSE;
23542 break;
23545 if (!all_match)
23546 break;
23549 ok_(__FILE__, line)(all_match, "Triangle %u vertices {%.8e, %.8e, %.8e, %.8e}, "
23550 "{%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e} "
23551 "do not match {%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e}, "
23552 "{%.8e, %.8e, %.8e, %.8e}.\n", i,
23553 current->v[0].x, current->v[0].y, current->v[0].z, current->v[0].w,
23554 current->v[1].x, current->v[1].y, current->v[1].z, current->v[1].w,
23555 current->v[2].x, current->v[2].y, current->v[2].z, current->v[2].w,
23556 expected->v[0].x, expected->v[0].y, expected->v[0].z, expected->v[0].w,
23557 expected->v[1].x, expected->v[1].y, expected->v[1].z, expected->v[1].w,
23558 expected->v[2].x, expected->v[2].y, expected->v[2].z, expected->v[2].w);
23560 release_resource_readback(&rb);
23563 static void test_quad_tessellation(void)
23565 #if 0
23566 struct point_data
23568 float4 position : SV_POSITION;
23571 struct patch_constant_data
23573 float edges[4] : SV_TessFactor;
23574 float inside[2] : SV_InsideTessFactor;
23577 float4 tess_factors;
23578 float2 inside_tess_factors;
23580 patch_constant_data patch_constant(InputPatch<point_data, 4> input)
23582 patch_constant_data output;
23584 output.edges[0] = tess_factors.x;
23585 output.edges[1] = tess_factors.y;
23586 output.edges[2] = tess_factors.z;
23587 output.edges[3] = tess_factors.w;
23588 output.inside[0] = inside_tess_factors.x;
23589 output.inside[1] = inside_tess_factors.y;
23591 return output;
23594 [domain("quad")]
23595 [outputcontrolpoints(4)]
23596 [outputtopology("triangle_ccw")]
23597 [partitioning("integer")]
23598 [patchconstantfunc("patch_constant")]
23599 point_data hs_main(InputPatch<point_data, 4> input,
23600 uint i : SV_OutputControlPointID)
23602 return input[i];
23605 [domain("quad")]
23606 point_data ds_main(patch_constant_data input,
23607 float2 tess_coord : SV_DomainLocation,
23608 const OutputPatch<point_data, 4> patch)
23610 point_data output;
23612 float4 a = lerp(patch[0].position, patch[1].position, tess_coord.x);
23613 float4 b = lerp(patch[2].position, patch[3].position, tess_coord.x);
23614 output.position = lerp(a, b, tess_coord.y);
23616 return output;
23618 #endif
23619 static const DWORD hs_quad_ccw_code[] =
23621 0x43425844, 0xdf8df700, 0x58b08fb1, 0xbd23d2c3, 0xcf884094, 0x00000001, 0x000002b8, 0x00000004,
23622 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
23623 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
23624 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
23625 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
23626 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
23627 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
23628 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
23629 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
23630 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
23631 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
23632 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
23633 0x01002097, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
23634 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
23635 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
23636 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
23637 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
23638 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
23639 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
23640 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
23641 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
23642 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
23644 static const DWORD ds_quad_code[] =
23646 0x43425844, 0xeb6b7631, 0x07f5469e, 0xed0cbf4a, 0x7158b3a6, 0x00000001, 0x00000284, 0x00000004,
23647 0x00000030, 0x00000064, 0x00000128, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
23648 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
23649 0x004e4f49, 0x47534350, 0x000000bc, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b,
23650 0x00000003, 0x00000000, 0x00000001, 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001,
23651 0x00000001, 0x00000098, 0x00000002, 0x0000000b, 0x00000003, 0x00000002, 0x00000001, 0x00000098,
23652 0x00000003, 0x0000000b, 0x00000003, 0x00000003, 0x00000001, 0x000000a6, 0x00000000, 0x0000000c,
23653 0x00000003, 0x00000004, 0x00000001, 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005,
23654 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365,
23655 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
23656 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853,
23657 0x00000120, 0x00040050, 0x00000048, 0x01002093, 0x01001895, 0x0100086a, 0x0200005f, 0x0001c032,
23658 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
23659 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, 0x80219e46, 0x00000041, 0x00000002,
23660 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, 0x001000f2, 0x00000000, 0x0001c006,
23661 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, 0x0a000000, 0x001000f2, 0x00000001,
23662 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, 0x00000001, 0x00000000, 0x09000032,
23663 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, 0x00219e46, 0x00000000, 0x00000000,
23664 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x80100e46, 0x00000041, 0x00000001,
23665 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
23666 0x0100003e,
23668 #if 0
23670 [outputtopology("triangle_cw")]
23672 #endif
23673 static const DWORD hs_quad_cw_code[] =
23675 0x43425844, 0x1ab30cc8, 0x94174771, 0x61f4cdd0, 0xa287f62c, 0x00000001, 0x000002b8, 0x00000004,
23676 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
23677 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
23678 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
23679 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
23680 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
23681 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
23682 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
23683 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
23684 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
23685 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
23686 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
23687 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
23688 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
23689 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
23690 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
23691 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
23692 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
23693 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
23694 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
23695 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
23696 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
23698 #if 0
23699 struct point_data
23701 float4 pos : SV_POSITION;
23704 [maxvertexcount(3)]
23705 void main(triangle point_data vin[3], inout TriangleStream<point_data> vout)
23707 for (uint i = 0; i < 3; ++i)
23708 vout.Append(vin[i]);
23710 #endif
23711 static const DWORD gs_code[] =
23713 0x43425844, 0x8e49d18d, 0x6d08d6e5, 0xb7015628, 0xf9351fdd, 0x00000001, 0x00000164, 0x00000003,
23714 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
23715 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
23716 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
23717 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000000c8, 0x00020040,
23718 0x00000032, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068, 0x00000001,
23719 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000003,
23720 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
23721 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010001a, 0x00000000,
23722 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x01000013,
23723 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016,
23724 0x0100003e,
23726 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
23728 {0, "SV_POSITION", 0, 0, 4, 0},
23730 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
23731 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
23732 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
23733 static const BYTE zero_data[1024];
23734 static const struct triangle expected_quad_ccw[] =
23736 {{{-1.0f, -1.0f, 0.0f, 1.0f},
23737 { 1.0f, -1.0f, 0.0f, 1.0f},
23738 {-1.0f, 1.0f, 0.0f, 1.0f}}},
23739 {{{-1.0f, 1.0f, 0.0f, 1.0f},
23740 { 1.0f, -1.0f, 0.0f, 1.0f},
23741 { 1.0f, 1.0f, 0.0f, 1.0f}}},
23742 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
23743 { 0.0f, 0.0f, 0.0f, 0.0f},
23744 { 0.0f, 0.0f, 0.0f, 0.0f}}},
23746 static const struct triangle expected_quad_cw[] =
23748 {{{-1.0f, -1.0f, 0.0f, 1.0f},
23749 {-1.0f, 1.0f, 0.0f, 1.0f},
23750 { 1.0f, -1.0f, 0.0f, 1.0f}}},
23751 {{{-1.0f, 1.0f, 0.0f, 1.0f},
23752 { 1.0f, 1.0f, 0.0f, 1.0f},
23753 { 1.0f, -1.0f, 0.0f, 1.0f}}},
23754 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
23755 { 0.0f, 0.0f, 0.0f, 0.0f},
23756 { 0.0f, 0.0f, 0.0f, 0.0f}}},
23758 struct
23760 float tess_factors[4];
23761 float inside_tess_factors[2];
23762 DWORD padding[2];
23763 } constant;
23765 D3D11_QUERY_DATA_SO_STATISTICS so_statistics;
23766 struct d3d11_test_context test_context;
23767 ID3D11DeviceContext *context;
23768 ID3D11Buffer *cb, *so_buffer;
23769 D3D11_QUERY_DESC query_desc;
23770 ID3D11Asynchronous *query;
23771 ID3D11GeometryShader *gs;
23772 ID3D11DomainShader *ds;
23773 const UINT offset = 0;
23774 ID3D11HullShader *hs;
23775 ID3D11Device *device;
23776 unsigned int i;
23777 HRESULT hr;
23779 if (!init_test_context(&test_context, &feature_level))
23780 return;
23782 device = test_context.device;
23783 context = test_context.immediate_context;
23785 draw_color_quad(&test_context, &white);
23786 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
23788 set_quad_color(&test_context, &green);
23789 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
23791 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
23792 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
23793 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0, NULL, &gs);
23794 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
23795 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
23797 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
23798 constant.tess_factors[i] = 1.0f;
23799 for (i = 0; i < ARRAY_SIZE(constant.inside_tess_factors); ++i)
23800 constant.inside_tess_factors[i] = 1.0f;
23801 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
23802 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb);
23803 hr = ID3D11Device_CreateHullShader(device, hs_quad_ccw_code, sizeof(hs_quad_ccw_code), NULL, &hs);
23804 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
23805 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
23806 hr = ID3D11Device_CreateDomainShader(device, ds_quad_code, sizeof(ds_quad_code), NULL, &ds);
23807 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
23808 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
23810 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
23811 ID3D11DeviceContext_Draw(context, 4, 0);
23812 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
23813 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
23814 check_triangles(so_buffer, expected_quad_ccw, ARRAY_SIZE(expected_quad_ccw));
23816 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
23818 ID3D11HullShader_Release(hs);
23819 hr = ID3D11Device_CreateHullShader(device, hs_quad_cw_code, sizeof(hs_quad_cw_code), NULL, &hs);
23820 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
23821 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
23823 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
23824 ID3D11DeviceContext_Draw(context, 4, 0);
23825 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
23826 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
23827 check_triangles(so_buffer, expected_quad_cw, ARRAY_SIZE(expected_quad_cw));
23829 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
23831 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
23832 query_desc.Query = D3D11_QUERY_SO_STATISTICS_STREAM0;
23833 query_desc.MiscFlags = 0;
23834 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
23835 ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
23836 ID3D11DeviceContext_Begin(context, query);
23838 set_quad_color(&test_context, &white);
23839 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
23840 constant.tess_factors[i] = 2.0f;
23841 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
23842 ID3D11DeviceContext_Draw(context, 4, 0);
23843 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
23845 set_quad_color(&test_context, &green);
23846 constant.tess_factors[0] = 0.0f; /* A patch is discarded. */
23847 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
23848 ID3D11DeviceContext_Draw(context, 4, 0);
23849 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
23851 ID3D11DeviceContext_End(context, query);
23852 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
23853 ok(so_statistics.NumPrimitivesWritten == 8, "Got unexpected primitives written %u.\n",
23854 (unsigned int)so_statistics.NumPrimitivesWritten);
23855 ok(so_statistics.PrimitivesStorageNeeded == 8, "Got unexpected primitives storage needed %u.\n",
23856 (unsigned int)so_statistics.PrimitivesStorageNeeded);
23857 ID3D11DeviceContext_Begin(context, query);
23859 constant.tess_factors[0] = 5.0f;
23860 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
23861 ID3D11DeviceContext_Draw(context, 4, 0);
23862 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
23864 ID3D11DeviceContext_End(context, query);
23865 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
23866 ok(so_statistics.NumPrimitivesWritten == 11, "Got unexpected primitives written %u.\n",
23867 (unsigned int)so_statistics.NumPrimitivesWritten);
23868 ok(so_statistics.PrimitivesStorageNeeded == 11, "Got unexpected primitives storage needed %u.\n",
23869 (unsigned int)so_statistics.PrimitivesStorageNeeded);
23870 ID3D11Asynchronous_Release(query);
23872 ID3D11Buffer_Release(so_buffer);
23873 ID3D11GeometryShader_Release(gs);
23874 ID3D11DomainShader_Release(ds);
23875 ID3D11HullShader_Release(hs);
23876 ID3D11Buffer_Release(cb);
23877 release_test_context(&test_context);
23880 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
23881 static void check_so_desc_(unsigned int line, ID3D11Device *device,
23882 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
23883 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
23884 unsigned int rasterizer_stream)
23886 ID3D11GeometryShader *gs;
23887 HRESULT hr;
23889 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
23890 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
23891 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
23892 if (SUCCEEDED(hr))
23893 ID3D11GeometryShader_Release(gs);
23896 #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)
23897 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
23898 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
23899 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
23900 unsigned int rasterizer_stream)
23902 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
23903 HRESULT hr;
23905 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
23906 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
23907 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
23908 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
23909 if (SUCCEEDED(hr))
23910 ID3D11GeometryShader_Release(gs);
23913 static void test_stream_output(void)
23915 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
23916 struct d3d11_test_context test_context;
23917 unsigned int i, count;
23918 ID3D11Device *device;
23920 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
23921 static const DWORD vs_code[] =
23923 #if 0
23924 struct data
23926 float4 position : SV_Position;
23927 float4 attrib1 : ATTRIB1;
23928 float3 attrib2 : attrib2;
23929 float2 attrib3 : ATTriB3;
23930 float attrib4 : ATTRIB4;
23933 void main(in data i, out data o)
23935 o = i;
23937 #endif
23938 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
23939 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
23940 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
23941 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
23942 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
23943 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
23944 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
23945 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
23946 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
23947 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
23948 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
23949 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
23950 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
23951 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
23952 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
23953 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
23954 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
23955 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
23956 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
23957 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
23959 static const DWORD gs_code[] =
23961 #if 0
23962 struct data
23964 float4 position : SV_Position;
23965 float4 attrib1 : ATTRIB1;
23966 float3 attrib2 : attrib2;
23967 float2 attrib3 : ATTriB3;
23968 float attrib4 : ATTRIB4;
23971 [maxvertexcount(1)]
23972 void main(point data i[1], inout PointStream<data> o)
23974 o.Append(i[0]);
23976 #endif
23977 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
23978 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
23979 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
23980 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
23981 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
23982 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
23983 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
23984 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
23985 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
23986 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
23987 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
23988 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
23989 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
23990 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
23991 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
23992 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
23993 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
23994 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
23995 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
23996 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
23997 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
23999 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
24001 {0, "SV_Position", 0, 0, 4, 0},
24003 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
24005 {0, "SV_Position", 0, 0, 4, 0},
24006 {0, NULL, 0, 0, 0, 0},
24008 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
24010 /* SemanticName and SemanticIndex */
24012 {0, "sv_position", 0, 0, 4, 0},
24013 {0, "attrib", 1, 0, 4, 0},
24016 {0, "sv_position", 0, 0, 4, 0},
24017 {0, "ATTRIB", 1, 0, 4, 0},
24019 /* Gaps */
24021 {0, "SV_POSITION", 0, 0, 4, 0},
24022 {0, NULL, 0, 0, 8, 0},
24023 {0, "ATTRIB", 1, 0, 4, 0},
24026 {0, "SV_POSITION", 0, 0, 4, 0},
24027 {0, NULL, 0, 0, 4, 0},
24028 {0, NULL, 0, 0, 4, 0},
24029 {0, "ATTRIB", 1, 0, 4, 0},
24031 /* ComponentCount */
24033 {0, "ATTRIB", 1, 0, 4, 0},
24036 {0, "ATTRIB", 2, 0, 3, 0},
24039 {0, "ATTRIB", 3, 0, 2, 0},
24042 {0, "ATTRIB", 4, 0, 1, 0},
24044 /* ComponentIndex */
24046 {0, "ATTRIB", 1, 1, 3, 0},
24049 {0, "ATTRIB", 1, 2, 2, 0},
24052 {0, "ATTRIB", 1, 3, 1, 0},
24055 {0, "ATTRIB", 3, 1, 1, 0},
24057 /* OutputSlot */
24059 {0, "attrib", 1, 0, 4, 0},
24062 {0, "attrib", 1, 0, 4, 1},
24065 {0, "attrib", 1, 0, 4, 2},
24068 {0, "attrib", 1, 0, 4, 3},
24071 {0, "attrib", 1, 0, 4, 0},
24072 {0, "attrib", 2, 0, 3, 1},
24073 {0, NULL, 0, 0, 1, 1},
24074 {0, "attrib", 3, 0, 2, 2},
24075 {0, NULL, 0, 0, 2, 2},
24076 {0, "attrib", 4, 0, 1, 3},
24077 {0, NULL, 0, 0, 7, 3},
24080 {0, "attrib", 1, 0, 4, 0},
24081 {0, "attrib", 2, 0, 3, 1},
24082 {0, NULL, 0, 0, 1, 1},
24083 {0, "attrib", 3, 0, 2, 2},
24084 {0, NULL, 0, 0, 1, 2},
24085 {0, NULL, 0, 0, 1, 2},
24086 {0, "attrib", 4, 0, 1, 3},
24087 {0, NULL, 0, 0, 3, 3},
24088 {0, NULL, 0, 0, 1, 3},
24089 {0, NULL, 0, 0, 1, 3},
24090 {0, NULL, 0, 0, 1, 3},
24091 {0, NULL, 0, 0, 1, 3},
24094 {0, "attrib", 1, 0, 4, 0},
24095 {0, "attrib", 2, 0, 3, 0},
24096 {0, "attrib", 3, 0, 2, 0},
24097 {0, NULL, 0, 0, 1, 0},
24098 {0, "attrib", 4, 0, 1, 0},
24101 {0, "attrib", 1, 0, 4, 0},
24102 {0, "attrib", 2, 0, 3, 0},
24103 {0, "attrib", 3, 0, 2, 3},
24104 {0, NULL, 0, 0, 1, 3},
24105 {0, "attrib", 4, 0, 1, 3},
24107 /* Multiple occurrences of the same output */
24109 {0, "ATTRIB", 1, 0, 2, 0},
24110 {0, "ATTRIB", 1, 2, 2, 1},
24113 {0, "ATTRIB", 1, 0, 1, 0},
24114 {0, "ATTRIB", 1, 1, 3, 0},
24117 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
24119 /* SemanticName and SemanticIndex */
24121 {0, "SV_Position", 0, 0, 4, 0},
24122 {0, "ATTRIB", 0, 0, 4, 0},
24125 {0, "sv_position", 0, 0, 4, 0},
24126 {0, "ATTRIB_", 1, 0, 4, 0},
24128 /* Gaps */
24130 {0, "SV_POSITION", 0, 0, 4, 0},
24131 {0, NULL, 0, 1, 8, 0},
24132 {0, "ATTRIB", 1, 0, 4, 0},
24135 {0, "SV_POSITION", 0, 0, 4, 0},
24136 {0, NULL, 1, 0, 8, 0},
24137 {0, "ATTRIB", 1, 0, 4, 0},
24139 /* Buffer stride */
24141 {0, "SV_POSITION", 0, 0, 4, 0},
24142 {0, NULL, 0, 0, 8, 0},
24143 {0, NULL, 0, 0, 8, 0},
24144 {0, "ATTRIB", 1, 0, 4, 0},
24146 /* ComponentCount */
24148 {0, "ATTRIB", 2, 0, 5, 0},
24151 {0, "ATTRIB", 2, 0, 4, 0},
24154 {0, "ATTRIB", 3, 0, 3, 0},
24157 {0, "ATTRIB", 4, 0, 2, 0},
24159 /* ComponentIndex */
24161 {0, "ATTRIB", 1, 1, 4, 0},
24164 {0, "ATTRIB", 1, 2, 3, 0},
24167 {0, "ATTRIB", 1, 3, 2, 0},
24170 {0, "ATTRIB", 1, 4, 0, 0},
24173 {0, "ATTRIB", 1, 4, 1, 0},
24176 {0, "ATTRIB", 3, 2, 1, 0},
24179 {0, "ATTRIB", 3, 2, 0, 0},
24181 /* OutputSlot */
24183 {0, "attrib", 1, 0, 4, 4},
24186 {0, "attrib", 1, 0, 4, 4},
24189 {0, "attrib", 1, 0, 4, 4},
24192 {0, "attrib", 1, 0, 4, 4},
24195 {0, "attrib", 1, 0, 4, 0},
24196 {0, "attrib", 2, 0, 3, 1},
24197 {0, NULL, 0, 0, 1, 1},
24198 {0, "attrib", 3, 0, 2, 2},
24199 {0, NULL, 0, 0, 2, 2},
24200 {0, "attrib", 4, 0, 1, 3},
24201 {0, NULL, 0, 0, 3, 4},
24204 {0, "attrib", 1, 0, 4, 0},
24205 {0, "attrib", 2, 0, 3, 0},
24206 {0, "attrib", 3, 0, 2, 0},
24207 {0, NULL, 0, 0, 1, 0},
24208 {0, "attrib", 4, 0, 1, 0},
24209 {0, NULL, 0, 0, 3, 3},
24210 {0, NULL, 0, 0, 1, 3},
24211 {0, NULL, 0, 0, 1, 3},
24212 {0, NULL, 0, 0, 1, 3},
24213 {0, NULL, 0, 0, 1, 3},
24216 {0, "attrib", 1, 0, 4, 0},
24217 {0, NULL, 0, 0, 3, 1},
24218 {0, NULL, 0, 0, 1, 1},
24219 {0, NULL, 0, 0, 1, 2},
24220 {0, "attrib", 2, 0, 3, 3},
24221 {0, NULL, 0, 0, 1, 3},
24224 {0, "attrib", 2, 0, 3, 3},
24225 {0, NULL, 0, 0, 3, 1},
24226 {0, NULL, 0, 0, 1, 3},
24227 {0, "attrib", 1, 0, 4, 0},
24228 {0, NULL, 0, 0, 1, 2},
24229 {0, NULL, 0, 0, 1, 1},
24231 /* Stream */
24233 {1, "attrib", 1, 0, 4, 0},
24236 {4, "attrib", 1, 0, 4, 0},
24238 /* Multiple occurrences of the same output */
24240 {0, "ATTRIB", 1, 0, 4, 0},
24241 {0, "ATTRIB", 1, 0, 4, 1},
24244 {0, "ATTRIB", 1, 0, 4, 0},
24245 {0, "ATTRIB", 1, 0, 3, 0},
24249 if (!init_test_context(&test_context, &feature_level))
24250 return;
24252 device = test_context.device;
24254 for (i = 0; i < ARRAY_SIZE(stride); ++i)
24255 stride[i] = 64;
24257 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
24258 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
24259 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
24260 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
24261 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
24262 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
24264 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
24265 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
24266 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
24267 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
24269 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
24270 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
24271 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
24272 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
24273 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
24275 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
24276 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
24277 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
24278 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
24280 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
24282 unsigned int max_output_slot = 0;
24283 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
24285 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
24286 max_output_slot = max(max_output_slot, e->OutputSlot);
24287 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
24288 break;
24291 /* Buffer strides are required for all buffers. */
24292 if (!max_output_slot)
24294 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
24295 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
24296 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
24297 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
24298 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
24299 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
24300 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
24301 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
24302 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
24303 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
24305 else
24307 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
24308 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
24309 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
24310 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
24314 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
24316 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
24318 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
24319 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
24320 break;
24323 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
24324 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
24325 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
24326 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
24327 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
24328 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
24329 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
24330 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
24333 /* Buffer strides */
24334 stride[1] = 63;
24335 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
24336 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
24337 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
24338 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
24339 stride[1] = 1;
24340 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
24341 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
24342 stride[0] = 0;
24343 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
24344 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
24346 /* Rasterizer stream */
24347 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
24348 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
24349 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
24350 NULL, 0, D3D11_SO_STREAM_COUNT);
24352 release_test_context(&test_context);
24355 static void test_fl10_stream_output_desc(void)
24357 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
24358 struct d3d11_test_context test_context;
24359 unsigned int i, count;
24360 ID3D11Device *device;
24362 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
24363 static const DWORD vs_code[] =
24365 #if 0
24366 struct data
24368 float4 position : SV_Position;
24369 float4 attrib1 : ATTRIB1;
24370 float3 attrib2 : attrib2;
24371 float2 attrib3 : ATTriB3;
24372 float attrib4 : ATTRIB4;
24375 void main(in data i, out data o)
24377 o = i;
24379 #endif
24380 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
24381 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
24382 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
24383 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
24384 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
24385 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
24386 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
24387 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
24388 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
24389 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
24390 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
24391 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
24392 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
24393 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
24394 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
24395 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
24396 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
24397 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
24398 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
24399 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
24401 static const DWORD gs_code[] =
24403 #if 0
24404 struct data
24406 float4 position : SV_Position;
24407 float4 attrib1 : ATTRIB1;
24408 float3 attrib2 : attrib2;
24409 float2 attrib3 : ATTriB3;
24410 float attrib4 : ATTRIB4;
24413 [maxvertexcount(1)]
24414 void main(point data i[1], inout PointStream<data> o)
24416 o.Append(i[0]);
24418 #endif
24419 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
24420 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
24421 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
24422 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
24423 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
24424 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
24425 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
24426 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
24427 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
24428 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
24429 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
24430 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
24431 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
24432 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
24433 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
24434 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
24435 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
24436 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
24437 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
24438 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
24439 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
24441 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
24443 {0, "SV_Position", 0, 0, 4, 0},
24445 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
24447 {0, "SV_Position", 0, 0, 4, 0},
24448 {0, NULL, 0, 0, 0, 0},
24450 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
24452 /* Gaps */
24454 {0, "SV_POSITION", 0, 0, 4, 0},
24455 {0, NULL, 0, 0, 8, 0},
24456 {0, "ATTRIB", 1, 0, 4, 0},
24459 {0, "SV_POSITION", 0, 0, 4, 0},
24460 {0, NULL, 0, 0, 4, 0},
24461 {0, NULL, 0, 0, 4, 0},
24462 {0, "ATTRIB", 1, 0, 4, 0},
24464 /* OutputSlot */
24466 {0, "attrib", 1, 0, 4, 0},
24467 {0, "attrib", 2, 0, 3, 0},
24468 {0, "attrib", 3, 0, 2, 0},
24469 {0, "attrib", 4, 0, 1, 0},
24472 {0, "attrib", 1, 0, 4, 0},
24473 {0, "attrib", 2, 0, 3, 1},
24474 {0, "attrib", 3, 0, 2, 2},
24475 {0, "attrib", 4, 0, 1, 3},
24478 {0, "attrib", 1, 0, 4, 0},
24479 {0, "attrib", 2, 0, 3, 3},
24482 {0, "attrib", 1, 0, 4, 0},
24483 {0, "attrib", 2, 0, 3, 0},
24484 {0, "attrib", 3, 0, 2, 0},
24485 {0, NULL, 0, 0, 1, 0},
24486 {0, "attrib", 4, 0, 1, 0},
24488 /* Multiple occurrences of the same output */
24490 {0, "ATTRIB", 1, 0, 2, 0},
24491 {0, "ATTRIB", 1, 2, 2, 1},
24494 {0, "ATTRIB", 1, 0, 1, 0},
24495 {0, "ATTRIB", 1, 1, 3, 0},
24498 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
24500 /* OutputSlot */
24502 {0, "attrib", 1, 0, 4, 0},
24503 {0, NULL, 0, 0, 4, 0},
24504 {0, "attrib", 4, 0, 1, 3},
24507 {0, "attrib", 1, 0, 4, 0},
24508 {0, NULL, 0, 0, 4, 0},
24509 {0, NULL, 0, 0, 4, 0},
24510 {0, "attrib", 4, 0, 1, 3},
24513 {0, "attrib", 1, 0, 4, 0},
24514 {0, "attrib", 2, 0, 3, 0},
24515 {0, "attrib", 3, 0, 2, 0},
24516 {0, "attrib", 4, 0, 1, 1},
24519 {0, "attrib", 1, 0, 4, 0},
24520 {0, "attrib", 2, 0, 3, 0},
24521 {0, "attrib", 3, 0, 2, 3},
24522 {0, NULL, 0, 0, 1, 3},
24523 {0, "attrib", 4, 0, 1, 3},
24526 {0, "attrib", 1, 0, 4, 0},
24527 {0, "attrib", 1, 0, 3, 1},
24528 {0, "attrib", 1, 0, 2, 2},
24529 {0, "attrib", 1, 0, 1, 3},
24530 {0, NULL, 0, 0, 3, 3},
24534 if (!init_test_context(&test_context, &feature_level))
24535 return;
24537 device = test_context.device;
24539 for (i = 0; i < ARRAY_SIZE(stride); ++i)
24540 stride[i] = 64;
24542 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
24543 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
24544 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
24545 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
24547 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
24548 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
24550 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
24551 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
24552 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
24553 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
24554 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
24556 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
24557 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
24559 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
24561 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
24563 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
24564 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
24565 break;
24568 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
24571 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
24573 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
24575 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
24576 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
24577 break;
24580 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
24581 stride, 1, 0);
24582 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
24583 stride, 2, 0);
24584 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
24585 stride, 3, 0);
24586 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
24587 stride, 4, 0);
24590 /* Buffer strides */
24591 stride[1] = 63;
24592 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
24593 &stride[1], 1, 0);
24594 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
24595 stride, 2, 0);
24596 stride[0] = 0;
24597 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
24598 stride, 1, 0);
24600 /* Rasterizer stream */
24601 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
24602 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
24603 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
24604 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
24605 NULL, 0, i);
24606 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
24608 release_test_context(&test_context);
24611 static void test_stream_output_resume(void)
24613 struct d3d11_test_context test_context;
24614 ID3D11Buffer *cb, *so_buffer, *buffer;
24615 unsigned int i, j, idx, offset;
24616 ID3D11DeviceContext *context;
24617 struct resource_readback rb;
24618 ID3D11GeometryShader *gs;
24619 const struct vec4 *data;
24620 ID3D11Device *device;
24621 HRESULT hr;
24623 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24624 static const DWORD gs_code[] =
24626 #if 0
24627 float4 constant;
24629 struct vertex
24631 float4 position : SV_POSITION;
24634 struct element
24636 float4 position : SV_POSITION;
24637 float4 so_output : so_output;
24640 [maxvertexcount(3)]
24641 void main(triangle vertex input[3], inout PointStream<element> output)
24643 element o;
24644 o.so_output = constant;
24645 o.position = input[0].position;
24646 output.Append(o);
24647 o.position = input[1].position;
24648 output.Append(o);
24649 o.position = input[2].position;
24650 output.Append(o);
24652 #endif
24653 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
24654 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
24655 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
24656 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
24657 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
24658 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
24659 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
24660 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
24661 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
24662 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
24663 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
24664 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
24665 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
24666 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
24668 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
24670 {0, "so_output", 0, 0, 4, 0},
24672 static const struct vec4 constants[] =
24674 {0.5f, 0.250f, 0.0f, 0.0f},
24675 {0.0f, 0.125f, 0.0f, 1.0f},
24676 {1.0f, 1.000f, 1.0f, 0.0f}
24678 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
24679 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
24680 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
24682 if (!init_test_context(&test_context, &feature_level))
24683 return;
24685 device = test_context.device;
24686 context = test_context.immediate_context;
24688 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
24689 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
24690 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
24692 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
24693 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
24695 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
24696 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
24698 offset = 0;
24699 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
24701 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
24702 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
24704 draw_color_quad(&test_context, &red);
24705 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
24707 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
24708 draw_color_quad(&test_context, &green);
24709 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
24711 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
24712 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
24713 draw_color_quad(&test_context, &red);
24714 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
24716 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
24717 draw_color_quad(&test_context, &red);
24718 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
24720 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
24721 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
24722 draw_color_quad(&test_context, &white);
24723 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
24725 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
24726 draw_color_quad(&test_context, &green);
24727 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
24729 buffer = NULL;
24730 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
24731 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
24732 draw_color_quad(&test_context, &white);
24733 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
24735 idx = 0;
24736 get_buffer_readback(so_buffer, &rb);
24737 for (i = 0; i < ARRAY_SIZE(constants); ++i)
24739 for (j = 0; j < 6; ++j) /* 2 triangles */
24741 data = get_readback_vec4(&rb, idx++, 0);
24742 ok(compare_vec4(data, &constants[i], 0),
24743 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
24744 data->x, data->y, data->z, data->w, idx, i, j);
24747 release_resource_readback(&rb);
24749 ID3D11Buffer_Release(cb);
24750 ID3D11Buffer_Release(so_buffer);
24751 ID3D11GeometryShader_Release(gs);
24752 release_test_context(&test_context);
24755 static void test_stream_output_components(void)
24757 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
24758 struct d3d11_test_context test_context;
24759 ID3D11InputLayout *input_layout[2];
24760 ID3D11Buffer *vb[2], *so_buffer;
24761 ID3D11DeviceContext *context;
24762 struct resource_readback rb;
24763 unsigned int stride, offset;
24764 ID3D11GeometryShader *gs;
24765 ID3D11VertexShader *vs;
24766 ID3D11PixelShader *ps;
24767 ID3D11Device *device;
24768 const float *result;
24769 unsigned int i, j;
24770 HRESULT hr;
24772 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24773 static const DWORD vs_code[] =
24775 #if 0
24776 struct vertex
24778 float4 position : POSITION;
24779 float4 color : COLOR;
24780 float4 color2 : COLOR2;
24783 void main(in vertex i, out vertex o)
24785 o = i;
24787 #endif
24788 0x43425844, 0x95991b76, 0x4898640b, 0xe36ad9d6, 0xfbfe78b4, 0x00000001, 0x00000194, 0x00000003,
24789 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
24790 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
24791 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
24792 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
24793 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
24794 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
24795 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
24796 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
24797 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
24798 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
24799 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
24800 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
24802 static const DWORD gs_code[] =
24804 #if 0
24805 struct vertex
24807 float4 position : POSITION;
24808 float4 color : COLOR;
24809 float4 color2 : COLOR2;
24812 [maxvertexcount(1)]
24813 void main(point vertex input[1], inout PointStream<vertex> output)
24815 output.Append(input[0]);
24817 #endif
24818 0x43425844, 0x218f7d27, 0x555fa7f1, 0x282c545f, 0x3989c843, 0x00000001, 0x000001c0, 0x00000003,
24819 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
24820 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
24821 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
24822 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
24823 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
24824 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
24825 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
24826 0x000000bc, 0x00020040, 0x0000002f, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x0400005f,
24827 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000002, 0x0100085d,
24828 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x03000065,
24829 0x001020f2, 0x00000002, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
24830 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001,
24831 0x06000036, 0x001020f2, 0x00000002, 0x00201e46, 0x00000000, 0x00000002, 0x01000013, 0x0100003e,
24833 static const DWORD ps_code[] =
24835 #if 0
24836 float4 main(float4 position : SV_Position,
24837 float2 texcoord : TEXCOORD) : SV_Target
24839 return float4(position.xy, texcoord);
24841 #endif
24842 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
24843 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
24844 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
24845 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
24846 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
24847 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
24848 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
24849 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
24850 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
24852 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
24854 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
24855 {"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
24856 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
24858 static const D3D11_INPUT_ELEMENT_DESC layout_desc2[] =
24860 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
24861 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
24862 {"COLOR", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
24864 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
24866 {0, "POSITION", 0, 0, 4, 0},
24867 {0, "COLOR", 0, 0, 3, 0},
24868 {0, "COLOR", 2, 0, 2, 0},
24870 static const D3D11_SO_DECLARATION_ENTRY so_declaration2[] =
24872 {0, "POSITION", 0, 0, 1, 0},
24873 {0, "POSITION", 0, 1, 1, 0},
24874 {0, "POSITION", 0, 2, 1, 0},
24875 {0, "POSITION", 0, 3, 1, 0},
24876 {0, "COLOR", 0, 0, 1, 0},
24877 {0, "COLOR", 0, 1, 1, 0},
24878 {0, "COLOR", 0, 2, 1, 0},
24879 {0, "COLOR", 2, 0, 1, 0},
24880 {0, "COLOR", 2, 1, 1, 0},
24882 static const D3D11_SO_DECLARATION_ENTRY so_declaration3[] =
24884 {0, "COLOR", 0, 2, 2, 0},
24885 {0, "COLOR", 2, 3, 1, 0},
24887 static const struct
24889 struct vec4 position;
24890 struct vec3 color;
24891 struct vec2 color2;
24893 vb_data[] =
24895 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.5f, 1.0f}},
24896 {{-1.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
24897 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f}, {0.5f, 0.4f}},
24898 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.1f, 0.6f}},
24900 static const struct
24902 struct vec4 position;
24903 struct vec4 color;
24904 struct vec4 color2;
24906 vb_data2[] =
24908 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
24909 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
24910 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
24911 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
24913 static const unsigned int vb_stride[] = {sizeof(*vb_data), sizeof(*vb_data2)};
24914 static const float expected_data[] =
24916 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f,
24917 -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
24918 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, 0.4f,
24919 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.1f, 0.6f,
24921 static const float expected_data2[] =
24923 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
24924 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
24925 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
24926 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
24928 static const float expected_data3[] =
24930 3.0f, 4.0f, 8.0f, 1.2f, 1.3f, 1.7f, 2.0f, 2.1f, 2.5f, 2.7f, 2.8f, 3.2f,
24932 static const struct
24934 BOOL with_ps;
24935 unsigned int vb_idx;
24936 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
24937 unsigned int so_entry_count;
24938 const float *expected_data;
24939 unsigned int expected_data_size;
24941 tests[] =
24943 {TRUE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
24944 {TRUE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
24945 {TRUE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
24946 {TRUE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
24947 {TRUE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
24949 {FALSE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
24950 {FALSE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
24951 {FALSE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
24952 {FALSE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
24953 {FALSE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
24956 if (!init_test_context(&test_context, &feature_level))
24957 return;
24959 device = test_context.device;
24960 context = test_context.immediate_context;
24962 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
24963 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data2), vb_data2);
24965 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
24966 vs_code, sizeof(vs_code), &input_layout[0]);
24967 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
24968 hr = ID3D11Device_CreateInputLayout(device, layout_desc2, ARRAY_SIZE(layout_desc2),
24969 vs_code, sizeof(vs_code), &input_layout[1]);
24970 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
24972 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
24973 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
24974 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
24975 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
24977 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
24978 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
24980 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
24982 gs = NULL;
24983 current_so_declaration = NULL;
24984 for (i = 0; i < ARRAY_SIZE(tests); ++i)
24986 ID3D11DeviceContext_PSSetShader(context, tests[i].with_ps ? ps : NULL, NULL, 0);
24988 if (current_so_declaration != tests[i].so_declaration)
24990 if (gs)
24991 ID3D11GeometryShader_Release(gs);
24993 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
24994 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
24995 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
24996 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
24997 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
24998 current_so_declaration = tests[i].so_declaration;
25001 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].vb_idx]);
25002 stride = vb_stride[tests[i].vb_idx];
25003 offset = 0;
25004 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[tests[i].vb_idx], &stride, &offset);
25006 offset = 0;
25007 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25009 ID3D11DeviceContext_Draw(context, 4, 0);
25011 get_buffer_readback(so_buffer, &rb);
25012 result = rb.map_desc.pData;
25013 for (j = 0; j < tests[i].expected_data_size; ++j)
25015 float expected_value = tests[i].expected_data[j];
25016 ok(compare_float(result[j], expected_value, 2),
25017 "Test %u: Got %.8e, expected %.8e at %u.\n",
25018 i, result[j], expected_value, j);
25020 release_resource_readback(&rb);
25023 for (i = 0; i < ARRAY_SIZE(vb); ++i)
25024 ID3D11Buffer_Release(vb[i]);
25025 ID3D11Buffer_Release(so_buffer);
25026 ID3D11VertexShader_Release(vs);
25027 ID3D11GeometryShader_Release(gs);
25028 ID3D11PixelShader_Release(ps);
25029 for (i = 0; i < ARRAY_SIZE(input_layout); ++i)
25030 ID3D11InputLayout_Release(input_layout[i]);
25031 release_test_context(&test_context);
25034 static void test_stream_output_vs(void)
25036 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
25037 struct d3d11_test_context test_context;
25038 ID3D11InputLayout *input_layout;
25039 ID3D11Buffer *vb, *so_buffer;
25040 ID3D11DeviceContext *context;
25041 struct resource_readback rb;
25042 ID3D11GeometryShader *gs;
25043 ID3D11VertexShader *vs;
25044 ID3D11Device *device;
25045 const float *result;
25046 unsigned int offset;
25047 unsigned int i, j;
25048 HRESULT hr;
25050 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25051 static const DWORD vs_code[] =
25053 #if 0
25054 struct vertex
25056 float4 position : POSITION;
25057 float4 color0 : COLOR0;
25058 float4 color1 : COLOR1;
25061 vertex main(in vertex i)
25063 return i;
25065 #endif
25066 0x43425844, 0xa67e993e, 0x1632c139, 0x02a7725f, 0xfb0221cd, 0x00000001, 0x00000194, 0x00000003,
25067 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
25068 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
25069 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
25070 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
25071 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
25072 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000001, 0x00000000,
25073 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
25074 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
25075 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
25076 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
25077 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
25078 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
25080 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
25082 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
25083 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
25084 {"COLOR", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
25086 static const D3D11_SO_DECLARATION_ENTRY all_so_decl[] =
25088 {0, "POSITION", 0, 0, 4, 0},
25089 {0, "COLOR", 0, 0, 3, 0},
25090 {0, "COLOR", 1, 0, 2, 0},
25092 static const D3D11_SO_DECLARATION_ENTRY position_so_decl[] =
25094 {0, "POSITION", 0, 0, 4, 0},
25096 static const D3D11_SO_DECLARATION_ENTRY position2_so_decl[] =
25098 {0, "POSITION", 0, 0, 2, 0},
25100 static const struct
25102 struct vec4 position;
25103 struct vec4 color0;
25104 struct vec4 color1;
25106 vb_data[] =
25108 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
25109 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
25110 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
25111 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
25113 static const unsigned int vb_stride[] = {sizeof(*vb_data)};
25114 static const float expected_data[] =
25116 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
25117 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
25118 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
25119 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
25121 static const float expected_data2[] =
25123 -1.0f, -1.0f, 0.0f, 1.0f,
25124 -1.0f, 1.0f, 0.0f, 1.0f,
25125 1.0f, -1.0f, 0.0f, 1.0f,
25126 1.0f, 1.0f, 0.0f, 1.0f,
25128 static const float expected_data3[] =
25130 -1.0f, -1.0f,
25131 -1.0f, 1.0f,
25132 1.0f, -1.0f,
25133 1.0f, 1.0f,
25135 static const struct
25137 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
25138 unsigned int so_entry_count;
25139 const float *expected_data;
25140 unsigned int expected_data_size;
25142 tests[] =
25144 {all_so_decl, ARRAY_SIZE(all_so_decl), expected_data, ARRAY_SIZE(expected_data)},
25145 {position_so_decl, ARRAY_SIZE(position_so_decl), expected_data2, ARRAY_SIZE(expected_data2)},
25146 {position2_so_decl, ARRAY_SIZE(position2_so_decl), expected_data3, ARRAY_SIZE(expected_data3)},
25149 if (!init_test_context(&test_context, &feature_level))
25150 return;
25152 device = test_context.device;
25153 context = test_context.immediate_context;
25155 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
25157 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
25158 vs_code, sizeof(vs_code), &input_layout);
25159 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
25161 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
25162 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
25164 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
25166 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
25167 offset = 0;
25168 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, vb_stride, &offset);
25169 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
25171 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
25173 gs = NULL;
25174 current_so_declaration = NULL;
25175 for (i = 0; i < ARRAY_SIZE(tests); ++i)
25177 if (current_so_declaration != tests[i].so_declaration)
25179 if (gs)
25180 ID3D11GeometryShader_Release(gs);
25182 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
25183 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
25184 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
25185 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
25186 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
25187 current_so_declaration = tests[i].so_declaration;
25190 offset = 0;
25191 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25193 ID3D11DeviceContext_Draw(context, 4, 0);
25195 get_buffer_readback(so_buffer, &rb);
25196 result = rb.map_desc.pData;
25197 for (j = 0; j < tests[i].expected_data_size; ++j)
25199 float expected_value = tests[i].expected_data[j];
25200 ok(compare_float(result[j], expected_value, 2),
25201 "Test %u: Got %.8e, expected %.8e at %u.\n",
25202 i, result[j], expected_value, j);
25204 release_resource_readback(&rb);
25207 ID3D11Buffer_Release(vb);
25208 ID3D11Buffer_Release(so_buffer);
25209 ID3D11VertexShader_Release(vs);
25210 ID3D11GeometryShader_Release(gs);
25211 ID3D11InputLayout_Release(input_layout);
25212 release_test_context(&test_context);
25215 static void test_gather(void)
25217 struct
25219 int width, height;
25220 int offset_x, offset_y;
25221 } constant;
25222 struct d3d11_test_context test_context;
25223 D3D11_TEXTURE2D_DESC texture_desc;
25224 ID3D11ShaderResourceView *srv;
25225 ID3D11Texture2D *texture, *rt;
25226 ID3D11DeviceContext *context;
25227 ID3D11RenderTargetView *rtv;
25228 struct resource_readback rb;
25229 ID3D11PixelShader *ps;
25230 ID3D11Device *device;
25231 unsigned int x, y;
25232 ID3D11Buffer *cb;
25233 HRESULT hr;
25235 static const DWORD gather4_code[] =
25237 #if 0
25238 SamplerState s;
25239 Texture2D<float4> t;
25241 int2 size;
25243 float4 main(float4 position : SV_Position) : SV_Target
25245 return t.Gather(s, position.xy / size);
25247 #endif
25248 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
25249 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
25250 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
25251 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
25252 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
25253 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
25254 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
25255 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
25256 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
25257 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
25258 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
25260 static const DWORD gather4_offset_code[] =
25262 #if 0
25263 SamplerState s;
25264 Texture2D<float4> t;
25266 int2 size;
25268 float4 main(float4 position : SV_Position) : SV_Target
25270 return t.Gather(s, position.xy / size, int2(1, 1));
25272 #endif
25273 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
25274 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
25275 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
25276 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
25277 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
25278 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
25279 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
25280 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
25281 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
25282 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
25283 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
25285 static const DWORD gather4_green_code[] =
25287 #if 0
25288 SamplerState s;
25289 Texture2D<float4> t;
25291 int2 size;
25293 float4 main(float4 position : SV_Position) : SV_Target
25295 return t.GatherGreen(s, position.xy / size);
25297 #endif
25298 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
25299 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
25300 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
25301 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
25302 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
25303 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
25304 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
25305 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
25306 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
25307 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
25308 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
25310 static const DWORD gather4_po_code[] =
25312 #if 0
25313 SamplerState s;
25314 Texture2D<float4> t;
25316 int2 size;
25317 int2 offset;
25319 float4 main(float4 position : SV_Position) : SV_Target
25321 return t.Gather(s, position.xy / size, offset);
25323 #endif
25324 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
25325 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
25326 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
25327 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
25328 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
25329 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
25330 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
25331 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
25332 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
25333 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
25334 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
25335 0x00000000, 0x0100003e,
25337 static const struct vec4 texture_data[] =
25339 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
25340 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
25341 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
25342 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
25344 static const struct vec4 expected_gather4[] =
25346 {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},
25347 {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},
25348 {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},
25349 {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},
25351 static const struct vec4 expected_gather4_offset[] =
25353 {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},
25354 {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},
25355 {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},
25356 {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},
25358 static const struct vec4 expected_gather4_green[] =
25360 {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},
25361 {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},
25362 {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},
25363 {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},
25365 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
25366 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
25368 if (!init_test_context(&test_context, NULL))
25369 return;
25371 device = test_context.device;
25372 context = test_context.immediate_context;
25374 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
25376 skip("Shader model 4.1 required for gather4 instruction.\n");
25377 release_test_context(&test_context);
25378 return;
25381 texture_desc.Width = 4;
25382 texture_desc.Height = 4;
25383 texture_desc.MipLevels = 1;
25384 texture_desc.ArraySize = 1;
25385 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
25386 texture_desc.SampleDesc.Count = 1;
25387 texture_desc.SampleDesc.Quality = 0;
25388 texture_desc.Usage = D3D11_USAGE_DEFAULT;
25389 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
25390 texture_desc.CPUAccessFlags = 0;
25391 texture_desc.MiscFlags = 0;
25392 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
25393 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
25394 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
25395 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
25396 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
25398 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
25399 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
25400 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
25401 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
25402 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
25403 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
25405 constant.width = texture_desc.Width;
25406 constant.height = texture_desc.Height;
25407 constant.offset_x = 1;
25408 constant.offset_y = 1;
25409 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
25410 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
25412 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
25413 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25414 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25416 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
25417 draw_quad(&test_context);
25418 get_texture_readback(rt, 0, &rb);
25419 for (y = 0; y < texture_desc.Height; ++y)
25421 for (x = 0; x < texture_desc.Width; ++x)
25423 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
25424 const struct vec4 *got = get_readback_vec4(&rb, x, y);
25425 ok(compare_vec4(got, expected, 0),
25426 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
25427 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
25430 release_resource_readback(&rb);
25432 ID3D11PixelShader_Release(ps);
25433 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
25434 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25435 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25437 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
25438 draw_quad(&test_context);
25439 get_texture_readback(rt, 0, &rb);
25440 for (y = 0; y < texture_desc.Height; ++y)
25442 for (x = 0; x < texture_desc.Width; ++x)
25444 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
25445 const struct vec4 *got = get_readback_vec4(&rb, x, y);
25446 ok(compare_vec4(got, expected, 0),
25447 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
25448 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
25451 release_resource_readback(&rb);
25453 ID3D11PixelShader_Release(ps);
25455 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
25457 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
25458 goto done;
25461 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
25462 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25463 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25465 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
25466 draw_quad(&test_context);
25467 get_texture_readback(rt, 0, &rb);
25468 for (y = 0; y < texture_desc.Height; ++y)
25470 for (x = 0; x < texture_desc.Width; ++x)
25472 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
25473 const struct vec4 *got = get_readback_vec4(&rb, x, y);
25474 ok(compare_vec4(got, expected, 0),
25475 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
25476 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
25479 release_resource_readback(&rb);
25481 ID3D11PixelShader_Release(ps);
25482 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
25483 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25484 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25486 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
25487 draw_quad(&test_context);
25488 get_texture_readback(rt, 0, &rb);
25489 for (y = 0; y < texture_desc.Height; ++y)
25491 for (x = 0; x < texture_desc.Width; ++x)
25493 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
25494 const struct vec4 *got = get_readback_vec4(&rb, x, y);
25495 ok(compare_vec4(got, expected, 0),
25496 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
25497 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
25500 release_resource_readback(&rb);
25502 constant.offset_x = 0;
25503 constant.offset_y = 0;
25504 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25505 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
25506 draw_quad(&test_context);
25507 get_texture_readback(rt, 0, &rb);
25508 for (y = 0; y < texture_desc.Height; ++y)
25510 for (x = 0; x < texture_desc.Width; ++x)
25512 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
25513 const struct vec4 *got = get_readback_vec4(&rb, x, y);
25514 ok(compare_vec4(got, expected, 0),
25515 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
25516 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
25519 release_resource_readback(&rb);
25521 ID3D11PixelShader_Release(ps);
25523 done:
25524 ID3D11Buffer_Release(cb);
25525 ID3D11Texture2D_Release(rt);
25526 ID3D11Texture2D_Release(texture);
25527 ID3D11RenderTargetView_Release(rtv);
25528 ID3D11ShaderResourceView_Release(srv);
25529 release_test_context(&test_context);
25532 static void test_gather_c(void)
25534 struct
25536 int width, height;
25537 int offset_x, offset_y;
25538 float compare_value;
25539 int padding[3];
25540 } constant;
25541 struct d3d11_test_context test_context;
25542 D3D11_TEXTURE2D_DESC texture_desc;
25543 D3D11_SAMPLER_DESC sampler_desc;
25544 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
25545 ID3D11ShaderResourceView *srv;
25546 ID3D11Texture2D *texture, *rt;
25547 ID3D11DeviceContext *context;
25548 ID3D11SamplerState *sampler;
25549 ID3D11RenderTargetView *rtv;
25550 struct resource_readback rb;
25551 ID3D11PixelShader *ps;
25552 ID3D11Device *device;
25553 unsigned int x, y;
25554 ID3D11Buffer *cb;
25555 HRESULT hr;
25557 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25558 static const DWORD gather4_c_code[] =
25560 #if 0
25561 SamplerComparisonState s;
25562 Texture2D<float4> t;
25564 int2 size;
25565 int2 offset;
25566 float compare;
25568 float4 main(float4 position : SV_Position) : SV_Target
25570 return t.GatherCmp(s, position.xy / size, compare);
25572 #endif
25573 0x43425844, 0xd3d04479, 0x901e9208, 0x7074fd0c, 0xbcadb2da, 0x00000001, 0x00000168, 0x00000003,
25574 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
25575 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
25576 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
25577 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
25578 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
25579 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
25580 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
25581 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
25582 0x00000000, 0x00100046, 0x00000000, 0x8e00007e, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
25583 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0020800a, 0x00000000,
25584 0x00000001, 0x0100003e,
25586 static const DWORD gather4_po_c_code[] =
25588 #if 0
25589 SamplerComparisonState s;
25590 Texture2D<float4> t;
25592 int2 size;
25593 int2 offset;
25594 float compare;
25596 float4 main(float4 position : SV_Position) : SV_Target
25598 return t.GatherCmp(s, position.xy / size, compare, offset);
25600 #endif
25601 0x43425844, 0x501de13e, 0x472d2d20, 0x6df0fee4, 0xef27d9e6, 0x00000001, 0x00000174, 0x00000003,
25602 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
25603 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
25604 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
25605 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d8, 0x00000050,
25606 0x00000036, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
25607 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
25608 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
25609 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
25610 0x00000000, 0x00100046, 0x00000000, 0x91000080, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
25611 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
25612 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
25614 static const float texture_data[] =
25616 0.00f, 0.10f, 0.20f, 0.30f,
25617 0.40f, 0.50f, 0.60f, 0.70f,
25618 0.80f, 0.90f, 0.05f, 0.15f,
25619 0.25f, 0.35f, 0.45f, 0.55f,
25621 static const struct vec4 expected_gather4_c[] =
25623 {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},
25624 {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},
25625 {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},
25626 {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},
25628 static const struct vec4 expected_gather4_po_c[] =
25630 {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},
25631 {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},
25632 {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},
25633 {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},
25635 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
25636 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
25638 if (!init_test_context(&test_context, &feature_level))
25639 return;
25641 device = test_context.device;
25642 context = test_context.immediate_context;
25644 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
25645 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
25646 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
25647 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
25648 sampler_desc.MipLODBias = 0.0f;
25649 sampler_desc.MaxAnisotropy = 0;
25650 sampler_desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
25651 sampler_desc.BorderColor[0] = 0.0f;
25652 sampler_desc.BorderColor[1] = 0.0f;
25653 sampler_desc.BorderColor[2] = 0.0f;
25654 sampler_desc.BorderColor[3] = 0.0f;
25655 sampler_desc.MinLOD = 0.0f;
25656 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
25658 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
25659 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
25660 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
25662 texture_desc.Width = 4;
25663 texture_desc.Height = 4;
25664 texture_desc.MipLevels = 1;
25665 texture_desc.ArraySize = 1;
25666 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
25667 texture_desc.SampleDesc.Count = 1;
25668 texture_desc.SampleDesc.Quality = 0;
25669 texture_desc.Usage = D3D11_USAGE_DEFAULT;
25670 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
25671 texture_desc.CPUAccessFlags = 0;
25672 texture_desc.MiscFlags = 0;
25673 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
25674 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
25675 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
25676 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
25677 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
25679 constant.width = texture_desc.Width;
25680 constant.height = texture_desc.Height;
25681 constant.offset_x = 1;
25682 constant.offset_y = 1;
25683 constant.compare_value = 0.5f;
25684 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
25685 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
25687 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
25688 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
25689 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
25690 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
25692 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
25693 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
25694 U(srv_desc).Texture2D.MostDetailedMip = 0;
25695 U(srv_desc).Texture2D.MipLevels = 1;
25696 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
25697 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
25698 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
25700 hr = ID3D11Device_CreatePixelShader(device, gather4_c_code, sizeof(gather4_c_code), NULL, &ps);
25701 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25702 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25704 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
25705 draw_quad(&test_context);
25706 get_texture_readback(rt, 0, &rb);
25707 for (y = 0; y < texture_desc.Height; ++y)
25709 for (x = 0; x < texture_desc.Width; ++x)
25711 const struct vec4 *expected = &expected_gather4_c[y * texture_desc.Width + x];
25712 const struct vec4 *got = get_readback_vec4(&rb, x, y);
25713 ok(compare_vec4(got, expected, 0),
25714 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
25715 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
25718 release_resource_readback(&rb);
25719 ID3D11PixelShader_Release(ps);
25721 hr = ID3D11Device_CreatePixelShader(device, gather4_po_c_code, sizeof(gather4_po_c_code), NULL, &ps);
25722 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25723 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25725 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
25726 draw_quad(&test_context);
25727 get_texture_readback(rt, 0, &rb);
25728 for (y = 0; y < texture_desc.Height; ++y)
25730 for (x = 0; x < texture_desc.Width; ++x)
25732 const struct vec4 *expected = &expected_gather4_po_c[y * texture_desc.Width + x];
25733 const struct vec4 *got = get_readback_vec4(&rb, x, y);
25734 ok(compare_vec4(got, expected, 0),
25735 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
25736 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
25739 release_resource_readback(&rb);
25740 ID3D11PixelShader_Release(ps);
25742 ID3D11ShaderResourceView_Release(srv);
25743 ID3D11Texture2D_Release(texture);
25745 ID3D11Buffer_Release(cb);
25746 ID3D11Texture2D_Release(rt);
25747 ID3D11RenderTargetView_Release(rtv);
25748 ID3D11SamplerState_Release(sampler);
25749 release_test_context(&test_context);
25752 static float clamp_depth_bias(float bias, float clamp)
25754 if (clamp > 0.0f)
25755 return min(bias, clamp);
25756 if (clamp < 0.0f)
25757 return max(bias, clamp);
25758 return bias;
25761 static void test_depth_bias(void)
25763 struct vec3 vertices[] =
25765 {-1.0f, -1.0f, 0.5f},
25766 {-1.0f, 1.0f, 0.5f},
25767 { 1.0f, -1.0f, 0.5f},
25768 { 1.0f, 1.0f, 0.5f},
25770 struct d3d11_test_context test_context;
25771 D3D11_RASTERIZER_DESC rasterizer_desc;
25772 struct swapchain_desc swapchain_desc;
25773 D3D11_TEXTURE2D_DESC texture_desc;
25774 ID3D11DeviceContext *context;
25775 double m, bias, depth, data;
25776 struct resource_readback rb;
25777 ID3D11DepthStencilView *dsv;
25778 unsigned int expected_value;
25779 ID3D11RasterizerState *rs;
25780 ID3D11Texture2D *texture;
25781 unsigned int format_idx;
25782 unsigned int y, i, j, k;
25783 unsigned int shift = 0;
25784 ID3D11Device *device;
25785 float *depth_values;
25786 DXGI_FORMAT format;
25787 const UINT32 *u32;
25788 const UINT16 *u16;
25789 UINT32 u32_value;
25790 HRESULT hr;
25792 static const struct
25794 float z;
25795 float exponent;
25797 quads[] =
25799 {0.125f, -3.0f},
25800 {0.250f, -2.0f},
25801 {0.500f, -1.0f},
25802 {1.000f, 0.0f},
25804 static const int bias_tests[] =
25806 -10000, -1000, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
25807 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100, 200, 500, 1000, 10000,
25809 static const float bias_clamp_tests[] =
25811 0.0f, -1e-5f, 1e-5f,
25813 static const float quad_slopes[] =
25815 0.0f, 0.5f, 1.0f
25817 static const float slope_scaled_bias_tests[] =
25819 0.0f, 0.5f, 1.0f, 2.0f, 128.0f, 1000.0f, 10000.0f,
25821 static const DXGI_FORMAT formats[] =
25823 DXGI_FORMAT_D32_FLOAT,
25824 DXGI_FORMAT_D24_UNORM_S8_UINT,
25825 DXGI_FORMAT_D16_UNORM,
25828 swapchain_desc.windowed = TRUE;
25829 swapchain_desc.buffer_count = 1;
25830 swapchain_desc.width = 200;
25831 swapchain_desc.height = 200;
25832 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
25833 swapchain_desc.flags = 0;
25834 if (!init_test_context_ext(&test_context, NULL, &swapchain_desc))
25835 return;
25837 device = test_context.device;
25838 context = test_context.immediate_context;
25840 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
25841 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
25842 rasterizer_desc.CullMode = D3D11_CULL_NONE;
25843 rasterizer_desc.FrontCounterClockwise = FALSE;
25844 rasterizer_desc.DepthBias = 0;
25845 rasterizer_desc.DepthBiasClamp = 0.0f;
25846 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
25847 rasterizer_desc.DepthClipEnable = TRUE;
25849 depth_values = heap_calloc(swapchain_desc.height, sizeof(*depth_values));
25850 ok(!!depth_values, "Failed to allocate memory.\n");
25852 for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx)
25854 format = formats[format_idx];
25856 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
25857 texture_desc.Format = format;
25858 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
25859 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
25860 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
25861 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
25862 ok(SUCCEEDED(hr), "Failed to create render depth stencil view, hr %#x.\n", hr);
25863 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
25864 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
25865 draw_quad_z(&test_context, 1.0f);
25866 switch (format)
25868 case DXGI_FORMAT_D32_FLOAT:
25869 check_texture_float(texture, 1.0f, 0);
25870 break;
25871 case DXGI_FORMAT_D24_UNORM_S8_UINT:
25872 /* FIXME: Depth/stencil byte order is reversed in wined3d. */
25873 shift = get_texture_color(texture, 0, 0) == 0xffffff ? 0 : 8;
25874 todo_wine
25875 check_texture_color(texture, 0xffffff, 1);
25876 break;
25877 case DXGI_FORMAT_D16_UNORM:
25878 get_texture_readback(texture, 0, &rb);
25879 check_readback_data_u16(&rb, NULL, 0xffffu, 0);
25880 release_resource_readback(&rb);
25881 break;
25882 default:
25883 trace("Unhandled format %#x.\n", format);
25884 break;
25886 draw_quad(&test_context);
25888 /* DepthBias */
25889 for (i = 0; i < ARRAY_SIZE(quads); ++i)
25891 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
25892 vertices[j].z = quads[i].z;
25893 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
25894 0, NULL, vertices, 0, 0);
25896 for (j = 0; j < ARRAY_SIZE(bias_tests); ++j)
25898 rasterizer_desc.DepthBias = bias_tests[j];
25900 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
25902 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
25903 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
25904 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
25905 ID3D11DeviceContext_RSSetState(context, rs);
25906 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
25907 draw_quad(&test_context);
25908 switch (format)
25910 case DXGI_FORMAT_D32_FLOAT:
25911 bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f);
25912 bias = clamp_depth_bias(bias, rasterizer_desc.DepthBiasClamp);
25913 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
25915 check_texture_float(texture, depth, 2);
25916 break;
25917 case DXGI_FORMAT_D24_UNORM_S8_UINT:
25918 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 16777215.0f,
25919 rasterizer_desc.DepthBiasClamp);
25920 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
25922 get_texture_readback(texture, 0, &rb);
25923 check_readback_data_u24(&rb, NULL, shift, depth * 16777215.0f + 0.5f, 1);
25924 release_resource_readback(&rb);
25925 break;
25926 case DXGI_FORMAT_D16_UNORM:
25927 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 65535.0f,
25928 rasterizer_desc.DepthBiasClamp);
25929 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
25931 get_texture_readback(texture, 0, &rb);
25932 check_readback_data_u16(&rb, NULL, depth * 65535.0f + 0.5f, 1);
25933 release_resource_readback(&rb);
25934 break;
25935 default:
25936 break;
25938 ID3D11RasterizerState_Release(rs);
25943 /* SlopeScaledDepthBias */
25944 rasterizer_desc.DepthBias = 0;
25945 for (i = 0; i < ARRAY_SIZE(quad_slopes); ++i)
25947 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
25948 vertices[j].z = j == 1 || j == 3 ? 0.0f : quad_slopes[i];
25949 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
25950 0, NULL, vertices, 0, 0);
25952 ID3D11DeviceContext_RSSetState(context, NULL);
25953 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
25954 draw_quad(&test_context);
25955 get_texture_readback(texture, 0, &rb);
25956 for (y = 0; y < texture_desc.Height; ++y)
25958 switch (format)
25960 case DXGI_FORMAT_D32_FLOAT:
25961 depth_values[y] = get_readback_float(&rb, 0, y);
25962 break;
25963 case DXGI_FORMAT_D24_UNORM_S8_UINT:
25964 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
25965 u32_value = *u32 >> shift;
25966 depth_values[y] = u32_value / 16777215.0f;
25967 break;
25968 case DXGI_FORMAT_D16_UNORM:
25969 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
25970 depth_values[y] = *u16 / 65535.0f;
25971 break;
25972 default:
25973 break;
25976 release_resource_readback(&rb);
25978 for (j = 0; j < ARRAY_SIZE(slope_scaled_bias_tests); ++j)
25980 rasterizer_desc.SlopeScaledDepthBias = slope_scaled_bias_tests[j];
25982 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
25984 BOOL all_match = TRUE;
25985 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
25986 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
25987 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
25988 ID3D11DeviceContext_RSSetState(context, rs);
25989 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
25990 draw_quad(&test_context);
25992 m = quad_slopes[i] / texture_desc.Height;
25993 bias = clamp_depth_bias(rasterizer_desc.SlopeScaledDepthBias * m, rasterizer_desc.DepthBiasClamp);
25994 get_texture_readback(texture, 0, &rb);
25995 for (y = 0; y < texture_desc.Height && all_match; ++y)
25997 depth = min(max(0.0f, depth_values[y] + bias), 1.0f);
25998 switch (format)
26000 case DXGI_FORMAT_D32_FLOAT:
26001 data = get_readback_float(&rb, 0, y);
26002 all_match = compare_float(data, depth, 64);
26003 ok(all_match,
26004 "Got depth %.8e, expected %.8e.\n", data, depth);
26005 break;
26006 case DXGI_FORMAT_D24_UNORM_S8_UINT:
26007 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
26008 u32_value = *u32 >> shift;
26009 expected_value = depth * 16777215.0f + 0.5f;
26010 all_match = compare_uint(u32_value, expected_value, 3);
26011 ok(all_match,
26012 "Got value %#x (%.8e), expected %#x (%.8e).\n",
26013 u32_value, u32_value / 16777215.0f,
26014 expected_value, expected_value / 16777215.0f);
26015 break;
26016 case DXGI_FORMAT_D16_UNORM:
26017 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
26018 expected_value = depth * 65535.0f + 0.5f;
26019 all_match = compare_uint(*u16, expected_value, 1);
26020 ok(all_match,
26021 "Got value %#x (%.8e), expected %#x (%.8e).\n",
26022 *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f);
26023 break;
26024 default:
26025 break;
26028 release_resource_readback(&rb);
26029 ID3D11RasterizerState_Release(rs);
26034 ID3D11Texture2D_Release(texture);
26035 ID3D11DepthStencilView_Release(dsv);
26038 heap_free(depth_values);
26039 release_test_context(&test_context);
26042 static void test_fractional_viewports(void)
26044 struct d3d11_test_context test_context;
26045 D3D11_TEXTURE2D_DESC texture_desc;
26046 ID3D11InputLayout *input_layout;
26047 ID3D11DeviceContext *context;
26048 struct resource_readback rb;
26049 ID3D11RenderTargetView *rtv;
26050 ID3D11VertexShader *vs;
26051 ID3D11PixelShader *ps;
26052 unsigned int i, x, y;
26053 ID3D11Device *device;
26054 ID3D11Texture2D *rt;
26055 UINT offset, stride;
26056 ID3D11Buffer *vb;
26057 HRESULT hr;
26059 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26060 static const DWORD vs_code[] =
26062 #if 0
26063 void main(in float4 in_position : POSITION,
26064 in float2 in_texcoord : TEXCOORD,
26065 out float4 position : SV_Position,
26066 out float2 texcoord : TEXCOORD)
26068 position = in_position;
26069 texcoord = in_texcoord;
26071 #endif
26072 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
26073 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
26074 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
26075 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
26076 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
26077 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
26078 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
26079 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
26080 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
26081 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
26082 0x00000001, 0x0100003e,
26084 static const DWORD ps_code[] =
26086 #if 0
26087 float4 main(float4 position : SV_Position,
26088 float2 texcoord : TEXCOORD) : SV_Target
26090 return float4(position.xy, texcoord);
26092 #endif
26093 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
26094 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
26095 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
26096 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
26097 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
26098 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
26099 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
26100 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
26101 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
26103 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
26105 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26106 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
26108 static const struct
26110 struct vec2 position;
26111 struct vec2 texcoord;
26113 quad[] =
26115 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
26116 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
26117 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
26118 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
26120 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
26121 static const float viewport_offsets[] =
26123 0.0f, 1.0f / 2.0f, 1.0f / 4.0f, 1.0f / 8.0f, 1.0f / 16.0f, 1.0f / 32.0f,
26124 1.0f / 64.0f, 1.0f / 128.0f, 1.0f / 256.0f, 63.0f / 128.0f,
26127 if (!init_test_context(&test_context, &feature_level))
26128 return;
26129 device = test_context.device;
26130 context = test_context.immediate_context;
26132 texture_desc.Width = 4;
26133 texture_desc.Height = 4;
26134 texture_desc.MipLevels = 1;
26135 texture_desc.ArraySize = 1;
26136 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
26137 texture_desc.SampleDesc.Count = 1;
26138 texture_desc.SampleDesc.Quality = 0;
26139 texture_desc.Usage = D3D11_USAGE_DEFAULT;
26140 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
26141 texture_desc.CPUAccessFlags = 0;
26142 texture_desc.MiscFlags = 0;
26143 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
26144 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
26145 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
26146 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
26147 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
26149 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
26150 vs_code, sizeof(vs_code), &input_layout);
26151 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
26152 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
26154 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
26155 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
26156 stride = sizeof(*quad);
26157 offset = 0;
26158 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
26160 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
26161 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
26162 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
26164 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
26165 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
26166 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
26168 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
26170 set_viewport(context, viewport_offsets[i], viewport_offsets[i],
26171 texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
26172 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
26173 ID3D11DeviceContext_Draw(context, 4, 0);
26174 get_texture_readback(rt, 0, &rb);
26175 for (y = 0; y < texture_desc.Height; ++y)
26177 for (x = 0; x < texture_desc.Width; ++x)
26179 const struct vec4 *v = get_readback_vec4(&rb, x, y);
26180 struct vec4 expected = {x + 0.5f, y + 0.5f,
26181 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
26182 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
26183 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
26184 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
26185 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
26186 todo_wine
26187 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
26188 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
26189 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
26192 release_resource_readback(&rb);
26195 ID3D11InputLayout_Release(input_layout);
26196 ID3D11Buffer_Release(vb);
26197 ID3D11VertexShader_Release(vs);
26198 ID3D11PixelShader_Release(ps);
26199 ID3D11RenderTargetView_Release(rtv);
26200 ID3D11Texture2D_Release(rt);
26201 release_test_context(&test_context);
26204 static void test_negative_viewports(const D3D_FEATURE_LEVEL feature_level)
26206 struct d3d11_test_context test_context;
26207 ID3D11DeviceContext *context;
26208 BOOL quirk;
26209 RECT rect;
26211 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
26212 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
26214 if (!init_test_context(&test_context, &feature_level))
26215 return;
26216 context = test_context.immediate_context;
26218 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
26219 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26220 draw_color_quad(&test_context, &green);
26221 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26223 set_viewport(context, -0.0f, -0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
26224 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26225 draw_color_quad(&test_context, &green);
26226 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26228 /* For feature levels greater than or equal to 11_0, a negative top left
26229 * corner shifts the bottom right corner by a whole integer. It seems that
26230 * floor() is used to round viewport corners to integers.
26232 quirk = feature_level >= D3D_FEATURE_LEVEL_11_0;
26234 set_viewport(context, -0.4f, -0.4f, 640.0f, 480.0f, 0.0f, 1.0f);
26235 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26236 draw_color_quad(&test_context, &green);
26237 SetRect(&rect, 0, 0, 639, 479);
26238 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
26239 SetRect(&rect, 639, 479, 640, 480);
26240 todo_wine_if(quirk)
26241 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
26243 set_viewport(context, -1.0f / 128.0f, -1.0 / 128.0f, 640.0f, 480.0f, 0.0f, 1.0f);
26244 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26245 draw_color_quad(&test_context, &green);
26246 SetRect(&rect, 0, 0, 639, 479);
26247 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
26248 SetRect(&rect, 639, 479, 640, 480);
26249 todo_wine_if(quirk)
26250 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
26252 release_test_context(&test_context);
26255 static void test_early_depth_stencil(void)
26257 ID3D11DepthStencilState *depth_stencil_state;
26258 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
26259 ID3D11Texture2D *texture, *depth_texture;
26260 struct d3d11_test_context test_context;
26261 D3D11_TEXTURE2D_DESC texture_desc;
26262 ID3D11UnorderedAccessView *uav;
26263 ID3D11DeviceContext *context;
26264 ID3D11DepthStencilView *dsv;
26265 ID3D11PixelShader *ps;
26266 ID3D11Device *device;
26267 HRESULT hr;
26269 static const DWORD ps_code[] =
26271 #if 0
26272 RWTexture2D<int> u;
26274 [earlydepthstencil]
26275 float4 main() : SV_Target
26277 InterlockedAdd(u[uint2(0, 0)], 1);
26278 return float4(1.0f, 1.0f, 1.0f, 1.0f);
26280 #endif
26281 0x43425844, 0xda4325ad, 0xc01d3815, 0xfd610cc9, 0x8ed1e351, 0x00000001, 0x000000ec, 0x00000003,
26282 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
26283 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
26284 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000074, 0x00000050, 0x0000001d,
26285 0x0100286a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x03000065, 0x001020f2, 0x00000000,
26286 0x0a0000ad, 0x0011e000, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
26287 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
26288 0x3f800000, 0x3f800000, 0x0100003e,
26290 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26291 static const UINT values[4] = {0};
26293 if (!init_test_context(&test_context, &feature_level))
26294 return;
26296 device = test_context.device;
26297 context = test_context.immediate_context;
26299 depth_stencil_desc.DepthEnable = TRUE;
26300 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
26301 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
26302 depth_stencil_desc.StencilEnable = FALSE;
26303 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
26304 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
26306 texture_desc.Width = 1;
26307 texture_desc.Height = 1;
26308 texture_desc.MipLevels = 1;
26309 texture_desc.ArraySize = 1;
26310 texture_desc.Format = DXGI_FORMAT_R32_SINT;
26311 texture_desc.SampleDesc.Count = 1;
26312 texture_desc.SampleDesc.Quality = 0;
26313 texture_desc.Usage = D3D11_USAGE_DEFAULT;
26314 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
26315 texture_desc.CPUAccessFlags = 0;
26316 texture_desc.MiscFlags = 0;
26317 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
26318 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
26319 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
26320 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
26322 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
26323 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
26324 texture_desc.Usage = D3D11_USAGE_DEFAULT;
26325 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
26326 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
26327 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
26328 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
26329 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
26331 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
26332 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
26333 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
26335 set_viewport(context, 0.0f, 0.0f, 1.0f, 100.0f, 0.5f, 0.5f);
26336 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
26337 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
26338 1, &test_context.backbuffer_rtv, dsv, 1, 1, &uav, NULL);
26340 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
26342 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
26343 draw_quad(&test_context);
26344 check_texture_color(texture, 100, 1);
26345 draw_quad(&test_context);
26346 check_texture_color(texture, 200, 1);
26347 check_texture_float(depth_texture, 0.6f, 1);
26349 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.3f, 0);
26350 draw_quad(&test_context);
26351 draw_quad(&test_context);
26352 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.55f, 0);
26353 draw_quad(&test_context);
26354 check_texture_color(texture, 300, 1);
26356 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
26357 draw_quad(&test_context);
26358 check_texture_color(texture, 400, 1);
26359 check_texture_float(depth_texture, 0.5f, 1);
26361 ID3D11Texture2D_Release(depth_texture);
26362 ID3D11DepthStencilView_Release(dsv);
26363 ID3D11DepthStencilState_Release(depth_stencil_state);
26364 ID3D11PixelShader_Release(ps);
26365 ID3D11Texture2D_Release(texture);
26366 ID3D11UnorderedAccessView_Release(uav);
26367 release_test_context(&test_context);
26370 static void test_conservative_depth_output(void)
26372 struct shader
26374 const DWORD *code;
26375 size_t size;
26378 ID3D11DepthStencilState *depth_stencil_state;
26379 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
26380 struct d3d11_test_context test_context;
26381 const struct shader *current_shader;
26382 D3D11_TEXTURE2D_DESC texture_desc;
26383 ID3D11DeviceContext *context;
26384 ID3D11DepthStencilView *dsv;
26385 ID3D11Texture2D *texture;
26386 ID3D11PixelShader *ps;
26387 DWORD expected_color;
26388 float expected_depth;
26389 ID3D11Device *device;
26390 struct vec4 ps_depth;
26391 ID3D11Buffer *cb;
26392 unsigned int i;
26393 HRESULT hr;
26395 static const DWORD ps_depth_le_code[] =
26397 #if 0
26398 float depth;
26400 float4 main(out float out_depth : SV_DepthLessEqual) : SV_Target0
26402 out_depth = depth;
26403 return float4(0.0f, 1.0f, 0.f, 1.0f);
26405 #endif
26406 0x43425844, 0x045c8d00, 0xc49e2ebe, 0x76f6022a, 0xf6996ecc, 0x00000001, 0x00000108, 0x00000003,
26407 0x0000002c, 0x0000003c, 0x00000098, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
26408 0x00000054, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
26409 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
26410 0x65677261, 0x56530074, 0x7065445f, 0x654c6874, 0x71457373, 0x006c6175, 0x58454853, 0x00000068,
26411 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065,
26412 0x001020f2, 0x00000000, 0x02000065, 0x00027001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
26413 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00027001, 0x0020800a, 0x00000000,
26414 0x00000000, 0x0100003e,
26416 static const struct shader ps_depth_le = {ps_depth_le_code, sizeof(ps_depth_le_code)};
26417 static const DWORD ps_depth_ge_code[] =
26419 #if 0
26420 float depth;
26422 float4 main(out float out_depth : SV_DepthGreaterEqual) : SV_Target0
26424 out_depth = depth;
26425 return float4(0.0f, 1.0f, 0.f, 1.0f);
26427 #endif
26428 0x43425844, 0xd17af83e, 0xa32c01cc, 0x0d8e9665, 0xe6dc17c2, 0x00000001, 0x0000010c, 0x00000003,
26429 0x0000002c, 0x0000003c, 0x0000009c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
26430 0x00000058, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
26431 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
26432 0x65677261, 0x56530074, 0x7065445f, 0x72476874, 0x65746165, 0x75714572, 0xab006c61, 0x58454853,
26433 0x00000068, 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
26434 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x00026001, 0x08000036, 0x001020f2, 0x00000000,
26435 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00026001, 0x0020800a,
26436 0x00000000, 0x00000000, 0x0100003e,
26438 static const struct shader ps_depth_ge = {ps_depth_ge_code, sizeof(ps_depth_ge_code)};
26439 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26440 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
26441 static const struct
26443 const struct shader *ps;
26444 float vs_depth;
26445 float ps_depth;
26446 BOOL passes_depth_test;
26448 tests[] =
26450 {&ps_depth_le, 0.7f, 0.7f, TRUE},
26451 {&ps_depth_le, 0.7f, 0.4f, FALSE},
26452 {&ps_depth_le, 0.4f, 0.4f, FALSE},
26453 /* {&ps_depth_le, 0.4f, 0.6f, FALSE}, undefined result */
26454 {&ps_depth_ge, 0.7f, 0.7f, TRUE},
26455 /* {&ps_depth_ge, 0.7f, 0.4f, TRUE}, undefined result */
26456 {&ps_depth_ge, 0.4f, 0.4f, FALSE},
26457 {&ps_depth_ge, 0.4f, 0.6f, TRUE},
26460 if (!init_test_context(&test_context, &feature_level))
26461 return;
26463 device = test_context.device;
26464 context = test_context.immediate_context;
26466 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_depth), NULL);
26468 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
26469 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
26470 texture_desc.Usage = D3D11_USAGE_DEFAULT;
26471 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
26472 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
26473 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
26474 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
26475 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
26477 depth_stencil_desc.DepthEnable = TRUE;
26478 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
26479 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_GREATER_EQUAL;
26480 depth_stencil_desc.StencilEnable = FALSE;
26481 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
26482 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
26484 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
26485 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
26486 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
26488 ps = NULL;
26489 current_shader = NULL;
26490 for (i = 0; i < ARRAY_SIZE(tests); ++i)
26492 if (current_shader != tests[i].ps)
26494 if (ps)
26495 ID3D11PixelShader_Release(ps);
26497 current_shader = tests[i].ps;
26498 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
26499 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
26500 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
26503 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26504 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
26505 ps_depth.x = tests[i].ps_depth;
26506 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_depth, 0, 0);
26507 draw_quad_z(&test_context, tests[i].vs_depth);
26509 expected_color = tests[i].passes_depth_test ? 0xff00ff00 : 0xffffffff;
26510 expected_depth = tests[i].passes_depth_test ? max(tests[i].vs_depth, tests[i].ps_depth) : 0.5f;
26511 check_texture_color(test_context.backbuffer, expected_color, 0);
26512 check_texture_float(texture, expected_depth, 1);
26515 ID3D11Buffer_Release(cb);
26516 ID3D11PixelShader_Release(ps);
26517 ID3D11DepthStencilView_Release(dsv);
26518 ID3D11DepthStencilState_Release(depth_stencil_state);
26519 ID3D11Texture2D_Release(texture);
26520 release_test_context(&test_context);
26523 static void test_format_compatibility(void)
26525 ID3D11Texture2D *dst_texture, *src_texture;
26526 D3D11_SUBRESOURCE_DATA resource_data;
26527 D3D11_TEXTURE2D_DESC texture_desc;
26528 ID3D11DeviceContext *context;
26529 struct resource_readback rb;
26530 DWORD colour, expected;
26531 ID3D11Device *device;
26532 unsigned int i, j;
26533 ULONG refcount;
26534 HRESULT hr;
26536 static const struct
26538 DXGI_FORMAT src_format;
26539 DXGI_FORMAT dst_format;
26540 size_t texel_size;
26541 BOOL success;
26543 test_data[] =
26545 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
26546 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
26547 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
26548 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
26549 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
26550 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
26551 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
26552 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
26553 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
26554 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
26555 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
26556 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
26557 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
26558 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
26559 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
26560 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_TYPELESS, 4, TRUE},
26561 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_FLOAT, 4, TRUE},
26562 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_UINT, 4, TRUE},
26563 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_SINT, 4, TRUE},
26564 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, FALSE},
26565 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_B8G8R8A8_TYPELESS, 4, FALSE},
26566 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R16G16_TYPELESS, 4, FALSE},
26567 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
26568 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
26569 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
26570 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
26572 static const DWORD initial_data[16] = {0};
26573 static const DWORD bitmap_data[] =
26575 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
26576 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
26577 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
26578 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
26581 if (!(device = create_device(NULL)))
26583 skip("Failed to create device.\n");
26584 return;
26586 ID3D11Device_GetImmediateContext(device, &context);
26588 texture_desc.Height = 4;
26589 texture_desc.MipLevels = 1;
26590 texture_desc.ArraySize = 1;
26591 texture_desc.SampleDesc.Count = 1;
26592 texture_desc.SampleDesc.Quality = 0;
26593 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
26594 texture_desc.CPUAccessFlags = 0;
26595 texture_desc.MiscFlags = 0;
26597 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
26599 unsigned int x, y, texel_dwords;
26600 BOOL broken = FALSE;
26601 D3D11_BOX box;
26603 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
26604 texture_desc.Format = test_data[i].src_format;
26605 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
26607 resource_data.pSysMem = bitmap_data;
26608 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
26609 resource_data.SysMemSlicePitch = 0;
26611 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
26612 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
26614 texture_desc.Format = test_data[i].dst_format;
26615 texture_desc.Usage = D3D11_USAGE_DEFAULT;
26617 resource_data.pSysMem = initial_data;
26619 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
26620 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
26622 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
26623 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0, 1, 1, 0,
26624 (ID3D11Resource *)src_texture, 0, &box);
26626 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
26627 get_texture_readback(dst_texture, 0, &rb);
26628 colour = get_readback_color(&rb, 0, 0, 0);
26629 if (test_data[i].src_format == DXGI_FORMAT_R9G9B9E5_SHAREDEXP && colour == bitmap_data[0])
26631 win_skip("Broken destination offset for %#x -> %#x copy.\n",
26632 test_data[i].src_format, test_data[i].dst_format);
26633 broken = TRUE;
26635 for (j = 0; j < ARRAY_SIZE(bitmap_data) && !broken; ++j)
26637 x = j % 4;
26638 y = j / 4;
26639 colour = get_readback_color(&rb, x, y, 0);
26640 expected = test_data[i].success && x >= texel_dwords && y
26641 ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
26642 todo_wine_if(test_data[i].src_format == DXGI_FORMAT_R9G9B9E5_SHAREDEXP && expected)
26643 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
26644 i, colour, x, y, expected);
26646 release_resource_readback(&rb);
26648 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
26650 get_texture_readback(dst_texture, 0, &rb);
26651 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
26653 x = j % 4;
26654 y = j / 4;
26655 colour = get_readback_color(&rb, x, y, 0);
26656 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
26657 todo_wine_if(test_data[i].src_format == DXGI_FORMAT_R9G9B9E5_SHAREDEXP && expected)
26658 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
26659 i, colour, x, y, expected);
26661 release_resource_readback(&rb);
26663 ID3D11Texture2D_Release(dst_texture);
26664 ID3D11Texture2D_Release(src_texture);
26667 ID3D11DeviceContext_Release(context);
26668 refcount = ID3D11Device_Release(device);
26669 ok(!refcount, "Device has %u references left.\n", refcount);
26672 static void check_clip_distance(struct d3d11_test_context *test_context, ID3D11Buffer *vb)
26674 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
26675 struct vertex
26677 float clip_distance0;
26678 float clip_distance1;
26681 ID3D11DeviceContext *context = test_context->immediate_context;
26682 struct resource_readback rb;
26683 struct vertex vertices[4];
26684 unsigned int i;
26685 RECT rect;
26687 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
26688 vertices[i].clip_distance0 = 1.0f;
26689 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
26690 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
26691 ID3D11DeviceContext_Draw(context, 4, 0);
26692 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
26694 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
26695 vertices[i].clip_distance0 = 0.0f;
26696 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
26697 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
26698 ID3D11DeviceContext_Draw(context, 4, 0);
26699 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
26701 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
26702 vertices[i].clip_distance0 = -1.0f;
26703 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
26704 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
26705 ID3D11DeviceContext_Draw(context, 4, 0);
26706 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
26708 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
26709 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
26710 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
26711 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
26712 ID3D11DeviceContext_Draw(context, 4, 0);
26713 get_texture_readback(test_context->backbuffer, 0, &rb);
26714 SetRect(&rect, 0, 0, 320, 480);
26715 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
26716 SetRect(&rect, 320, 0, 320, 480);
26717 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
26718 release_resource_readback(&rb);
26720 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
26721 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
26722 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
26723 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
26724 ID3D11DeviceContext_Draw(context, 4, 0);
26725 get_texture_readback(test_context->backbuffer, 0, &rb);
26726 SetRect(&rect, 0, 0, 640, 240);
26727 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
26728 SetRect(&rect, 0, 240, 640, 240);
26729 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
26730 release_resource_readback(&rb);
26733 static void test_clip_distance(void)
26735 struct d3d11_test_context test_context;
26736 ID3D11Buffer *vs_cb, *tess_cb, *gs_cb;
26737 D3D_FEATURE_LEVEL feature_level;
26738 ID3D11DomainShader *ds = NULL;
26739 ID3D11DeviceContext *context;
26740 struct resource_readback rb;
26741 unsigned int offset, stride;
26742 ID3D11HullShader *hs = NULL;
26743 ID3D11GeometryShader *gs;
26744 ID3D11Device *device;
26745 ID3D11Buffer *vb;
26746 unsigned int i;
26747 HRESULT hr;
26748 RECT rect;
26750 static const DWORD vs_code[] =
26752 #if 0
26753 bool use_constant;
26754 float clip_distance;
26756 struct input
26758 float4 position : POSITION;
26759 float distance0 : CLIP_DISTANCE0;
26760 float distance1 : CLIP_DISTANCE1;
26763 struct vertex
26765 float4 position : SV_POSITION;
26766 float user_clip : CLIP_DISTANCE;
26767 float clip : SV_ClipDistance;
26770 void main(input vin, out vertex vertex)
26772 vertex.position = vin.position;
26773 vertex.user_clip = vin.distance0;
26774 vertex.clip = vin.distance0;
26775 if (use_constant)
26776 vertex.clip = clip_distance;
26778 #endif
26779 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
26780 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
26781 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26782 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
26783 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
26784 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
26785 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
26786 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
26787 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
26788 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
26789 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
26790 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
26791 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
26792 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
26793 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
26795 static const DWORD vs_multiple_code[] =
26797 #if 0
26798 bool use_constant;
26799 float clip_distance0;
26800 float clip_distance1;
26802 struct input
26804 float4 position : POSITION;
26805 float distance0 : CLIP_DISTANCE0;
26806 float distance1 : CLIP_DISTANCE1;
26809 struct vertex
26811 float4 position : SV_POSITION;
26812 float user_clip : CLIP_DISTANCE;
26813 float2 clip : SV_ClipDistance;
26816 void main(input vin, out vertex vertex)
26818 vertex.position = vin.position;
26819 vertex.user_clip = vin.distance0;
26820 vertex.clip.x = vin.distance0;
26821 if (use_constant)
26822 vertex.clip.x = clip_distance0;
26823 vertex.clip.y = vin.distance1;
26824 if (use_constant)
26825 vertex.clip.y = clip_distance1;
26827 #endif
26828 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
26829 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
26830 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26831 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
26832 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
26833 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
26834 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
26835 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
26836 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
26837 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
26838 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
26839 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
26840 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
26841 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
26842 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
26843 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
26844 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
26846 #if 0
26847 bool use_constant;
26848 float clip_distance0;
26849 float clip_distance1;
26850 float tessellation_factor;
26852 struct vertex
26854 float4 position : SV_POSITION;
26855 float user_clip : CLIP_DISTANCE;
26856 float clip : SV_ClipDistance;
26859 struct patch_constant_data
26861 float edges[4] : SV_TessFactor;
26862 float inside[2] : SV_InsideTessFactor;
26865 patch_constant_data patch_constant()
26867 patch_constant_data output;
26869 output.edges[0] = tessellation_factor;
26870 output.edges[1] = tessellation_factor;
26871 output.edges[2] = tessellation_factor;
26872 output.edges[3] = tessellation_factor;
26873 output.inside[0] = tessellation_factor;
26874 output.inside[1] = tessellation_factor;
26876 return output;
26879 [domain("quad")]
26880 [outputcontrolpoints(4)]
26881 [outputtopology("triangle_cw")]
26882 [partitioning("pow2")]
26883 [patchconstantfunc("patch_constant")]
26884 vertex hs_main(InputPatch<vertex, 4> input,
26885 uint i : SV_OutputControlPointID)
26887 vertex o;
26888 o.position = input[i].position;
26889 o.user_clip = input[i].user_clip;
26890 o.clip = input[i].user_clip;
26891 return o;
26894 float4 interpolate_vec(float4 a, float4 b, float4 c, float4 d, float2 tess_coord)
26896 float4 e = lerp(a, b, tess_coord.x);
26897 float4 f = lerp(c, d, tess_coord.x);
26898 return lerp(e, f, tess_coord.y);
26901 float interpolate(float a, float b, float c, float d, float2 tess_coord)
26903 float e = lerp(a, b, tess_coord.x);
26904 float f = lerp(c, d, tess_coord.x);
26905 return lerp(e, f, tess_coord.y);
26908 [domain("quad")]
26909 vertex ds_main(patch_constant_data input,
26910 float2 tess_coord : SV_DomainLocation,
26911 const OutputPatch<vertex, 4> patch)
26913 vertex output;
26915 output.position = interpolate_vec(patch[0].position, patch[1].position,
26916 patch[2].position, patch[3].position, tess_coord);
26917 output.user_clip = interpolate(patch[0].user_clip, patch[1].user_clip,
26918 patch[2].user_clip, patch[3].user_clip, tess_coord);
26919 output.clip = interpolate(patch[0].clip, patch[1].clip,
26920 patch[2].clip, patch[3].clip, tess_coord);
26921 if (use_constant)
26922 output.clip = clip_distance0;
26924 return output;
26926 #endif
26927 static const DWORD hs_code[] =
26929 0x43425844, 0x5a6d7564, 0x5f30a6c9, 0x2cf3b848, 0x5b4c6dca, 0x00000001, 0x00000414, 0x00000004,
26930 0x00000030, 0x000000b4, 0x00000138, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
26931 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
26932 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
26933 0x00000002, 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
26934 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003,
26935 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c,
26936 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002,
26937 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f,
26938 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc,
26939 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
26940 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
26941 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
26942 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
26943 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
26944 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
26945 0x00000210, 0x00030050, 0x00000084, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01001096,
26946 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x01000072, 0x0200005f,
26947 0x00016000, 0x0400005f, 0x002010f2, 0x00000004, 0x00000000, 0x0400005f, 0x00201012, 0x00000004,
26948 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
26949 0x00102012, 0x00000002, 0x02000068, 0x00000001, 0x04000036, 0x00100012, 0x00000000, 0x00016001,
26950 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x07000036,
26951 0x00102012, 0x00000001, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x07000036, 0x00102012,
26952 0x00000002, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x0100003e, 0x01000073, 0x02000099,
26953 0x00000004, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x0000000b, 0x04000067,
26954 0x00102012, 0x00000001, 0x0000000c, 0x04000067, 0x00102012, 0x00000002, 0x0000000d, 0x04000067,
26955 0x00102012, 0x00000003, 0x0000000e, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000000,
26956 0x00000004, 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x07000036, 0x00902012, 0x0010000a,
26957 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002,
26958 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000004, 0x0000000f, 0x04000067, 0x00102012,
26959 0x00000005, 0x00000010, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000004, 0x00000002,
26960 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x08000036, 0x00d02012, 0x00000004, 0x0010000a,
26961 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e,
26963 static const DWORD ds_code[] =
26965 0x43425844, 0xc54dc020, 0x063a9622, 0x6f649eb9, 0xceb1dd36, 0x00000001, 0x0000054c, 0x00000004,
26966 0x00000030, 0x000000b4, 0x00000178, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
26967 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
26968 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
26969 0x00000002, 0x00000101, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
26970 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc, 0x00000006,
26971 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000001, 0x00000098,
26972 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000001, 0x00000098, 0x00000002, 0x0000000b,
26973 0x00000003, 0x00000002, 0x00000001, 0x00000098, 0x00000003, 0x0000000b, 0x00000003, 0x00000003,
26974 0x00000001, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000001, 0x000000a6,
26975 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
26976 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000007c,
26977 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
26978 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000,
26979 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43,
26980 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x58454853,
26981 0x00000348, 0x00040050, 0x000000d2, 0x01002093, 0x01001895, 0x0100086a, 0x04000059, 0x00208e46,
26982 0x00000000, 0x00000001, 0x0200005f, 0x0001c032, 0x0400005f, 0x002190f2, 0x00000004, 0x00000000,
26983 0x0400005f, 0x00219012, 0x00000004, 0x00000001, 0x0400005f, 0x00219012, 0x00000004, 0x00000002,
26984 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067,
26985 0x00102012, 0x00000002, 0x00000002, 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000,
26986 0x80219e46, 0x00000041, 0x00000002, 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032,
26987 0x001000f2, 0x00000000, 0x0001c006, 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000,
26988 0x0a000000, 0x001000f2, 0x00000001, 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46,
26989 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001,
26990 0x00219e46, 0x00000000, 0x00000000, 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
26991 0x80100e46, 0x00000041, 0x00000001, 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46,
26992 0x00000000, 0x00100e46, 0x00000001, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041,
26993 0x00000002, 0x00000001, 0x0021900a, 0x00000003, 0x00000001, 0x09000032, 0x00100012, 0x00000000,
26994 0x0001c00a, 0x0010000a, 0x00000000, 0x0021900a, 0x00000002, 0x00000001, 0x0a000000, 0x00100022,
26995 0x00000000, 0x8021900a, 0x00000041, 0x00000000, 0x00000001, 0x0021900a, 0x00000001, 0x00000001,
26996 0x09000032, 0x00100022, 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000,
26997 0x00000001, 0x08000000, 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a,
26998 0x00000000, 0x08000032, 0x00102012, 0x00000001, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a,
26999 0x00000000, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041, 0x00000002, 0x00000002,
27000 0x0021900a, 0x00000003, 0x00000002, 0x09000032, 0x00100012, 0x00000000, 0x0001c00a, 0x0010000a,
27001 0x00000000, 0x0021900a, 0x00000002, 0x00000002, 0x0a000000, 0x00100022, 0x00000000, 0x8021900a,
27002 0x00000041, 0x00000000, 0x00000002, 0x0021900a, 0x00000001, 0x00000002, 0x09000032, 0x00100022,
27003 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000, 0x00000002, 0x08000000,
27004 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a, 0x00000000, 0x08000032,
27005 0x00100012, 0x00000000, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000, 0x0b000037,
27006 0x00102012, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
27007 0x0010000a, 0x00000000, 0x0100003e,
27009 static const DWORD gs_code[] =
27011 #if 0
27012 bool use_constant;
27013 float clip_distance;
27015 struct vertex
27017 float4 position : SV_POSITION;
27018 float user_clip : CLIP_DISTANCE;
27019 float clip : SV_ClipDistance;
27022 [maxvertexcount(3)]
27023 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
27025 vertex o;
27026 o = input[0];
27027 o.clip = input[0].user_clip;
27028 if (use_constant)
27029 o.clip = clip_distance;
27030 output.Append(o);
27031 o = input[1];
27032 o.clip = input[1].user_clip;
27033 if (use_constant)
27034 o.clip = clip_distance;
27035 output.Append(o);
27036 o = input[2];
27037 o.clip = input[2].user_clip;
27038 if (use_constant)
27039 o.clip = clip_distance;
27040 output.Append(o);
27042 #endif
27043 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
27044 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
27045 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
27046 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
27047 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
27048 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
27049 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
27050 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
27051 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
27052 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
27053 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
27054 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
27055 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
27056 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
27057 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
27058 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
27059 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
27060 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
27061 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
27062 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
27063 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
27064 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
27065 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
27066 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
27067 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
27068 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
27070 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
27072 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
27073 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
27074 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
27076 struct
27078 float clip_distance0;
27079 float clip_distance1;
27081 vertices[] =
27083 {1.0f, 1.0f},
27084 {1.0f, 1.0f},
27085 {1.0f, 1.0f},
27086 {1.0f, 1.0f},
27088 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
27089 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
27090 struct
27092 BOOL use_constant;
27093 float clip_distance0;
27094 float clip_distance1;
27095 float tessellation_factor;
27096 } cb_data;
27098 if (!init_test_context(&test_context, NULL))
27099 return;
27100 device = test_context.device;
27101 context = test_context.immediate_context;
27102 feature_level = ID3D11Device_GetFeatureLevel(device);
27104 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
27105 vs_code, sizeof(vs_code), &test_context.input_layout);
27106 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
27108 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
27109 stride = sizeof(*vertices);
27110 offset = 0;
27111 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
27113 memset(&cb_data, 0, sizeof(cb_data));
27114 cb_data.tessellation_factor = 1.0f;
27115 vs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
27116 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &vs_cb);
27117 tess_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
27118 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &tess_cb);
27119 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, 1, &tess_cb);
27120 gs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
27121 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &gs_cb);
27123 /* vertex shader */
27124 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27125 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
27126 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
27128 check_clip_distance(&test_context, vb);
27130 cb_data.use_constant = TRUE;
27131 cb_data.clip_distance0 = -1.0f;
27132 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
27134 /* tessellation shaders */
27135 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
27137 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
27139 hr = ID3D11Device_CreateHullShader(device, hs_code, sizeof(hs_code), NULL, &hs);
27140 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
27141 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
27142 hr = ID3D11Device_CreateDomainShader(device, ds_code, sizeof(ds_code), NULL, &ds);
27143 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
27144 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
27146 check_clip_distance(&test_context, vb);
27148 cb_data.use_constant = FALSE;
27149 cb_data.tessellation_factor = 2.0f;
27150 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
27152 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
27153 vertices[i].clip_distance0 = 1.0f;
27154 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
27155 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27156 ID3D11DeviceContext_Draw(context, 4, 0);
27157 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
27159 cb_data.use_constant = TRUE;
27160 cb_data.clip_distance0 = -1.0f;
27161 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
27163 else
27165 skip("Tessellation shaders are not supported.\n");
27168 /* geometry shader */
27169 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
27170 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
27171 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
27173 check_clip_distance(&test_context, vb);
27175 cb_data.use_constant = TRUE;
27176 cb_data.clip_distance0 = 1.0f;
27177 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
27178 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27179 ID3D11DeviceContext_Draw(context, 4, 0);
27180 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
27182 /* multiple clip distances */
27183 ID3D11DeviceContext_HSSetShader(context, NULL, NULL, 0);
27184 ID3D11DeviceContext_DSSetShader(context, NULL, NULL, 0);
27185 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
27187 cb_data.use_constant = FALSE;
27188 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
27190 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
27191 vertices[i].clip_distance0 = 1.0f;
27192 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
27193 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27194 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
27195 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
27197 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
27199 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
27200 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
27202 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
27203 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27204 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
27205 get_texture_readback(test_context.backbuffer, 0, &rb);
27206 SetRect(&rect, 0, 0, 320, 240);
27207 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
27208 SetRect(&rect, 0, 240, 320, 480);
27209 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
27210 SetRect(&rect, 320, 0, 640, 480);
27211 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
27212 release_resource_readback(&rb);
27214 cb_data.use_constant = TRUE;
27215 cb_data.clip_distance0 = 0.0f;
27216 cb_data.clip_distance1 = 0.0f;
27217 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
27218 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27219 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
27220 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
27222 if (hs)
27223 ID3D11HullShader_Release(hs);
27224 if (ds)
27225 ID3D11DomainShader_Release(ds);
27226 ID3D11GeometryShader_Release(gs);
27227 ID3D11Buffer_Release(vb);
27228 ID3D11Buffer_Release(vs_cb);
27229 ID3D11Buffer_Release(tess_cb);
27230 ID3D11Buffer_Release(gs_cb);
27231 release_test_context(&test_context);
27234 static void test_combined_clip_and_cull_distances(void)
27236 struct d3d11_test_context test_context;
27237 ID3D11DeviceContext *context;
27238 struct resource_readback rb;
27239 unsigned int offset, stride;
27240 ID3D11Device *device;
27241 unsigned int i, j, k;
27242 ID3D11Buffer *vb;
27243 HRESULT hr;
27245 static const DWORD vs_code[] =
27247 #if 0
27248 struct input
27250 float4 position : POSITION;
27251 float clip0 : CLIP_DISTANCE0;
27252 float clip1 : CLIP_DISTANCE1;
27253 float clip2 : CLIP_DISTANCE2;
27254 float clip3 : CLIP_DISTANCE3;
27255 float cull0 : CULL_DISTANCE0;
27256 float cull1 : CULL_DISTANCE1;
27257 float cull2 : CULL_DISTANCE2;
27258 float cull3 : CULL_DISTANCE3;
27261 struct vertex
27263 float4 position : SV_Position;
27264 float3 clip0 : SV_ClipDistance1;
27265 float3 cull0 : SV_CullDistance1;
27266 float clip1 : SV_ClipDistance2;
27267 float cull1 : SV_CullDistance2;
27270 void main(input vin, out vertex vertex)
27272 vertex.position = vin.position;
27273 vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2);
27274 vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2);
27275 vertex.clip1 = vin.clip3;
27276 vertex.cull1 = vin.cull3;
27278 #endif
27279 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003,
27280 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0,
27281 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000,
27282 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
27283 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9,
27284 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000,
27285 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006,
27286 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7,
27287 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300,
27288 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f,
27289 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
27290 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c,
27291 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003,
27292 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002,
27293 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e,
27294 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f,
27295 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
27296 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f,
27297 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007,
27298 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
27299 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067,
27300 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036,
27301 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a,
27302 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042,
27303 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004,
27304 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002,
27305 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036,
27306 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e,
27308 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
27310 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
27311 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
27312 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
27313 {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
27314 {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
27315 {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
27316 {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
27317 {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
27318 {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
27320 struct
27322 float clip_distance[4];
27323 float cull_distance[4];
27325 vertices[4] =
27327 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
27328 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
27329 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
27330 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
27332 static const struct test
27334 float vertices[4];
27335 BOOL triangle_visible[2];
27337 cull_distance_tests[] =
27339 {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
27340 {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
27341 {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
27342 {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
27343 {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
27344 {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
27345 {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
27346 {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
27347 {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
27349 {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}},
27350 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
27351 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
27352 {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
27353 {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}},
27355 {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}},
27357 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
27358 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
27360 if (!init_test_context(&test_context, NULL))
27361 return;
27362 device = test_context.device;
27363 context = test_context.immediate_context;
27365 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
27366 vs_code, sizeof(vs_code), &test_context.input_layout);
27367 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
27369 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
27370 stride = sizeof(*vertices);
27371 offset = 0;
27372 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
27374 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27375 draw_color_quad(&test_context, &green);
27376 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
27378 for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i)
27380 for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j)
27382 const struct test *test = &cull_distance_tests[j];
27383 unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)];
27384 unsigned int color;
27386 for (k = 0; k < ARRAY_SIZE(vertices); ++k)
27387 vertices[k].cull_distance[i] = test->vertices[k];
27388 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
27390 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27391 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
27393 for (k = 0; k < ARRAY_SIZE(expected_color); ++k)
27394 expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff;
27396 if (expected_color[0] == expected_color[1])
27398 check_texture_color(test_context.backbuffer, *expected_color, 1);
27400 else
27402 get_texture_readback(test_context.backbuffer, 0, &rb);
27403 color = get_readback_color(&rb, 160, 240, 0);
27404 ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color);
27405 color = get_readback_color(&rb, 480, 240, 0);
27406 ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color);
27407 release_resource_readback(&rb);
27411 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
27412 vertices[j].cull_distance[i] = 1.0f;
27415 for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i)
27417 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
27418 vertices[j].clip_distance[i] = -1.0f;
27419 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
27421 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27422 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
27423 check_texture_color(test_context.backbuffer, 0xffffffff, 1);
27425 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
27426 vertices[j].clip_distance[i] = 1.0f;
27429 memset(vertices, 0, sizeof(vertices));
27430 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
27431 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27432 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
27433 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
27435 ID3D11Buffer_Release(vb);
27436 release_test_context(&test_context);
27439 static void test_generate_mips(void)
27441 static const DWORD ps_code[] =
27443 #if 0
27444 Texture2D t;
27445 SamplerState s;
27447 float4 main(float4 position : SV_POSITION) : SV_Target
27449 float2 p;
27451 p.x = position.x / 640.0f;
27452 p.y = position.y / 480.0f;
27453 return t.Sample(s, p);
27455 #endif
27456 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
27457 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27458 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
27459 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27460 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
27461 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
27462 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
27463 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
27464 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
27465 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
27467 static const DWORD ps_code_3d[] =
27469 #if 0
27470 Texture3D t;
27471 SamplerState s;
27473 float4 main(float4 position : SV_POSITION) : SV_Target
27475 float3 p;
27477 p.x = position.x / 640.0f;
27478 p.y = position.y / 480.0f;
27479 p.z = 0.5f;
27480 return t.Sample(s, p);
27482 #endif
27483 0x43425844, 0xa1e26083, 0xeb45763e, 0x1e5a5089, 0xdfbbe0df, 0x00000001, 0x00000148, 0x00000003,
27484 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27485 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
27486 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27487 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ac, 0x00000040,
27488 0x0000002b, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
27489 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
27490 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
27491 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f000000,
27492 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
27493 0x00000000, 0x0100003e,
27495 static const struct
27497 D3D11_RESOURCE_DIMENSION dim;
27498 D3D11_SRV_DIMENSION srv_dim;
27499 unsigned int array_size;
27501 resource_types[] =
27503 {D3D11_RESOURCE_DIMENSION_BUFFER, D3D11_SRV_DIMENSION_BUFFER, 1},
27504 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2D, 1},
27505 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2DARRAY, 4},
27506 {D3D11_RESOURCE_DIMENSION_TEXTURE3D, D3D11_SRV_DIMENSION_TEXTURE3D, 1},
27508 static const struct
27510 DXGI_FORMAT texture_format;
27511 UINT bind_flags;
27512 UINT misc_flags;
27513 BOOL null_srv;
27514 UINT base_level;
27515 BOOL expected_creation;
27516 BOOL expected_mips;
27518 tests[] =
27520 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
27521 0, TRUE, FALSE},
27522 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
27523 0, TRUE, FALSE},
27524 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
27525 0, TRUE, FALSE},
27526 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
27527 0, TRUE, FALSE},
27528 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
27529 0, FALSE, FALSE},
27530 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
27531 0, FALSE, FALSE},
27532 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
27533 0, TRUE, TRUE},
27534 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
27535 1, TRUE, TRUE},
27536 {DXGI_FORMAT_R8G8B8A8_TYPELESS, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
27537 1, TRUE, TRUE},
27538 {DXGI_FORMAT_R8G8B8A8_UINT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, TRUE,
27539 1, TRUE, FALSE},
27541 static const struct
27543 POINT pos;
27544 DWORD color;
27546 expected[] =
27548 {{200, 200}, 0xffff0000},
27549 {{280, 200}, 0xffff0000},
27550 {{360, 200}, 0xff00ff00},
27551 {{440, 200}, 0xff00ff00},
27552 {{200, 270}, 0xff0000ff},
27553 {{280, 270}, 0xff0000ff},
27554 {{360, 270}, 0xff000000},
27555 {{440, 270}, 0xff000000},
27557 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
27558 static const RECT r1 = {8, 8, 16, 16};
27559 static const RECT r2 = {16, 8, 24, 16};
27560 static const RECT r3 = {8, 16, 16, 24};
27561 static const RECT r4 = {16, 16, 24, 24};
27562 DWORD *data, *zero_data, color, expected_color;
27563 ID3D11ShaderResourceView *srv, *srv_sampling;
27564 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
27565 struct d3d11_test_context test_context;
27566 D3D11_TEXTURE2D_DESC texture2d_desc;
27567 D3D11_TEXTURE3D_DESC texture3d_desc;
27568 ID3D11SamplerState *sampler_state;
27569 D3D11_SAMPLER_DESC sampler_desc;
27570 D3D11_BUFFER_DESC buffer_desc;
27571 unsigned int i, j, k, x, y, z;
27572 ID3D11PixelShader *ps, *ps_3d;
27573 ID3D11DeviceContext *context;
27574 struct resource_readback rb;
27575 ID3D11Resource *resource;
27576 ID3D11Device *device;
27577 HRESULT hr;
27579 if (!init_test_context(&test_context, NULL))
27580 return;
27582 device = test_context.device;
27583 context = test_context.immediate_context;
27585 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
27586 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27588 hr = ID3D11Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), NULL, &ps_3d);
27589 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27591 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
27592 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
27593 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
27594 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
27595 sampler_desc.MipLODBias = 0.0f;
27596 sampler_desc.MaxAnisotropy = 0;
27597 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
27598 sampler_desc.BorderColor[0] = 0.0f;
27599 sampler_desc.BorderColor[1] = 0.0f;
27600 sampler_desc.BorderColor[2] = 0.0f;
27601 sampler_desc.BorderColor[3] = 0.0f;
27602 sampler_desc.MinLOD = 0.0f;
27603 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
27605 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
27606 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
27607 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
27609 data = heap_alloc(sizeof(*data) * 32 * 32 * 32);
27611 for (z = 0; z < 32; ++z)
27613 for (y = 0; y < 32; ++y)
27615 for (x = 0; x < 32; ++x)
27617 DWORD *dst = &data[z * 32 * 32 + y * 32 + x];
27618 POINT pt;
27620 pt.x = x;
27621 pt.y = y;
27622 if (PtInRect(&r1, pt))
27623 *dst = 0xffff0000;
27624 else if (PtInRect(&r2, pt))
27625 *dst = 0xff00ff00;
27626 else if (PtInRect(&r3, pt))
27627 *dst = 0xff0000ff;
27628 else if (PtInRect(&r4, pt))
27629 *dst = 0xff000000;
27630 else
27631 *dst = 0xffffffff;
27636 zero_data = heap_alloc_zero(sizeof(*zero_data) * 16 * 16 * 16);
27638 for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
27640 for (j = 0; j < ARRAY_SIZE(tests); ++j)
27642 unsigned int base_multiplier = 1u << tests[j].base_level;
27644 if (is_warp_device(device) && tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT)
27646 /* Testing this format seems to break the WARP device. */
27647 skip("Skipping test with DXGI_FORMAT_R8G8B8A8_UINT on WARP.\n");
27648 continue;
27651 switch (resource_types[i].dim)
27653 case D3D11_RESOURCE_DIMENSION_BUFFER:
27654 buffer_desc.ByteWidth = 32 * base_multiplier;
27655 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
27656 buffer_desc.BindFlags = tests[j].bind_flags;
27657 buffer_desc.CPUAccessFlags = 0;
27658 buffer_desc.MiscFlags = tests[j].misc_flags;
27659 buffer_desc.StructureByteStride = 0;
27661 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL,
27662 (ID3D11Buffer **)&resource);
27663 break;
27664 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
27665 texture2d_desc.Width = 32 * base_multiplier;
27666 texture2d_desc.Height = 32 * base_multiplier;
27667 texture2d_desc.MipLevels = 0;
27668 texture2d_desc.ArraySize = resource_types[i].array_size;
27669 texture2d_desc.Format = tests[j].texture_format;
27670 texture2d_desc.SampleDesc.Count = 1;
27671 texture2d_desc.SampleDesc.Quality = 0;
27672 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
27673 texture2d_desc.BindFlags = tests[j].bind_flags;
27674 texture2d_desc.CPUAccessFlags = 0;
27675 texture2d_desc.MiscFlags = tests[j].misc_flags;
27677 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL,
27678 (ID3D11Texture2D **)&resource);
27679 break;
27680 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
27681 texture3d_desc.Width = 32 * base_multiplier;
27682 texture3d_desc.Height = 32 * base_multiplier;
27683 texture3d_desc.Depth = 32 * base_multiplier;
27684 texture3d_desc.MipLevels = 0;
27685 texture3d_desc.Format = tests[j].texture_format;
27686 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
27687 texture3d_desc.BindFlags = tests[j].bind_flags;
27688 texture3d_desc.CPUAccessFlags = 0;
27689 texture3d_desc.MiscFlags = tests[j].misc_flags;
27691 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL,
27692 (ID3D11Texture3D **)&resource);
27693 break;
27694 default:
27695 break;
27697 if (tests[j].expected_creation && (resource_types[i].dim != D3D11_RESOURCE_DIMENSION_BUFFER
27698 || !(tests[j].misc_flags & D3D11_RESOURCE_MISC_GENERATE_MIPS)))
27700 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create resource, hr %#x.\n", i, j, hr);
27702 else
27704 ok(hr == E_INVALIDARG, "Resource type %u, test %u: unexpectedly succeeded "
27705 "to create resource, hr %#x.\n", i, j, hr);
27706 continue;
27709 if (tests[j].null_srv)
27711 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
27713 else
27715 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
27716 srv_desc.ViewDimension = resource_types[i].srv_dim;
27717 switch (resource_types[i].srv_dim)
27719 case D3D11_SRV_DIMENSION_BUFFER:
27720 srv_desc.Buffer.ElementOffset = 0;
27721 srv_desc.Buffer.ElementWidth = 0;
27722 break;
27723 case D3D11_SRV_DIMENSION_TEXTURE2D:
27724 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level;
27725 srv_desc.Texture2D.MipLevels = ~0u;
27726 break;
27727 case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
27728 srv_desc.Texture2DArray.MostDetailedMip = tests[j].base_level;
27729 srv_desc.Texture2DArray.MipLevels = ~0u;
27730 srv_desc.Texture2DArray.FirstArraySlice = 0;
27731 srv_desc.Texture2DArray.ArraySize = resource_types[i].array_size;
27732 break;
27733 case D3D11_SRV_DIMENSION_TEXTURE3D:
27734 srv_desc.Texture3D.MostDetailedMip = tests[j].base_level;
27735 srv_desc.Texture3D.MipLevels = ~0u;
27736 break;
27737 default:
27738 break;
27740 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
27742 if (resource_types[i].dim == D3D11_RESOURCE_DIMENSION_BUFFER)
27744 ok(FAILED(hr), "Test %u: unexpectedly succeeded to create shader resource view, "
27745 "hr %#x.\n", j, hr);
27746 ID3D11Resource_Release(resource);
27747 continue;
27749 else
27751 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create "
27752 "shader resource view, hr %#x.\n", i, j, hr);
27755 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level,
27756 NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
27757 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level + 1,
27758 NULL, zero_data, sizeof(*zero_data) * 16, sizeof(*zero_data) * 16 * 16);
27760 ID3D11DeviceContext_GenerateMips(context, srv);
27762 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
27764 srv_desc.Format = tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT
27765 ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
27766 srv_desc.ViewDimension = resource_types[i].dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D
27767 ? D3D11_SRV_DIMENSION_TEXTURE3D : D3D11_SRV_DIMENSION_TEXTURE2D;
27768 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level + 1;
27769 srv_desc.Texture2D.MipLevels = ~0u;
27770 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
27771 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create shader resource view, "
27772 "hr %#x.\n", i, j, hr);
27773 ID3D11DeviceContext_PSSetShader(context, resource_types[i].dim
27774 == D3D11_RESOURCE_DIMENSION_TEXTURE3D ? ps_3d : ps, NULL, 0);
27775 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
27777 draw_quad(&test_context);
27779 get_texture_readback(test_context.backbuffer, 0, &rb);
27780 for (k = 0; k < ARRAY_SIZE(expected); ++k)
27782 color = get_readback_color(&rb, expected[k].pos.x, expected[k].pos.y, 0);
27783 expected_color = tests[j].expected_mips ? expected[k].color : 0;
27784 ok(color == expected_color, "Resource type %u, test %u: pixel (%u, %u) "
27785 "has color %08x, expected %08x.\n",
27786 i, j, expected[k].pos.x, expected[k].pos.y, color, expected_color);
27788 release_resource_readback(&rb);
27790 ID3D11ShaderResourceView_Release(srv_sampling);
27791 ID3D11ShaderResourceView_Release(srv);
27792 ID3D11Resource_Release(resource);
27796 /* Test the effect of sRGB views. */
27797 for (y = 0; y < 32; ++y)
27799 for (x = 0; x < 32; ++x)
27801 DWORD *dst = &data[y * 32 + x];
27803 *dst = (x + y) % 2 * 0xffffffff;
27806 texture2d_desc.Width = 32;
27807 texture2d_desc.Height = 32;
27808 texture2d_desc.MipLevels = 0;
27809 texture2d_desc.ArraySize = 1;
27810 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
27811 texture2d_desc.SampleDesc.Count = 1;
27812 texture2d_desc.SampleDesc.Quality = 0;
27813 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
27814 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
27815 texture2d_desc.CPUAccessFlags = 0;
27816 texture2d_desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
27818 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D11Texture2D **)&resource);
27819 ok(SUCCEEDED(hr), "Failed to create resource, hr %#x.\n", hr);
27820 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
27821 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
27822 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
27823 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
27824 srv_desc.Texture2D.MostDetailedMip = 0;
27825 srv_desc.Texture2D.MipLevels = ~0u;
27826 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
27827 ID3D11DeviceContext_UpdateSubresource(context, resource,
27828 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
27830 ID3D11DeviceContext_GenerateMips(context, srv);
27832 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
27834 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
27835 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
27836 srv_desc.Texture2D.MostDetailedMip = 1;
27837 srv_desc.Texture2D.MipLevels = ~0u;
27838 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
27839 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
27840 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27841 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
27843 draw_quad(&test_context);
27845 get_texture_readback(test_context.backbuffer, 0, &rb);
27846 color = get_readback_color(&rb, 320, 240, 0);
27847 ok(compare_color(color, 0x7fbcbcbc, 1) || broken(compare_color(color, 0x7f7f7f7f, 1)), /* AMD */
27848 "Unexpected color %08x.\n", color);
27849 release_resource_readback(&rb);
27851 ID3D11ShaderResourceView_Release(srv_sampling);
27852 ID3D11ShaderResourceView_Release(srv);
27854 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
27855 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
27856 srv_desc.Texture2D.MostDetailedMip = 0;
27857 srv_desc.Texture2D.MipLevels = ~0u;
27858 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
27859 ID3D11DeviceContext_UpdateSubresource(context, resource,
27860 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
27862 ID3D11DeviceContext_GenerateMips(context, srv);
27864 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
27866 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
27867 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
27868 srv_desc.Texture2D.MostDetailedMip = 1;
27869 srv_desc.Texture2D.MipLevels = ~0u;
27870 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
27871 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
27872 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27873 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
27875 draw_quad(&test_context);
27877 get_texture_readback(test_context.backbuffer, 0, &rb);
27878 check_readback_data_color(&rb, NULL, 0x7f7f7f7f, 1);
27879 release_resource_readback(&rb);
27881 ID3D11ShaderResourceView_Release(srv_sampling);
27882 ID3D11ShaderResourceView_Release(srv);
27884 ID3D11Resource_Release(resource);
27886 heap_free(zero_data);
27887 heap_free(data);
27889 ID3D11SamplerState_Release(sampler_state);
27890 ID3D11PixelShader_Release(ps_3d);
27891 ID3D11PixelShader_Release(ps);
27892 release_test_context(&test_context);
27895 static void test_alpha_to_coverage(void)
27897 struct ps_cb
27899 struct vec2 top;
27900 struct vec2 bottom;
27901 float alpha[2];
27902 float padding[2];
27905 struct d3d11_test_context test_context;
27906 ID3D11Texture2D *render_targets[3];
27907 D3D11_TEXTURE2D_DESC texture_desc;
27908 ID3D11Texture2D *readback_texture;
27909 ID3D11RenderTargetView *rtvs[3];
27910 ID3D11BlendState *blend_state;
27911 ID3D11DeviceContext *context;
27912 D3D11_BLEND_DESC blend_desc;
27913 struct resource_readback rb;
27914 UINT quality_level_count;
27915 ID3D11PixelShader *ps;
27916 struct ps_cb cb_data;
27917 ID3D11Device *device;
27918 ID3D11Buffer *cb;
27919 unsigned int i;
27920 HRESULT hr;
27921 RECT rect;
27923 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
27924 static const DWORD ps_code[] =
27926 #if 0
27927 float2 top;
27928 float2 bottom;
27929 float alpha1;
27930 float alpha2;
27932 void main(float4 position : SV_Position,
27933 out float4 target0 : SV_Target0,
27934 out float4 target1 : SV_Target1,
27935 out float4 target2 : SV_Target2)
27937 float alpha = all(top <= position.xy) && all(position.xy <= bottom) ? 1.0f : 0.0f;
27938 target0 = float4(0.0f, 1.0f, 0.0f, alpha);
27939 target1 = float4(0.0f, 0.0f, 1.0f, alpha1);
27940 target2 = float4(0.0f, 1.0f, 0.0f, alpha2);
27942 #endif
27943 0x43425844, 0x771ff802, 0xca927279, 0x5bdd75ae, 0xf53cb31b, 0x00000001, 0x00000264, 0x00000003,
27944 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27945 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27946 0x4e47534f, 0x0000005c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003,
27947 0x00000000, 0x0000000f, 0x00000050, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
27948 0x00000050, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x545f5653, 0x65677261,
27949 0xabab0074, 0x52444853, 0x00000198, 0x00000040, 0x00000066, 0x04000059, 0x00208e46, 0x00000000,
27950 0x00000002, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
27951 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001,
27952 0x0800001d, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00208046, 0x00000000, 0x00000000,
27953 0x07000001, 0x00100012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0800001d,
27954 0x00100062, 0x00000000, 0x00208ba6, 0x00000000, 0x00000000, 0x00101106, 0x00000000, 0x07000001,
27955 0x00100022, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x07000001, 0x00100012,
27956 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00102082, 0x00000000,
27957 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x08000036, 0x00102072, 0x00000000, 0x00004002,
27958 0x00000000, 0x3f800000, 0x00000000, 0x00000000, 0x08000036, 0x00102072, 0x00000001, 0x00004002,
27959 0x00000000, 0x00000000, 0x3f800000, 0x00000000, 0x06000036, 0x00102082, 0x00000001, 0x0020800a,
27960 0x00000000, 0x00000001, 0x08000036, 0x00102072, 0x00000002, 0x00004002, 0x00000000, 0x3f800000,
27961 0x00000000, 0x00000000, 0x06000036, 0x00102082, 0x00000002, 0x0020801a, 0x00000000, 0x00000001,
27962 0x0100003e,
27964 static const DWORD colors[] = {0xff00ff00, 0xbfff0000, 0x8000ff00};
27966 if (!init_test_context(&test_context, NULL))
27967 return;
27968 device = test_context.device;
27969 context = test_context.immediate_context;
27971 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
27972 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27973 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27975 memset(&blend_desc, 0, sizeof(blend_desc));
27976 blend_desc.AlphaToCoverageEnable = TRUE;
27977 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
27978 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
27979 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
27980 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
27982 render_targets[0] = test_context.backbuffer;
27983 rtvs[0] = test_context.backbuffer_rtv;
27984 for (i = 1; i < ARRAY_SIZE(render_targets); ++i)
27986 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
27987 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
27988 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27989 hr = ID3D11Device_CreateRenderTargetView(device,
27990 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
27991 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
27993 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
27995 cb_data.top.x = cb_data.top.y = 0.0f;
27996 cb_data.bottom.x = cb_data.bottom.y = 200.0f;
27997 cb_data.alpha[0] = 0.75;
27998 cb_data.alpha[1] = 0.5f;
27999 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
28000 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
28002 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
28003 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
28004 draw_quad(&test_context);
28005 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
28007 DWORD expected_color;
28009 assert(i < ARRAY_SIZE(colors));
28010 expected_color = colors[i];
28011 get_texture_readback(render_targets[i], 0, &rb);
28012 SetRect(&rect, 0, 0, 200, 200);
28013 check_readback_data_color(&rb, &rect, expected_color, 1);
28014 SetRect(&rect, 200, 0, 640, 200);
28015 todo_wine
28016 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28017 SetRect(&rect, 0, 200, 640, 480);
28018 todo_wine
28019 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28020 release_resource_readback(&rb);
28022 if (i > 0)
28023 ID3D11Texture2D_Release(render_targets[i]);
28024 render_targets[i] = NULL;
28027 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
28028 texture_desc.Format = DXGI_FORMAT_R16G16_UNORM;
28029 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[0]);
28030 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28031 hr = ID3D11Device_CreateRenderTargetView(device,
28032 (ID3D11Resource *)render_targets[0], NULL, &rtvs[0]);
28033 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
28034 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
28036 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
28037 draw_quad(&test_context);
28038 get_texture_readback(render_targets[0], 0, &rb);
28039 SetRect(&rect, 0, 0, 200, 200);
28040 check_readback_data_color(&rb, &rect, 0xffff0000, 1);
28041 SetRect(&rect, 200, 0, 640, 200);
28042 todo_wine
28043 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28044 SetRect(&rect, 0, 200, 640, 480);
28045 todo_wine
28046 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28047 release_resource_readback(&rb);
28049 ID3D11Texture2D_Release(render_targets[0]);
28050 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
28051 ID3D11RenderTargetView_Release(rtvs[i]);
28053 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
28054 hr = ID3D11Device_CheckMultisampleQualityLevels(device,
28055 texture_desc.Format, 4, &quality_level_count);
28056 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
28057 if (!quality_level_count)
28059 skip("4xMSAA not supported.\n");
28060 goto done;
28062 texture_desc.SampleDesc.Count = 4;
28063 texture_desc.SampleDesc.Quality = 0;
28065 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
28067 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
28068 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28069 hr = ID3D11Device_CreateRenderTargetView(device,
28070 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
28071 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
28073 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
28075 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
28076 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
28077 draw_quad(&test_context);
28078 texture_desc.SampleDesc.Count = 1;
28079 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
28080 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28081 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
28083 DWORD expected_color;
28085 assert(i < ARRAY_SIZE(colors));
28086 expected_color = colors[i];
28088 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
28089 (ID3D11Resource *)render_targets[i], 0, texture_desc.Format);
28091 get_texture_readback(readback_texture, 0, &rb);
28092 SetRect(&rect, 0, 0, 200, 200);
28093 check_readback_data_color(&rb, &rect, expected_color, 1);
28094 SetRect(&rect, 200, 0, 640, 200);
28095 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28096 SetRect(&rect, 0, 200, 640, 480);
28097 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28098 release_resource_readback(&rb);
28100 ID3D11Texture2D_Release(readback_texture);
28102 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
28104 ID3D11Texture2D_Release(render_targets[i]);
28105 ID3D11RenderTargetView_Release(rtvs[i]);
28108 done:
28109 ID3D11Buffer_Release(cb);
28110 ID3D11PixelShader_Release(ps);
28111 ID3D11BlendState_Release(blend_state);
28112 release_test_context(&test_context);
28115 static void test_unbound_multisample_texture(void)
28117 struct d3d11_test_context test_context;
28118 ID3D11DeviceContext *context;
28119 ID3D11PixelShader *ps;
28120 struct uvec4 cb_data;
28121 ID3D11Device *device;
28122 ID3D11Buffer *cb;
28123 unsigned int i;
28124 HRESULT hr;
28126 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28127 static const DWORD ps_code[] =
28129 #if 0
28130 Texture2DMS<float4, 4> t;
28132 uint sample_index;
28134 float4 main(float4 position : SV_Position) : SV_Target
28136 float3 p;
28137 t.GetDimensions(p.x, p.y, p.z);
28138 p *= float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
28139 /* sample index must be a literal */
28140 switch (sample_index)
28142 case 1: return t.Load(int2(p.xy), 1);
28143 case 2: return t.Load(int2(p.xy), 2);
28144 case 3: return t.Load(int2(p.xy), 3);
28145 default: return t.Load(int2(p.xy), 0);
28148 #endif
28149 0x43425844, 0x03d62416, 0x1914ee8b, 0xccd08d68, 0x27f42136, 0x00000001, 0x000002f8, 0x00000003,
28150 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
28151 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
28152 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
28153 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000025c, 0x00000040,
28154 0x00000097, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04042058, 0x00107000, 0x00000000,
28155 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
28156 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46,
28157 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000,
28158 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
28159 0x00000000, 0x00000000, 0x0400004c, 0x0020800a, 0x00000000, 0x00000000, 0x03000006, 0x00004001,
28160 0x00000001, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000, 0x08000036, 0x001000c2,
28161 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0900002e, 0x001020f2,
28162 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
28163 0x03000006, 0x00004001, 0x00000002, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000,
28164 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
28165 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001,
28166 0x00000002, 0x0100003e, 0x03000006, 0x00004001, 0x00000003, 0x0500001b, 0x00100032, 0x00000001,
28167 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000,
28168 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46,
28169 0x00000000, 0x00004001, 0x00000003, 0x0100003e, 0x0100000a, 0x0500001b, 0x00100032, 0x00000000,
28170 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
28171 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46,
28172 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000017, 0x0100003e,
28175 if (!init_test_context(&test_context, NULL))
28176 return;
28177 device = test_context.device;
28178 context = test_context.immediate_context;
28180 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
28181 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
28182 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
28184 memset(&cb_data, 0, sizeof(cb_data));
28185 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
28186 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
28188 for (i = 0; i < 4; ++i)
28190 cb_data.x = i;
28191 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_data, 0, 0);
28192 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28193 draw_quad(&test_context);
28194 check_texture_color(test_context.backbuffer, 0x00000000, 1);
28197 ID3D11Buffer_Release(cb);
28198 ID3D11PixelShader_Release(ps);
28199 release_test_context(&test_context);
28202 static void test_multiple_viewports(void)
28204 struct
28206 unsigned int draw_id;
28207 unsigned int padding[3];
28208 } constant;
28209 D3D11_VIEWPORT vp[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE + 1];
28210 struct d3d11_test_context test_context;
28211 D3D11_TEXTURE2D_DESC texture_desc;
28212 ID3D11DeviceContext *context;
28213 ID3D11RenderTargetView *rtv;
28214 ID3D11Texture2D *texture;
28215 ID3D11GeometryShader *gs;
28216 ID3D11PixelShader *ps;
28217 ID3D11Device *device;
28218 ID3D11Buffer *cb;
28219 HRESULT hr;
28221 static const DWORD gs_code[] =
28223 #if 0
28224 struct gs_in
28226 float4 pos : SV_Position;
28229 struct gs_out
28231 float4 pos : SV_Position;
28232 uint viewport : SV_ViewportArrayIndex;
28235 [maxvertexcount(6)]
28236 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
28238 gs_out o;
28239 for (uint instance_id = 0; instance_id < 2; ++instance_id)
28241 o.viewport = instance_id;
28242 for (uint i = 0; i < 3; ++i)
28244 o.pos = vin[i].pos;
28245 vout.Append(o);
28247 vout.RestartStrip();
28250 #endif
28251 0x43425844, 0xabbb660f, 0x0729bf23, 0x14a9a104, 0x1b454917, 0x00000001, 0x0000021c, 0x00000003,
28252 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
28253 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
28254 0x4e47534f, 0x0000005c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
28255 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005, 0x00000001, 0x00000001, 0x00000e01,
28256 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569, 0x4174726f, 0x79617272, 0x65646e49,
28257 0xabab0078, 0x52444853, 0x00000150, 0x00020040, 0x00000054, 0x05000061, 0x002010f2, 0x00000003,
28258 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
28259 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000005, 0x0200005e, 0x00000006,
28260 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
28261 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x03040003, 0x0010001a, 0x00000000,
28262 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
28263 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000,
28264 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036,
28265 0x00102012, 0x00000001, 0x0010000a, 0x00000000, 0x01000013, 0x0700001e, 0x00100022, 0x00000000,
28266 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012,
28267 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
28269 static const DWORD ps_code[] =
28271 #if 0
28272 uint draw_id;
28274 float4 main(in float4 pos : SV_Position,
28275 in uint viewport : SV_ViewportArrayIndex) : SV_Target
28277 return float4(viewport, draw_id, 0, 0);
28279 #endif
28280 0x43425844, 0x77334c0f, 0x5df3ca7a, 0xc53c00db, 0x3e6e5750, 0x00000001, 0x00000150, 0x00000003,
28281 0x0000002c, 0x00000090, 0x000000c4, 0x4e475349, 0x0000005c, 0x00000002, 0x00000008, 0x00000038,
28282 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005,
28283 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569,
28284 0x4174726f, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
28285 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261,
28286 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46, 0x00000000,
28287 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000005, 0x03000065, 0x001020f2, 0x00000000,
28288 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022, 0x00000000,
28289 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000,
28290 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
28292 static const struct vec4 expected_values[] =
28294 {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},
28295 {0.0f, 5.0f}, {0.5f, 0.5f}, {1.0f, 5.0f}, {0.5f, 0.5f},
28297 static const float clear_color[] = {0.5f, 0.5f, 0.0f, 0.0f};
28298 ID3D11RasterizerState *rasterizer_state;
28299 D3D11_RASTERIZER_DESC rasterizer_desc;
28300 unsigned int count, i;
28301 D3D11_RECT rects[2];
28302 RECT rect;
28303 int width;
28305 if (!init_test_context(&test_context, NULL))
28306 return;
28308 device = test_context.device;
28309 context = test_context.immediate_context;
28311 memset(&constant, 0, sizeof(constant));
28312 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
28313 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
28315 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
28316 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
28317 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
28319 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
28320 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
28321 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
28323 texture_desc.Width = 32;
28324 texture_desc.Height = 32;
28325 texture_desc.MipLevels = 1;
28326 texture_desc.ArraySize = 1;
28327 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
28328 texture_desc.SampleDesc.Count = 1;
28329 texture_desc.SampleDesc.Quality = 0;
28330 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28331 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
28332 texture_desc.CPUAccessFlags = 0;
28333 texture_desc.MiscFlags = 0;
28334 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
28335 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28337 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
28338 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
28339 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
28341 width = texture_desc.Width / 2;
28343 vp[0].TopLeftX = 0.0f;
28344 vp[0].TopLeftY = 0.0f;
28345 vp[0].Width = width;
28346 vp[0].Height = texture_desc.Height;
28347 vp[0].MinDepth = 0.0f;
28348 vp[0].MaxDepth = 1.0f;
28350 vp[1] = vp[0];
28351 vp[1].TopLeftX = width;
28352 vp[1].Width = width;
28353 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
28355 count = enable_debug_layer ? ARRAY_SIZE(vp) - 1 : ARRAY_SIZE(vp);
28356 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
28357 ok(count == 2, "Unexpected viewport count %d.\n", count);
28359 constant.draw_id = 0;
28360 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
28361 draw_quad(&test_context);
28362 constant.draw_id = 1;
28363 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
28364 draw_quad(&test_context);
28366 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
28367 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[0], 1);
28368 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
28369 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[1], 1);
28371 /* One viewport. */
28372 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
28373 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
28374 constant.draw_id = 2;
28375 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
28376 draw_quad(&test_context);
28377 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
28378 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[2], 1);
28379 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
28380 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[3], 1);
28382 /* Reset viewports. */
28383 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
28384 ID3D11DeviceContext_RSSetViewports(context, 0, NULL);
28385 constant.draw_id = 3;
28386 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
28387 draw_quad(&test_context);
28388 check_texture_sub_resource_vec4(texture, 0, NULL, &expected_values[4], 1);
28390 /* Two viewports, only first scissor rectangle set. */
28391 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
28392 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
28393 rasterizer_desc.CullMode = D3D11_CULL_BACK;
28394 rasterizer_desc.DepthClipEnable = TRUE;
28395 rasterizer_desc.ScissorEnable = TRUE;
28396 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
28397 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
28399 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
28400 ID3D11RasterizerState_Release(rasterizer_state);
28402 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
28403 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
28405 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
28406 memset(&rects[1], 0, sizeof(*rects));
28407 ID3D11DeviceContext_RSSetScissorRects(context, 1, rects);
28408 constant.draw_id = 4;
28409 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
28410 draw_quad(&test_context);
28412 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
28413 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[5], 1);
28414 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
28415 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[6], 1);
28416 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
28417 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[7], 1);
28419 /* Set both rectangles. */
28420 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
28421 SetRect(&rects[1], width, 0, 2 * width, texture_desc.Height / 2);
28422 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
28423 ID3D11DeviceContext_RSSetScissorRects(context, 2, rects);
28424 constant.draw_id = 5;
28425 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
28426 draw_quad(&test_context);
28428 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
28429 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[8], 1);
28430 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
28431 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[9], 1);
28433 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height / 2 - 1);
28434 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[10], 1);
28435 SetRect(&rect, width, texture_desc.Height / 2, 2 * width - 1, texture_desc.Height - 1);
28436 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[11], 1);
28438 if (enable_debug_layer)
28439 goto done;
28441 /* Viewport count exceeding maximum value. */
28442 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
28444 vp[0].TopLeftX = 1.0f;
28445 vp[0].TopLeftY = 0.0f;
28446 vp[0].Width = width;
28447 vp[0].Height = texture_desc.Height;
28448 vp[0].MinDepth = 0.0f;
28449 vp[0].MaxDepth = 1.0f;
28450 for (i = 1; i < ARRAY_SIZE(vp); ++i)
28452 vp[i] = vp[0];
28454 ID3D11DeviceContext_RSSetViewports(context, ARRAY_SIZE(vp), vp);
28456 count = ARRAY_SIZE(vp);
28457 memset(vp, 0, sizeof(vp));
28458 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
28459 ok(count == 1, "Unexpected viewport count %d.\n", count);
28460 ok(vp[0].TopLeftX == 0.0f && vp[0].Width == width, "Unexpected viewport.\n");
28462 done:
28463 ID3D11RenderTargetView_Release(rtv);
28464 ID3D11Texture2D_Release(texture);
28466 ID3D11Buffer_Release(cb);
28467 ID3D11GeometryShader_Release(gs);
28468 ID3D11PixelShader_Release(ps);
28469 release_test_context(&test_context);
28472 static void test_multisample_resolve(void)
28474 struct d3d11_test_context test_context;
28475 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
28476 ID3D11Texture2D *texture, *ms_texture;
28477 D3D11_TEXTURE2D_DESC texture_desc;
28478 ID3D11DeviceContext *context;
28479 ID3D11RenderTargetView *rtv;
28480 ID3D11Device *device;
28481 unsigned int i;
28482 HRESULT hr;
28484 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28485 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
28486 static const struct vec4 color = {0.25f, 0.5f, 0.75f, 1.0f};
28487 static const struct
28489 DXGI_FORMAT src_format;
28490 DXGI_FORMAT dst_format;
28491 DXGI_FORMAT format;
28493 DXGI_FORMAT rtv_format;
28495 const struct vec4 *color;
28496 DWORD expected_color;
28498 BOOL todo;
28500 tests[] =
28502 {DXGI_FORMAT_R8G8B8A8_UNORM,
28503 DXGI_FORMAT_R8G8B8A8_UNORM,
28504 DXGI_FORMAT_R8G8B8A8_UNORM,
28505 DXGI_FORMAT_R8G8B8A8_UNORM,
28506 &green, 0xff00ff00},
28507 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28508 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28509 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28510 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28511 &green, 0xff00ff00},
28512 {DXGI_FORMAT_R8G8B8A8_UNORM,
28513 DXGI_FORMAT_R8G8B8A8_UNORM,
28514 DXGI_FORMAT_R8G8B8A8_UNORM,
28515 DXGI_FORMAT_R8G8B8A8_UNORM,
28516 &color, 0xffbf7f40},
28517 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28518 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28519 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28520 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28521 &color, 0xffe1bc89},
28523 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28524 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28525 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28526 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28527 &green, 0xff00ff00},
28528 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
28529 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28530 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28531 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28532 &green, 0xff00ff00},
28533 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28534 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28535 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28536 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28537 &color, 0xffe1bc89, TRUE},
28538 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
28539 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28540 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28541 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28542 &color, 0xffe1bc89},
28544 {DXGI_FORMAT_R8G8B8A8_UNORM,
28545 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28546 DXGI_FORMAT_R8G8B8A8_UNORM,
28547 DXGI_FORMAT_R8G8B8A8_UNORM,
28548 &green, 0xff00ff00},
28549 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
28550 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28551 DXGI_FORMAT_R8G8B8A8_UNORM,
28552 DXGI_FORMAT_R8G8B8A8_UNORM,
28553 &green, 0xff00ff00},
28554 {DXGI_FORMAT_R8G8B8A8_UNORM,
28555 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28556 DXGI_FORMAT_R8G8B8A8_UNORM,
28557 DXGI_FORMAT_R8G8B8A8_UNORM,
28558 &color, 0xffbf7f40},
28559 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
28560 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28561 DXGI_FORMAT_R8G8B8A8_UNORM,
28562 DXGI_FORMAT_R8G8B8A8_UNORM,
28563 &color, 0xffbf7f40},
28565 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
28566 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28567 DXGI_FORMAT_R8G8B8A8_UNORM,
28568 DXGI_FORMAT_R8G8B8A8_UNORM,
28569 &green, 0xff00ff00},
28570 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
28571 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28572 DXGI_FORMAT_R8G8B8A8_UNORM,
28573 DXGI_FORMAT_R8G8B8A8_UNORM,
28574 &color, 0xffbf7f40},
28575 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
28576 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28577 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28578 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28579 &green, 0xff00ff00},
28580 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
28581 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28582 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28583 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28584 &color, 0xffe1bc89},
28585 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
28586 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28587 DXGI_FORMAT_R8G8B8A8_UNORM,
28588 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28589 &green, 0xff00ff00},
28590 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
28591 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28592 DXGI_FORMAT_R8G8B8A8_UNORM,
28593 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28594 &color, 0xffe1bc89},
28595 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
28596 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28597 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28598 DXGI_FORMAT_R8G8B8A8_UNORM,
28599 &green, 0xff00ff00},
28600 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
28601 DXGI_FORMAT_R8G8B8A8_TYPELESS,
28602 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
28603 DXGI_FORMAT_R8G8B8A8_UNORM,
28604 &color, 0xffbf7f40},
28607 if (!init_test_context(&test_context, NULL))
28608 return;
28609 device = test_context.device;
28610 context = test_context.immediate_context;
28612 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &i);
28613 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
28614 if (!i)
28616 skip("4xMSAA not supported.\n");
28617 release_test_context(&test_context);
28618 return;
28621 for (i = 0; i < ARRAY_SIZE(tests); ++i)
28623 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
28624 texture_desc.Format = tests[i].dst_format;
28625 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
28626 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
28628 texture_desc.Format = tests[i].src_format;
28629 texture_desc.SampleDesc.Count = 4;
28630 texture_desc.SampleDesc.Quality = 0;
28631 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ms_texture);
28632 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
28633 rtv_desc.Format = tests[i].rtv_format;
28634 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
28635 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)ms_texture, &rtv_desc, &rtv);
28636 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
28638 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
28639 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
28640 draw_color_quad(&test_context, tests[i].color);
28641 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)texture, 0,
28642 (ID3D11Resource *)ms_texture, 0, tests[i].format);
28643 todo_wine_if(tests[i].todo)
28644 check_texture_color(texture, tests[i].expected_color, 2);
28646 ID3D11RenderTargetView_Release(rtv);
28647 ID3D11Texture2D_Release(ms_texture);
28648 ID3D11Texture2D_Release(texture);
28651 release_test_context(&test_context);
28654 static void test_sample_shading(void)
28656 struct shader
28658 const DWORD *code;
28659 size_t size;
28662 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
28663 struct d3d11_test_context test_context;
28664 struct swapchain_desc swapchain_desc;
28665 D3D11_TEXTURE2D_DESC texture_desc;
28666 ID3D11UnorderedAccessView *uav;
28667 D3D11_BUFFER_DESC buffer_desc;
28668 ID3D11ShaderResourceView *srv;
28669 ID3D11DeviceContext *context;
28670 ID3D11RenderTargetView *rtv;
28671 struct resource_readback rb;
28672 ID3D11Buffer *buffer, *cb;
28673 ID3D11Texture2D *texture;
28674 struct uvec4 ps_constant;
28675 ID3D11PixelShader *ps;
28676 ID3D11Device *device;
28677 unsigned int data;
28678 unsigned int i;
28679 HRESULT hr;
28681 static const DWORD ps_unused_sample_index_code[] =
28683 #if 0
28684 RWByteAddressBuffer u;
28686 float4 main(uint id : SV_SampleIndex) : SV_Target
28688 u.InterlockedAdd(0, 1);
28689 return float4(0.0f, 1.0f, 0.0f, 1.0f);
28691 #endif
28692 0x43425844, 0x41e4574b, 0x1e6441d6, 0x5e756375, 0xacd5dc27, 0x00000001, 0x00000104, 0x00000003,
28693 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
28694 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000001, 0x535f5653, 0x6c706d61, 0x646e4965,
28695 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
28696 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064,
28697 0x00000050, 0x00000019, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2,
28698 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
28699 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
28700 0x0100003e,
28702 static const struct shader ps_unused_sample_index
28703 = {ps_unused_sample_index_code, sizeof(ps_unused_sample_index_code)};
28704 static const DWORD ps_sample_index_code[] =
28706 #if 0
28707 RWByteAddressBuffer u;
28709 float4 main(uint id : SV_SampleIndex) : SV_Target
28711 u.InterlockedAdd(0, 1);
28712 u.InterlockedAdd(4, id);
28713 return float4(0.0f, 1.0f, 0.0f, 1.0f);
28715 #endif
28716 0x43425844, 0x943ab9ed, 0x91520b4a, 0xb75df9d0, 0x692cd3e6, 0x00000001, 0x00000130, 0x00000003,
28717 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
28718 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
28719 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
28720 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000090,
28721 0x00000050, 0x00000024, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
28722 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001,
28723 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
28724 0x00000004, 0x0010100a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
28725 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
28727 static const struct shader ps_sample_index = {ps_sample_index_code, sizeof(ps_sample_index_code)};
28728 static const DWORD ps_samplepos_code[] =
28730 #if 0
28731 Texture2DMS<float> t;
28732 RWByteAddressBuffer u;
28734 float4 main() : SV_Target
28736 float2 sample_position = t.GetSamplePosition(0);
28737 u.InterlockedAdd(0, 1);
28738 u.InterlockedAdd(4, sample_position.x + sample_position.y);
28739 return float4(0.0f, 1.0f, 0.0f, 1.0f);
28741 #endif
28742 0x43425844, 0x9ec7f344, 0x588f5863, 0x436c0531, 0x69dc54bb, 0x00000001, 0x00000160, 0x00000003,
28743 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28744 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28745 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e8, 0x00000050, 0x0000003a,
28746 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
28747 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
28748 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0800006e, 0x00100032, 0x00000000, 0x00107046,
28749 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
28750 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
28751 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
28752 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
28754 static const struct shader ps_samplepos = {ps_samplepos_code, sizeof(ps_samplepos_code)};
28755 static const DWORD ps_samplepos_rasterizer_code[] =
28757 #if 0
28758 RWByteAddressBuffer u;
28760 float4 main() : SV_Target
28762 float2 sample_position = GetRenderTargetSamplePosition(0);
28763 u.InterlockedAdd(0, 1);
28764 u.InterlockedAdd(4, sample_position.x + sample_position.y);
28765 return float4(0.0f, 1.0f, 0.0f, 1.0f);
28767 #endif
28768 0x43425844, 0xe31795d9, 0x4e9951da, 0xc1713913, 0xfb12da31, 0x00000001, 0x00000148, 0x00000003,
28769 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28770 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28771 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d0, 0x00000050, 0x00000034,
28772 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
28773 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
28774 0x0600006e, 0x00100032, 0x00000000, 0x0000e046, 0x00004001, 0x00000000, 0x07000000, 0x00100012,
28775 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
28776 0x0010000a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
28777 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
28778 0x3f800000, 0x0100003e,
28780 static const struct shader ps_samplepos_rasterizer
28781 = {ps_samplepos_rasterizer_code, sizeof(ps_samplepos_rasterizer_code)};
28782 static const DWORD ps_samplepos_indexed_code[] =
28784 #if 0
28785 RWByteAddressBuffer u;
28787 float4 main(uint id : SV_SampleIndex) : SV_Target
28789 float2 sample_position = GetRenderTargetSamplePosition(id);
28790 u.InterlockedAdd(0, 1);
28791 u.InterlockedAdd(4, sample_position.x + sample_position.y);
28792 return float4(0.0f, 1.0f, 0.0f, 1.0f);
28794 #endif
28795 0x43425844, 0x4b501464, 0x0cd4f636, 0x36428677, 0x6db6b4fb, 0x00000001, 0x00000180, 0x00000003,
28796 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
28797 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
28798 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
28799 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e0,
28800 0x00000050, 0x00000038, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
28801 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad,
28802 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0600006e, 0x00100032,
28803 0x00000000, 0x0000e046, 0x0010100a, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
28804 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
28805 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
28806 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
28808 static const struct shader ps_samplepos_indexed
28809 = {ps_samplepos_indexed_code, sizeof(ps_samplepos_indexed_code)};
28810 static const DWORD ps_sampleinfo_code[] =
28812 #if 0
28813 Texture2DMS<float> t;
28814 RWByteAddressBuffer u;
28816 float4 main() : SV_Target
28818 uint width, height, sample_count;
28819 t.GetDimensions(width, height, sample_count);
28820 u.InterlockedAdd(0, 1);
28821 u.InterlockedAdd(4, sample_count);
28822 return float4(0.0f, 1.0f, 0.0f, 1.0f);
28824 #endif
28825 0x43425844, 0x4e4f4065, 0x20d88902, 0xd4750e8c, 0x652b8c04, 0x00000001, 0x00000124, 0x00000003,
28826 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28827 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28828 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050, 0x0000002b,
28829 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
28830 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
28831 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a,
28832 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000,
28833 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
28834 0x0100003e,
28836 static const struct shader ps_sampleinfo = {ps_sampleinfo_code, sizeof(ps_sampleinfo_code)};
28837 static const DWORD ps_sampleinfo_rasterizer_code[] =
28839 #if 0
28840 RWByteAddressBuffer u;
28842 float4 main() : SV_Target
28844 uint sample_count = GetRenderTargetSampleCount();
28845 u.InterlockedAdd(0, 1);
28846 u.InterlockedAdd(4, sample_count);
28847 return float4(0.0f, 1.0f, 0.0f, 1.0f);
28849 #endif
28850 0x43425844, 0xfbbd8619, 0x9c2654c8, 0xb385363a, 0x4aacd10f, 0x00000001, 0x00000110, 0x00000003,
28851 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28852 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28853 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000098, 0x00000050, 0x00000026,
28854 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
28855 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
28856 0x0400086f, 0x00100012, 0x00000000, 0x0000e00a, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
28857 0x00000004, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
28858 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
28860 static const struct shader ps_sampleinfo_rasterizer
28861 = {ps_sampleinfo_rasterizer_code, sizeof(ps_sampleinfo_rasterizer_code)};
28862 static const DWORD ps_sample_code[] =
28864 #if 0
28865 RWByteAddressBuffer u;
28867 float4 main(sample float4 position : SV_Position) : SV_Target
28869 u.InterlockedAdd(0, 1);
28870 u.InterlockedAdd(4, position.x);
28871 return float4(0.0f, 1.0f, 0.0f, 1.0f);
28873 #endif
28874 0x43425844, 0x46ecbadb, 0xedccbea6, 0x236d7923, 0x0c356c8c, 0x00000001, 0x00000148, 0x00000003,
28875 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
28876 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x7469736f, 0x006e6f69,
28877 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
28878 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050,
28879 0x0000002b, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04003864, 0x00101012, 0x00000000,
28880 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000,
28881 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500001c, 0x00100012, 0x00000000,
28882 0x0010100a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
28883 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
28884 0x3f800000, 0x0100003e,
28886 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
28887 static const DWORD ps_color_code[] =
28889 #if 0
28890 float4 main(uint id : SV_SampleIndex) : SV_Target
28892 switch (id)
28894 case 0: return float4(1.0f, 0.0f, 0.0f, 1.0f);
28895 case 1: return float4(0.0f, 1.0f, 0.0f, 1.0f);
28896 case 2: return float4(0.0f, 0.0f, 1.0f, 1.0f);
28897 default: return float4(0.0f, 0.0f, 0.0f, 1.0f);
28900 #endif
28901 0x43425844, 0x94c35f48, 0x04c6b0f7, 0x407d8214, 0xc24f01e5, 0x00000001, 0x00000194, 0x00000003,
28902 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
28903 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
28904 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
28905 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f4,
28906 0x00000050, 0x0000003d, 0x0100086a, 0x04000863, 0x00101012, 0x00000000, 0x0000000a, 0x03000065,
28907 0x001020f2, 0x00000000, 0x0300004c, 0x0010100a, 0x00000000, 0x03000006, 0x00004001, 0x00000000,
28908 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
28909 0x0100003e, 0x03000006, 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
28910 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x03000006, 0x00004001, 0x00000002,
28911 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000,
28912 0x0100003e, 0x0100000a, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
28913 0x00000000, 0x3f800000, 0x0100003e, 0x01000017, 0x0100003e,
28915 static const DWORD ps_resolve_code[] =
28917 #if 0
28918 Texture2DMS<float4> t;
28920 uint sample;
28921 uint rt_size;
28923 float4 main(float4 position : SV_Position) : SV_Target
28925 float3 p;
28926 t.GetDimensions(p.x, p.y, p.z);
28927 p *= float3(position.x / rt_size, position.y / rt_size, 0);
28928 return t.Load((int2)p.xy, sample);
28930 #endif
28931 0x43425844, 0x68a4590b, 0xc1ec3070, 0x1b957c43, 0x0c080741, 0x00000001, 0x000001c8, 0x00000003,
28932 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
28933 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
28934 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
28935 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000012c, 0x00000050,
28936 0x0000004b, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002058, 0x00107000,
28937 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
28938 0x00000000, 0x02000068, 0x00000001, 0x06000056, 0x00100012, 0x00000000, 0x0020801a, 0x00000000,
28939 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00100006, 0x00000000,
28940 0x8900003d, 0x80000102, 0x00155543, 0x001000c2, 0x00000000, 0x00004001, 0x00000000, 0x001074e6,
28941 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000,
28942 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000,
28943 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8c00002e, 0x80000102, 0x00155543,
28944 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0020800a, 0x00000000,
28945 0x00000000, 0x0100003e,
28947 static const struct
28949 const struct shader *ps;
28950 BOOL sample_shading;
28951 BOOL todo;
28952 BOOL broken;
28954 tests[] =
28956 {&ps_unused_sample_index, FALSE, FALSE, TRUE /* broken on Nvidia */},
28957 {&ps_sample_index, TRUE},
28958 {&ps_samplepos, FALSE},
28959 {&ps_samplepos_rasterizer, FALSE},
28960 {&ps_samplepos_indexed, TRUE, TRUE},
28961 {&ps_sampleinfo, FALSE},
28962 {&ps_sampleinfo_rasterizer, FALSE},
28963 {&ps_sample, TRUE, TRUE, TRUE /* broken on Intel */},
28965 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
28966 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28967 static const unsigned int zero[4] = {0};
28969 swapchain_desc.windowed = TRUE;
28970 swapchain_desc.buffer_count = 1;
28971 swapchain_desc.width = 32;
28972 swapchain_desc.height = 32;
28973 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
28974 swapchain_desc.flags = 0;
28975 if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc))
28976 return;
28977 device = test_context.device;
28978 context = test_context.immediate_context;
28980 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
28981 texture_desc.SampleDesc.Count = 4;
28982 texture_desc.SampleDesc.Quality = 0;
28983 texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
28984 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
28985 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
28986 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
28987 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
28988 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
28989 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
28991 buffer_desc.ByteWidth = 1024;
28992 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
28993 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
28994 buffer_desc.CPUAccessFlags = 0;
28995 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
28996 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
28997 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
28998 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
28999 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
29000 U(uav_desc).Buffer.FirstElement = 0;
29001 U(uav_desc).Buffer.NumElements = 256;
29002 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
29003 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
29004 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
29006 for (i = 0; i < ARRAY_SIZE(tests); ++i)
29008 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
29009 ok(hr == S_OK, "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
29010 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29012 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
29013 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29014 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
29015 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL);
29016 draw_quad(&test_context);
29017 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
29018 get_buffer_readback(buffer, &rb);
29019 data = get_readback_color(&rb, 0, 0, 0);
29020 ok(1024 <= data && data <= 1056, "Test %u: Got unexpected value %u.\n", i, data);
29021 release_resource_readback(&rb);
29023 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
29024 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
29025 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
29026 1, &rtv, NULL, 1, 1, &uav, NULL);
29027 draw_quad(&test_context);
29028 get_buffer_readback(buffer, &rb);
29029 data = get_readback_color(&rb, 0, 0, 0);
29030 todo_wine_if(tests[i].todo)
29032 if (tests[i].sample_shading)
29034 ok(4096 <= data || broken(tests[i].broken && data >= 1024),
29035 "Test %u: Got unexpected value %u.\n", i, data);
29037 else
29039 ok((1024 <= data && data <= 1056) || broken(tests[i].broken && data >= 4096),
29040 "Test %u: Got unexpected value %u.\n", i, data);
29043 release_resource_readback(&rb);
29045 ID3D11PixelShader_Release(ps);
29048 if (is_warp_device(device))
29050 skip("Sample shading tests fail on WARP.\n");
29051 goto done;
29054 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps);
29055 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
29056 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29057 ID3D11PixelShader_Release(ps);
29059 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
29060 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
29061 draw_quad(&test_context);
29062 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
29063 (ID3D11Resource *)texture, 0, texture_desc.Format);
29064 check_texture_color(test_context.backbuffer, 0xff404040, 2);
29066 hr = ID3D11Device_CreatePixelShader(device, ps_resolve_code, sizeof(ps_resolve_code), NULL, &ps);
29067 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
29068 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29069 ID3D11PixelShader_Release(ps);
29070 ps_constant.x = 0;
29071 ps_constant.y = texture_desc.Width;
29072 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
29073 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
29075 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29076 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
29077 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
29078 draw_quad(&test_context);
29079 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
29080 ps_constant.x = 1;
29081 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
29082 draw_quad(&test_context);
29083 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
29084 ps_constant.x = 2;
29085 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
29086 draw_quad(&test_context);
29087 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
29088 ps_constant.x = 3;
29089 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
29090 draw_quad(&test_context);
29091 check_texture_color(test_context.backbuffer, 0xff000000, 0);
29093 ID3D11Buffer_Release(cb);
29094 done:
29095 ID3D11Buffer_Release(buffer);
29096 ID3D11UnorderedAccessView_Release(uav);
29097 ID3D11RenderTargetView_Release(rtv);
29098 ID3D11ShaderResourceView_Release(srv);
29099 ID3D11Texture2D_Release(texture);
29100 release_test_context(&test_context);
29103 static void test_sample_mask(void)
29105 static const DWORD ps_code[] =
29107 #if 0
29108 float4 main(in float4 pos : SV_Position, out uint sample_mask : SV_Coverage) : SV_Target
29110 sample_mask = 0x5;
29111 return float4(1.0, 1.0, 1.0, 1.0);
29113 #endif
29114 0x43425844, 0x196779a9, 0xda85988a, 0xb7f0a0b6, 0xb30dd6ba, 0x00000001, 0x00000114, 0x00000003,
29115 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29116 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
29117 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
29118 0x00000000, 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000001, 0xffffffff, 0x00000e01,
29119 0x545f5653, 0x65677261, 0x56530074, 0x766f435f, 0x67617265, 0xabab0065, 0x58454853, 0x00000054,
29120 0x00000050, 0x00000015, 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x0000f000,
29121 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
29122 0x04000036, 0x0000f001, 0x00004001, 0x00000005, 0x0100003e,
29124 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
29125 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
29126 struct d3d11_test_context test_context;
29127 D3D11_TEXTURE2D_DESC texture_desc;
29128 ID3D11DeviceContext *context;
29129 ID3D11RenderTargetView *rtv;
29130 ID3D11Texture2D *texture;
29131 ID3D11PixelShader *ps;
29132 ID3D11Device *device;
29133 UINT quality_levels;
29134 HRESULT hr;
29136 if (!init_test_context(&test_context, &feature_level))
29137 return;
29138 device = test_context.device;
29139 context = test_context.immediate_context;
29141 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &quality_levels);
29142 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
29143 if (!quality_levels)
29145 skip("4xMSAA not supported.\n");
29146 release_test_context(&test_context);
29147 return;
29150 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
29151 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
29152 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29154 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
29155 texture_desc.SampleDesc.Count = 4;
29156 texture_desc.SampleDesc.Quality = 0;
29157 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
29158 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
29159 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
29160 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
29162 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
29163 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
29164 draw_quad(&test_context);
29165 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
29166 (ID3D11Resource *)texture, 0, texture_desc.Format);
29167 check_texture_color(test_context.backbuffer, 0x7f7f7f7f, 1);
29169 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, 0xb);
29170 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
29171 draw_quad(&test_context);
29172 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
29173 (ID3D11Resource *)texture, 0, texture_desc.Format);
29174 check_texture_color(test_context.backbuffer, 0x3f3f3f3f, 1);
29176 ID3D11RenderTargetView_Release(rtv);
29177 ID3D11Texture2D_Release(texture);
29178 ID3D11PixelShader_Release(ps);
29179 release_test_context(&test_context);
29182 static void test_depth_clip(void)
29184 struct d3d11_test_context test_context;
29185 D3D11_TEXTURE2D_DESC texture_desc;
29186 D3D11_RASTERIZER_DESC rs_desc;
29187 ID3D11DeviceContext *context;
29188 ID3D11DepthStencilView *dsv;
29189 ID3D11RasterizerState *rs;
29190 ID3D11Texture2D *texture;
29191 ID3D11Device *device;
29192 unsigned int count;
29193 D3D11_VIEWPORT vp;
29194 HRESULT hr;
29196 if (!init_test_context(&test_context, NULL))
29197 return;
29198 device = test_context.device;
29199 context = test_context.immediate_context;
29201 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
29202 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
29203 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
29205 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
29206 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
29207 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
29208 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
29209 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
29211 count = 1;
29212 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
29214 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
29215 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
29216 draw_quad_z(&test_context, 2.0f);
29217 check_texture_float(texture, 1.0f, 1);
29218 draw_quad_z(&test_context, 0.5f);
29219 check_texture_float(texture, 0.5f, 1);
29220 draw_quad_z(&test_context, -1.0f);
29221 check_texture_float(texture, 0.5f, 1);
29223 rs_desc.FillMode = D3D11_FILL_SOLID;
29224 rs_desc.CullMode = D3D11_CULL_BACK;
29225 rs_desc.FrontCounterClockwise = FALSE;
29226 rs_desc.DepthBias = 0;
29227 rs_desc.DepthBiasClamp = 0.0f;
29228 rs_desc.SlopeScaledDepthBias = 0.0f;
29229 rs_desc.DepthClipEnable = FALSE;
29230 rs_desc.ScissorEnable = FALSE;
29231 rs_desc.MultisampleEnable = FALSE;
29232 rs_desc.AntialiasedLineEnable = FALSE;
29233 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
29234 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
29236 ID3D11DeviceContext_RSSetState(context, rs);
29238 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
29239 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
29240 draw_quad_z(&test_context, 2.0f);
29241 check_texture_float(texture, 0.6f, 1);
29242 draw_quad_z(&test_context, 0.5f);
29243 check_texture_float(texture, 0.5f, 1);
29244 draw_quad_z(&test_context, -1.0f);
29245 check_texture_float(texture, 0.4f, 1);
29247 ID3D11DepthStencilView_Release(dsv);
29248 ID3D11Texture2D_Release(texture);
29249 ID3D11RasterizerState_Release(rs);
29250 release_test_context(&test_context);
29253 static void test_staging_buffers(void)
29255 struct d3d11_test_context test_context;
29256 ID3D11Buffer *dst_buffer, *src_buffer;
29257 D3D11_SUBRESOURCE_DATA resource_data;
29258 D3D11_BUFFER_DESC buffer_desc;
29259 ID3D11DeviceContext *context;
29260 struct resource_readback rb;
29261 float data[16], value;
29262 ID3D11Device *device;
29263 unsigned int i;
29264 HRESULT hr;
29266 if (!init_test_context(&test_context, NULL))
29267 return;
29268 device = test_context.device;
29269 context = test_context.immediate_context;
29271 buffer_desc.ByteWidth = sizeof(data);
29272 buffer_desc.Usage = D3D11_USAGE_STAGING;
29273 buffer_desc.BindFlags = 0;
29274 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
29275 buffer_desc.MiscFlags = 0;
29276 buffer_desc.StructureByteStride = 0;
29278 for (i = 0; i < ARRAY_SIZE(data); ++i)
29279 data[i] = i;
29280 resource_data.pSysMem = data;
29281 resource_data.SysMemPitch = 0;
29282 resource_data.SysMemSlicePitch = 0;
29284 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &src_buffer);
29285 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
29287 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
29288 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
29289 buffer_desc.CPUAccessFlags = 0;
29290 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &dst_buffer);
29291 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
29293 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
29294 get_buffer_readback(dst_buffer, &rb);
29295 for (i = 0; i < ARRAY_SIZE(data); ++i)
29297 value = get_readback_float(&rb, i, 0);
29298 ok(value == data[i], "Got unexpected value %.8e at %u.\n", value, i);
29300 release_resource_readback(&rb);
29302 for (i = 0; i < ARRAY_SIZE(data); ++i)
29303 data[i] = 2 * i;
29304 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, NULL, data, 0, 0);
29305 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
29306 get_buffer_readback(dst_buffer, &rb);
29307 for (i = 0; i < ARRAY_SIZE(data); ++i)
29309 value = get_readback_float(&rb, i, 0);
29310 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
29312 release_resource_readback(&rb);
29314 ID3D11Buffer_Release(dst_buffer);
29315 ID3D11Buffer_Release(src_buffer);
29316 release_test_context(&test_context);
29319 static void test_render_a8(void)
29321 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
29322 struct d3d11_test_context test_context;
29323 D3D11_TEXTURE2D_DESC texture_desc;
29324 ID3D11DeviceContext *context;
29325 ID3D11RenderTargetView *rtv;
29326 struct resource_readback rb;
29327 ID3D11Texture2D *texture;
29328 ID3D11PixelShader *ps;
29329 ID3D11Device *device;
29330 unsigned int i;
29331 HRESULT hr;
29333 static const DWORD ps_code[] =
29335 #if 0
29336 void main(out float4 target : SV_Target)
29338 target = float4(0.0f, 0.25f, 0.5f, 1.0f);
29340 #endif
29341 0x43425844, 0x8a06129f, 0x3041bde2, 0x09389749, 0xb339ba8b, 0x00000001, 0x000000b0, 0x00000003,
29342 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
29343 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
29344 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
29345 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
29346 0x3e800000, 0x3f000000, 0x3f800000, 0x0100003e,
29349 if (!init_test_context(&test_context, NULL))
29350 return;
29351 device = test_context.device;
29352 context = test_context.immediate_context;
29354 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
29355 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
29356 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29358 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
29359 texture_desc.Format = DXGI_FORMAT_A8_UNORM;
29360 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
29361 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
29362 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
29363 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
29365 for (i = 0; i < 2; ++i)
29367 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
29368 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
29369 draw_quad(&test_context);
29370 get_texture_readback(texture, 0, &rb);
29371 check_readback_data_u8(&rb, NULL, 0xff, 0);
29372 release_resource_readback(&rb);
29374 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
29375 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
29376 draw_quad(&test_context);
29377 check_texture_sub_resource_color(test_context.backbuffer, 0, NULL, 0xff7f4000, 1);
29380 ID3D11PixelShader_Release(ps);
29381 ID3D11Texture2D_Release(texture);
29382 ID3D11RenderTargetView_Release(rtv);
29383 release_test_context(&test_context);
29386 static void test_standard_pattern(void)
29388 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
29389 struct d3d11_test_context test_context;
29390 struct swapchain_desc swapchain_desc;
29391 D3D11_TEXTURE2D_DESC texture_desc;
29392 ID3D11UnorderedAccessView *uav;
29393 D3D11_BUFFER_DESC buffer_desc;
29394 ID3D11ShaderResourceView *srv;
29395 ID3D11DeviceContext *context;
29396 struct resource_readback rb;
29397 ID3D11Texture2D *texture;
29398 ID3D11PixelShader *ps;
29399 ID3D11Buffer *buffer;
29400 ID3D11Device *device;
29401 unsigned int i;
29402 HRESULT hr;
29404 static const DWORD ps_samplepos[] =
29406 #if 0
29407 Texture2DMS<float> t;
29408 RWByteAddressBuffer u;
29410 float4 main() : SV_Target
29412 u.Store2(0, asuint(t.GetSamplePosition(0)));
29413 u.Store2(8, asuint(t.GetSamplePosition(1)));
29414 u.Store2(16, asuint(t.GetSamplePosition(2)));
29415 u.Store2(24, asuint(t.GetSamplePosition(3)));
29416 return float4(0.0f, 1.0f, 0.0f, 1.0f);
29418 #endif
29419 0x43425844, 0xa1db77e8, 0x804d8862, 0x0e3c213d, 0x2703dec6, 0x00000001, 0x00000190, 0x00000003,
29420 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
29421 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
29422 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000118, 0x00000050, 0x00000046,
29423 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
29424 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0800006e, 0x00100032, 0x00000000,
29425 0x00107046, 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x0800006e, 0x001000c2, 0x00000000,
29426 0x00107406, 0x00000000, 0x00004001, 0x00000001, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001,
29427 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x0800006e, 0x00100032, 0x00000000, 0x00107046,
29428 0x00000000, 0x00004001, 0x00000002, 0x00000000, 0x0800006e, 0x001000c2, 0x00000000, 0x00107406,
29429 0x00000000, 0x00004001, 0x00000003, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001,
29430 0x00000010, 0x00100e46, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
29431 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e
29433 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
29434 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29435 static const unsigned int zero[4] = {0};
29436 static const float standard_pos4[] =
29438 -2 / 16.0f, -6 / 16.0f,
29439 6 / 16.0f, -2 / 16.0f,
29440 -6 / 16.0f, 2 / 16.0f,
29441 2 / 16.0f, 6 / 16.0f,
29444 swapchain_desc.windowed = TRUE;
29445 swapchain_desc.buffer_count = 1;
29446 swapchain_desc.width = 32;
29447 swapchain_desc.height = 32;
29448 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
29449 swapchain_desc.flags = 0;
29450 if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc))
29451 return;
29452 device = test_context.device;
29453 context = test_context.immediate_context;
29455 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
29456 texture_desc.SampleDesc.Count = 4;
29457 texture_desc.SampleDesc.Quality = D3D11_STANDARD_MULTISAMPLE_PATTERN;
29458 texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
29459 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
29460 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
29461 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
29462 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
29464 buffer_desc.ByteWidth = 1024;
29465 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
29466 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
29467 buffer_desc.CPUAccessFlags = 0;
29468 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
29469 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
29470 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
29471 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
29472 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
29473 U(uav_desc).Buffer.FirstElement = 0;
29474 U(uav_desc).Buffer.NumElements = 256;
29475 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
29476 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
29477 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
29479 hr = ID3D11Device_CreatePixelShader(device, ps_samplepos, sizeof(ps_samplepos), NULL, &ps);
29480 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
29481 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29483 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
29484 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29485 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
29486 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL);
29487 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
29488 draw_quad(&test_context);
29489 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
29490 get_buffer_readback(buffer, &rb);
29491 for (i = 0; i < ARRAY_SIZE(standard_pos4); ++i)
29493 float data = get_readback_float(&rb, i, 0);
29494 /* Wine does not support GetSamplePosition. */
29495 todo_wine ok(data == standard_pos4[i], "Got sample position %.8e, expected %.8e.\n", data, standard_pos4[i]);
29497 release_resource_readback(&rb);
29499 ID3D11PixelShader_Release(ps);
29500 ID3D11Buffer_Release(buffer);
29501 ID3D11UnorderedAccessView_Release(uav);
29502 ID3D11ShaderResourceView_Release(srv);
29503 ID3D11Texture2D_Release(texture);
29504 release_test_context(&test_context);
29507 static void test_desktop_window(void)
29509 ID3D11RenderTargetView *backbuffer_rtv;
29510 DXGI_SWAP_CHAIN_DESC swapchain_desc;
29511 ID3D11DeviceContext *context;
29512 ID3D11Texture2D *backbuffer;
29513 IDXGISwapChain *swapchain;
29514 IDXGIDevice *dxgi_device;
29515 IDXGIAdapter *adapter;
29516 IDXGIFactory *factory;
29517 ID3D11Device *device;
29518 ULONG refcount;
29519 HRESULT hr;
29521 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
29523 if (!(device = create_device(NULL)))
29525 skip("Failed to create device.\n");
29526 return;
29529 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
29530 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
29531 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
29532 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
29533 IDXGIDevice_Release(dxgi_device);
29534 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
29535 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
29536 IDXGIAdapter_Release(adapter);
29538 swapchain_desc.BufferDesc.Width = 640;
29539 swapchain_desc.BufferDesc.Height = 480;
29540 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
29541 swapchain_desc.BufferDesc.RefreshRate.Denominator = 1;
29542 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29543 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
29544 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
29545 swapchain_desc.SampleDesc.Count = 1;
29546 swapchain_desc.SampleDesc.Quality = 0;
29547 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
29548 swapchain_desc.BufferCount = 1;
29549 swapchain_desc.OutputWindow = GetDesktopWindow();
29550 swapchain_desc.Windowed = TRUE;
29551 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
29552 swapchain_desc.Flags = 0;
29554 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
29555 ok(hr == S_OK || broken(hr == DXGI_ERROR_INVALID_CALL) /* Not available on all Windows versions. */,
29556 "Failed to create swapchain, hr %#x.\n", hr);
29557 IDXGIFactory_Release(factory);
29558 if (FAILED(hr))
29560 ID3D11Device_Release(device);
29561 return;
29564 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
29565 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
29567 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &backbuffer_rtv);
29568 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
29570 ID3D11Device_GetImmediateContext(device, &context);
29572 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red);
29573 check_texture_color(backbuffer, 0xff0000ff, 1);
29575 hr = IDXGISwapChain_Present(swapchain, 0, 0);
29576 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
29578 ID3D11RenderTargetView_Release(backbuffer_rtv);
29579 ID3D11Texture2D_Release(backbuffer);
29580 IDXGISwapChain_Release(swapchain);
29581 ID3D11DeviceContext_Release(context);
29582 refcount = ID3D11Device_Release(device);
29583 ok(!refcount, "Device has %u references left.\n", refcount);
29586 static void test_sample_attached_rtv(void)
29588 ID3D11ShaderResourceView *srv, *srv2, *srv_test, *srv_ds;
29589 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc, srvds_desc;
29590 ID3D11Texture2D *texture, *texture2, *dstexture;
29591 ID3D11RenderTargetView *rtv, *rtv2, *rtvs[2];
29592 D3D11_DEPTH_STENCIL_VIEW_DESC dsview_desc;
29593 struct d3d11_test_context test_context;
29594 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
29595 D3D11_TEXTURE2D_DESC texture_desc;
29596 D3D_FEATURE_LEVEL feature_level;
29597 D3D11_SAMPLER_DESC sampler_desc;
29598 ID3D11DepthStencilView *dsview;
29599 ID3D11BlendState *blend_state;
29600 ID3D11DeviceContext *context;
29601 D3D11_BLEND_DESC blend_desc;
29602 ID3D11SamplerState *sampler;
29603 struct resource_readback rb;
29604 ID3D11PixelShader *ps;
29605 ID3D11Device *device;
29606 unsigned int x, y;
29607 unsigned int i;
29608 D3D11_BOX box;
29609 DWORD color;
29610 HRESULT hr;
29612 static const DWORD ps_ld_code[] =
29614 #if 0
29615 Texture2D t;
29617 struct PS_OUTPUT
29619 float4 color0: SV_Target0;
29620 float4 color1: SV_Target1;
29623 PS_OUTPUT main(float4 position : SV_POSITION)
29625 PS_OUTPUT output;
29626 float3 p;
29628 t.GetDimensions(0, p.x, p.y, p.z);
29629 p.z = 0;
29630 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
29631 output.color0 = output.color1 = t.Load(int3(p)) + float4(0.25, 0.25, 0.25, 0.25);
29632 return output;
29634 #endif
29635 0x43425844, 0x08dd0517, 0x07d7e538, 0x4cad261f, 0xa2ae5942, 0x00000001, 0x00000200, 0x00000003,
29636 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29637 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
29638 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
29639 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
29640 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000014c, 0x00000040, 0x00000053, 0x04001858,
29641 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
29642 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0700003d,
29643 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032,
29644 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000,
29645 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
29646 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0500001b,
29647 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46,
29648 0x00000000, 0x00107e46, 0x00000000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
29649 0x00004002, 0x3e800000, 0x3e800000, 0x3e800000, 0x3e800000, 0x05000036, 0x001020f2, 0x00000000,
29650 0x00100e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00100e46, 0x00000000, 0x0100003e,
29652 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
29653 static const struct
29655 DXGI_FORMAT texture_format, dsv_format, srv_format;
29656 UINT dsv_flags;
29657 BOOL srv_bind_allowed;
29659 ds_tests[] =
29661 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
29662 0, FALSE},
29663 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
29664 D3D11_DSV_READ_ONLY_DEPTH, TRUE},
29665 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_X24_TYPELESS_G8_UINT,
29666 D3D11_DSV_READ_ONLY_DEPTH, FALSE},
29667 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_X24_TYPELESS_G8_UINT,
29668 D3D11_DSV_READ_ONLY_STENCIL, TRUE},
29669 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT,
29670 0, FALSE},
29671 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT,
29672 D3D11_DSV_READ_ONLY_DEPTH, TRUE},
29675 if (!init_test_context(&test_context, NULL))
29676 return;
29678 device = test_context.device;
29679 context = test_context.immediate_context;
29681 feature_level = ID3D11Device_GetFeatureLevel(device);
29683 texture_desc.SampleDesc.Count = 1;
29684 texture_desc.SampleDesc.Quality = 0;
29685 texture_desc.Usage = D3D11_USAGE_DEFAULT;
29686 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
29687 texture_desc.CPUAccessFlags = 0;
29688 texture_desc.MiscFlags = 0;
29690 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
29691 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
29692 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
29693 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
29694 sampler_desc.MipLODBias = 0.0f;
29695 sampler_desc.MaxAnisotropy = 0;
29696 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
29697 sampler_desc.BorderColor[0] = 0.0f;
29698 sampler_desc.BorderColor[1] = 0.0f;
29699 sampler_desc.BorderColor[2] = 0.0f;
29700 sampler_desc.BorderColor[3] = 0.0f;
29701 sampler_desc.MinLOD = 0.0f;
29702 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
29704 hr = ID3D11Device_CreatePixelShader(device, ps_ld_code, sizeof(ps_ld_code), NULL, &ps);
29705 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
29707 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29709 texture_desc.Width = 64;
29710 texture_desc.Height = 64;
29711 texture_desc.MipLevels = 2;
29712 texture_desc.ArraySize = 1;
29713 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29715 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
29716 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
29718 texture_desc.Width = 640;
29719 texture_desc.Height = 480;
29720 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture2);
29721 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
29723 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
29724 sampler_desc.MipLODBias = 0.0f;
29725 sampler_desc.MinLOD = 0.0f;
29726 sampler_desc.MaxLOD = 0.0f;
29728 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
29729 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
29731 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
29733 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
29735 memset(&rtv_desc, 0, sizeof(rtv_desc));
29736 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29737 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
29738 U(rtv_desc).Texture2D.MipSlice = 0;
29740 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv);
29741 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
29742 U(rtv_desc).Texture2D.MipSlice = 1;
29743 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv2);
29744 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
29746 rtvs[0] = test_context.backbuffer_rtv;
29747 rtvs[1] = rtv;
29749 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
29751 memset(&srv_desc, 0, sizeof(srv_desc));
29752 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29753 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29754 U(srv_desc).Texture2D.MipLevels = 1;
29756 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
29757 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
29758 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
29760 draw_quad(&test_context);
29762 set_box(&box, 0, 0, 0, 320, 240, 1);
29763 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2, 1, 0, 0, 0, (ID3D11Resource *)texture2, 0, &box);
29765 get_texture_readback(texture2, 0, &rb);
29766 for (y = 0; y < 4; ++y)
29768 for (x = 0; x < 4; ++x)
29770 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
29771 ok(compare_color(color, 0x40404040, 2),
29772 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
29775 release_resource_readback(&rb);
29776 get_texture_readback(texture2, 1, &rb);
29777 for (y = 0; y < 4; ++y)
29779 for (x = 0; x < 4; ++x)
29781 color = get_readback_color(&rb, 40 + x * 80, 30 + y * 60, 0);
29782 ok(compare_color(color, 0x40404040, 2),
29783 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
29786 release_resource_readback(&rb);
29788 ID3D11ShaderResourceView_Release(srv);
29789 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
29791 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
29793 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv);
29794 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
29796 U(srv_desc).Texture2D.MostDetailedMip = 1;
29797 U(srv_desc).Texture2D.MipLevels = 1;
29798 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv2);
29799 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
29801 memset(&blend_desc, 0, sizeof(blend_desc));
29802 blend_desc.IndependentBlendEnable = TRUE;
29803 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
29804 blend_desc.RenderTarget[1].RenderTargetWriteMask = 0;
29805 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
29806 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
29807 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
29808 ID3D11BlendState_Release(blend_state);
29810 /* SRV does not get bound if resource is attached as render target, even if write mask is 0. */
29811 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
29812 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
29813 ok(!srv_test, "Unexpected SRV %p.\n", srv_test);
29815 blend_desc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
29816 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
29817 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
29818 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
29819 ID3D11BlendState_Release(blend_state);
29821 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
29823 draw_quad(&test_context);
29824 draw_quad(&test_context);
29826 get_texture_readback(test_context.backbuffer, 0, &rb);
29827 for (y = 0; y < 4; ++y)
29829 for (x = 0; x < 4; ++x)
29831 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
29832 ok(compare_color(color, 0x40404040, 2),
29833 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
29836 release_resource_readback(&rb);
29838 get_texture_readback(texture2, 0, &rb);
29839 for (y = 0; y < 4; ++y)
29841 for (x = 0; x < 4; ++x)
29843 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
29844 ok(compare_color(color, 0x40404040, 2),
29845 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
29848 release_resource_readback(&rb);
29850 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
29851 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
29852 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
29853 ok(!!srv_test, "Unexpected SRV %p.\n", srv_test);
29854 ID3D11ShaderResourceView_Release(srv_test);
29856 draw_quad(&test_context);
29857 get_texture_readback(test_context.backbuffer, 0, &rb);
29858 for (y = 0; y < 4; ++y)
29860 for (x = 0; x < 4; ++x)
29862 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
29863 ok(compare_color(color, 0x80808080, 2),
29864 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
29867 release_resource_readback(&rb);
29869 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
29871 /* SRV is reset when the same resource is set as render target. */
29872 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
29873 ok(!srv_test, "Unexpected SRV %p.\n", srv_test);
29875 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
29876 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
29877 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
29878 ok(!!srv_test, "Unexpected SRV %p.\n", srv_test);
29879 ID3D11ShaderResourceView_Release(srv_test);
29881 draw_quad(&test_context);
29882 get_texture_readback(test_context.backbuffer, 0, &rb);
29883 for (y = 0; y < 4; ++y)
29885 for (x = 0; x < 4; ++x)
29887 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
29888 ok(compare_color(color, 0x80808080, 2),
29889 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
29892 release_resource_readback(&rb);
29894 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
29895 memset(&dsview_desc, 0, sizeof(dsview_desc));
29896 dsview_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
29898 memset(&srvds_desc, 0, sizeof(srvds_desc));
29899 srvds_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29900 U(srvds_desc).Texture2D.MipLevels = 1;
29902 for (i = 0; i < ARRAY_SIZE(ds_tests); ++i)
29904 if (ds_tests[i].dsv_flags && feature_level < D3D_FEATURE_LEVEL_11_0)
29906 static unsigned int skip_once;
29908 if (!skip_once++)
29909 skip("Read only depths or stencils are not supported.\n");
29911 continue;
29914 texture_desc.Format = ds_tests[i].texture_format;
29915 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &dstexture);
29916 ok(hr == S_OK, "Test %u, got unexpected hr %#x.\n", i, hr);
29917 dsview_desc.Format = ds_tests[i].dsv_format;
29918 dsview_desc.Flags = ds_tests[i].dsv_flags;
29919 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)dstexture, &dsview_desc, &dsview);
29920 ok(hr == S_OK, "Test %u, got unexpected hr %#x.\n", i, hr);
29922 srvds_desc.Format = ds_tests[i].srv_format;
29923 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dstexture, &srvds_desc, &srv_ds);
29924 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
29926 ID3D11DeviceContext_OMSetRenderTargets(context, 1, rtvs, NULL);
29927 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_ds);
29928 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
29929 ok(!!srv_test, "Test %u, unexpected SRV %p.\n", i, srv_test);
29930 ID3D11ShaderResourceView_Release(srv_test);
29932 ID3D11DeviceContext_OMSetRenderTargets(context, 1, rtvs, dsview);
29933 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
29934 ok(!!srv_test == ds_tests[i].srv_bind_allowed, "Test %u, unexpected SRV %p.\n", i, srv_test);
29935 if (srv_test)
29936 ID3D11ShaderResourceView_Release(srv_test);
29938 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_ds);
29939 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
29940 ok(!!srv_test == ds_tests[i].srv_bind_allowed, "Test %u, unexpected SRV %p.\n", i, srv_test);
29941 if (srv_test)
29942 ID3D11ShaderResourceView_Release(srv_test);
29944 ID3D11Texture2D_Release(dstexture);
29945 ID3D11DepthStencilView_Release(dsview);
29946 ID3D11ShaderResourceView_Release(srv_ds);
29949 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
29951 ID3D11RenderTargetView_Release(rtv2);
29952 ID3D11RenderTargetView_Release(rtv);
29953 ID3D11ShaderResourceView_Release(srv2);
29954 ID3D11ShaderResourceView_Release(srv);
29955 ID3D11SamplerState_Release(sampler);
29956 ID3D11PixelShader_Release(ps);
29957 ID3D11Texture2D_Release(texture2);
29958 ID3D11Texture2D_Release(texture);
29959 ID3D11SamplerState_Release(sampler);
29961 release_test_context(&test_context);
29964 static void test_color_mask(void)
29966 struct d3d11_test_context test_context;
29967 D3D11_TEXTURE2D_DESC texture_desc;
29968 ID3D11RenderTargetView *rtvs[8];
29969 ID3D11BlendState *blend_state;
29970 ID3D11DeviceContext *context;
29971 struct resource_readback rb;
29972 D3D11_BLEND_DESC blend_desc;
29973 ID3D11Texture2D *rts[8];
29974 ID3D11PixelShader *ps;
29975 ID3D11Device *device;
29976 unsigned int i;
29977 DWORD color;
29978 HRESULT hr;
29980 static const DWORD expected_colors[] =
29981 {0xff000080, 0xff0080ff, 0xff8000ff, 0x80808080, 0x800000ff, 0xff008080, 0x800080ff, 0xff0000ff};
29983 static const DWORD ps_code[] =
29985 #if 0
29986 void main(float4 position : SV_Position,
29987 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
29988 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
29989 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
29990 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
29992 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.5f, 0.5f, 0.5f, 0.5f);
29994 #endif
29995 0x43425844, 0x7b1ab233, 0xdbe32d3b, 0x77084cc5, 0xe874d2b5, 0x00000001, 0x000002b0, 0x00000003,
29996 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29997 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
29998 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
29999 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
30000 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
30001 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
30002 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
30003 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
30004 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
30005 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
30006 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
30007 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
30008 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000,
30009 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000,
30010 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3f000000,
30011 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3f000000,
30012 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3f000000,
30013 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3f000000,
30014 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3f000000,
30015 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3f000000,
30016 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
30019 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
30021 if (!init_test_context(&test_context, NULL))
30022 return;
30024 device = test_context.device;
30025 context = test_context.immediate_context;
30027 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30028 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30029 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30031 memset(&blend_desc, 0, sizeof(blend_desc));
30032 blend_desc.IndependentBlendEnable = TRUE;
30033 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED;
30034 blend_desc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN;
30035 blend_desc.RenderTarget[2].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_BLUE;
30036 blend_desc.RenderTarget[3].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
30037 blend_desc.RenderTarget[4].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALPHA;
30038 blend_desc.RenderTarget[5].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED | D3D11_COLOR_WRITE_ENABLE_GREEN;
30039 blend_desc.RenderTarget[6].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN | D3D11_COLOR_WRITE_ENABLE_ALPHA;
30040 blend_desc.RenderTarget[7].RenderTargetWriteMask = 0;
30042 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
30043 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
30044 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
30045 ID3D11BlendState_Release(blend_state);
30047 for (i = 0; i < 8; ++i)
30049 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30050 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
30051 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
30053 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rts[i], NULL, &rtvs[i]);
30054 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
30057 ID3D11DeviceContext_OMSetRenderTargets(context, 8, rtvs, NULL);
30059 for (i = 0; i < 8; ++i)
30060 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], red);
30061 draw_quad(&test_context);
30063 for (i = 0; i < 8; ++i)
30065 get_texture_readback(rts[i], 0, &rb);
30066 color = get_readback_color(&rb, 320, 240, 0);
30067 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
30068 release_resource_readback(&rb);
30071 blend_desc.IndependentBlendEnable = FALSE;
30072 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
30073 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
30074 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
30075 ID3D11BlendState_Release(blend_state);
30077 for (i = 0; i < 8; ++i)
30078 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], red);
30079 draw_quad(&test_context);
30081 for (i = 0; i < 8; ++i)
30083 get_texture_readback(rts[i], 0, &rb);
30084 color = get_readback_color(&rb, 320, 240, 0);
30085 ok(compare_color(color, expected_colors[0], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
30086 release_resource_readback(&rb);
30088 ID3D11Texture2D_Release(rts[i]);
30089 ID3D11RenderTargetView_Release(rtvs[i]);
30092 ID3D11PixelShader_Release(ps);
30093 release_test_context(&test_context);
30096 static void test_independent_blend(void)
30098 struct d3d11_test_context test_context;
30099 D3D11_TEXTURE2D_DESC texture_desc;
30100 ID3D11RenderTargetView *rtvs[8];
30101 ID3D11BlendState *blend_state;
30102 ID3D11DeviceContext *context;
30103 struct resource_readback rb;
30104 ID3D11Texture2D *rts[8];
30105 ID3D11PixelShader *ps;
30106 ID3D11Device *device;
30107 unsigned int i;
30108 DWORD color;
30109 HRESULT hr;
30111 static const DWORD ps_code[] =
30113 #if 0
30114 void main(float4 position : SV_Position,
30115 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
30116 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
30117 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
30118 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
30120 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.1f, 0.2f, 0.3f, 0.4f);
30122 #endif
30123 0x43425844, 0xb3dca7dc, 0x4a31f0f1, 0x747569cb, 0xae7af5ce, 0x00000001, 0x000002b0, 0x00000003,
30124 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30125 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
30126 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
30127 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
30128 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
30129 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
30130 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
30131 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
30132 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
30133 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
30134 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
30135 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
30136 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3dcccccd,
30137 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3dcccccd,
30138 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3dcccccd,
30139 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3dcccccd,
30140 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3dcccccd,
30141 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3dcccccd,
30142 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3dcccccd,
30143 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3dcccccd,
30144 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x0100003e,
30147 D3D11_BLEND_DESC blend_desc =
30149 .IndependentBlendEnable = TRUE,
30150 .RenderTarget =
30152 {TRUE, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD,
30153 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
30154 {TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
30155 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
30156 {TRUE, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_OP_ADD,
30157 D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
30158 {TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
30159 D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN, D3D11_COLOR_WRITE_ENABLE_ALL},
30160 {TRUE, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_OP_ADD,
30161 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
30162 {TRUE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_BLEND_FACTOR, D3D11_BLEND_OP_SUBTRACT,
30163 D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_REV_SUBTRACT, D3D11_COLOR_WRITE_ENABLE_ALL},
30164 {FALSE, 0, 0, 0, 0, 0, 0, D3D11_COLOR_WRITE_ENABLE_ALL},
30165 {TRUE, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_OP_ADD,
30166 D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_DEST_ALPHA, D3D11_BLEND_OP_SUBTRACT,
30167 D3D11_COLOR_WRITE_ENABLE_ALL},
30171 static const DWORD expected_colors[] =
30172 {0x66426e1c, 0xb34c3319, 0xa6214a05, 0x66333319, 0xb34c4829, 0x4d19000a, 0x664c3319, 0x081f3305};
30174 static const float clear_color[] = {0.1f, 0.5f, 0.2f, 0.7f};
30175 static const float blend_factor[] = {0.8f, 0.4f, 0.6f, 0.2f};
30177 if (!init_test_context(&test_context, NULL))
30178 return;
30180 device = test_context.device;
30181 context = test_context.immediate_context;
30183 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30184 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30185 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30187 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
30188 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
30189 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
30190 ID3D11BlendState_Release(blend_state);
30192 for (i = 0; i < 8; ++i)
30194 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30195 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
30196 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
30198 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rts[i], NULL, &rtvs[i]);
30199 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
30202 ID3D11DeviceContext_OMSetRenderTargets(context, 8, rtvs, NULL);
30204 for (i = 0; i < 8; ++i)
30205 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
30206 draw_quad(&test_context);
30208 for (i = 0; i < 8; ++i)
30210 get_texture_readback(rts[i], 0, &rb);
30211 color = get_readback_color(&rb, 320, 240, 0);
30212 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
30213 release_resource_readback(&rb);
30216 blend_desc.IndependentBlendEnable = FALSE;
30217 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
30218 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
30219 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
30220 ID3D11BlendState_Release(blend_state);
30222 for (i = 0; i < 8; ++i)
30223 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
30224 draw_quad(&test_context);
30226 for (i = 0; i < 8; ++i)
30228 get_texture_readback(rts[i], 0, &rb);
30229 color = get_readback_color(&rb, 320, 240, 0);
30230 ok(compare_color(color, expected_colors[0], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
30231 release_resource_readback(&rb);
30233 ID3D11Texture2D_Release(rts[i]);
30234 ID3D11RenderTargetView_Release(rtvs[i]);
30237 ID3D11PixelShader_Release(ps);
30238 release_test_context(&test_context);
30241 static void test_dual_source_blend(void)
30243 struct d3d11_test_context test_context;
30244 ID3D11BlendState *blend_state;
30245 ID3D11DeviceContext *context;
30246 ID3D11PixelShader *ps;
30247 ID3D11Device *device;
30248 DWORD color;
30249 HRESULT hr;
30251 static const DWORD ps_code[] =
30253 #if 0
30254 void main(float4 position : SV_Position,
30255 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1)
30257 t0 = float4(0.5, 0.5, 0.0, 1.0);
30258 t1 = float4(0.0, 0.5, 0.5, 0.0);
30260 #endif
30261 0x43425844, 0x87120d01, 0xa0014738, 0x3a32d86c, 0x9d757441, 0x00000001, 0x00000118, 0x00000003,
30262 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30263 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
30264 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
30265 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
30266 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03000065,
30267 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x08000036, 0x001020f2, 0x00000000,
30268 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001,
30269 0x00004002, 0x00000000, 0x3f000000, 0x3f000000, 0x00000000, 0x0100003e
30272 static const D3D11_BLEND_DESC blend_desc =
30274 .RenderTarget[0].BlendEnable = TRUE,
30275 .RenderTarget[0].SrcBlend = D3D11_BLEND_SRC1_COLOR,
30276 .RenderTarget[0].DestBlend = D3D11_BLEND_SRC1_COLOR,
30277 .RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD,
30278 .RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE,
30279 .RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO,
30280 .RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD,
30281 .RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL,
30284 static const float clear_color[] = {0.7f, 0.0f, 1.0f, 1.0f};
30286 if (!init_test_context(&test_context, NULL))
30287 return;
30289 device = test_context.device;
30290 context = test_context.immediate_context;
30292 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30293 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30294 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30296 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
30297 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
30298 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
30299 ID3D11BlendState_Release(blend_state);
30301 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, clear_color);
30302 draw_quad(&test_context);
30304 color = get_texture_color(test_context.backbuffer, 320, 240);
30305 ok(compare_color(color, 0x80804000, 1), "Got unexpected color 0x%08x.\n", color);
30307 ID3D11PixelShader_Release(ps);
30308 release_test_context(&test_context);
30311 static void test_deferred_context_state(void)
30313 ID3D11Buffer *green_buffer, *blue_buffer, *ret_buffer;
30314 ID3D11DeviceContext *immediate, *deferred;
30315 struct d3d11_test_context test_context;
30316 ID3D11CommandList *list1, *list2;
30317 ID3D11Device *device;
30318 HRESULT hr;
30320 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
30321 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
30323 if (!init_test_context(&test_context, NULL))
30324 return;
30326 device = test_context.device;
30327 immediate = test_context.immediate_context;
30329 green_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(green), &green);
30330 blue_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(blue), &blue);
30331 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
30333 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
30334 todo_wine ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
30335 if (hr != S_OK)
30337 ID3D11Buffer_Release(blue_buffer);
30338 ID3D11Buffer_Release(green_buffer);
30339 release_test_context(&test_context);
30340 return;
30343 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
30344 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
30346 ID3D11DeviceContext_PSSetConstantBuffers(deferred, 0, 1, &blue_buffer);
30348 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
30349 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
30350 ID3D11Buffer_Release(ret_buffer);
30352 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
30353 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
30355 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
30356 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
30357 ID3D11Buffer_Release(ret_buffer);
30359 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list2);
30360 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
30362 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
30363 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
30365 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
30366 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
30367 ID3D11DeviceContext_PSGetConstantBuffers(immediate, 0, 1, &ret_buffer);
30368 ok(ret_buffer == green_buffer, "Got unexpected buffer %p.\n", ret_buffer);
30369 ID3D11Buffer_Release(ret_buffer);
30371 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
30372 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
30373 ID3D11DeviceContext_PSGetConstantBuffers(immediate, 0, 1, &ret_buffer);
30374 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
30376 ID3D11CommandList_Release(list2);
30377 ID3D11CommandList_Release(list1);
30378 ID3D11DeviceContext_Release(deferred);
30379 ID3D11Buffer_Release(blue_buffer);
30380 ID3D11Buffer_Release(green_buffer);
30381 release_test_context(&test_context);
30384 static void test_deferred_context_rendering(void)
30386 ID3D11DeviceContext *immediate, *deferred;
30387 struct d3d11_test_context test_context;
30388 D3D11_TEXTURE2D_DESC texture_desc;
30389 ID3D11CommandList *list1, *list2;
30390 ID3D11RenderTargetView *rtv;
30391 ID3D11Texture2D *texture;
30392 ID3D11Device *device;
30393 DWORD color;
30394 HRESULT hr;
30396 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30397 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
30398 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
30400 if (!init_test_context(&test_context, NULL))
30401 return;
30403 device = test_context.device;
30404 immediate = test_context.immediate_context;
30406 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
30408 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
30409 todo_wine ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
30410 if (hr != S_OK)
30412 release_test_context(&test_context);
30413 return;
30416 ID3D11DeviceContext_ClearRenderTargetView(deferred, test_context.backbuffer_rtv, green);
30418 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
30419 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
30421 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
30422 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
30424 color = get_texture_color(test_context.backbuffer, 320, 240);
30425 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
30427 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
30428 color = get_texture_color(test_context.backbuffer, 320, 240);
30429 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
30431 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
30432 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
30433 color = get_texture_color(test_context.backbuffer, 320, 240);
30434 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
30436 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
30437 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, TRUE);
30438 color = get_texture_color(test_context.backbuffer, 320, 240);
30439 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
30441 ID3D11CommandList_Release(list2);
30443 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, TRUE);
30444 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
30445 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
30447 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
30448 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, TRUE);
30449 color = get_texture_color(test_context.backbuffer, 320, 240);
30450 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
30452 ID3D11CommandList_Release(list2);
30453 ID3D11CommandList_Release(list1);
30454 ID3D11DeviceContext_Release(deferred);
30456 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30457 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30458 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30459 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
30460 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
30462 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
30463 ID3D11DeviceContext_ClearRenderTargetView(immediate, rtv, green);
30465 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
30466 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
30468 ID3D11DeviceContext_CopyResource(deferred, (ID3D11Resource *)test_context.backbuffer, (ID3D11Resource *)texture);
30470 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
30471 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
30473 ID3D11DeviceContext_ClearRenderTargetView(immediate, rtv, blue);
30474 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
30475 color = get_texture_color(test_context.backbuffer, 320, 240);
30476 ok(color == 0xffff0000, "Got unexpected color %#08x.\n", color);
30478 ID3D11CommandList_Release(list1);
30479 ID3D11DeviceContext_Release(deferred);
30481 ID3D11RenderTargetView_Release(rtv);
30482 ID3D11Texture2D_Release(texture);
30483 release_test_context(&test_context);
30486 START_TEST(d3d11)
30488 unsigned int argc, i;
30489 char **argv;
30491 use_mt = !getenv("WINETEST_NO_MT_D3D");
30493 argc = winetest_get_mainargs(&argv);
30494 for (i = 2; i < argc; ++i)
30496 if (!strcmp(argv[i], "--validate"))
30497 enable_debug_layer = TRUE;
30498 else if (!strcmp(argv[i], "--warp"))
30499 use_warp_adapter = TRUE;
30500 else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
30501 use_adapter_idx = atoi(argv[++i]);
30502 else if (!strcmp(argv[i], "--single"))
30503 use_mt = FALSE;
30506 print_adapter_info();
30508 queue_test(test_create_device);
30509 queue_for_each_feature_level(test_device_interfaces);
30510 queue_test(test_immediate_context);
30511 queue_test(test_create_deferred_context);
30512 queue_test(test_create_texture1d);
30513 queue_test(test_texture1d_interfaces);
30514 queue_test(test_create_texture2d);
30515 queue_test(test_texture2d_interfaces);
30516 queue_test(test_create_texture3d);
30517 queue_test(test_texture3d_interfaces);
30518 queue_test(test_create_buffer);
30519 queue_test(test_create_depthstencil_view);
30520 queue_test(test_depthstencil_view_interfaces);
30521 queue_test(test_create_rendertarget_view);
30522 queue_test(test_create_shader_resource_view);
30523 queue_for_each_feature_level(test_create_shader);
30524 queue_test(test_create_sampler_state);
30525 queue_test(test_create_blend_state);
30526 queue_test(test_create_depthstencil_state);
30527 queue_test(test_create_rasterizer_state);
30528 queue_test(test_create_query);
30529 queue_test(test_occlusion_query);
30530 queue_test(test_pipeline_statistics_query);
30531 queue_test(test_timestamp_query);
30532 queue_test(test_so_statistics_query);
30533 queue_test(test_device_removed_reason);
30534 queue_test(test_private_data);
30535 queue_for_each_feature_level(test_state_refcounting);
30536 queue_test(test_device_context_state);
30537 queue_test(test_blend);
30538 queue_test(test_texture1d);
30539 queue_test(test_texture);
30540 queue_test(test_cube_maps);
30541 queue_test(test_depth_stencil_sampling);
30542 queue_test(test_sample_c_lz);
30543 queue_test(test_multiple_render_targets);
30544 queue_test(test_render_target_views);
30545 queue_test(test_layered_rendering);
30546 queue_test(test_scissor);
30547 queue_test(test_clear_state);
30548 queue_test(test_il_append_aligned);
30549 queue_test(test_instance_id);
30550 queue_test(test_vertex_id);
30551 queue_test(test_fragment_coords);
30552 queue_test(test_initial_texture_data);
30553 queue_test(test_update_subresource);
30554 queue_test(test_copy_subresource_region);
30555 queue_test(test_copy_subresource_region_1d);
30556 queue_test(test_copy_subresource_region_3d);
30557 queue_test(test_resource_map);
30558 queue_for_each_feature_level(test_resource_access);
30559 queue_test(test_check_multisample_quality_levels);
30560 queue_for_each_feature_level(test_swapchain_formats);
30561 queue_test(test_swapchain_views);
30562 queue_test(test_swapchain_flip);
30563 queue_test(test_clear_render_target_view_1d);
30564 queue_test(test_clear_render_target_view_2d);
30565 queue_test(test_clear_render_target_view_3d);
30566 queue_test(test_clear_depth_stencil_view);
30567 queue_test(test_clear_buffer_unordered_access_view);
30568 queue_test(test_initial_depth_stencil_state);
30569 queue_test(test_draw_depth_only);
30570 queue_test(test_draw_uav_only);
30571 queue_test(test_cb_relative_addressing);
30572 queue_test(test_vs_input_relative_addressing);
30573 queue_test(test_getdc);
30574 queue_test(test_shader_stage_input_output_matching);
30575 queue_test(test_shader_interstage_interface);
30576 queue_test(test_sm4_if_instruction);
30577 queue_test(test_sm4_breakc_instruction);
30578 queue_test(test_sm4_continuec_instruction);
30579 queue_test(test_sm4_discard_instruction);
30580 queue_test(test_sm5_swapc_instruction);
30581 queue_test(test_create_input_layout);
30582 queue_test(test_input_assembler);
30583 queue_test(test_null_sampler);
30584 queue_test(test_check_feature_support);
30585 queue_test(test_create_unordered_access_view);
30586 queue_test(test_immediate_constant_buffer);
30587 queue_test(test_fp_specials);
30588 queue_test(test_uint_shader_instructions);
30589 queue_test(test_index_buffer_offset);
30590 queue_test(test_face_culling);
30591 queue_test(test_line_antialiasing_blending);
30592 queue_for_each_feature_level(test_format_support);
30593 queue_for_each_9_x_feature_level(test_fl9_draw);
30594 queue_test(test_ddy);
30595 queue_test(test_shader_input_registers_limits);
30596 queue_test(test_unbind_shader_resource_view);
30597 queue_test(test_stencil_separate);
30598 queue_test(test_uav_load);
30599 queue_test(test_cs_uav_store);
30600 queue_test(test_uav_store_immediate_constant);
30601 queue_test(test_ps_cs_uav_binding);
30602 queue_test(test_atomic_instructions);
30603 queue_test(test_sm4_ret_instruction);
30604 queue_test(test_primitive_restart);
30605 queue_test(test_resinfo_instruction);
30606 queue_test(test_sm5_bufinfo_instruction);
30607 queue_test(test_sampleinfo_instruction);
30608 queue_test(test_render_target_device_mismatch);
30609 queue_test(test_buffer_srv);
30610 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
30611 test_unaligned_raw_buffer_access);
30612 queue_test(test_uav_counters);
30613 queue_test(test_dispatch_indirect);
30614 queue_test(test_compute_shader_registers);
30615 queue_test(test_tgsm);
30616 queue_test(test_geometry_shader);
30617 queue_test(test_quad_tessellation);
30618 queue_test(test_stream_output);
30619 queue_test(test_fl10_stream_output_desc);
30620 queue_test(test_stream_output_resume);
30621 queue_test(test_stream_output_components);
30622 queue_test(test_stream_output_vs);
30623 queue_test(test_gather);
30624 queue_test(test_gather_c);
30625 queue_test(test_depth_bias);
30626 queue_test(test_fractional_viewports);
30627 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0, test_negative_viewports);
30628 queue_test(test_early_depth_stencil);
30629 queue_test(test_conservative_depth_output);
30630 queue_test(test_format_compatibility);
30631 queue_test(test_clip_distance);
30632 queue_test(test_combined_clip_and_cull_distances);
30633 queue_test(test_generate_mips);
30634 queue_test(test_alpha_to_coverage);
30635 queue_test(test_unbound_multisample_texture);
30636 queue_test(test_multiple_viewports);
30637 queue_test(test_multisample_resolve);
30638 queue_test(test_sample_shading);
30639 queue_test(test_sample_mask);
30640 queue_test(test_depth_clip);
30641 queue_test(test_staging_buffers);
30642 queue_test(test_render_a8);
30643 queue_test(test_standard_pattern);
30644 queue_test(test_desktop_window);
30645 queue_test(test_sample_attached_rtv);
30646 queue_test(test_color_mask);
30647 queue_test(test_independent_blend);
30648 queue_test(test_dual_source_blend);
30649 queue_test(test_deferred_context_state);
30650 queue_test(test_deferred_context_rendering);
30652 run_queued_tests();