d3d11/tests: Add test for staging buffers.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blobc470e24f646f886fa0efc01ce7495e4ee4a41ebd
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 use_warp_adapter;
42 static BOOL use_mt = TRUE;
44 static struct test_entry
46 union
48 void (*test)(void);
49 void (*test_fl)(D3D_FEATURE_LEVEL fl);
50 } u;
51 D3D_FEATURE_LEVEL fl;
52 } *mt_tests;
53 size_t mt_tests_size, mt_test_count;
55 struct format_support
57 DXGI_FORMAT format;
58 D3D_FEATURE_LEVEL fl_required;
59 D3D_FEATURE_LEVEL fl_optional;
62 static const struct format_support display_format_support[] =
64 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
65 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
66 {DXGI_FORMAT_B8G8R8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
67 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
68 {DXGI_FORMAT_R16G16B16A16_FLOAT, D3D_FEATURE_LEVEL_10_0},
69 {DXGI_FORMAT_R10G10B10A2_UNORM, D3D_FEATURE_LEVEL_10_0},
70 {DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0},
73 struct vec2
75 float x, y;
78 struct vec3
80 float x, y, z;
83 struct vec4
85 float x, y, z, w;
88 struct ivec4
90 int x, y, z, w;
93 struct uvec4
95 unsigned int x, y, z, w;
98 struct device_desc
100 const D3D_FEATURE_LEVEL *feature_level;
101 UINT flags;
104 struct swapchain_desc
106 BOOL windowed;
107 unsigned buffer_count;
108 unsigned int width, height;
109 DXGI_SWAP_EFFECT swap_effect;
110 DWORD flags;
113 static void queue_test_entry(const struct test_entry *t)
115 if (mt_test_count >= mt_tests_size)
117 mt_tests_size = max(16, mt_tests_size * 2);
118 mt_tests = heap_realloc(mt_tests, mt_tests_size * sizeof(*t));
120 mt_tests[mt_test_count++] = *t;
123 static void queue_test_fl(void (*test)(const D3D_FEATURE_LEVEL fl), D3D_FEATURE_LEVEL fl)
125 struct test_entry t;
127 t.u.test_fl = test;
128 t.fl = fl;
129 queue_test_entry(&t);
132 static void queue_test(void (*test)(void))
134 struct test_entry t;
136 t.u.test = test;
137 t.fl = 0;
138 queue_test_entry(&t);
141 static void run_mt_test(const struct test_entry *t)
143 if (t->fl)
144 t->u.test_fl(t->fl);
145 else
146 t->u.test();
149 static DWORD WINAPI thread_func(void *ctx)
151 LONG *i = ctx, j;
153 while (*i < mt_test_count)
155 j = *i;
156 if (InterlockedCompareExchange(i, j + 1, j) == j)
157 run_mt_test(&mt_tests[j]);
160 return 0;
163 static void run_queued_tests(void)
165 unsigned int thread_count, i;
166 HANDLE *threads;
167 SYSTEM_INFO si;
168 LONG test_idx;
170 if (!use_mt)
172 for (i = 0; i < mt_test_count; ++i)
174 run_mt_test(&mt_tests[i]);
177 return;
180 GetSystemInfo(&si);
181 thread_count = si.dwNumberOfProcessors;
182 threads = heap_calloc(thread_count, sizeof(*threads));
183 for (i = 0, test_idx = 0; i < thread_count; ++i)
185 threads[i] = CreateThread(NULL, 0, thread_func, &test_idx, 0, NULL);
186 ok(!!threads[i], "Failed to create thread %u.\n", i);
188 WaitForMultipleObjects(thread_count, threads, TRUE, INFINITE);
189 for (i = 0; i < thread_count; ++i)
191 CloseHandle(threads[i]);
193 heap_free(threads);
196 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
198 box->left = left;
199 box->top = top;
200 box->front = front;
201 box->right = right;
202 box->bottom = bottom;
203 box->back = back;
206 static ULONG get_refcount(void *iface)
208 IUnknown *unknown = iface;
209 IUnknown_AddRef(unknown);
210 return IUnknown_Release(unknown);
213 #define check_interface(a, b, c, d) check_interface_(__LINE__, a, b, c, d)
214 static HRESULT check_interface_(unsigned int line, void *iface, REFIID riid, BOOL supported, BOOL is_broken)
216 HRESULT hr, expected_hr, broken_hr;
217 IUnknown *unknown = iface, *out;
219 if (supported)
221 expected_hr = S_OK;
222 broken_hr = E_NOINTERFACE;
224 else
226 expected_hr = E_NOINTERFACE;
227 broken_hr = S_OK;
230 hr = IUnknown_QueryInterface(unknown, riid, (void **)&out);
231 ok_(__FILE__, line)(hr == expected_hr || broken(is_broken && hr == broken_hr),
232 "Got hr %#x, expected %#x.\n", hr, expected_hr);
233 if (SUCCEEDED(hr))
234 IUnknown_Release(out);
235 return hr;
238 static BOOL compare_float(float f, float g, unsigned int ulps)
240 int x = *(int *)&f;
241 int y = *(int *)&g;
243 if (x < 0)
244 x = INT_MIN - x;
245 if (y < 0)
246 y = INT_MIN - y;
248 if (abs(x - y) > ulps)
249 return FALSE;
251 return TRUE;
254 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
256 return compare_float(v1->x, v2->x, ulps)
257 && compare_float(v1->y, v2->y, ulps)
258 && compare_float(v1->z, v2->z, ulps)
259 && compare_float(v1->w, v2->w, ulps);
262 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
264 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
267 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
269 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
270 return FALSE;
271 c1 >>= 8; c2 >>= 8;
272 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
273 return FALSE;
274 c1 >>= 8; c2 >>= 8;
275 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
276 return FALSE;
277 c1 >>= 8; c2 >>= 8;
278 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
279 return FALSE;
280 return TRUE;
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 DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
940 return *(DWORD *)get_readback_data(rb, x, y, z, sizeof(DWORD));
943 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
945 return *(float *)get_readback_data(rb, x, y, 0, sizeof(float));
948 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
950 return get_readback_data(rb, x, y, 0, sizeof(struct vec4));
953 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
955 return get_readback_data(rb, x, y, 0, sizeof(struct uvec4));
958 static void release_resource_readback(struct resource_readback *rb)
960 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
961 ID3D11Resource_Release(rb->resource);
962 ID3D11DeviceContext_Release(rb->immediate_context);
965 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
967 struct resource_readback rb;
968 DWORD color;
970 get_texture_readback(texture, 0, &rb);
971 color = get_readback_color(&rb, x, y, 0);
972 release_resource_readback(&rb);
974 return color;
977 #define check_readback_data_color(a, b, c, d) check_readback_data_color_(__LINE__, a, b, c, d)
978 static void check_readback_data_color_(unsigned int line, struct resource_readback *rb,
979 const RECT *rect, DWORD expected_color, BYTE max_diff)
981 unsigned int x = 0, y = 0, z = 0;
982 BOOL all_match = TRUE;
983 RECT default_rect;
984 DWORD color = 0;
986 if (!rect)
988 SetRect(&default_rect, 0, 0, rb->width, rb->height);
989 rect = &default_rect;
992 for (z = 0; z < rb->depth; ++z)
994 for (y = rect->top; y < rect->bottom; ++y)
996 for (x = rect->left; x < rect->right; ++x)
998 color = get_readback_color(rb, x, y, z);
999 if (!compare_color(color, expected_color, max_diff))
1001 all_match = FALSE;
1002 break;
1005 if (!all_match)
1006 break;
1008 if (!all_match)
1009 break;
1011 ok_(__FILE__, line)(all_match,
1012 "Got 0x%08x, expected 0x%08x at (%u, %u, %u), sub-resource %u.\n",
1013 color, expected_color, x, y, z, rb->sub_resource_idx);
1016 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
1017 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
1018 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1020 struct resource_readback rb;
1022 get_texture_readback(texture, sub_resource_idx, &rb);
1023 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1024 release_resource_readback(&rb);
1027 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
1028 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
1029 DWORD expected_color, BYTE max_diff)
1031 unsigned int sub_resource_idx, sub_resource_count;
1032 D3D11_TEXTURE2D_DESC texture_desc;
1034 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1035 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1036 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1037 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1040 #define check_texture1d_sub_resource_color(a, b, c, d, e) check_texture1d_sub_resource_color_(__LINE__, a, b, c, d, e)
1041 static void check_texture1d_sub_resource_color_(unsigned int line, ID3D11Texture1D *texture,
1042 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1044 struct resource_readback rb;
1046 get_texture1d_readback(texture, sub_resource_idx, &rb);
1047 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1048 release_resource_readback(&rb);
1051 #define check_texture1d_color(t, c, d) check_texture1d_color_(__LINE__, t, c, d)
1052 static void check_texture1d_color_(unsigned int line, ID3D11Texture1D *texture,
1053 DWORD expected_color, BYTE max_diff)
1055 unsigned int sub_resource_idx, sub_resource_count;
1056 D3D11_TEXTURE1D_DESC texture_desc;
1058 ID3D11Texture1D_GetDesc(texture, &texture_desc);
1059 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1060 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1061 check_texture1d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1064 #define check_texture3d_sub_resource_color(a, b, c, d, e) check_texture3d_sub_resource_color_(__LINE__, a, b, c, d, e)
1065 static void check_texture3d_sub_resource_color_(unsigned int line, ID3D11Texture3D *texture,
1066 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1068 struct resource_readback rb;
1070 get_texture3d_readback(texture, sub_resource_idx, &rb);
1071 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1072 release_resource_readback(&rb);
1075 #define check_texture3d_color(t, c, d) check_texture3d_color_(__LINE__, t, c, d)
1076 static void check_texture3d_color_(unsigned int line, ID3D11Texture3D *texture,
1077 DWORD expected_color, BYTE max_diff)
1079 unsigned int sub_resource_idx, sub_resource_count;
1080 D3D11_TEXTURE3D_DESC texture_desc;
1082 ID3D11Texture3D_GetDesc(texture, &texture_desc);
1083 sub_resource_count = texture_desc.MipLevels;
1084 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1085 check_texture3d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1088 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
1089 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
1090 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
1092 struct resource_readback rb;
1093 unsigned int x = 0, y = 0;
1094 BOOL all_match = TRUE;
1095 float value = 0.0f;
1096 RECT default_rect;
1098 get_texture_readback(texture, sub_resource_idx, &rb);
1099 if (!rect)
1101 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1102 rect = &default_rect;
1104 for (y = rect->top; y < rect->bottom; ++y)
1106 for (x = rect->left; x < rect->right; ++x)
1108 value = get_readback_float(&rb, x, y);
1109 if (!compare_float(value, expected_value, max_diff))
1111 all_match = FALSE;
1112 break;
1115 if (!all_match)
1116 break;
1118 release_resource_readback(&rb);
1119 ok_(__FILE__, line)(all_match,
1120 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
1121 value, expected_value, x, y, sub_resource_idx);
1124 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
1125 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
1126 float expected_value, BYTE max_diff)
1128 unsigned int sub_resource_idx, sub_resource_count;
1129 D3D11_TEXTURE2D_DESC texture_desc;
1131 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1132 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1133 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1134 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1137 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
1138 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
1139 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
1141 struct resource_readback rb;
1142 unsigned int x = 0, y = 0;
1143 struct vec4 value = {0};
1144 BOOL all_match = TRUE;
1145 RECT default_rect;
1147 get_texture_readback(texture, sub_resource_idx, &rb);
1148 if (!rect)
1150 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1151 rect = &default_rect;
1153 for (y = rect->top; y < rect->bottom; ++y)
1155 for (x = rect->left; x < rect->right; ++x)
1157 value = *get_readback_vec4(&rb, x, y);
1158 if (!compare_vec4(&value, expected_value, max_diff))
1160 all_match = FALSE;
1161 break;
1164 if (!all_match)
1165 break;
1167 release_resource_readback(&rb);
1168 ok_(__FILE__, line)(all_match,
1169 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
1170 value.x, value.y, value.z, value.w,
1171 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1172 x, y, sub_resource_idx);
1175 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
1176 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
1177 const struct vec4 *expected_value, BYTE max_diff)
1179 unsigned int sub_resource_idx, sub_resource_count;
1180 D3D11_TEXTURE2D_DESC texture_desc;
1182 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1183 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1184 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1185 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1188 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
1189 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
1190 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
1192 struct resource_readback rb;
1193 unsigned int x = 0, y = 0;
1194 struct uvec4 value = {0};
1195 BOOL all_match = TRUE;
1196 RECT default_rect;
1198 get_texture_readback(texture, sub_resource_idx, &rb);
1199 if (!rect)
1201 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1202 rect = &default_rect;
1204 for (y = rect->top; y < rect->bottom; ++y)
1206 for (x = rect->left; x < rect->right; ++x)
1208 value = *get_readback_uvec4(&rb, x, y);
1209 if (!compare_uvec4(&value, expected_value))
1211 all_match = FALSE;
1212 break;
1215 if (!all_match)
1216 break;
1218 release_resource_readback(&rb);
1219 ok_(__FILE__, line)(all_match,
1220 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
1221 "at (%u, %u), sub-resource %u.\n",
1222 value.x, value.y, value.z, value.w,
1223 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1224 x, y, sub_resource_idx);
1227 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
1228 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
1229 const struct uvec4 *expected_value)
1231 unsigned int sub_resource_idx, sub_resource_count;
1232 D3D11_TEXTURE2D_DESC texture_desc;
1234 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1235 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1236 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1237 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
1240 static IDXGIAdapter *create_adapter(void)
1242 IDXGIFactory4 *factory4;
1243 IDXGIFactory *factory;
1244 IDXGIAdapter *adapter;
1245 HRESULT hr;
1247 if (!use_warp_adapter && !use_adapter_idx)
1248 return NULL;
1250 if (FAILED(hr = CreateDXGIFactory1(&IID_IDXGIFactory, (void **)&factory)))
1252 trace("Failed to create IDXGIFactory, hr %#x.\n", hr);
1253 return NULL;
1256 adapter = NULL;
1257 if (use_warp_adapter)
1259 if (SUCCEEDED(hr = IDXGIFactory_QueryInterface(factory, &IID_IDXGIFactory4, (void **)&factory4)))
1261 hr = IDXGIFactory4_EnumWarpAdapter(factory4, &IID_IDXGIAdapter, (void **)&adapter);
1262 IDXGIFactory4_Release(factory4);
1264 else
1266 trace("Failed to get IDXGIFactory4, hr %#x.\n", hr);
1269 else
1271 hr = IDXGIFactory_EnumAdapters(factory, use_adapter_idx, &adapter);
1273 IDXGIFactory_Release(factory);
1274 if (FAILED(hr))
1275 trace("Failed to get adapter, hr %#x.\n", hr);
1276 return adapter;
1279 static ID3D11Device *create_device(const struct device_desc *desc)
1281 static const D3D_FEATURE_LEVEL default_feature_level[] =
1283 D3D_FEATURE_LEVEL_11_0,
1284 D3D_FEATURE_LEVEL_10_1,
1285 D3D_FEATURE_LEVEL_10_0,
1287 const D3D_FEATURE_LEVEL *feature_level;
1288 UINT flags = desc ? desc->flags : 0;
1289 unsigned int feature_level_count;
1290 IDXGIAdapter *adapter;
1291 ID3D11Device *device;
1292 HRESULT hr;
1294 if (desc && desc->feature_level)
1296 feature_level = desc->feature_level;
1297 feature_level_count = 1;
1299 else
1301 feature_level = default_feature_level;
1302 feature_level_count = ARRAY_SIZE(default_feature_level);
1305 if ((adapter = create_adapter()))
1307 hr = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags,
1308 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL);
1309 IDXGIAdapter_Release(adapter);
1310 return SUCCEEDED(hr) ? device : NULL;
1313 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags,
1314 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1315 return device;
1316 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags,
1317 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1318 return device;
1319 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags,
1320 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1321 return device;
1323 return NULL;
1326 static void get_device_adapter_desc(ID3D11Device *device, DXGI_ADAPTER_DESC *adapter_desc)
1328 IDXGIDevice *dxgi_device;
1329 IDXGIAdapter *adapter;
1330 HRESULT hr;
1332 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1333 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1334 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1335 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1336 IDXGIDevice_Release(dxgi_device);
1337 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1338 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1339 IDXGIAdapter_Release(adapter);
1342 static void print_adapter_info(void)
1344 DXGI_ADAPTER_DESC adapter_desc;
1345 ID3D11Device *device;
1347 if (!(device = create_device(NULL)))
1348 return;
1350 get_device_adapter_desc(device, &adapter_desc);
1351 trace("Adapter: %s, %04x:%04x.\n", wine_dbgstr_w(adapter_desc.Description),
1352 adapter_desc.VendorId, adapter_desc.DeviceId);
1353 ID3D11Device_Release(device);
1356 static BOOL is_warp_device(ID3D11Device *device)
1358 DXGI_ADAPTER_DESC adapter_desc;
1359 get_device_adapter_desc(device, &adapter_desc);
1360 return !adapter_desc.SubSysId && !adapter_desc.Revision
1361 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1362 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1365 static BOOL is_vendor_device(ID3D11Device *device, unsigned int vendor_id)
1367 DXGI_ADAPTER_DESC adapter_desc;
1369 if (!strcmp(winetest_platform, "wine"))
1370 return FALSE;
1372 get_device_adapter_desc(device, &adapter_desc);
1373 return adapter_desc.VendorId == vendor_id;
1376 static BOOL is_amd_device(ID3D11Device *device)
1378 return is_vendor_device(device, 0x1002);
1381 static BOOL is_intel_device(ID3D11Device *device)
1383 return is_vendor_device(device, 0x8086);
1386 static BOOL is_nvidia_device(ID3D11Device *device)
1388 return is_vendor_device(device, 0x10de);
1391 static BOOL is_d3d11_2_runtime(ID3D11Device *device)
1393 ID3D11Device2 *device2;
1394 HRESULT hr;
1396 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11Device2, (void **)&device2);
1397 if (SUCCEEDED(hr))
1398 ID3D11Device2_Release(device2);
1399 return hr == S_OK;
1402 static BOOL check_compute_shaders_via_sm4_support(ID3D11Device *device)
1404 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
1406 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1407 D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(options))))
1408 return FALSE;
1409 return options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x;
1412 static BOOL is_buffer(ID3D11Resource *resource)
1414 D3D11_RESOURCE_DIMENSION dimension;
1415 ID3D11Resource_GetType(resource, &dimension);
1416 return dimension == D3D11_RESOURCE_DIMENSION_BUFFER;
1419 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window,
1420 const struct swapchain_desc *swapchain_desc)
1422 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1423 IDXGISwapChain *swapchain;
1424 IDXGIDevice *dxgi_device;
1425 IDXGIAdapter *adapter;
1426 IDXGIFactory *factory;
1427 HRESULT hr;
1429 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1430 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1431 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1432 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1433 IDXGIDevice_Release(dxgi_device);
1434 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1435 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1436 IDXGIAdapter_Release(adapter);
1438 dxgi_desc.BufferDesc.Width = 640;
1439 dxgi_desc.BufferDesc.Height = 480;
1440 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1441 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1442 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1443 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1444 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1445 dxgi_desc.SampleDesc.Count = 1;
1446 dxgi_desc.SampleDesc.Quality = 0;
1447 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1448 dxgi_desc.BufferCount = 1;
1449 dxgi_desc.OutputWindow = window;
1450 dxgi_desc.Windowed = TRUE;
1451 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1452 dxgi_desc.Flags = 0;
1454 if (swapchain_desc)
1456 dxgi_desc.Windowed = swapchain_desc->windowed;
1457 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1458 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1459 if (swapchain_desc->width)
1460 dxgi_desc.BufferDesc.Width = swapchain_desc->width;
1461 if (swapchain_desc->height)
1462 dxgi_desc.BufferDesc.Height = swapchain_desc->height;
1464 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1465 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1468 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1469 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1470 IDXGIFactory_Release(factory);
1472 return swapchain;
1475 struct d3d11_test_context
1477 ID3D11Device *device;
1478 HWND window;
1479 IDXGISwapChain *swapchain;
1480 ID3D11Texture2D *backbuffer;
1481 ID3D11RenderTargetView *backbuffer_rtv;
1482 ID3D11DeviceContext *immediate_context;
1484 ID3D11InputLayout *input_layout;
1485 ID3D11VertexShader *vs;
1486 const DWORD *vs_code;
1487 ID3D11Buffer *vs_cb;
1488 ID3D11Buffer *vb;
1490 ID3D11PixelShader *ps;
1491 ID3D11Buffer *ps_cb;
1494 #define init_test_context(a, b) init_test_context_(__LINE__, a, b, NULL)
1495 #define init_test_context_ext(a, b, c) init_test_context_(__LINE__, a, b, c)
1496 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1497 const D3D_FEATURE_LEVEL *feature_level, const struct swapchain_desc *swapchain_desc)
1499 unsigned int rt_width, rt_height;
1500 struct device_desc device_desc;
1501 HRESULT hr;
1502 RECT rect;
1504 memset(context, 0, sizeof(*context));
1506 device_desc.feature_level = feature_level;
1507 device_desc.flags = 0;
1508 if (!(context->device = create_device(&device_desc)))
1510 skip_(__FILE__, line)("Failed to create device.\n");
1511 return FALSE;
1514 rt_width = swapchain_desc && swapchain_desc->width ? swapchain_desc->width : 640;
1515 rt_height = swapchain_desc && swapchain_desc->height ? swapchain_desc->height : 480;
1516 SetRect(&rect, 0, 0, rt_width, rt_height);
1517 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1518 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1519 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1520 context->swapchain = create_swapchain(context->device, context->window, swapchain_desc);
1521 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1522 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1524 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1525 NULL, &context->backbuffer_rtv);
1526 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1528 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1530 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1532 set_viewport(context->immediate_context, 0.0f, 0.0f, rt_width, rt_height, 0.0f, 1.0f);
1534 return TRUE;
1537 #define release_test_context(context) release_test_context_(__LINE__, context)
1538 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1540 ULONG ref;
1542 if (context->input_layout)
1543 ID3D11InputLayout_Release(context->input_layout);
1544 if (context->vs)
1545 ID3D11VertexShader_Release(context->vs);
1546 if (context->vs_cb)
1547 ID3D11Buffer_Release(context->vs_cb);
1548 if (context->vb)
1549 ID3D11Buffer_Release(context->vb);
1550 if (context->ps)
1551 ID3D11PixelShader_Release(context->ps);
1552 if (context->ps_cb)
1553 ID3D11Buffer_Release(context->ps_cb);
1555 ID3D11DeviceContext_Release(context->immediate_context);
1556 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1557 ID3D11Texture2D_Release(context->backbuffer);
1558 IDXGISwapChain_Release(context->swapchain);
1559 DestroyWindow(context->window);
1561 ref = ID3D11Device_Release(context->device);
1562 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1565 #define draw_quad(context) draw_quad_vs_(__LINE__, context, NULL, 0)
1566 #define draw_quad_vs(a, b, c) draw_quad_vs_(__LINE__, a, b, c)
1567 static void draw_quad_vs_(unsigned int line, struct d3d11_test_context *context,
1568 const DWORD *vs_code, size_t vs_code_size)
1570 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1572 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1574 static const DWORD default_vs_code[] =
1576 #if 0
1577 float4 main(float4 position : POSITION) : SV_POSITION
1579 return position;
1581 #endif
1582 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1583 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1584 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1585 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1586 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1587 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1588 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1589 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1590 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1591 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1592 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1593 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1594 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1595 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1596 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1598 static const struct vec3 quad[] =
1600 {-1.0f, -1.0f, 0.0f},
1601 {-1.0f, 1.0f, 0.0f},
1602 { 1.0f, -1.0f, 0.0f},
1603 { 1.0f, 1.0f, 0.0f},
1606 ID3D11Device *device = context->device;
1607 unsigned int stride, offset;
1608 HRESULT hr;
1610 if (!vs_code)
1612 vs_code = default_vs_code;
1613 vs_code_size = sizeof(default_vs_code);
1616 if (!context->input_layout)
1618 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1619 vs_code, vs_code_size, &context->input_layout);
1620 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1623 if (context->vs_code != vs_code)
1625 if (context->vs)
1626 ID3D11VertexShader_Release(context->vs);
1628 hr = ID3D11Device_CreateVertexShader(device, vs_code, vs_code_size, NULL, &context->vs);
1629 ok_(__FILE__, line)(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
1631 context->vs_code = vs_code;
1634 if (!context->vb)
1635 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1637 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1638 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1639 stride = sizeof(*quad);
1640 offset = 0;
1641 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1642 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1644 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1647 #define draw_quad_z(context, z) draw_quad_z_(__LINE__, context, z)
1648 static void draw_quad_z_(unsigned int line, struct d3d11_test_context *context, float z)
1650 static const DWORD vs_code[] =
1652 #if 0
1653 float depth;
1655 void main(float4 in_position : POSITION, out float4 out_position : SV_Position)
1657 out_position = in_position;
1658 out_position.z = depth;
1660 #endif
1661 0x43425844, 0x22d7ff76, 0xd53b167c, 0x1b49ccf1, 0xbebfec39, 0x00000001, 0x00000100, 0x00000003,
1662 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1663 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000b0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1664 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1665 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x52444853, 0x00000064, 0x00010040,
1666 0x00000019, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010b2, 0x00000000,
1667 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x05000036, 0x001020b2, 0x00000000, 0x00101c46,
1668 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
1671 struct vec4 data = {z};
1673 if (!context->vs_cb)
1674 context->vs_cb = create_buffer(context->device, D3D11_BIND_CONSTANT_BUFFER, sizeof(data), NULL);
1676 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1677 (ID3D11Resource *)context->vs_cb, 0, NULL, &data, 0, 0);
1679 ID3D11DeviceContext_VSSetConstantBuffers(context->immediate_context, 0, 1, &context->vs_cb);
1680 draw_quad_vs_(__LINE__, context, vs_code, sizeof(vs_code));
1683 static void set_quad_color(struct d3d11_test_context *context, const struct vec4 *color)
1685 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1686 (ID3D11Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1689 #define draw_color_quad(a, b) draw_color_quad_(__LINE__, a, b, NULL, 0)
1690 #define draw_color_quad_vs(a, b, c, d) draw_color_quad_(__LINE__, a, b, c, d)
1691 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context,
1692 const struct vec4 *color, const DWORD *vs_code, size_t vs_code_size)
1694 static const DWORD ps_color_code[] =
1696 #if 0
1697 float4 color;
1699 float4 main() : SV_TARGET
1701 return color;
1703 #endif
1704 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1705 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1706 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1707 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1708 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1709 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1710 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1711 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1712 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1713 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1714 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1717 ID3D11Device *device = context->device;
1718 HRESULT hr;
1720 if (!context->ps)
1722 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1723 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1726 if (!context->ps_cb)
1727 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1729 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1730 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1732 set_quad_color(context, color);
1734 draw_quad_vs_(line, context, vs_code, vs_code_size);
1737 static void test_create_device(void)
1739 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1741 D3D_FEATURE_LEVEL_11_0,
1742 D3D_FEATURE_LEVEL_10_1,
1743 D3D_FEATURE_LEVEL_10_0,
1744 D3D_FEATURE_LEVEL_9_3,
1745 D3D_FEATURE_LEVEL_9_2,
1746 D3D_FEATURE_LEVEL_9_1,
1748 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1749 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1750 ID3D11DeviceContext *immediate_context;
1751 IDXGISwapChain *swapchain;
1752 ID3D11Device *device;
1753 ULONG refcount;
1754 HWND window;
1755 HRESULT hr;
1757 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1758 &device, NULL, NULL)))
1760 skip("Failed to create HAL device.\n");
1761 if ((device = create_device(NULL)))
1763 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
1764 ID3D11Device_Release(device);
1766 return;
1769 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
1770 trace("Feature level %#x.\n", supported_feature_level);
1771 ID3D11Device_Release(device);
1773 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
1774 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1776 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
1777 &feature_level, NULL);
1778 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1779 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1780 feature_level, supported_feature_level);
1782 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
1783 ARRAY_SIZE(default_feature_levels), D3D11_SDK_VERSION, NULL, &feature_level, NULL);
1784 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1785 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1786 feature_level, supported_feature_level);
1788 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
1789 &immediate_context);
1790 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1792 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
1793 refcount = get_refcount(immediate_context);
1794 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1796 ID3D11DeviceContext_GetDevice(immediate_context, &device);
1797 refcount = ID3D11Device_Release(device);
1798 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1800 refcount = ID3D11DeviceContext_Release(immediate_context);
1801 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
1803 device = (ID3D11Device *)0xdeadbeef;
1804 feature_level = 0xdeadbeef;
1805 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1806 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1807 &device, &feature_level, &immediate_context);
1808 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
1809 ok(!device, "Got unexpected device pointer %p.\n", device);
1810 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1811 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1813 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
1815 swapchain_desc.BufferDesc.Width = 800;
1816 swapchain_desc.BufferDesc.Height = 600;
1817 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
1818 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
1819 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1820 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1821 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1822 swapchain_desc.SampleDesc.Count = 1;
1823 swapchain_desc.SampleDesc.Quality = 0;
1824 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1825 swapchain_desc.BufferCount = 1;
1826 swapchain_desc.OutputWindow = window;
1827 swapchain_desc.Windowed = TRUE;
1828 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1829 swapchain_desc.Flags = 0;
1831 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1832 &swapchain_desc, NULL, NULL, NULL, NULL);
1833 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1835 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1836 &swapchain_desc, NULL, NULL, &feature_level, NULL);
1837 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1838 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1839 feature_level, supported_feature_level);
1841 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1842 &swapchain_desc, &swapchain, &device, NULL, NULL);
1843 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1845 check_interface(swapchain, &IID_IDXGISwapChain1, TRUE, FALSE);
1847 memset(&obtained_desc, 0, sizeof(obtained_desc));
1848 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
1849 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
1850 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
1851 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
1852 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
1853 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
1854 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
1855 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
1856 obtained_desc.BufferDesc.RefreshRate.Numerator);
1857 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
1858 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
1859 obtained_desc.BufferDesc.RefreshRate.Denominator);
1860 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
1861 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
1862 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
1863 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
1864 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
1865 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
1866 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
1867 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
1868 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
1869 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
1870 ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
1871 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
1872 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
1873 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
1874 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
1875 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
1876 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
1877 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
1878 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
1879 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
1880 ok(obtained_desc.Flags == swapchain_desc.Flags,
1881 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
1883 refcount = IDXGISwapChain_Release(swapchain);
1884 ok(!refcount, "Swapchain has %u references left.\n", refcount);
1886 feature_level = ID3D11Device_GetFeatureLevel(device);
1887 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1888 feature_level, supported_feature_level);
1890 refcount = ID3D11Device_Release(device);
1891 ok(!refcount, "Device has %u references left.\n", refcount);
1893 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1894 NULL, NULL, &device, NULL, NULL);
1895 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1896 ID3D11Device_Release(device);
1898 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1899 NULL, NULL, NULL, NULL, NULL);
1900 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1902 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1903 NULL, NULL, NULL, &feature_level, NULL);
1904 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1905 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1906 feature_level, supported_feature_level);
1908 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1909 NULL, NULL, NULL, NULL, &immediate_context);
1910 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1911 ID3D11DeviceContext_Release(immediate_context);
1913 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1914 &swapchain_desc, NULL, NULL, NULL, NULL);
1915 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1917 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1918 &swapchain_desc, &swapchain, NULL, NULL, NULL);
1919 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1920 IDXGISwapChain_Release(swapchain);
1922 swapchain_desc.OutputWindow = NULL;
1923 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1924 &swapchain_desc, NULL, NULL, NULL, NULL);
1925 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1926 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1927 &swapchain_desc, NULL, &device, NULL, NULL);
1928 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1929 ID3D11Device_Release(device);
1931 swapchain = (IDXGISwapChain *)0xdeadbeef;
1932 device = (ID3D11Device *)0xdeadbeef;
1933 feature_level = 0xdeadbeef;
1934 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1935 swapchain_desc.OutputWindow = NULL;
1936 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1937 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1938 ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1939 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1940 ok(!device, "Got unexpected device pointer %p.\n", device);
1941 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1942 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1944 swapchain = (IDXGISwapChain *)0xdeadbeef;
1945 device = (ID3D11Device *)0xdeadbeef;
1946 feature_level = 0xdeadbeef;
1947 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1948 swapchain_desc.OutputWindow = window;
1949 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
1950 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1951 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1952 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1953 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1954 ok(!device, "Got unexpected device pointer %p.\n", device);
1955 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1956 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1958 DestroyWindow(window);
1961 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
1963 struct device_desc device_desc;
1964 IDXGIAdapter *dxgi_adapter;
1965 IDXGIDevice *dxgi_device;
1966 ID3D11Device *device;
1967 IUnknown *iface;
1968 ULONG refcount;
1969 HRESULT hr;
1971 device_desc.feature_level = &feature_level;
1972 device_desc.flags = 0;
1973 if (!(device = create_device(&device_desc)))
1975 skip("Failed to create device for feature level %#x.\n", feature_level);
1976 return;
1979 check_interface(device, &IID_IUnknown, TRUE, FALSE);
1980 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
1981 check_interface(device, &IID_IDXGIDevice, TRUE, FALSE);
1982 check_interface(device, &IID_IDXGIDevice1, TRUE, FALSE);
1983 check_interface(device, &IID_ID3D10Multithread, TRUE, TRUE); /* Not available on all Windows versions. */
1984 todo_wine check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
1985 todo_wine check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
1986 check_interface(device, &IID_ID3D11InfoQueue, FALSE, FALSE); /* Non-debug mode. */
1988 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1989 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1990 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1991 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1992 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1993 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1994 IUnknown_Release(iface);
1995 IDXGIAdapter_Release(dxgi_adapter);
1996 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1997 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1998 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1999 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
2000 IUnknown_Release(iface);
2001 IDXGIAdapter_Release(dxgi_adapter);
2002 IDXGIDevice_Release(dxgi_device);
2004 refcount = ID3D11Device_Release(device);
2005 ok(!refcount, "Device has %u references left.\n", refcount);
2007 device_desc.feature_level = &feature_level;
2008 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
2009 if (!(device = create_device(&device_desc)))
2011 skip("Failed to create debug device for feature level %#x.\n", feature_level);
2012 return;
2015 todo_wine check_interface(device, &IID_ID3D11InfoQueue, TRUE, FALSE);
2017 refcount = ID3D11Device_Release(device);
2018 ok(!refcount, "Device has %u references left.\n", refcount);
2021 static void test_get_immediate_context(void)
2023 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
2024 ULONG expected_refcount, refcount;
2025 ID3D11Device *device;
2027 if (!(device = create_device(NULL)))
2029 skip("Failed to create device.\n");
2030 return;
2033 expected_refcount = get_refcount(device) + 1;
2034 ID3D11Device_GetImmediateContext(device, &immediate_context);
2035 refcount = get_refcount(device);
2036 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
2037 previous_immediate_context = immediate_context;
2039 ID3D11Device_GetImmediateContext(device, &immediate_context);
2040 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
2041 refcount = get_refcount(device);
2042 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
2044 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
2045 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2046 refcount = ID3D11DeviceContext_Release(immediate_context);
2047 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2049 ID3D11Device_GetImmediateContext(device, &immediate_context);
2050 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
2051 refcount = ID3D11DeviceContext_Release(immediate_context);
2052 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2054 refcount = ID3D11Device_Release(device);
2055 ok(!refcount, "Device has %u references left.\n", refcount);
2058 static void test_create_texture1d(void)
2060 ULONG refcount, expected_refcount;
2061 D3D11_SUBRESOURCE_DATA data = {0};
2062 ID3D11Device *device, *tmp;
2063 D3D11_TEXTURE1D_DESC desc;
2064 ID3D11Texture1D *texture;
2065 unsigned int i;
2066 HRESULT hr;
2068 if (!(device = create_device(NULL)))
2070 skip("Failed to create device.\n");
2071 return;
2074 desc.Width = 512;
2075 desc.MipLevels = 1;
2076 desc.ArraySize = 1;
2077 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2078 desc.Usage = D3D11_USAGE_DEFAULT;
2079 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2080 desc.CPUAccessFlags = 0;
2081 desc.MiscFlags = 0;
2083 hr = ID3D11Device_CreateTexture1D(device, &desc, &data, &texture);
2084 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2086 expected_refcount = get_refcount(device) + 1;
2087 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2088 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2089 refcount = get_refcount(device);
2090 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2091 tmp = NULL;
2092 expected_refcount = refcount + 1;
2093 ID3D11Texture1D_GetDevice(texture, &tmp);
2094 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2095 refcount = get_refcount(device);
2096 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2097 ID3D11Device_Release(tmp);
2099 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2100 ID3D11Texture1D_Release(texture);
2102 desc.MipLevels = 0;
2103 expected_refcount = get_refcount(device) + 1;
2104 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2105 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2106 refcount = get_refcount(device);
2107 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2108 tmp = NULL;
2109 expected_refcount = refcount + 1;
2110 ID3D11Texture1D_GetDevice(texture, &tmp);
2111 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2112 refcount = get_refcount(device);
2113 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2114 ID3D11Device_Release(tmp);
2116 ID3D11Texture1D_GetDesc(texture, &desc);
2117 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2118 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2119 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2120 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2121 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2122 ok(desc.BindFlags == D3D11_BIND_SHADER_RESOURCE, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
2123 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
2124 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
2126 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2127 ID3D11Texture1D_Release(texture);
2129 desc.MipLevels = 1;
2130 desc.ArraySize = 2;
2131 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2132 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2134 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2135 ID3D11Texture1D_Release(texture);
2137 for (i = 0; i < 4; ++i)
2139 desc.ArraySize = i;
2140 desc.Format = DXGI_FORMAT_R32G32B32A32_TYPELESS;
2141 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2142 desc.MiscFlags = 0;
2143 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, (ID3D11Texture1D **)&texture);
2144 ok(hr == (i ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2145 if (SUCCEEDED(hr))
2146 ID3D11Texture1D_Release(texture);
2149 refcount = ID3D11Device_Release(device);
2150 ok(!refcount, "Device has %u references left.\n", refcount);
2153 static void test_texture1d_interfaces(void)
2155 ID3D10Texture1D *d3d10_texture;
2156 D3D11_TEXTURE1D_DESC desc;
2157 ID3D11Texture1D *texture;
2158 ID3D11Device *device;
2159 unsigned int i;
2160 ULONG refcount;
2161 HRESULT hr;
2163 static const struct test
2165 BOOL implements_d3d10_interfaces;
2166 UINT bind_flags;
2167 UINT misc_flags;
2168 UINT expected_bind_flags;
2169 UINT expected_misc_flags;
2171 desc_conversion_tests[] =
2174 TRUE,
2175 D3D11_BIND_SHADER_RESOURCE, 0,
2176 D3D10_BIND_SHADER_RESOURCE, 0
2179 TRUE,
2180 D3D11_BIND_UNORDERED_ACCESS, 0,
2181 D3D11_BIND_UNORDERED_ACCESS, 0
2184 FALSE,
2185 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2186 0, 0
2189 TRUE,
2190 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2191 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2195 if (!(device = create_device(NULL)))
2197 skip("Failed to create ID3D11Device, skipping tests.\n");
2198 return;
2201 desc.Width = 512;
2202 desc.MipLevels = 0;
2203 desc.ArraySize = 1;
2204 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2205 desc.Usage = D3D11_USAGE_DEFAULT;
2206 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2207 desc.CPUAccessFlags = 0;
2208 desc.MiscFlags = 0;
2210 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2211 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2212 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2213 hr = check_interface(texture, &IID_ID3D10Texture1D, TRUE, TRUE); /* Not available on all Windows versions. */
2214 ID3D11Texture1D_Release(texture);
2215 if (FAILED(hr))
2217 win_skip("1D textures do not implement ID3D10Texture1D, skipping tests.\n");
2218 ID3D11Device_Release(device);
2219 return;
2222 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2224 const struct test *current = &desc_conversion_tests[i];
2225 D3D10_TEXTURE1D_DESC d3d10_desc;
2226 ID3D10Device *d3d10_device;
2228 desc.Width = 512;
2229 desc.MipLevels = 1;
2230 desc.ArraySize = 1;
2231 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2232 desc.Usage = D3D11_USAGE_DEFAULT;
2233 desc.BindFlags = current->bind_flags;
2234 desc.CPUAccessFlags = 0;
2235 desc.MiscFlags = current->misc_flags;
2237 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2238 /* Shared resources are not supported by REF and WARP devices. */
2239 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2240 "Test %u: Failed to create a 1d texture, hr %#x.\n", i, hr);
2241 if (FAILED(hr))
2243 win_skip("Failed to create ID3D11Texture1D, skipping test %u.\n", i);
2244 continue;
2247 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2249 hr = ID3D11Texture1D_QueryInterface(texture, &IID_ID3D10Texture1D, (void **)&d3d10_texture);
2250 ID3D11Texture1D_Release(texture);
2252 if (current->implements_d3d10_interfaces)
2254 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture1D.\n", i);
2256 else
2258 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture1D.\n", i);
2259 if (SUCCEEDED(hr)) ID3D10Texture1D_Release(d3d10_texture);
2260 continue;
2263 ID3D10Texture1D_GetDesc(d3d10_texture, &d3d10_desc);
2265 ok(d3d10_desc.Width == desc.Width,
2266 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2267 ok(d3d10_desc.MipLevels == desc.MipLevels,
2268 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2269 ok(d3d10_desc.ArraySize == desc.ArraySize,
2270 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2271 ok(d3d10_desc.Format == desc.Format,
2272 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2273 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2274 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2275 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2276 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2277 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2278 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2280 d3d10_device = (ID3D10Device *)0xdeadbeef;
2281 ID3D10Texture1D_GetDevice(d3d10_texture, &d3d10_device);
2282 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2283 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2285 ID3D10Texture1D_Release(d3d10_texture);
2288 refcount = ID3D11Device_Release(device);
2289 ok(!refcount, "Device has %u references left.\n", refcount);
2292 static void test_create_texture2d(void)
2294 ULONG refcount, expected_refcount;
2295 D3D11_SUBRESOURCE_DATA data = {0};
2296 D3D_FEATURE_LEVEL feature_level;
2297 ID3D11Device *device, *tmp;
2298 D3D11_TEXTURE2D_DESC desc;
2299 ID3D11Texture2D *texture;
2300 UINT quality_level_count;
2301 unsigned int i;
2302 HRESULT hr;
2304 static const struct
2306 DXGI_FORMAT format;
2307 UINT array_size;
2308 D3D11_BIND_FLAG bind_flags;
2309 UINT misc_flags;
2310 BOOL succeeds;
2311 BOOL todo;
2313 tests[] =
2315 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
2316 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
2317 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
2318 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
2319 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2320 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2321 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2322 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2323 FALSE, FALSE},
2324 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2325 FALSE, FALSE},
2326 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2327 FALSE, FALSE},
2328 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2329 TRUE, FALSE},
2330 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2331 TRUE, FALSE},
2332 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2333 TRUE, FALSE},
2334 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2335 TRUE, FALSE},
2336 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2337 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2338 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2339 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2340 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2341 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2342 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2343 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2344 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2345 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2346 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2347 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2348 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2349 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2350 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2351 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2352 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2353 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2354 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2355 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
2356 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2357 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2358 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
2359 TRUE, FALSE},
2360 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2361 TRUE, FALSE},
2362 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2363 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
2364 FALSE, TRUE},
2365 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2366 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
2367 FALSE, TRUE},
2368 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
2369 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
2370 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
2371 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2372 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2373 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2374 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2375 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2376 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2377 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2378 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2379 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2380 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2381 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2382 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2383 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2384 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2385 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2386 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2387 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2388 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2389 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2390 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
2391 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2392 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
2393 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
2394 FALSE, TRUE},
2395 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2396 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2397 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2398 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2399 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2402 if (!(device = create_device(NULL)))
2404 skip("Failed to create device.\n");
2405 return;
2408 feature_level = ID3D11Device_GetFeatureLevel(device);
2410 desc.Width = 512;
2411 desc.Height = 512;
2412 desc.MipLevels = 1;
2413 desc.ArraySize = 1;
2414 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2415 desc.SampleDesc.Count = 1;
2416 desc.SampleDesc.Quality = 0;
2417 desc.Usage = D3D11_USAGE_DEFAULT;
2418 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2419 desc.CPUAccessFlags = 0;
2420 desc.MiscFlags = 0;
2422 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
2423 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2425 expected_refcount = get_refcount(device) + 1;
2426 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2427 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2428 refcount = get_refcount(device);
2429 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2430 tmp = NULL;
2431 expected_refcount = refcount + 1;
2432 ID3D11Texture2D_GetDevice(texture, &tmp);
2433 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2434 refcount = get_refcount(device);
2435 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2436 ID3D11Device_Release(tmp);
2438 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2439 ID3D11Texture2D_Release(texture);
2441 desc.MipLevels = 0;
2442 expected_refcount = get_refcount(device) + 1;
2443 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2444 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2445 refcount = get_refcount(device);
2446 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2447 tmp = NULL;
2448 expected_refcount = refcount + 1;
2449 ID3D11Texture2D_GetDevice(texture, &tmp);
2450 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2451 refcount = get_refcount(device);
2452 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2453 ID3D11Device_Release(tmp);
2455 ID3D11Texture2D_GetDesc(texture, &desc);
2456 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2457 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
2458 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2459 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2460 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2461 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
2462 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
2463 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2464 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
2465 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
2466 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
2468 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2469 ID3D11Texture2D_Release(texture);
2471 desc.MipLevels = 1;
2472 desc.ArraySize = 2;
2473 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2474 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2476 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2477 ID3D11Texture2D_Release(texture);
2479 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
2480 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
2481 desc.ArraySize = 1;
2482 desc.SampleDesc.Count = 2;
2483 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2484 if (quality_level_count)
2486 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
2487 ID3D11Texture2D_Release(texture);
2488 desc.SampleDesc.Quality = quality_level_count;
2489 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2491 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2493 /* We assume 15 samples multisampling is never supported in practice. */
2494 desc.SampleDesc.Count = 15;
2495 desc.SampleDesc.Quality = 0;
2496 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2497 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2499 desc.SampleDesc.Count = 1;
2500 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2502 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
2503 BOOL todo = tests[i].todo;
2505 if (feature_level < D3D_FEATURE_LEVEL_10_1
2506 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
2507 && tests[i].array_size > 6)
2509 expected_hr = E_INVALIDARG;
2510 todo = TRUE;
2513 desc.ArraySize = tests[i].array_size;
2514 desc.Format = tests[i].format;
2515 desc.BindFlags = tests[i].bind_flags;
2516 desc.MiscFlags = tests[i].misc_flags;
2517 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, (ID3D11Texture2D **)&texture);
2519 todo_wine_if(todo)
2520 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
2521 i, hr, desc.Format);
2523 if (SUCCEEDED(hr))
2524 ID3D11Texture2D_Release(texture);
2527 refcount = ID3D11Device_Release(device);
2528 ok(!refcount, "Device has %u references left.\n", refcount);
2531 static void test_texture2d_interfaces(void)
2533 ID3D10Texture2D *d3d10_texture;
2534 D3D11_TEXTURE2D_DESC desc;
2535 ID3D11Texture2D *texture;
2536 ID3D11Device *device;
2537 unsigned int i;
2538 ULONG refcount;
2539 HRESULT hr;
2541 static const struct test
2543 BOOL implements_d3d10_interfaces;
2544 UINT bind_flags;
2545 UINT misc_flags;
2546 UINT expected_bind_flags;
2547 UINT expected_misc_flags;
2549 desc_conversion_tests[] =
2552 TRUE,
2553 D3D11_BIND_SHADER_RESOURCE, 0,
2554 D3D10_BIND_SHADER_RESOURCE, 0
2557 TRUE,
2558 D3D11_BIND_UNORDERED_ACCESS, 0,
2559 D3D11_BIND_UNORDERED_ACCESS, 0
2562 FALSE,
2563 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2564 0, 0
2567 TRUE,
2568 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2569 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2572 TRUE,
2573 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
2574 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2578 if (!(device = create_device(NULL)))
2580 skip("Failed to create ID3D11Device, skipping tests.\n");
2581 return;
2584 desc.Width = 512;
2585 desc.Height = 512;
2586 desc.MipLevels = 0;
2587 desc.ArraySize = 1;
2588 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2589 desc.SampleDesc.Count = 1;
2590 desc.SampleDesc.Quality = 0;
2591 desc.Usage = D3D11_USAGE_DEFAULT;
2592 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2593 desc.CPUAccessFlags = 0;
2594 desc.MiscFlags = 0;
2596 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2597 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2598 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2599 hr = check_interface(texture, &IID_ID3D10Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
2600 ID3D11Texture2D_Release(texture);
2601 if (FAILED(hr))
2603 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
2604 ID3D11Device_Release(device);
2605 return;
2608 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2610 const struct test *current = &desc_conversion_tests[i];
2611 D3D10_TEXTURE2D_DESC d3d10_desc;
2612 ID3D10Device *d3d10_device;
2614 desc.Width = 512;
2615 desc.Height = 512;
2616 desc.MipLevels = 1;
2617 desc.ArraySize = 1;
2618 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2619 desc.SampleDesc.Count = 1;
2620 desc.SampleDesc.Quality = 0;
2621 desc.Usage = D3D11_USAGE_DEFAULT;
2622 desc.BindFlags = current->bind_flags;
2623 desc.CPUAccessFlags = 0;
2624 desc.MiscFlags = current->misc_flags;
2626 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2627 /* Shared resources are not supported by REF and WARP devices. */
2628 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2629 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2630 if (FAILED(hr))
2632 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
2633 continue;
2636 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2638 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2639 ID3D11Texture2D_Release(texture);
2641 if (current->implements_d3d10_interfaces)
2643 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2645 else
2647 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2648 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
2649 continue;
2652 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
2654 ok(d3d10_desc.Width == desc.Width,
2655 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2656 ok(d3d10_desc.Height == desc.Height,
2657 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2658 ok(d3d10_desc.MipLevels == desc.MipLevels,
2659 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2660 ok(d3d10_desc.ArraySize == desc.ArraySize,
2661 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2662 ok(d3d10_desc.Format == desc.Format,
2663 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2664 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
2665 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
2666 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2667 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
2668 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2669 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2670 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2671 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2672 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2673 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2674 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2675 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2677 d3d10_device = (ID3D10Device *)0xdeadbeef;
2678 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
2679 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2680 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2682 ID3D10Texture2D_Release(d3d10_texture);
2685 refcount = ID3D11Device_Release(device);
2686 ok(!refcount, "Device has %u references left.\n", refcount);
2689 static void test_create_texture3d(void)
2691 ULONG refcount, expected_refcount;
2692 D3D11_SUBRESOURCE_DATA data = {0};
2693 ID3D11Device *device, *tmp;
2694 D3D11_TEXTURE3D_DESC desc;
2695 ID3D11Texture3D *texture;
2696 unsigned int i;
2697 HRESULT hr;
2699 static const struct
2701 DXGI_FORMAT format;
2702 D3D11_BIND_FLAG bind_flags;
2703 BOOL succeeds;
2704 BOOL todo;
2706 tests[] =
2708 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
2709 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
2710 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2711 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2712 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2713 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2714 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2715 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2716 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2717 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2718 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2719 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2722 if (!(device = create_device(NULL)))
2724 skip("Failed to create ID3D11Device, skipping tests.\n");
2725 return;
2728 desc.Width = 64;
2729 desc.Height = 64;
2730 desc.Depth = 64;
2731 desc.MipLevels = 1;
2732 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2733 desc.Usage = D3D11_USAGE_DEFAULT;
2734 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2735 desc.CPUAccessFlags = 0;
2736 desc.MiscFlags = 0;
2738 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2739 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2741 expected_refcount = get_refcount(device) + 1;
2742 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2743 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2744 refcount = get_refcount(device);
2745 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2746 tmp = NULL;
2747 expected_refcount = refcount + 1;
2748 ID3D11Texture3D_GetDevice(texture, &tmp);
2749 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2750 refcount = get_refcount(device);
2751 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2752 ID3D11Device_Release(tmp);
2754 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2755 ID3D11Texture3D_Release(texture);
2757 desc.MipLevels = 0;
2758 expected_refcount = get_refcount(device) + 1;
2759 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2760 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2761 refcount = get_refcount(device);
2762 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2763 tmp = NULL;
2764 expected_refcount = refcount + 1;
2765 ID3D11Texture3D_GetDevice(texture, &tmp);
2766 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2767 refcount = get_refcount(device);
2768 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2769 ID3D11Device_Release(tmp);
2771 ID3D11Texture3D_GetDesc(texture, &desc);
2772 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2773 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2774 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2775 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2776 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2777 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2778 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2779 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2780 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2782 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2783 ID3D11Texture3D_Release(texture);
2785 desc.MipLevels = 1;
2786 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2788 desc.Format = tests[i].format;
2789 desc.BindFlags = tests[i].bind_flags;
2790 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, (ID3D11Texture3D **)&texture);
2792 todo_wine_if(tests[i].todo)
2793 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2795 if (SUCCEEDED(hr))
2796 ID3D11Texture3D_Release(texture);
2799 refcount = ID3D11Device_Release(device);
2800 ok(!refcount, "Device has %u references left.\n", refcount);
2803 static void test_texture3d_interfaces(void)
2805 ID3D10Texture3D *d3d10_texture;
2806 D3D11_TEXTURE3D_DESC desc;
2807 ID3D11Texture3D *texture;
2808 ID3D11Device *device;
2809 unsigned int i;
2810 ULONG refcount;
2811 HRESULT hr;
2813 static const struct test
2815 BOOL implements_d3d10_interfaces;
2816 UINT bind_flags;
2817 UINT misc_flags;
2818 UINT expected_bind_flags;
2819 UINT expected_misc_flags;
2821 desc_conversion_tests[] =
2824 TRUE,
2825 D3D11_BIND_SHADER_RESOURCE, 0,
2826 D3D10_BIND_SHADER_RESOURCE, 0
2829 TRUE,
2830 D3D11_BIND_UNORDERED_ACCESS, 0,
2831 D3D11_BIND_UNORDERED_ACCESS, 0
2834 FALSE,
2835 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2836 0, 0
2839 TRUE,
2840 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2841 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2845 if (!(device = create_device(NULL)))
2847 skip("Failed to create ID3D11Device.\n");
2848 return;
2851 desc.Width = 64;
2852 desc.Height = 64;
2853 desc.Depth = 64;
2854 desc.MipLevels = 0;
2855 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2856 desc.Usage = D3D11_USAGE_DEFAULT;
2857 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2858 desc.CPUAccessFlags = 0;
2859 desc.MiscFlags = 0;
2861 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2862 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2863 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2864 hr = check_interface(texture, &IID_ID3D10Texture3D, TRUE, TRUE); /* Not available on all Windows versions. */
2865 ID3D11Texture3D_Release(texture);
2866 if (FAILED(hr))
2868 win_skip("3D textures do not implement ID3D10Texture3D.\n");
2869 ID3D11Device_Release(device);
2870 return;
2873 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2875 const struct test *current = &desc_conversion_tests[i];
2876 D3D10_TEXTURE3D_DESC d3d10_desc;
2877 ID3D10Device *d3d10_device;
2879 desc.Width = 64;
2880 desc.Height = 64;
2881 desc.Depth = 64;
2882 desc.MipLevels = 1;
2883 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2884 desc.Usage = D3D11_USAGE_DEFAULT;
2885 desc.BindFlags = current->bind_flags;
2886 desc.CPUAccessFlags = 0;
2887 desc.MiscFlags = current->misc_flags;
2889 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2890 /* Shared resources are not supported by REF and WARP devices. */
2891 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2892 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
2893 if (FAILED(hr))
2895 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
2896 continue;
2899 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2901 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2902 ID3D11Texture3D_Release(texture);
2904 if (current->implements_d3d10_interfaces)
2906 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
2908 else
2910 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
2911 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2912 continue;
2915 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
2917 ok(d3d10_desc.Width == desc.Width,
2918 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2919 ok(d3d10_desc.Height == desc.Height,
2920 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2921 ok(d3d10_desc.Depth == desc.Depth,
2922 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
2923 ok(d3d10_desc.MipLevels == desc.MipLevels,
2924 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2925 ok(d3d10_desc.Format == desc.Format,
2926 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2927 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2928 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2929 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2930 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2931 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2932 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2933 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2934 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2936 d3d10_device = (ID3D10Device *)0xdeadbeef;
2937 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
2938 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2939 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2941 ID3D10Texture3D_Release(d3d10_texture);
2944 refcount = ID3D11Device_Release(device);
2945 ok(!refcount, "Device has %u references left.\n", refcount);
2948 static void test_create_buffer(void)
2950 ID3D10Buffer *d3d10_buffer;
2951 HRESULT expected_hr, hr;
2952 D3D11_BUFFER_DESC desc;
2953 ID3D11Buffer *buffer;
2954 ID3D11Device *device;
2955 unsigned int i;
2956 ULONG refcount;
2958 static const struct test
2960 BOOL succeeds;
2961 BOOL implements_d3d10_interfaces;
2962 UINT bind_flags;
2963 UINT misc_flags;
2964 UINT structure_stride;
2965 UINT expected_bind_flags;
2966 UINT expected_misc_flags;
2968 tests[] =
2971 TRUE, TRUE,
2972 D3D11_BIND_VERTEX_BUFFER, 0, 0,
2973 D3D10_BIND_VERTEX_BUFFER, 0
2976 TRUE, TRUE,
2977 D3D11_BIND_INDEX_BUFFER, 0, 0,
2978 D3D10_BIND_INDEX_BUFFER, 0
2981 TRUE, TRUE,
2982 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
2983 D3D10_BIND_CONSTANT_BUFFER, 0
2986 TRUE, TRUE,
2987 D3D11_BIND_SHADER_RESOURCE, 0, 0,
2988 D3D10_BIND_SHADER_RESOURCE, 0
2991 TRUE, TRUE,
2992 D3D11_BIND_STREAM_OUTPUT, 0, 0,
2993 D3D10_BIND_STREAM_OUTPUT, 0
2996 TRUE, TRUE,
2997 D3D11_BIND_RENDER_TARGET, 0, 0,
2998 D3D10_BIND_RENDER_TARGET, 0
3001 TRUE, TRUE,
3002 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
3003 D3D11_BIND_UNORDERED_ACCESS, 0
3006 TRUE, TRUE,
3007 0, D3D11_RESOURCE_MISC_SHARED, 0,
3008 0, D3D10_RESOURCE_MISC_SHARED
3011 TRUE, TRUE,
3012 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
3013 0, 0
3016 FALSE, FALSE,
3017 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3020 FALSE, FALSE,
3021 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3024 FALSE, FALSE,
3025 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3028 TRUE, TRUE,
3029 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3030 D3D10_BIND_SHADER_RESOURCE, 0
3033 FALSE, FALSE,
3034 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3037 FALSE, FALSE,
3038 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3041 TRUE, TRUE,
3042 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3043 D3D11_BIND_UNORDERED_ACCESS, 0
3046 FALSE, FALSE,
3047 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3049 /* Structured buffers do not implement ID3D10Buffer. */
3051 TRUE, FALSE,
3052 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3055 TRUE, FALSE,
3056 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3059 FALSE, FALSE,
3060 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
3063 FALSE, FALSE,
3064 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
3067 FALSE, FALSE,
3068 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
3071 FALSE, FALSE,
3072 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
3075 FALSE, FALSE,
3076 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
3079 TRUE, FALSE,
3080 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
3083 FALSE, FALSE,
3084 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
3087 TRUE, FALSE,
3088 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
3091 TRUE, FALSE,
3092 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
3095 FALSE, FALSE,
3096 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
3099 TRUE, FALSE,
3100 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
3103 TRUE, TRUE,
3104 0, 0, 513,
3105 0, 0
3108 TRUE, TRUE,
3109 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
3110 D3D10_BIND_CONSTANT_BUFFER, 0
3113 TRUE, TRUE,
3114 D3D11_BIND_SHADER_RESOURCE, 0, 513,
3115 D3D10_BIND_SHADER_RESOURCE, 0
3118 TRUE, TRUE,
3119 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
3120 D3D11_BIND_UNORDERED_ACCESS, 0
3123 FALSE, FALSE,
3124 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3127 FALSE, FALSE,
3128 D3D11_BIND_SHADER_RESOURCE,
3129 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3132 TRUE, TRUE,
3133 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
3134 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
3138 if (!(device = create_device(NULL)))
3140 skip("Failed to create ID3D11Device.\n");
3141 return;
3144 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
3145 hr = check_interface(buffer, &IID_ID3D10Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
3146 ID3D11Buffer_Release(buffer);
3147 if (FAILED(hr))
3149 win_skip("Buffers do not implement ID3D10Buffer.\n");
3150 ID3D11Device_Release(device);
3151 return;
3154 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3156 const struct test *current = &tests[i];
3157 D3D11_BUFFER_DESC obtained_desc;
3158 D3D10_BUFFER_DESC d3d10_desc;
3159 ID3D10Device *d3d10_device;
3161 desc.ByteWidth = 1024;
3162 desc.Usage = D3D11_USAGE_DEFAULT;
3163 desc.BindFlags = current->bind_flags;
3164 desc.CPUAccessFlags = 0;
3165 desc.MiscFlags = current->misc_flags;
3166 desc.StructureByteStride = current->structure_stride;
3168 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
3169 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
3170 /* Shared resources are not supported by REF and WARP devices. */
3171 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
3172 i, hr, expected_hr);
3173 if (FAILED(hr))
3175 if (hr == E_OUTOFMEMORY)
3176 win_skip("Failed to create a buffer, skipping test %u.\n", i);
3177 continue;
3180 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
3181 desc.StructureByteStride = 0;
3183 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
3185 ok(obtained_desc.ByteWidth == desc.ByteWidth,
3186 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
3187 ok(obtained_desc.Usage == desc.Usage,
3188 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
3189 ok(obtained_desc.BindFlags == desc.BindFlags,
3190 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
3191 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
3192 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
3193 ok(obtained_desc.MiscFlags == desc.MiscFlags,
3194 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
3195 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
3196 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
3198 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
3199 ID3D11Buffer_Release(buffer);
3201 if (current->implements_d3d10_interfaces)
3203 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
3205 else
3207 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
3208 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
3209 continue;
3212 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
3214 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
3215 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
3216 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
3217 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
3218 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
3219 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
3220 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
3221 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
3222 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
3223 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
3225 d3d10_device = (ID3D10Device *)0xdeadbeef;
3226 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
3227 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
3228 if (d3d10_device) ID3D10Device_Release(d3d10_device);
3230 ID3D10Buffer_Release(d3d10_buffer);
3233 memset(&desc, 0, sizeof(desc));
3234 desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
3235 for (i = 0; i <= 32; ++i)
3237 desc.ByteWidth = i;
3238 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
3239 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
3240 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
3241 if (SUCCEEDED(hr))
3242 ID3D11Buffer_Release(buffer);
3245 refcount = ID3D11Device_Release(device);
3246 ok(!refcount, "Device has %u references left.\n", refcount);
3249 static void test_create_depthstencil_view(void)
3251 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
3252 D3D11_TEXTURE2D_DESC texture_desc;
3253 ULONG refcount, expected_refcount;
3254 ID3D11DepthStencilView *dsview;
3255 ID3D11Device *device, *tmp;
3256 ID3D11Texture2D *texture;
3257 unsigned int i;
3258 HRESULT hr;
3260 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3261 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
3262 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
3263 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
3264 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
3265 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
3266 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
3267 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
3268 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
3269 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
3270 static const struct
3272 struct
3274 unsigned int miplevel_count;
3275 unsigned int array_size;
3276 DXGI_FORMAT format;
3277 } texture;
3278 struct dsv_desc dsv_desc;
3279 struct dsv_desc expected_dsv_desc;
3281 tests[] =
3283 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
3284 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
3285 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3286 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
3287 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
3288 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3289 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3290 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3291 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3292 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3293 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
3294 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
3295 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
3296 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
3297 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
3298 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
3299 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
3300 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3301 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3302 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3303 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3304 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3305 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3306 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3307 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3308 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
3309 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
3311 static const struct
3313 struct
3315 unsigned int miplevel_count;
3316 unsigned int array_size;
3317 DXGI_FORMAT format;
3318 } texture;
3319 struct dsv_desc dsv_desc;
3321 invalid_desc_tests[] =
3323 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
3324 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
3325 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
3326 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
3327 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
3328 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3329 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
3330 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
3331 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
3332 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
3333 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
3334 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
3335 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
3337 #undef FMT_UNKNOWN
3338 #undef D24S8
3339 #undef R24G8_TL
3340 #undef DIM_UNKNOWN
3341 #undef TEX_1D
3342 #undef TEX_1D_ARRAY
3343 #undef TEX_2D
3344 #undef TEX_2D_ARRAY
3345 #undef TEX_2DMS
3346 #undef TEX_2DMS_ARR
3348 if (!(device = create_device(NULL)))
3350 skip("Failed to create device.\n");
3351 return;
3354 texture_desc.Width = 512;
3355 texture_desc.Height = 512;
3356 texture_desc.MipLevels = 1;
3357 texture_desc.ArraySize = 1;
3358 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
3359 texture_desc.SampleDesc.Count = 1;
3360 texture_desc.SampleDesc.Quality = 0;
3361 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3362 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3363 texture_desc.CPUAccessFlags = 0;
3364 texture_desc.MiscFlags = 0;
3366 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3367 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
3369 expected_refcount = get_refcount(device) + 1;
3370 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
3371 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
3372 refcount = get_refcount(device);
3373 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3374 tmp = NULL;
3375 expected_refcount = refcount + 1;
3376 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
3377 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3378 refcount = get_refcount(device);
3379 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3380 ID3D11Device_Release(tmp);
3382 memset(&dsv_desc, 0, sizeof(dsv_desc));
3383 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
3384 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
3385 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
3386 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
3387 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
3388 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
3390 ID3D11DepthStencilView_Release(dsview);
3391 ID3D11Texture2D_Release(texture);
3393 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3395 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
3397 texture_desc.MipLevels = tests[i].texture.miplevel_count;
3398 texture_desc.ArraySize = tests[i].texture.array_size;
3399 texture_desc.Format = tests[i].texture.format;
3401 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3402 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3404 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
3406 current_desc = NULL;
3408 else
3410 current_desc = &dsv_desc;
3411 get_dsv_desc(current_desc, &tests[i].dsv_desc);
3414 expected_refcount = get_refcount(texture);
3415 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
3416 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
3417 refcount = get_refcount(texture);
3418 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3420 /* Not available on all Windows versions. */
3421 check_interface(dsview, &IID_ID3D10DepthStencilView, TRUE, TRUE);
3423 memset(&dsv_desc, 0, sizeof(dsv_desc));
3424 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
3425 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
3427 ID3D11DepthStencilView_Release(dsview);
3428 ID3D11Texture2D_Release(texture);
3431 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3433 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3434 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
3435 texture_desc.Format = invalid_desc_tests[i].texture.format;
3437 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3438 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3440 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
3441 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
3442 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3444 ID3D11Texture2D_Release(texture);
3447 refcount = ID3D11Device_Release(device);
3448 ok(!refcount, "Device has %u references left.\n", refcount);
3451 static void test_depthstencil_view_interfaces(void)
3453 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
3454 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
3455 ID3D10DepthStencilView *d3d10_dsview;
3456 D3D11_TEXTURE2D_DESC texture_desc;
3457 ID3D11DepthStencilView *dsview;
3458 ID3D11Texture2D *texture;
3459 ID3D11Device *device;
3460 ULONG refcount;
3461 HRESULT hr;
3463 if (!(device = create_device(NULL)))
3465 skip("Failed to create device.\n");
3466 return;
3469 texture_desc.Width = 512;
3470 texture_desc.Height = 512;
3471 texture_desc.MipLevels = 1;
3472 texture_desc.ArraySize = 1;
3473 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
3474 texture_desc.SampleDesc.Count = 1;
3475 texture_desc.SampleDesc.Quality = 0;
3476 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3477 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3478 texture_desc.CPUAccessFlags = 0;
3479 texture_desc.MiscFlags = 0;
3481 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3482 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
3484 dsv_desc.Format = texture_desc.Format;
3485 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
3486 dsv_desc.Flags = 0;
3487 U(dsv_desc).Texture2D.MipSlice = 0;
3489 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
3490 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
3492 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
3493 ID3D11DepthStencilView_Release(dsview);
3494 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3495 "Depth stencil view should implement ID3D10DepthStencilView.\n");
3497 if (FAILED(hr))
3499 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
3500 goto done;
3503 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
3504 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
3505 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
3506 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
3507 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
3508 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
3510 ID3D10DepthStencilView_Release(d3d10_dsview);
3512 done:
3513 ID3D11Texture2D_Release(texture);
3515 refcount = ID3D11Device_Release(device);
3516 ok(!refcount, "Device has %u references left.\n", refcount);
3519 static void test_create_rendertarget_view(void)
3521 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
3522 D3D11_TEXTURE3D_DESC texture3d_desc;
3523 D3D11_TEXTURE2D_DESC texture2d_desc;
3524 D3D11_SUBRESOURCE_DATA data = {0};
3525 ULONG refcount, expected_refcount;
3526 D3D11_BUFFER_DESC buffer_desc;
3527 ID3D11RenderTargetView *rtview;
3528 ID3D11Device *device, *tmp;
3529 ID3D11Texture3D *texture3d;
3530 ID3D11Texture2D *texture2d;
3531 ID3D11Resource *texture;
3532 ID3D11Buffer *buffer;
3533 unsigned int i;
3534 HRESULT hr;
3536 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3537 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3538 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3539 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
3540 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
3541 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
3542 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
3543 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
3544 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
3545 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
3546 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
3547 static const struct
3549 struct
3551 unsigned int miplevel_count;
3552 unsigned int depth_or_array_size;
3553 DXGI_FORMAT format;
3554 } texture;
3555 struct rtv_desc rtv_desc;
3556 struct rtv_desc expected_rtv_desc;
3558 tests[] =
3560 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
3561 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
3562 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3563 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
3564 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
3565 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3566 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3567 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3568 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3569 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3570 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
3571 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
3572 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
3573 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
3574 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
3575 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
3576 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
3577 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3578 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3579 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3580 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3581 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3582 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3583 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3584 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3585 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3586 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3587 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3588 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3589 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3590 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3591 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3592 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
3593 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
3594 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
3595 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
3596 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3597 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3598 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
3599 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
3600 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
3601 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
3602 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
3603 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
3605 static const struct
3607 struct
3609 D3D11_RTV_DIMENSION dimension;
3610 unsigned int miplevel_count;
3611 unsigned int depth_or_array_size;
3612 DXGI_FORMAT format;
3613 } texture;
3614 struct rtv_desc rtv_desc;
3616 invalid_desc_tests[] =
3618 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3619 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3620 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3621 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3622 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
3623 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
3624 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
3625 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3626 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
3627 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
3628 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
3629 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
3630 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
3631 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
3632 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
3633 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3634 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3635 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3636 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3637 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3638 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3639 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3640 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3641 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
3642 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
3643 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3644 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3645 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
3646 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3647 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3648 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
3649 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
3650 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
3651 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
3652 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
3654 #undef FMT_UNKNOWN
3655 #undef RGBA8_UNORM
3656 #undef RGBA8_TL
3657 #undef DIM_UNKNOWN
3658 #undef TEX_1D
3659 #undef TEX_1D_ARRAY
3660 #undef TEX_2D
3661 #undef TEX_2D_ARRAY
3662 #undef TEX_2DMS
3663 #undef TEX_2DMS_ARR
3664 #undef TEX_3D
3666 if (!(device = create_device(NULL)))
3668 skip("Failed to create device.\n");
3669 return;
3672 buffer_desc.ByteWidth = 1024;
3673 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3674 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3675 buffer_desc.CPUAccessFlags = 0;
3676 buffer_desc.MiscFlags = 0;
3677 buffer_desc.StructureByteStride = 0;
3679 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
3680 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3682 expected_refcount = get_refcount(device) + 1;
3683 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3684 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3685 refcount = get_refcount(device);
3686 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3687 tmp = NULL;
3688 expected_refcount = refcount + 1;
3689 ID3D11Buffer_GetDevice(buffer, &tmp);
3690 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3691 refcount = get_refcount(device);
3692 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3693 ID3D11Device_Release(tmp);
3695 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3696 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
3697 U1(U(rtv_desc).Buffer).ElementOffset = 0;
3698 U2(U(rtv_desc).Buffer).ElementWidth = 64;
3700 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
3701 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3703 expected_refcount = get_refcount(device) + 1;
3704 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
3705 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
3706 refcount = get_refcount(device);
3707 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3708 tmp = NULL;
3709 expected_refcount = refcount + 1;
3710 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
3711 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3712 refcount = get_refcount(device);
3713 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3714 ID3D11Device_Release(tmp);
3716 /* Not available on all Windows versions. */
3717 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3719 ID3D11RenderTargetView_Release(rtview);
3720 ID3D11Buffer_Release(buffer);
3722 texture2d_desc.Width = 512;
3723 texture2d_desc.Height = 512;
3724 texture2d_desc.SampleDesc.Count = 1;
3725 texture2d_desc.SampleDesc.Quality = 0;
3726 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3727 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3728 texture2d_desc.CPUAccessFlags = 0;
3729 texture2d_desc.MiscFlags = 0;
3731 texture3d_desc.Width = 64;
3732 texture3d_desc.Height = 64;
3733 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3734 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3735 texture3d_desc.CPUAccessFlags = 0;
3736 texture3d_desc.MiscFlags = 0;
3738 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3740 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3742 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3744 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3745 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3746 texture2d_desc.Format = tests[i].texture.format;
3748 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3749 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3750 texture = (ID3D11Resource *)texture2d;
3752 else
3754 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3755 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3756 texture3d_desc.Format = tests[i].texture.format;
3758 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3759 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3760 texture = (ID3D11Resource *)texture3d;
3763 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
3765 current_desc = NULL;
3767 else
3769 current_desc = &rtv_desc;
3770 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3773 expected_refcount = get_refcount(texture);
3774 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3775 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3776 refcount = get_refcount(texture);
3777 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3779 /* Not available on all Windows versions. */
3780 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3782 memset(&rtv_desc, 0, sizeof(rtv_desc));
3783 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
3784 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3786 ID3D11RenderTargetView_Release(rtview);
3787 ID3D11Resource_Release(texture);
3790 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3792 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
3793 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
3795 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3797 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3798 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3799 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3801 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3802 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3803 texture = (ID3D11Resource *)texture2d;
3805 else
3807 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3808 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3809 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3811 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3812 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3813 texture = (ID3D11Resource *)texture3d;
3816 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3817 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3818 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3820 ID3D11Resource_Release(texture);
3823 refcount = ID3D11Device_Release(device);
3824 ok(!refcount, "Device has %u references left.\n", refcount);
3827 static void test_create_shader_resource_view(void)
3829 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
3830 D3D11_TEXTURE3D_DESC texture3d_desc;
3831 D3D11_TEXTURE2D_DESC texture2d_desc;
3832 ULONG refcount, expected_refcount;
3833 ID3D11ShaderResourceView *srview;
3834 D3D_FEATURE_LEVEL feature_level;
3835 D3D11_BUFFER_DESC buffer_desc;
3836 ID3D11Device *device, *tmp;
3837 ID3D11Texture3D *texture3d;
3838 ID3D11Texture2D *texture2d;
3839 ID3D11Resource *texture;
3840 ID3D11Buffer *buffer;
3841 unsigned int i;
3842 HRESULT hr;
3844 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3845 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3846 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
3847 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
3848 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3849 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
3850 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
3851 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
3852 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
3853 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
3854 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
3855 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
3856 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
3857 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
3858 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3859 static const struct
3861 struct
3863 unsigned int miplevel_count;
3864 unsigned int depth_or_array_size;
3865 DXGI_FORMAT format;
3866 } texture;
3867 struct srv_desc srv_desc;
3868 struct srv_desc expected_srv_desc;
3870 tests[] =
3872 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3873 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3874 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3875 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3876 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3877 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3878 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3879 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3880 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3881 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3882 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3883 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3884 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3885 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3886 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3887 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3888 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3889 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3890 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3891 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3892 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3893 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3894 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3895 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3896 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3897 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3898 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3899 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3900 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3901 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3902 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3903 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3904 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3905 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3906 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3907 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3908 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3909 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3910 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3911 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3912 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3913 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3914 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3915 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3916 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3917 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
3918 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
3919 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
3921 static const struct
3923 struct
3925 D3D11_SRV_DIMENSION dimension;
3926 unsigned int miplevel_count;
3927 unsigned int depth_or_array_size;
3928 DXGI_FORMAT format;
3929 } texture;
3930 struct srv_desc srv_desc;
3932 invalid_desc_tests[] =
3934 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3935 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3936 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3937 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3938 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3939 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3940 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3941 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3942 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3943 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3944 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3945 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3946 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3947 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3948 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3949 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3950 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3951 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3952 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3953 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3954 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3955 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3956 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3957 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3958 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
3959 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
3960 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3961 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3962 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3963 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
3964 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
3965 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
3966 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
3967 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
3968 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3969 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3970 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 1}},
3971 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3972 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 1}},
3973 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3974 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3975 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3976 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3977 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3978 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3979 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3980 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3981 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3982 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3983 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3984 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3985 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3986 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3987 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3988 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3989 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3991 #undef FMT_UNKNOWN
3992 #undef RGBA8_UNORM
3993 #undef RGBA8_SRGB
3994 #undef RGBA8_UINT
3995 #undef RGBA8_TL
3996 #undef DIM_UNKNOWN
3997 #undef TEX_1D
3998 #undef TEX_1D_ARRAY
3999 #undef TEX_2D
4000 #undef TEX_2D_ARRAY
4001 #undef TEX_2DMS
4002 #undef TEX_2DMS_ARR
4003 #undef TEX_3D
4004 #undef TEX_CUBE
4005 #undef CUBE_ARRAY
4007 if (!(device = create_device(NULL)))
4009 skip("Failed to create device.\n");
4010 return;
4012 feature_level = ID3D11Device_GetFeatureLevel(device);
4014 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
4016 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
4017 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4019 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
4020 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
4021 U1(U(srv_desc).Buffer).ElementOffset = 0;
4022 U2(U(srv_desc).Buffer).ElementWidth = 64;
4024 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
4025 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4027 expected_refcount = get_refcount(device) + 1;
4028 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
4029 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
4030 refcount = get_refcount(device);
4031 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4032 tmp = NULL;
4033 expected_refcount = refcount + 1;
4034 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
4035 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4036 refcount = get_refcount(device);
4037 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4038 ID3D11Device_Release(tmp);
4040 /* Not available on all Windows versions. */
4041 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
4042 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
4044 ID3D11ShaderResourceView_Release(srview);
4045 ID3D11Buffer_Release(buffer);
4047 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
4049 buffer_desc.ByteWidth = 1024;
4050 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4051 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4052 buffer_desc.CPUAccessFlags = 0;
4053 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
4054 buffer_desc.StructureByteStride = 4;
4056 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
4057 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
4059 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
4060 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
4062 memset(&srv_desc, 0, sizeof(srv_desc));
4063 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
4065 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
4066 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
4067 srv_desc.ViewDimension);
4068 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
4069 U1(U(srv_desc).Buffer).FirstElement);
4070 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
4071 U2(U(srv_desc).Buffer).NumElements);
4073 ID3D11ShaderResourceView_Release(srview);
4074 ID3D11Buffer_Release(buffer);
4076 else
4078 skip("Structured buffers require feature level 11_0.\n");
4081 texture2d_desc.Width = 512;
4082 texture2d_desc.Height = 512;
4083 texture2d_desc.SampleDesc.Count = 1;
4084 texture2d_desc.SampleDesc.Quality = 0;
4085 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
4086 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4087 texture2d_desc.CPUAccessFlags = 0;
4089 texture3d_desc.Width = 64;
4090 texture3d_desc.Height = 64;
4091 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
4092 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4093 texture3d_desc.CPUAccessFlags = 0;
4094 texture3d_desc.MiscFlags = 0;
4096 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4098 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
4100 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
4102 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
4103 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
4104 texture2d_desc.Format = tests[i].texture.format;
4105 texture2d_desc.MiscFlags = 0;
4107 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
4108 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4109 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
4111 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
4112 && (texture2d_desc.ArraySize != 6
4113 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4114 && feature_level < D3D_FEATURE_LEVEL_10_1)
4116 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
4117 continue;
4120 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4121 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4122 texture = (ID3D11Resource *)texture2d;
4124 else
4126 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
4127 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
4128 texture3d_desc.Format = tests[i].texture.format;
4130 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4131 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4132 texture = (ID3D11Resource *)texture3d;
4135 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
4137 current_desc = NULL;
4139 else
4141 current_desc = &srv_desc;
4142 get_srv_desc(current_desc, &tests[i].srv_desc);
4145 expected_refcount = get_refcount(texture);
4146 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
4147 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
4148 refcount = get_refcount(texture);
4149 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
4151 /* Not available on all Windows versions. */
4152 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
4153 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
4155 memset(&srv_desc, 0, sizeof(srv_desc));
4156 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
4157 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
4159 ID3D11ShaderResourceView_Release(srview);
4160 ID3D11Resource_Release(texture);
4163 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
4165 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
4166 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
4168 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
4170 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4171 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
4172 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
4173 texture2d_desc.MiscFlags = 0;
4175 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
4176 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4177 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
4179 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
4180 && feature_level < D3D_FEATURE_LEVEL_10_1)
4182 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
4183 continue;
4186 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4187 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4188 texture = (ID3D11Resource *)texture2d;
4190 else
4192 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4193 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
4194 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
4196 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4197 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4198 texture = (ID3D11Resource *)texture3d;
4201 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
4202 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
4203 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
4205 ID3D11Resource_Release(texture);
4208 refcount = ID3D11Device_Release(device);
4209 ok(!refcount, "Device has %u references left.\n", refcount);
4212 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
4214 #if 0
4215 float4 light;
4216 float4x4 mat;
4218 struct input
4220 float4 position : POSITION;
4221 float3 normal : NORMAL;
4224 struct output
4226 float4 position : POSITION;
4227 float4 diffuse : COLOR;
4230 output main(const input v)
4232 output o;
4234 o.position = mul(v.position, mat);
4235 o.diffuse = dot((float3)light, v.normal);
4237 return o;
4239 #endif
4240 static const DWORD vs_4_1[] =
4242 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
4243 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
4244 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
4245 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
4246 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4247 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
4248 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
4249 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
4250 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
4251 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
4252 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
4253 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
4254 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
4255 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
4256 0x0100003e,
4258 static const DWORD vs_4_0[] =
4260 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
4261 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
4262 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
4263 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
4264 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
4265 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
4266 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
4267 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
4268 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
4269 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
4270 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
4271 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
4272 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
4273 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
4274 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
4275 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
4277 static const DWORD vs_3_0[] =
4279 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
4280 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
4281 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
4282 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
4283 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
4284 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
4285 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
4286 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
4287 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
4288 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
4289 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
4290 0x0000ffff,
4292 static const DWORD vs_2_0[] =
4294 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
4295 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
4296 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
4297 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
4298 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
4299 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
4300 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
4301 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
4302 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
4303 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
4304 0x90e40001, 0x0000ffff,
4307 #if 0
4308 float4 main(const float4 color : COLOR) : SV_TARGET
4310 float4 o;
4312 o = color;
4314 return o;
4316 #endif
4317 static const DWORD ps_4_1[] =
4319 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
4320 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4321 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4322 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4323 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
4324 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4325 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4327 static const DWORD ps_4_0[] =
4329 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
4330 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4331 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4332 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4333 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4334 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4335 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4337 static const DWORD ps_4_0_level_9_0[] =
4339 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
4340 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
4341 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
4342 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
4343 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
4344 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
4345 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
4346 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
4347 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4348 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
4349 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
4350 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4351 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
4352 0xabab0054,
4354 static const DWORD ps_4_0_level_9_1[] =
4356 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
4357 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
4358 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
4359 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
4360 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4361 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4362 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
4363 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4364 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
4365 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
4366 0x45475241, 0xabab0054,
4368 static const DWORD ps_4_0_level_9_3[] =
4370 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
4371 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
4372 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
4373 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
4374 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4375 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4376 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
4377 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4378 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
4379 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
4380 0x45475241, 0xabab0054,
4383 #if 0
4384 struct gs_out
4386 float4 pos : SV_POSITION;
4389 [maxvertexcount(4)]
4390 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
4392 float offset = 0.1 * vin[0].w;
4393 gs_out v;
4395 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
4396 vout.Append(v);
4397 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
4398 vout.Append(v);
4399 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
4400 vout.Append(v);
4401 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
4402 vout.Append(v);
4404 #endif
4405 static const DWORD gs_4_1[] =
4407 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
4408 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4409 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4410 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4411 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
4412 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
4413 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
4414 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
4415 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
4416 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
4417 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
4418 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4419 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
4420 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4421 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
4422 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
4423 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
4424 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4426 static const DWORD gs_4_0[] =
4428 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
4429 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4430 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4431 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4432 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
4433 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
4434 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
4435 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4436 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
4437 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4438 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
4439 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
4440 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
4441 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
4442 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
4443 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4444 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
4445 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4448 ULONG refcount, expected_refcount;
4449 struct device_desc device_desc;
4450 ID3D11Device *device, *tmp;
4451 ID3D11GeometryShader *gs;
4452 ID3D11VertexShader *vs;
4453 ID3D11PixelShader *ps;
4454 HRESULT hr;
4456 device_desc.feature_level = &feature_level;
4457 device_desc.flags = 0;
4458 if (!(device = create_device(&device_desc)))
4460 skip("Failed to create device for feature level %#x.\n", feature_level);
4461 return;
4464 /* level_9 shaders */
4465 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
4466 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4467 ID3D11PixelShader_Release(ps);
4469 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
4470 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4471 ID3D11PixelShader_Release(ps);
4473 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
4474 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4475 ID3D11PixelShader_Release(ps);
4477 /* vertex shader */
4478 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
4479 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4481 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
4482 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4484 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
4485 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
4486 hr, feature_level);
4488 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4489 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
4490 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4491 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4492 else
4493 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4495 refcount = get_refcount(device);
4496 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4497 refcount, expected_refcount);
4498 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4500 tmp = NULL;
4501 expected_refcount = refcount + 1;
4502 ID3D11VertexShader_GetDevice(vs, &tmp);
4503 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4504 refcount = get_refcount(device);
4505 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4506 refcount, expected_refcount);
4507 ID3D11Device_Release(tmp);
4509 /* Not available on all Windows versions. */
4510 check_interface(vs, &IID_ID3D10VertexShader, TRUE, TRUE);
4512 refcount = ID3D11VertexShader_Release(vs);
4513 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
4516 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
4517 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4519 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
4520 hr, feature_level);
4521 refcount = ID3D11VertexShader_Release(vs);
4522 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
4524 else
4526 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4527 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
4528 hr, feature_level);
4529 if (SUCCEEDED(hr))
4530 ID3D11VertexShader_Release(vs);
4533 /* pixel shader */
4534 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4535 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
4536 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4537 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4538 else
4539 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4541 refcount = get_refcount(device);
4542 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4543 refcount, expected_refcount);
4544 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4546 tmp = NULL;
4547 expected_refcount = refcount + 1;
4548 ID3D11PixelShader_GetDevice(ps, &tmp);
4549 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4550 refcount = get_refcount(device);
4551 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4552 refcount, expected_refcount);
4553 ID3D11Device_Release(tmp);
4555 /* Not available on all Windows versions. */
4556 check_interface(ps, &IID_ID3D10PixelShader, TRUE, TRUE);
4558 refcount = ID3D11PixelShader_Release(ps);
4559 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
4562 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
4563 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4565 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
4566 hr, feature_level);
4567 refcount = ID3D11PixelShader_Release(ps);
4568 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
4570 else
4572 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4573 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4574 if (SUCCEEDED(hr))
4575 ID3D11PixelShader_Release(ps);
4578 /* geometry shader */
4579 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4580 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
4581 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4582 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4583 else
4584 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4586 refcount = get_refcount(device);
4587 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4588 refcount, expected_refcount);
4589 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4591 tmp = NULL;
4592 expected_refcount = refcount + 1;
4593 ID3D11GeometryShader_GetDevice(gs, &tmp);
4594 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4595 refcount = get_refcount(device);
4596 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4597 refcount, expected_refcount);
4598 ID3D11Device_Release(tmp);
4600 /* Not available on all Windows versions. */
4601 check_interface(gs, &IID_ID3D10GeometryShader, TRUE, TRUE);
4603 refcount = ID3D11GeometryShader_Release(gs);
4604 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4607 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
4608 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4610 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4611 hr, feature_level);
4612 refcount = ID3D11GeometryShader_Release(gs);
4613 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4615 else
4617 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4618 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4619 hr, feature_level);
4620 if (SUCCEEDED(hr))
4621 ID3D11GeometryShader_Release(gs);
4624 refcount = ID3D11Device_Release(device);
4625 ok(!refcount, "Device has %u references left.\n", refcount);
4628 static void test_create_sampler_state(void)
4630 static const struct test
4632 D3D11_FILTER filter;
4633 D3D10_FILTER expected_filter;
4635 desc_conversion_tests[] =
4637 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
4638 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
4639 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
4640 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
4641 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
4642 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
4643 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
4644 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
4645 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
4646 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
4647 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
4649 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
4650 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
4652 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
4653 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
4655 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
4656 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
4658 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
4659 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
4660 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
4663 ID3D11SamplerState *sampler_state1, *sampler_state2;
4664 ID3D10SamplerState *d3d10_sampler_state;
4665 ULONG refcount, expected_refcount;
4666 ID3D11Device *device, *tmp;
4667 D3D11_SAMPLER_DESC desc;
4668 unsigned int i;
4669 HRESULT hr;
4671 if (!(device = create_device(NULL)))
4673 skip("Failed to create device.\n");
4674 return;
4677 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
4678 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4680 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
4681 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4682 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4683 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
4684 desc.MipLODBias = 0.0f;
4685 desc.MaxAnisotropy = 16;
4686 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4687 desc.BorderColor[0] = 0.0f;
4688 desc.BorderColor[1] = 1.0f;
4689 desc.BorderColor[2] = 0.0f;
4690 desc.BorderColor[3] = 1.0f;
4691 desc.MinLOD = 0.0f;
4692 desc.MaxLOD = 16.0f;
4694 expected_refcount = get_refcount(device) + 1;
4695 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4696 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4697 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
4698 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4699 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4700 refcount = get_refcount(device);
4701 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4702 tmp = NULL;
4703 expected_refcount = refcount + 1;
4704 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
4705 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4706 refcount = get_refcount(device);
4707 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4708 ID3D11Device_Release(tmp);
4710 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
4711 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4712 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4713 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4714 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4715 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4716 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4717 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4718 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4719 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4720 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4721 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4722 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4724 refcount = ID3D11SamplerState_Release(sampler_state2);
4725 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4726 refcount = ID3D11SamplerState_Release(sampler_state1);
4727 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4729 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4731 const struct test *current = &desc_conversion_tests[i];
4732 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4734 desc.Filter = current->filter;
4735 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4736 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4737 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4738 desc.MipLODBias = 0.0f;
4739 desc.MaxAnisotropy = 16;
4740 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4741 desc.BorderColor[0] = 0.0f;
4742 desc.BorderColor[1] = 1.0f;
4743 desc.BorderColor[2] = 0.0f;
4744 desc.BorderColor[3] = 1.0f;
4745 desc.MinLOD = 0.0f;
4746 desc.MaxLOD = 16.0f;
4748 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4749 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4751 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
4752 (void **)&d3d10_sampler_state);
4753 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4754 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4755 if (FAILED(hr))
4757 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
4758 ID3D11SamplerState_Release(sampler_state1);
4759 break;
4762 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4763 expected_desc.Filter = current->expected_filter;
4764 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4765 expected_desc.MaxAnisotropy = 0;
4766 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4767 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4769 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
4770 ok(d3d10_desc.Filter == expected_desc.Filter,
4771 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
4772 ok(d3d10_desc.AddressU == expected_desc.AddressU,
4773 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
4774 ok(d3d10_desc.AddressV == expected_desc.AddressV,
4775 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
4776 ok(d3d10_desc.AddressW == expected_desc.AddressW,
4777 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
4778 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
4779 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
4780 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4781 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
4782 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4783 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
4784 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
4785 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
4786 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
4787 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
4788 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4789 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
4790 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
4791 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
4792 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
4793 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
4794 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
4796 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
4797 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4798 refcount = ID3D11SamplerState_Release(sampler_state1);
4799 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4802 refcount = ID3D11Device_Release(device);
4803 ok(!refcount, "Device has %u references left.\n", refcount);
4806 static void test_create_blend_state(void)
4808 static const D3D11_BLEND_DESC desc_conversion_tests[] =
4811 FALSE, FALSE,
4814 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4815 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
4820 FALSE, TRUE,
4823 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4824 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4827 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4828 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
4831 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4832 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4835 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4836 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
4839 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4840 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4843 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4844 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4847 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4848 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4851 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4852 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4857 FALSE, TRUE,
4860 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4861 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4864 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
4865 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4868 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
4869 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4872 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4873 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4876 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
4877 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4880 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
4881 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4884 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4885 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4888 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4889 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4895 ID3D11BlendState *blend_state1, *blend_state2;
4896 D3D11_BLEND_DESC desc, obtained_desc;
4897 ID3D10BlendState *d3d10_blend_state;
4898 D3D10_BLEND_DESC d3d10_blend_desc;
4899 ULONG refcount, expected_refcount;
4900 ID3D11Device *device, *tmp;
4901 unsigned int i, j;
4902 HRESULT hr;
4904 if (!(device = create_device(NULL)))
4906 skip("Failed to create device.\n");
4907 return;
4910 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
4911 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4913 memset(&desc, 0, sizeof(desc));
4914 desc.AlphaToCoverageEnable = FALSE;
4915 desc.IndependentBlendEnable = FALSE;
4916 desc.RenderTarget[0].BlendEnable = FALSE;
4917 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
4918 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
4919 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
4920 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
4921 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
4922 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
4923 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
4925 expected_refcount = get_refcount(device) + 1;
4926 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
4927 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4928 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
4929 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4930 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4931 refcount = get_refcount(device);
4932 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4933 tmp = NULL;
4934 expected_refcount = refcount + 1;
4935 ID3D11BlendState_GetDevice(blend_state1, &tmp);
4936 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4937 refcount = get_refcount(device);
4938 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4939 ID3D11Device_Release(tmp);
4941 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
4942 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
4943 obtained_desc.AlphaToCoverageEnable);
4944 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
4945 obtained_desc.IndependentBlendEnable);
4946 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4948 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
4949 "Got unexpected blend enable %#x for render target %u.\n",
4950 obtained_desc.RenderTarget[i].BlendEnable, i);
4951 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
4952 "Got unexpected src blend %u for render target %u.\n",
4953 obtained_desc.RenderTarget[i].SrcBlend, i);
4954 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
4955 "Got unexpected dest blend %u for render target %u.\n",
4956 obtained_desc.RenderTarget[i].DestBlend, i);
4957 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
4958 "Got unexpected blend op %u for render target %u.\n",
4959 obtained_desc.RenderTarget[i].BlendOp, i);
4960 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
4961 "Got unexpected src blend alpha %u for render target %u.\n",
4962 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
4963 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
4964 "Got unexpected dest blend alpha %u for render target %u.\n",
4965 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
4966 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
4967 "Got unexpected blend op alpha %u for render target %u.\n",
4968 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
4969 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
4970 "Got unexpected render target write mask %#x for render target %u.\n",
4971 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
4974 /* Not available on all Windows versions. */
4975 check_interface(blend_state1, &IID_ID3D10BlendState, TRUE, TRUE);
4976 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
4978 refcount = ID3D11BlendState_Release(blend_state1);
4979 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4980 refcount = ID3D11BlendState_Release(blend_state2);
4981 ok(!refcount, "Blend state has %u references left.\n", refcount);
4983 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4985 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
4987 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
4988 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4990 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
4991 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4992 "Blend state should implement ID3D10BlendState.\n");
4993 if (FAILED(hr))
4995 win_skip("Blend state does not implement ID3D10BlendState.\n");
4996 ID3D11BlendState_Release(blend_state1);
4997 break;
5000 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
5001 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
5002 "Got unexpected alpha to coverage enable %#x for test %u.\n",
5003 d3d10_blend_desc.AlphaToCoverageEnable, i);
5004 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
5005 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
5006 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
5007 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
5008 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
5009 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
5010 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
5011 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
5012 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
5013 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
5014 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
5015 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
5016 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
5018 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
5019 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
5020 "Got unexpected blend enable %#x for test %u, render target %u.\n",
5021 d3d10_blend_desc.BlendEnable[j], i, j);
5022 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
5023 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
5024 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
5027 ID3D10BlendState_Release(d3d10_blend_state);
5029 refcount = ID3D11BlendState_Release(blend_state1);
5030 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5033 refcount = ID3D11Device_Release(device);
5034 ok(!refcount, "Device has %u references left.\n", refcount);
5037 static void test_create_depthstencil_state(void)
5039 ID3D11DepthStencilState *ds_state1, *ds_state2;
5040 ULONG refcount, expected_refcount;
5041 D3D11_DEPTH_STENCIL_DESC ds_desc;
5042 ID3D11Device *device, *tmp;
5043 HRESULT hr;
5045 if (!(device = create_device(NULL)))
5047 skip("Failed to create device.\n");
5048 return;
5051 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
5052 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5054 ds_desc.DepthEnable = TRUE;
5055 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
5056 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
5057 ds_desc.StencilEnable = FALSE;
5058 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
5059 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
5060 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
5061 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
5062 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
5063 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
5064 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
5065 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
5066 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
5067 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
5069 expected_refcount = get_refcount(device) + 1;
5070 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
5071 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5072 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
5073 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5074 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
5075 refcount = get_refcount(device);
5076 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5077 tmp = NULL;
5078 expected_refcount = refcount + 1;
5079 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
5080 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5081 refcount = get_refcount(device);
5082 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5083 ID3D11Device_Release(tmp);
5085 /* Not available on all Windows versions. */
5086 check_interface(ds_state1, &IID_ID3D10DepthStencilState, TRUE, TRUE);
5088 refcount = ID3D11DepthStencilState_Release(ds_state2);
5089 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5090 refcount = ID3D11DepthStencilState_Release(ds_state1);
5091 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5093 ds_desc.DepthEnable = FALSE;
5094 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
5095 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
5096 ds_desc.StencilEnable = FALSE;
5097 ds_desc.StencilReadMask = 0;
5098 ds_desc.StencilWriteMask = 0;
5099 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
5100 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
5101 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
5102 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
5103 ds_desc.BackFace = ds_desc.FrontFace;
5105 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
5106 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5108 memset(&ds_desc, 0, sizeof(ds_desc));
5109 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
5110 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
5111 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
5112 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
5113 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
5114 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
5115 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
5116 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
5117 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
5118 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
5119 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
5120 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
5121 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
5122 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
5123 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
5124 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
5125 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
5126 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
5127 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
5128 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
5129 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
5130 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
5131 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
5132 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
5133 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
5134 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
5136 ID3D11DepthStencilState_Release(ds_state1);
5138 refcount = ID3D11Device_Release(device);
5139 ok(!refcount, "Device has %u references left.\n", refcount);
5142 static void test_create_rasterizer_state(void)
5144 ID3D11RasterizerState *rast_state1, *rast_state2;
5145 ID3D10RasterizerState *d3d10_rast_state;
5146 ULONG refcount, expected_refcount;
5147 D3D10_RASTERIZER_DESC d3d10_desc;
5148 D3D11_RASTERIZER_DESC desc;
5149 ID3D11Device *device, *tmp;
5150 HRESULT hr;
5152 if (!(device = create_device(NULL)))
5154 skip("Failed to create device.\n");
5155 return;
5158 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
5159 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5161 desc.FillMode = D3D11_FILL_SOLID;
5162 desc.CullMode = D3D11_CULL_BACK;
5163 desc.FrontCounterClockwise = FALSE;
5164 desc.DepthBias = 0;
5165 desc.DepthBiasClamp = 0.0f;
5166 desc.SlopeScaledDepthBias = 0.0f;
5167 desc.DepthClipEnable = TRUE;
5168 desc.ScissorEnable = FALSE;
5169 desc.MultisampleEnable = FALSE;
5170 desc.AntialiasedLineEnable = FALSE;
5172 expected_refcount = get_refcount(device) + 1;
5173 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
5174 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5175 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
5176 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5177 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
5178 refcount = get_refcount(device);
5179 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5180 tmp = NULL;
5181 expected_refcount = refcount + 1;
5182 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
5183 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5184 refcount = get_refcount(device);
5185 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5186 ID3D11Device_Release(tmp);
5188 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
5189 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5190 "Rasterizer state should implement ID3D10RasterizerState.\n");
5191 if (SUCCEEDED(hr))
5193 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
5194 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
5195 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
5196 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
5197 d3d10_desc.FrontCounterClockwise);
5198 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
5199 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
5200 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
5201 d3d10_desc.SlopeScaledDepthBias);
5202 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
5203 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
5204 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
5205 d3d10_desc.MultisampleEnable);
5206 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
5207 d3d10_desc.AntialiasedLineEnable);
5209 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
5210 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
5213 refcount = ID3D11RasterizerState_Release(rast_state2);
5214 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5215 refcount = ID3D11RasterizerState_Release(rast_state1);
5216 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5218 refcount = ID3D11Device_Release(device);
5219 ok(!refcount, "Device has %u references left.\n", refcount);
5222 static void test_create_query(void)
5224 static const struct
5226 D3D11_QUERY query;
5227 D3D_FEATURE_LEVEL required_feature_level;
5228 BOOL is_predicate;
5229 BOOL can_use_create_predicate;
5230 BOOL todo;
5232 tests[] =
5234 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5235 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5236 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5237 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5238 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5239 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
5240 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
5241 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
5242 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5243 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5244 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5245 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5246 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5247 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5248 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5249 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5252 ULONG refcount, expected_refcount;
5253 D3D_FEATURE_LEVEL feature_level;
5254 D3D11_QUERY_DESC query_desc;
5255 ID3D11Predicate *predicate;
5256 ID3D11Device *device, *tmp;
5257 HRESULT hr, expected_hr;
5258 ID3D11Query *query;
5259 unsigned int i;
5261 if (!(device = create_device(NULL)))
5263 skip("Failed to create device.\n");
5264 return;
5266 feature_level = ID3D11Device_GetFeatureLevel(device);
5268 hr = ID3D11Device_CreateQuery(device, NULL, &query);
5269 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5270 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
5271 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5273 for (i = 0; i < ARRAY_SIZE(tests); ++i)
5275 if (tests[i].required_feature_level > feature_level)
5277 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
5278 continue;
5281 query_desc.Query = tests[i].query;
5282 query_desc.MiscFlags = 0;
5284 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
5285 todo_wine_if(tests[i].todo)
5286 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5288 query_desc.Query = tests[i].query;
5289 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
5290 todo_wine_if(tests[i].todo)
5291 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5292 if (FAILED(hr))
5293 continue;
5295 check_interface(query, &IID_ID3D11Predicate, tests[i].is_predicate, FALSE);
5296 ID3D11Query_Release(query);
5298 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
5299 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
5300 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5302 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
5303 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
5304 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5305 if (SUCCEEDED(hr))
5306 ID3D11Predicate_Release(predicate);
5309 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
5310 expected_refcount = get_refcount(device) + 1;
5311 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
5312 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5313 refcount = get_refcount(device);
5314 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5315 tmp = NULL;
5316 expected_refcount = refcount + 1;
5317 ID3D11Predicate_GetDevice(predicate, &tmp);
5318 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5319 refcount = get_refcount(device);
5320 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5321 ID3D11Device_Release(tmp);
5322 /* Not available on all Windows versions. */
5323 check_interface(predicate, &IID_ID3D10Predicate, TRUE, TRUE);
5324 ID3D11Predicate_Release(predicate);
5326 refcount = ID3D11Device_Release(device);
5327 ok(!refcount, "Device has %u references left.\n", refcount);
5330 #define get_query_data(a, b, c, d) get_query_data_(__LINE__, a, b, c, d)
5331 static void get_query_data_(unsigned int line, ID3D11DeviceContext *context,
5332 ID3D11Asynchronous *query, void *data, unsigned int data_size)
5334 unsigned int i;
5335 HRESULT hr;
5337 for (i = 0; i < 500; ++i)
5339 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
5340 break;
5341 Sleep(10);
5343 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5344 memset(data, 0xff, data_size);
5345 hr = ID3D11DeviceContext_GetData(context, query, data, data_size, 0);
5346 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5349 static void test_occlusion_query(void)
5351 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5352 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5354 struct d3d11_test_context test_context;
5355 D3D11_TEXTURE2D_DESC texture_desc;
5356 ID3D11DeviceContext *context;
5357 ID3D11RenderTargetView *rtv;
5358 D3D11_QUERY_DESC query_desc;
5359 ID3D11Asynchronous *query;
5360 unsigned int data_size, i;
5361 ID3D11Texture2D *texture;
5362 ID3D11Device *device;
5363 union
5365 UINT64 uint;
5366 DWORD dword[2];
5367 } data;
5368 HRESULT hr;
5370 if (!init_test_context(&test_context, NULL))
5371 return;
5373 device = test_context.device;
5374 context = test_context.immediate_context;
5376 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5378 query_desc.Query = D3D11_QUERY_OCCLUSION;
5379 query_desc.MiscFlags = 0;
5380 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5381 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5382 data_size = ID3D11Asynchronous_GetDataSize(query);
5383 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
5385 memset(&data, 0xff, sizeof(data));
5386 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5387 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5388 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5389 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5390 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5391 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5393 ID3D11DeviceContext_End(context, query);
5394 ID3D11DeviceContext_Begin(context, query);
5395 ID3D11DeviceContext_Begin(context, query);
5397 memset(&data, 0xff, sizeof(data));
5398 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5399 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5400 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5401 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5402 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5403 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5405 draw_color_quad(&test_context, &red);
5407 ID3D11DeviceContext_End(context, query);
5408 get_query_data(context, query, &data, sizeof(data));
5409 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5411 memset(&data, 0xff, sizeof(data));
5412 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
5413 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5414 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
5415 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5416 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
5417 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5418 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
5419 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5420 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5421 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5423 memset(&data, 0xff, sizeof(data));
5424 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
5425 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5426 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5427 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5429 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
5430 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5431 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
5432 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5434 ID3D11DeviceContext_Begin(context, query);
5435 ID3D11DeviceContext_End(context, query);
5436 ID3D11DeviceContext_End(context, query);
5438 get_query_data(context, query, &data, sizeof(data));
5439 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5440 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5441 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5443 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
5444 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
5445 texture_desc.MipLevels = 1;
5446 texture_desc.ArraySize = 1;
5447 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
5448 texture_desc.SampleDesc.Count = 1;
5449 texture_desc.SampleDesc.Quality = 0;
5450 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5451 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5452 texture_desc.CPUAccessFlags = 0;
5453 texture_desc.MiscFlags = 0;
5454 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5455 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5456 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
5457 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5459 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
5460 set_viewport(context, 0.0f, 0.0f, texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
5462 ID3D11DeviceContext_Begin(context, query);
5463 for (i = 0; i < 100; i++)
5464 draw_color_quad(&test_context, &red);
5465 ID3D11DeviceContext_End(context, query);
5467 get_query_data(context, query, &data, sizeof(data));
5468 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
5469 || (data.dword[0] == 0xffffffff && !data.dword[1])
5470 || broken(!data.uint),
5471 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5472 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5473 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5475 ID3D11Asynchronous_Release(query);
5477 /* The following test exercises a code path in wined3d. A wined3d context
5478 * associated with the query is destroyed when the swapchain is released. */
5479 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5480 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5482 set_viewport(context, 0.0f, 0.0f, 64.0f, 64.0f, 0.0f, 1.0f);
5483 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5484 ID3D11DeviceContext_Begin(context, query);
5485 draw_color_quad(&test_context, &red);
5486 ID3D11DeviceContext_End(context, query);
5488 ID3D11RenderTargetView_Release(test_context.backbuffer_rtv);
5489 ID3D11Texture2D_Release(test_context.backbuffer);
5490 IDXGISwapChain_Release(test_context.swapchain);
5491 test_context.swapchain = create_swapchain(device, test_context.window, NULL);
5492 hr = IDXGISwapChain_GetBuffer(test_context.swapchain, 0, &IID_ID3D11Texture2D,
5493 (void **)&test_context.backbuffer);
5494 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
5495 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer,
5496 NULL, &test_context.backbuffer_rtv);
5497 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5498 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
5499 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5501 get_query_data(context, query, &data, sizeof(data));
5502 /* This test occasionally succeeds with CSMT enabled because of a race condition. */
5503 if (0)
5504 todo_wine ok(data.dword[0] == 0x1000 && !data.dword[1],
5505 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5507 ID3D11Asynchronous_Release(query);
5508 ID3D11RenderTargetView_Release(rtv);
5509 ID3D11Texture2D_Release(texture);
5510 release_test_context(&test_context);
5513 static void test_pipeline_statistics_query(void)
5515 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5516 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5518 D3D11_QUERY_DATA_PIPELINE_STATISTICS data;
5519 struct d3d11_test_context test_context;
5520 ID3D11DeviceContext *context;
5521 D3D11_QUERY_DESC query_desc;
5522 ID3D11Asynchronous *query;
5523 unsigned int data_size;
5524 ID3D11Device *device;
5525 HRESULT hr;
5527 if (!init_test_context(&test_context, NULL))
5528 return;
5530 device = test_context.device;
5531 context = test_context.immediate_context;
5533 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5535 query_desc.Query = D3D11_QUERY_PIPELINE_STATISTICS;
5536 query_desc.MiscFlags = 0;
5537 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5538 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5539 data_size = ID3D11Asynchronous_GetDataSize(query);
5540 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
5542 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5543 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5544 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5545 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5547 ID3D11DeviceContext_End(context, query);
5548 ID3D11DeviceContext_Begin(context, query);
5549 ID3D11DeviceContext_Begin(context, query);
5551 memset(&data, 0xff, sizeof(data));
5552 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5553 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5554 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5555 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5556 ok(data.IAVertices == ~(UINT64)0, "Data was modified.\n");
5558 draw_quad(&test_context);
5560 ID3D11DeviceContext_End(context, query);
5561 get_query_data(context, query, &data, sizeof(data));
5562 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5563 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5564 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5565 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5566 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5567 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5568 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5569 todo_wine
5570 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5571 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5572 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5573 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5575 ID3D11DeviceContext_Begin(context, query);
5576 draw_color_quad(&test_context, &red);
5577 ID3D11DeviceContext_End(context, query);
5578 get_query_data(context, query, &data, sizeof(data));
5579 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5580 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5581 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5582 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5583 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5584 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5585 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5586 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5587 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5588 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5589 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5591 ID3D11Asynchronous_Release(query);
5592 release_test_context(&test_context);
5595 static void test_timestamp_query(void)
5597 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5599 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
5600 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
5601 struct d3d11_test_context test_context;
5602 ID3D11DeviceContext *context;
5603 D3D11_QUERY_DESC query_desc;
5604 unsigned int data_size;
5605 ID3D11Device *device;
5606 UINT64 timestamp;
5607 HRESULT hr;
5609 if (!init_test_context(&test_context, NULL))
5610 return;
5612 device = test_context.device;
5613 context = test_context.immediate_context;
5615 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5616 query_desc.MiscFlags = 0;
5617 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5618 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5619 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
5620 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
5622 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
5623 query_desc.MiscFlags = 0;
5624 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
5625 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5626 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
5627 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
5629 disjoint.Frequency = 0xdeadbeef;
5630 disjoint.Disjoint = 0xdeadbeef;
5631 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5632 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5633 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5634 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5635 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5636 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5638 /* Test a TIMESTAMP_DISJOINT query. */
5639 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5641 disjoint.Frequency = 0xdeadbeef;
5642 disjoint.Disjoint = 0xdeadbeef;
5643 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5644 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5645 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5646 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5647 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5648 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5650 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5651 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5652 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
5653 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5655 prev_disjoint = disjoint;
5657 disjoint.Frequency = 0xdeadbeef;
5658 disjoint.Disjoint = 0xff;
5659 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
5660 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5661 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
5662 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5663 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
5664 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5665 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
5666 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5667 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5668 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
5670 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5671 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5672 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
5673 D3D11_ASYNC_GETDATA_DONOTFLUSH);
5674 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5675 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
5676 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
5678 memset(&timestamp, 0xff, sizeof(timestamp));
5679 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
5680 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5681 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5682 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5683 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5685 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
5686 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5688 memset(&timestamp, 0xff, sizeof(timestamp));
5689 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5690 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5691 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5693 draw_color_quad(&test_context, &red);
5695 ID3D11DeviceContext_End(context, timestamp_query);
5696 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5698 timestamp = 0xdeadbeef;
5699 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5700 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5701 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5703 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5704 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5705 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
5707 timestamp = 0xdeadbeef;
5708 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
5709 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5710 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
5711 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5712 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5713 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5714 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
5715 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5716 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5718 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5719 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5720 disjoint.Frequency = 0xdeadbeef;
5721 disjoint.Disjoint = 0xff;
5722 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5723 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5724 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
5725 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5727 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
5728 ID3D11Asynchronous_Release(timestamp_query);
5729 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5730 query_desc.MiscFlags = 0;
5731 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5732 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5734 draw_color_quad(&test_context, &red);
5736 ID3D11DeviceContext_End(context, timestamp_query);
5737 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5739 ID3D11Asynchronous_Release(timestamp_query);
5740 ID3D11Asynchronous_Release(timestamp_disjoint_query);
5741 release_test_context(&test_context);
5744 static void test_device_removed_reason(void)
5746 ID3D11Device *device;
5747 ULONG refcount;
5748 HRESULT hr;
5750 if (!(device = create_device(NULL)))
5752 skip("Failed to create device.\n");
5753 return;
5756 hr = ID3D11Device_GetDeviceRemovedReason(device);
5757 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5758 hr = ID3D11Device_GetDeviceRemovedReason(device);
5759 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5761 refcount = ID3D11Device_Release(device);
5762 ok(!refcount, "Device has %u references left.\n", refcount);
5765 static void test_private_data(void)
5767 ULONG refcount, expected_refcount;
5768 D3D11_TEXTURE2D_DESC texture_desc;
5769 ID3D10Texture2D *d3d10_texture;
5770 ID3D11Device *test_object;
5771 ID3D11Texture2D *texture;
5772 IDXGIDevice *dxgi_device;
5773 IDXGISurface *surface;
5774 ID3D11Device *device;
5775 IUnknown *ptr;
5776 HRESULT hr;
5777 UINT size;
5779 static const GUID test_guid =
5780 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
5781 static const GUID test_guid2 =
5782 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
5783 static const DWORD data[] = {1, 2, 3, 4};
5785 if (!(device = create_device(NULL)))
5787 skip("Failed to create device.\n");
5788 return;
5791 test_object = create_device(NULL);
5793 texture_desc.Width = 512;
5794 texture_desc.Height = 512;
5795 texture_desc.MipLevels = 1;
5796 texture_desc.ArraySize = 1;
5797 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5798 texture_desc.SampleDesc.Count = 1;
5799 texture_desc.SampleDesc.Quality = 0;
5800 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5801 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5802 texture_desc.CPUAccessFlags = 0;
5803 texture_desc.MiscFlags = 0;
5805 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5806 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5807 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
5808 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
5810 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
5811 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5812 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5813 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5814 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5815 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5816 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5817 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5819 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5820 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5821 size = sizeof(ptr) * 2;
5822 ptr = (IUnknown *)0xdeadbeef;
5823 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5824 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5825 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5826 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5828 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
5829 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
5830 size = sizeof(ptr) * 2;
5831 ptr = (IUnknown *)0xdeadbeef;
5832 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
5833 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5834 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5835 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5836 IDXGIDevice_Release(dxgi_device);
5838 refcount = get_refcount(test_object);
5839 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5840 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5841 expected_refcount = refcount + 1;
5842 refcount = get_refcount(test_object);
5843 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5844 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5845 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5846 refcount = get_refcount(test_object);
5847 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5849 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5850 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5851 --expected_refcount;
5852 refcount = get_refcount(test_object);
5853 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5855 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5856 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5857 size = sizeof(data);
5858 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
5859 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5860 refcount = get_refcount(test_object);
5861 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5862 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5863 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5864 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5865 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5867 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5868 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5869 ++expected_refcount;
5870 size = 2 * sizeof(ptr);
5871 ptr = NULL;
5872 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5873 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5874 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
5875 ++expected_refcount;
5876 refcount = get_refcount(test_object);
5877 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5878 IUnknown_Release(ptr);
5879 --expected_refcount;
5881 ptr = (IUnknown *)0xdeadbeef;
5882 size = 1;
5883 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5884 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5885 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5886 size = 2 * sizeof(ptr);
5887 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5888 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5889 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5890 refcount = get_refcount(test_object);
5891 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5893 size = 1;
5894 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5895 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
5896 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5897 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5898 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
5899 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5900 size = 0xdeadbabe;
5901 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
5902 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
5903 ok(size == 0, "Got unexpected size %u.\n", size);
5904 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5905 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
5906 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5907 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5909 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
5910 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5911 ptr = NULL;
5912 size = sizeof(ptr);
5913 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
5914 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5915 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5916 IUnknown_Release(ptr);
5918 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
5919 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5920 "Texture should implement ID3D10Texture2D.\n");
5921 if (SUCCEEDED(hr))
5923 ptr = NULL;
5924 size = sizeof(ptr);
5925 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
5926 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5927 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5928 IUnknown_Release(ptr);
5929 ID3D10Texture2D_Release(d3d10_texture);
5932 IDXGISurface_Release(surface);
5933 ID3D11Texture2D_Release(texture);
5934 refcount = ID3D11Device_Release(device);
5935 ok(!refcount, "Device has %u references left.\n", refcount);
5936 refcount = ID3D11Device_Release(test_object);
5937 ok(!refcount, "Test object has %u references left.\n", refcount);
5940 static void test_state_refcounting(const D3D_FEATURE_LEVEL feature_level)
5942 ID3D11RasterizerState *rasterizer_state, *tmp_rasterizer_state;
5943 ID3D11Predicate *predicate, *tmp_predicate;
5944 ID3D11SamplerState *sampler, *tmp_sampler;
5945 ID3D11ShaderResourceView *srv, *tmp_srv;
5946 ID3D11RenderTargetView *rtv, *tmp_rtv;
5947 D3D11_RASTERIZER_DESC rasterizer_desc;
5948 D3D11_TEXTURE2D_DESC texture_desc;
5949 D3D11_QUERY_DESC predicate_desc;
5950 D3D11_SAMPLER_DESC sampler_desc;
5951 struct device_desc device_desc;
5952 ID3D11DeviceContext *context;
5953 ID3D11Texture2D *texture;
5954 ID3D11Device *device;
5955 ULONG refcount;
5956 HRESULT hr;
5958 device_desc.feature_level = &feature_level;
5959 device_desc.flags = 0;
5960 if (!(device = create_device(&device_desc)))
5962 skip("Failed to create device for feature level %#x.\n", feature_level);
5963 return;
5966 ID3D11Device_GetImmediateContext(device, &context);
5968 /* ID3D11SamplerState */
5969 memset(&sampler_desc, 0, sizeof(sampler_desc));
5970 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5971 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5972 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5973 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5974 sampler_desc.MaxLOD = FLT_MAX;
5975 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
5976 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5978 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
5979 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5980 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5981 ID3D11SamplerState_Release(tmp_sampler);
5983 tmp_sampler = sampler;
5984 refcount = get_refcount(sampler);
5985 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
5986 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
5987 refcount = ID3D11SamplerState_Release(sampler);
5988 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5989 sampler = NULL;
5990 ID3D11DeviceContext_PSGetSamplers(context, 0, 1, &sampler);
5991 ok(sampler == tmp_sampler, "Got sampler %p, expected %p.\n", sampler, tmp_sampler);
5992 refcount = ID3D11SamplerState_Release(sampler);
5993 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5995 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
5996 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5997 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5998 refcount = ID3D11SamplerState_Release(tmp_sampler);
5999 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6001 /* ID3D11RasterizerState */
6002 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
6003 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
6004 rasterizer_desc.CullMode = D3D11_CULL_BACK;
6005 rasterizer_desc.DepthClipEnable = TRUE;
6006 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
6007 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
6009 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
6010 refcount = ID3D11RasterizerState_Release(rasterizer_state);
6011 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6012 ID3D11DeviceContext_RSGetState(context, &tmp_rasterizer_state);
6013 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
6014 tmp_rasterizer_state, rasterizer_state);
6015 refcount = ID3D11RasterizerState_Release(tmp_rasterizer_state);
6016 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6018 /* ID3D11ShaderResourceView */
6019 memset(&texture_desc, 0, sizeof(texture_desc));
6020 texture_desc.Width = 32;
6021 texture_desc.Height = 32;
6022 texture_desc.MipLevels = 1;
6023 texture_desc.ArraySize = 1;
6024 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6025 texture_desc.SampleDesc.Count = 1;
6026 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6027 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6028 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6029 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6030 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6031 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
6032 ID3D11Texture2D_Release(texture);
6034 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6035 refcount = ID3D11ShaderResourceView_Release(srv);
6036 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6037 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &tmp_srv);
6038 ok(tmp_srv == srv, "Got SRV %p, expected %p.\n", tmp_srv, srv);
6039 refcount = ID3D11ShaderResourceView_Release(tmp_srv);
6040 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6042 /* ID3D11RenderTargetView */
6043 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6044 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6045 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6046 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
6047 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
6048 ID3D11Texture2D_Release(texture);
6050 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6051 refcount = ID3D11RenderTargetView_Release(rtv);
6052 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6053 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &tmp_rtv, NULL);
6054 ok(tmp_rtv == rtv, "Got RTV %p, expected %p.\n", tmp_rtv, rtv);
6055 refcount = ID3D11RenderTargetView_Release(tmp_rtv);
6056 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6058 /* ID3D11Predicate */
6059 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
6061 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
6062 predicate_desc.MiscFlags = 0;
6063 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
6064 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
6066 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
6067 refcount = ID3D11Predicate_Release(predicate);
6068 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6069 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, NULL);
6070 ok(tmp_predicate == predicate, "Got predicate %p, expected %p.\n", tmp_predicate, predicate);
6071 refcount = ID3D11Predicate_Release(tmp_predicate);
6072 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6075 ID3D11DeviceContext_Release(context);
6076 refcount = ID3D11Device_Release(device);
6077 ok(!refcount, "Device has %u references left.\n", refcount);
6080 static void test_device_context_state(void)
6082 ID3DDeviceContextState *context_state, *previous_context_state;
6083 ID3D11SamplerState *sampler, *tmp_sampler;
6084 ID3D11DeviceContext1 *context = NULL;
6085 D3D11_SAMPLER_DESC sampler_desc;
6086 D3D_FEATURE_LEVEL feature_level;
6087 ID3D11Device *d3d11_device;
6088 ID3D11Device1 *device;
6089 ULONG refcount;
6090 HRESULT hr;
6092 if (!(d3d11_device = create_device(NULL)))
6094 skip("Failed to create device.\n");
6095 return;
6098 hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11Device1, (void **)&device);
6099 ID3D11Device_Release(d3d11_device);
6100 if (FAILED(hr))
6102 skip("ID3D11Device1 is not available.\n");
6103 return;
6106 todo_wine check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
6107 todo_wine check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
6109 feature_level = ID3D11Device1_GetFeatureLevel(device);
6110 ID3D11Device1_GetImmediateContext1(device, &context);
6111 todo_wine ok(!!context, "Failed to get immediate context.\n");
6112 if (!context)
6114 ID3D11Device1_Release(device);
6115 return;
6118 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
6119 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
6120 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
6121 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
6122 sampler_desc.MipLODBias = 0.0f;
6123 sampler_desc.MaxAnisotropy = 0;
6124 sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
6125 sampler_desc.BorderColor[0] = 0.0f;
6126 sampler_desc.BorderColor[1] = 1.0f;
6127 sampler_desc.BorderColor[2] = 0.0f;
6128 sampler_desc.BorderColor[3] = 1.0f;
6129 sampler_desc.MinLOD = 0.0f;
6130 sampler_desc.MaxLOD = 16.0f;
6131 hr = ID3D11Device1_CreateSamplerState(device, &sampler_desc, &sampler);
6132 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6134 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
6135 tmp_sampler = NULL;
6136 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
6137 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6138 ID3D11SamplerState_Release(tmp_sampler);
6140 feature_level = min(feature_level, D3D_FEATURE_LEVEL_10_1);
6141 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
6142 &IID_ID3D10Device, NULL, &context_state);
6143 ok(SUCCEEDED(hr), "Failed to create device context state, hr %#x.\n", hr);
6144 refcount = get_refcount(context_state);
6145 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
6147 /* Enable ID3D10Device behavior. */
6148 previous_context_state = NULL;
6149 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
6150 refcount = ID3DDeviceContextState_Release(context_state);
6151 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6153 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
6154 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
6155 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
6156 ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler);
6157 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
6159 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
6160 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
6162 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
6163 refcount = ID3DDeviceContextState_Release(context_state);
6164 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6165 refcount = ID3DDeviceContextState_Release(previous_context_state);
6166 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6168 /* ID3DDeviceContextState retains the previous state. */
6169 tmp_sampler = NULL;
6170 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
6171 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6172 ID3D11SamplerState_Release(tmp_sampler);
6174 tmp_sampler = NULL;
6175 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
6176 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
6177 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
6178 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
6179 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
6180 tmp_sampler = NULL;
6181 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
6182 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6183 ID3D11SamplerState_Release(tmp_sampler);
6185 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
6186 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
6188 ID3D11SamplerState_Release(sampler);
6189 ID3D11DeviceContext1_Release(context);
6190 refcount = ID3D11Device1_Release(device);
6191 ok(!refcount, "Device has %u references left.\n", refcount);
6194 static void test_blend(void)
6196 ID3D11BlendState *src_blend, *dst_blend;
6197 struct d3d11_test_context test_context;
6198 ID3D11RenderTargetView *offscreen_rtv;
6199 D3D11_TEXTURE2D_DESC texture_desc;
6200 ID3D11InputLayout *input_layout;
6201 ID3D11DeviceContext *context;
6202 D3D11_BLEND_DESC blend_desc;
6203 unsigned int stride, offset;
6204 ID3D11Texture2D *offscreen;
6205 ID3D11VertexShader *vs;
6206 ID3D11PixelShader *ps;
6207 ID3D11Device *device;
6208 ID3D11Buffer *vb;
6209 DWORD color;
6210 HRESULT hr;
6212 static const DWORD vs_code[] =
6214 #if 0
6215 struct vs_out
6217 float4 position : SV_POSITION;
6218 float4 color : COLOR;
6221 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
6223 struct vs_out o;
6225 o.position = position;
6226 o.color = color;
6228 return o;
6230 #endif
6231 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
6232 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
6233 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
6234 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
6235 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
6236 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
6237 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
6238 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
6239 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
6240 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
6242 static const DWORD ps_code[] =
6244 #if 0
6245 struct vs_out
6247 float4 position : SV_POSITION;
6248 float4 color : COLOR;
6251 float4 main(struct vs_out i) : SV_TARGET
6253 return i.color;
6255 #endif
6256 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
6257 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
6258 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
6259 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
6260 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6261 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
6262 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
6263 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
6265 static const struct
6267 struct vec3 position;
6268 DWORD diffuse;
6270 quads[] =
6272 /* quad1 */
6273 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
6274 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
6275 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
6276 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
6277 /* quad2 */
6278 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
6279 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
6280 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
6281 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
6283 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
6285 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
6286 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
6288 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
6289 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6291 if (!init_test_context(&test_context, NULL))
6292 return;
6294 device = test_context.device;
6295 context = test_context.immediate_context;
6297 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
6298 vs_code, sizeof(vs_code), &input_layout);
6299 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6301 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
6303 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
6304 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6305 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
6306 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6308 memset(&blend_desc, 0, sizeof(blend_desc));
6309 blend_desc.RenderTarget[0].BlendEnable = TRUE;
6310 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
6311 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
6312 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
6313 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
6314 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
6315 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
6316 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
6318 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
6319 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6321 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
6322 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
6323 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
6324 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
6326 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
6327 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6329 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
6330 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6331 stride = sizeof(*quads);
6332 offset = 0;
6333 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
6334 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
6335 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6337 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6339 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
6340 ID3D11DeviceContext_Draw(context, 4, 0);
6341 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
6342 ID3D11DeviceContext_Draw(context, 4, 4);
6344 color = get_texture_color(test_context.backbuffer, 320, 360);
6345 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
6346 color = get_texture_color(test_context.backbuffer, 320, 120);
6347 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
6349 texture_desc.Width = 128;
6350 texture_desc.Height = 128;
6351 texture_desc.MipLevels = 1;
6352 texture_desc.ArraySize = 1;
6353 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
6354 texture_desc.SampleDesc.Count = 1;
6355 texture_desc.SampleDesc.Quality = 0;
6356 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6357 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
6358 texture_desc.CPUAccessFlags = 0;
6359 texture_desc.MiscFlags = 0;
6361 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
6362 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
6364 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
6365 goto done;
6368 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
6369 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
6371 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
6373 set_viewport(context, 0.0f, 0.0f, 128.0f, 128.0f, 0.0f, 1.0f);
6375 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
6377 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
6378 ID3D11DeviceContext_Draw(context, 4, 0);
6379 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
6380 ID3D11DeviceContext_Draw(context, 4, 4);
6382 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
6383 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
6384 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
6385 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
6387 ID3D11RenderTargetView_Release(offscreen_rtv);
6388 ID3D11Texture2D_Release(offscreen);
6389 done:
6390 ID3D11BlendState_Release(dst_blend);
6391 ID3D11BlendState_Release(src_blend);
6392 ID3D11PixelShader_Release(ps);
6393 ID3D11VertexShader_Release(vs);
6394 ID3D11Buffer_Release(vb);
6395 ID3D11InputLayout_Release(input_layout);
6396 release_test_context(&test_context);
6399 static void test_texture1d(void)
6401 struct shader
6403 const DWORD *code;
6404 size_t size;
6406 struct texture
6408 UINT width;
6409 UINT miplevel_count;
6410 UINT array_size;
6411 DXGI_FORMAT format;
6412 D3D11_SUBRESOURCE_DATA data[3];
6415 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
6416 struct d3d11_test_context test_context;
6417 const struct texture *current_texture;
6418 D3D11_TEXTURE1D_DESC texture_desc;
6419 D3D11_SAMPLER_DESC sampler_desc;
6420 const struct shader *current_ps;
6421 D3D_FEATURE_LEVEL feature_level;
6422 ID3D11ShaderResourceView *srv;
6423 ID3D11DeviceContext *context;
6424 ID3D11SamplerState *sampler;
6425 struct resource_readback rb;
6426 ID3D11Texture1D *texture;
6427 struct vec4 ps_constant;
6428 ID3D11PixelShader *ps;
6429 ID3D11Device *device;
6430 unsigned int i, x;
6431 ID3D11Buffer *cb;
6432 DWORD color;
6433 HRESULT hr;
6435 static const DWORD ps_ld_code[] =
6437 #if 0
6438 Texture1D t;
6440 float miplevel;
6442 float4 main(float4 position : SV_POSITION) : SV_TARGET
6444 float2 p;
6445 t.GetDimensions(miplevel, p.x, p.y);
6446 p.y = miplevel;
6447 p *= float2(position.x / 640.0f, 1.0f);
6448 return t.Load(int2(p));
6450 #endif
6451 0x43425844, 0x7b0c6359, 0x598178f6, 0xef2ddbdb, 0x88fc794c, 0x00000001, 0x000001ac, 0x00000003,
6452 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6453 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6454 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6455 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
6456 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001058, 0x00107000, 0x00000000,
6457 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6458 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
6459 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
6460 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000e2,
6461 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
6462 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
6463 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
6464 0x00107e46, 0x00000000, 0x0100003e,
6466 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
6467 static const DWORD ps_ld_sint8_code[] =
6469 #if 0
6470 Texture1D<int4> t;
6472 float4 main(float4 position : SV_POSITION) : SV_TARGET
6474 float2 p, s;
6475 int4 c;
6477 p = float2(position.x / 640.0f, 0.0f);
6478 t.GetDimensions(0, s.x, s.y);
6479 p *= s;
6481 c = t.Load(int2(p));
6482 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
6484 #endif
6485 0x43425844, 0x65a13d1e, 0x8a0bfc92, 0xa2f2708a, 0x0bafafb6, 0x00000001, 0x00000234, 0x00000003,
6486 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6487 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6488 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6489 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000198, 0x00000040,
6490 0x00000066, 0x04001058, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101012, 0x00000000,
6491 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6492 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
6493 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
6494 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
6495 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6496 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0500002b,
6497 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
6498 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204, 0x3c010204, 0x0a000034, 0x001000f2,
6499 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000, 0xbf800000, 0xbf800000, 0xbf800000,
6500 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
6501 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002,
6502 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
6504 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
6505 static const DWORD ps_ld_uint8_code[] =
6507 #if 0
6508 Texture1D<uint4> t;
6510 float4 main(float4 position : SV_POSITION) : SV_TARGET
6512 float2 p, s;
6514 p = float2(position.x / 640.0f, 0.0f);
6515 t.GetDimensions(0, s.x, s.y);
6516 p *= s;
6518 return t.Load(int2(p)) / (float4)255;
6520 #endif
6521 0x43425844, 0x35186c1f, 0x55bad4fd, 0xb7c97a57, 0x99c060e7, 0x00000001, 0x000001bc, 0x00000003,
6522 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6523 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6524 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6525 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000120, 0x00000040,
6526 0x00000048, 0x04001058, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101012, 0x00000000,
6527 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6528 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
6529 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
6530 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
6531 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6532 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x05000056,
6533 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46,
6534 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081, 0x3b808081, 0x0100003e,
6536 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
6537 static DWORD ps_ld_array_code[] =
6539 #if 0
6540 Texture1DArray t;
6542 float miplevel;
6544 float4 main(float4 position : SV_POSITION) : SV_TARGET
6546 float3 p;
6547 t.GetDimensions(miplevel, p.x, p.y, p.z);
6548 p.y = 1;
6549 p.z = miplevel;
6550 p *= float3(position.x / 640.0f, 1.0f, 1.0f);
6551 return t.Load(int3(p));
6553 #endif
6554 0x43425844, 0xbfccadc4, 0xc00ff13d, 0x2ba75365, 0xf747cbee, 0x00000001, 0x000001c0, 0x00000003,
6555 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6556 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6557 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6558 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000124, 0x00000040,
6559 0x00000049, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003858, 0x00107000, 0x00000000,
6560 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6561 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
6562 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
6563 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000c2,
6564 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x00100072, 0x00000000, 0x00100386,
6565 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x00000000, 0x0500001b, 0x001000d2,
6566 0x00000000, 0x00100906, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000001,
6567 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
6569 static const struct shader ps_ld_array = {ps_ld_array_code, sizeof(ps_ld_array_code)};
6571 static const DWORD rgba_level_0[] =
6573 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6575 static const DWORD rgba_level_1[] =
6577 0xffffffff, 0xff0000ff,
6579 static const DWORD rgba_level_2[] =
6581 0xffff0000,
6583 static const DWORD srgb_data[] =
6585 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
6587 static const DWORD r32_uint[] =
6589 0, 1, 2, 3,
6591 static const DWORD r9g9b9e5_data[] =
6593 0x80000100, 0x80020000, 0x84000000, 0x84000100,
6595 static const DWORD array_data0[] =
6597 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6599 static const DWORD array_data1[] =
6601 0x00ffff00, 0xff000000, 0x00ff0000, 0x000000ff,
6603 static const DWORD array_data2[] =
6605 0x000000ff, 0xffff00ff, 0x0000ff00, 0xff000000,
6607 static const struct texture rgba_texture =
6609 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
6611 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
6612 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
6613 {rgba_level_2, sizeof(*rgba_level_2), 0},
6616 static const struct texture srgb_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6617 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6618 static const struct texture sint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
6619 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6620 static const struct texture uint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
6621 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6622 static const struct texture r32u_typeless = {4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6623 {{r32_uint, 4 * sizeof(*r32_uint)}}};
6624 static const struct texture r9g9b9e5_texture = {4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
6625 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
6626 static const struct texture array_texture = {4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6628 {array_data0, 4 * sizeof(*array_data0)},
6629 {array_data1, 4 * sizeof(*array_data1)},
6630 {array_data2, 4 * sizeof(*array_data2)},
6634 static const DWORD level_1_colors[] =
6636 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6638 static const DWORD level_2_colors[] =
6640 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6642 static const DWORD srgb_colors[] =
6644 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
6646 static const DWORD sint8_colors[] =
6648 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
6650 static const DWORD r32u_colors[4] =
6652 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6654 static const DWORD r9g9b9e5_colors[4] =
6656 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
6658 static const DWORD zero_colors[4] = {0};
6659 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6660 static const struct texture_test
6662 const struct shader *ps;
6663 const struct texture *texture;
6664 D3D11_FILTER filter;
6665 float lod_bias;
6666 float min_lod;
6667 float max_lod;
6668 float ps_constant;
6669 const DWORD *expected_colors;
6671 texture_tests[] =
6673 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
6674 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
6675 #define MIP_MAX D3D11_FLOAT32_MAX
6676 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6677 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6678 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6679 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6680 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6681 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6682 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6683 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6684 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6685 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6686 {&ps_ld_array, &array_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, array_data1},
6688 #undef POINT
6689 #undef POINT_LINEAR
6690 #undef MIP_MAX
6691 static const struct srv_test
6693 const struct shader *ps;
6694 const struct texture *texture;
6695 struct srv_desc srv_desc;
6696 float ps_constant;
6697 const DWORD *expected_colors;
6699 srv_tests[] =
6701 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
6702 #define R32_UINT DXGI_FORMAT_R32_UINT
6703 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_1D, 0, 1}, 0.0f, r32u_colors},
6704 #undef TEX_1D
6705 #undef R32_UINT
6706 #undef FMT_UNKNOWN
6709 if (!init_test_context(&test_context, NULL))
6710 return;
6712 device = test_context.device;
6713 context = test_context.immediate_context;
6714 feature_level = ID3D11Device_GetFeatureLevel(device);
6716 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6718 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6720 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6721 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6722 texture_desc.CPUAccessFlags = 0;
6723 texture_desc.MiscFlags = 0;
6725 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6726 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
6727 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
6728 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
6729 sampler_desc.MipLODBias = 0.0f;
6730 sampler_desc.MaxAnisotropy = 0;
6731 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
6732 sampler_desc.BorderColor[0] = 0.0f;
6733 sampler_desc.BorderColor[1] = 0.0f;
6734 sampler_desc.BorderColor[2] = 0.0f;
6735 sampler_desc.BorderColor[3] = 0.0f;
6736 sampler_desc.MinLOD = 0.0f;
6737 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6739 ps = NULL;
6740 srv = NULL;
6741 sampler = NULL;
6742 texture = NULL;
6743 current_ps = NULL;
6744 current_texture = NULL;
6745 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6747 const struct texture_test *test = &texture_tests[i];
6749 if (current_ps != test->ps)
6751 if (ps)
6752 ID3D11PixelShader_Release(ps);
6754 current_ps = test->ps;
6756 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6757 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6759 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6762 if (current_texture != test->texture)
6764 if (texture)
6765 ID3D11Texture1D_Release(texture);
6766 if (srv)
6767 ID3D11ShaderResourceView_Release(srv);
6769 current_texture = test->texture;
6771 if (current_texture)
6773 texture_desc.Width = current_texture->width;
6774 texture_desc.MipLevels = current_texture->miplevel_count;
6775 texture_desc.ArraySize = current_texture->array_size;
6776 texture_desc.Format = current_texture->format;
6778 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
6779 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
6781 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6782 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6784 else
6786 texture = NULL;
6787 srv = NULL;
6790 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6793 if (!sampler || (sampler_desc.Filter != test->filter
6794 || sampler_desc.MipLODBias != test->lod_bias
6795 || sampler_desc.MinLOD != test->min_lod
6796 || sampler_desc.MaxLOD != test->max_lod))
6798 if (sampler)
6799 ID3D11SamplerState_Release(sampler);
6801 sampler_desc.Filter = test->filter;
6802 sampler_desc.MipLODBias = test->lod_bias;
6803 sampler_desc.MinLOD = test->min_lod;
6804 sampler_desc.MaxLOD = test->max_lod;
6806 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6807 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6809 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6812 ps_constant.x = test->ps_constant;
6813 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6815 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6817 draw_quad(&test_context);
6819 get_texture_readback(test_context.backbuffer, 0, &rb);
6820 for (x = 0; x < 4; ++x)
6822 color = get_readback_color(&rb, 80 + x * 160, 0, 0);
6823 ok(compare_color(color, test->expected_colors[x], 2),
6824 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
6826 release_resource_readback(&rb);
6828 if (srv)
6829 ID3D11ShaderResourceView_Release(srv);
6830 ID3D11SamplerState_Release(sampler);
6831 if (texture)
6832 ID3D11Texture1D_Release(texture);
6833 ID3D11PixelShader_Release(ps);
6835 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
6837 win_skip("SRV tests are broken on WARP.\n");
6838 ID3D11Buffer_Release(cb);
6839 release_test_context(&test_context);
6840 return;
6843 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6844 sampler_desc.MipLODBias = 0.0f;
6845 sampler_desc.MinLOD = 0.0f;
6846 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6848 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6849 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6851 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6853 ps = NULL;
6854 srv = NULL;
6855 texture = NULL;
6856 current_ps = NULL;
6857 current_texture = NULL;
6858 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
6860 const struct srv_test *test = &srv_tests[i];
6862 if (current_ps != test->ps)
6864 if (ps)
6865 ID3D11PixelShader_Release(ps);
6867 current_ps = test->ps;
6869 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6870 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6872 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6875 if (current_texture != test->texture)
6877 if (texture)
6878 ID3D11Texture1D_Release(texture);
6880 current_texture = test->texture;
6882 texture_desc.Width = current_texture->width;
6883 texture_desc.MipLevels = current_texture->miplevel_count;
6884 texture_desc.ArraySize = current_texture->array_size;
6885 texture_desc.Format = current_texture->format;
6887 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
6888 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
6891 if (srv)
6892 ID3D11ShaderResourceView_Release(srv);
6894 get_srv_desc(&srv_desc, &test->srv_desc);
6895 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
6896 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6898 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6900 ps_constant.x = test->ps_constant;
6901 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6903 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6905 draw_quad(&test_context);
6907 get_texture_readback(test_context.backbuffer, 0, &rb);
6908 for (x = 0; x < 4; ++x)
6910 color = get_readback_color(&rb, 80 + x * 160, 0, 0);
6911 ok(compare_color(color, test->expected_colors[x], 1),
6912 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
6914 release_resource_readback(&rb);
6916 ID3D11PixelShader_Release(ps);
6917 ID3D11Texture1D_Release(texture);
6918 ID3D11ShaderResourceView_Release(srv);
6919 ID3D11SamplerState_Release(sampler);
6921 ID3D11Buffer_Release(cb);
6922 release_test_context(&test_context);
6925 static void test_texture(void)
6927 struct shader
6929 const DWORD *code;
6930 size_t size;
6932 struct texture
6934 UINT width;
6935 UINT height;
6936 UINT miplevel_count;
6937 UINT array_size;
6938 DXGI_FORMAT format;
6939 D3D11_SUBRESOURCE_DATA data[3];
6942 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
6943 struct d3d11_test_context test_context;
6944 const struct texture *current_texture;
6945 D3D11_TEXTURE2D_DESC texture_desc;
6946 D3D11_SAMPLER_DESC sampler_desc;
6947 const struct shader *current_ps;
6948 D3D_FEATURE_LEVEL feature_level;
6949 ID3D11ShaderResourceView *srv;
6950 ID3D11DeviceContext *context;
6951 ID3D11SamplerState *sampler;
6952 struct resource_readback rb;
6953 ID3D11Texture2D *texture;
6954 struct vec4 ps_constant;
6955 ID3D11PixelShader *ps;
6956 ID3D11Device *device;
6957 unsigned int i, x, y;
6958 ID3D11Buffer *cb;
6959 DWORD color;
6960 HRESULT hr;
6962 static const DWORD ps_ld_code[] =
6964 #if 0
6965 Texture2D t;
6967 float miplevel;
6969 float4 main(float4 position : SV_POSITION) : SV_TARGET
6971 float3 p;
6972 t.GetDimensions(miplevel, p.x, p.y, p.z);
6973 p.z = miplevel;
6974 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
6975 return t.Load(int3(p));
6977 #endif
6978 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
6979 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6980 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6981 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6982 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
6983 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
6984 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6985 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
6986 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
6987 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
6988 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
6989 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
6990 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
6991 0x00107e46, 0x00000000, 0x0100003e,
6993 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
6994 static const DWORD ps_ld_sint8_code[] =
6996 #if 0
6997 Texture2D<int4> t;
6999 float4 main(float4 position : SV_POSITION) : SV_TARGET
7001 float3 p, s;
7002 int4 c;
7004 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
7005 t.GetDimensions(0, s.x, s.y, s.z);
7006 p *= s;
7008 c = t.Load(int3(p));
7009 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
7011 #endif
7012 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
7013 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7014 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7015 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7016 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
7017 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
7018 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
7019 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
7020 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
7021 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
7022 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
7023 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7024 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
7025 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
7026 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
7027 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7028 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
7029 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
7031 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
7032 static const DWORD ps_ld_uint8_code[] =
7034 #if 0
7035 Texture2D<uint4> t;
7037 float4 main(float4 position : SV_POSITION) : SV_TARGET
7039 float3 p, s;
7041 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
7042 t.GetDimensions(0, s.x, s.y, s.z);
7043 p *= s;
7045 return t.Load(int3(p)) / (float4)255;
7047 #endif
7048 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
7049 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7050 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7051 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7052 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
7053 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
7054 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
7055 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
7056 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
7057 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
7058 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
7059 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7060 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
7061 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
7062 0x3b808081, 0x0100003e,
7064 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
7065 static const DWORD ps_sample_code[] =
7067 #if 0
7068 Texture2D t;
7069 SamplerState s;
7071 float4 main(float4 position : SV_POSITION) : SV_Target
7073 float2 p;
7075 p.x = position.x / 640.0f;
7076 p.y = position.y / 480.0f;
7077 return t.Sample(s, p);
7079 #endif
7080 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
7081 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7082 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7083 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7084 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7085 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7086 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7087 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7088 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7089 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7091 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
7092 static const DWORD ps_sample_b_code[] =
7094 #if 0
7095 Texture2D t;
7096 SamplerState s;
7098 float bias;
7100 float4 main(float4 position : SV_POSITION) : SV_Target
7102 float2 p;
7104 p.x = position.x / 640.0f;
7105 p.y = position.y / 480.0f;
7106 return t.SampleBias(s, p, bias);
7108 #endif
7109 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
7110 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7111 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7112 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7113 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
7114 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
7115 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7116 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
7117 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
7118 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
7119 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
7121 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
7122 static const DWORD ps_sample_l_code[] =
7124 #if 0
7125 Texture2D t;
7126 SamplerState s;
7128 float level;
7130 float4 main(float4 position : SV_POSITION) : SV_Target
7132 float2 p;
7134 p.x = position.x / 640.0f;
7135 p.y = position.y / 480.0f;
7136 return t.SampleLevel(s, p, level);
7138 #endif
7139 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
7140 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7141 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7142 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7143 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
7144 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
7145 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7146 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
7147 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
7148 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
7149 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
7151 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
7152 static const DWORD ps_sample_2d_array_code[] =
7154 #if 0
7155 Texture2DArray t;
7156 SamplerState s;
7158 float layer;
7160 float4 main(float4 position : SV_POSITION) : SV_TARGET
7162 float3 d;
7163 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
7164 t.GetDimensions(d.x, d.y, d.z);
7165 d.z = layer;
7166 return t.Sample(s, p * d);
7168 #endif
7169 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
7170 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7171 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7172 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7173 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
7174 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
7175 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7176 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
7177 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
7178 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
7179 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
7180 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
7181 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7183 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
7184 static const DWORD red_data[] =
7186 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
7187 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
7188 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
7189 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
7191 static const DWORD green_data[] =
7193 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
7194 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
7195 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
7196 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
7198 static const DWORD blue_data[] =
7200 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
7201 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
7202 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
7203 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
7205 static const DWORD rgba_level_0[] =
7207 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7208 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
7209 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
7210 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7212 static const DWORD rgba_level_1[] =
7214 0xffffffff, 0xff0000ff,
7215 0xff000000, 0xff00ff00,
7217 static const DWORD rgba_level_2[] =
7219 0xffff0000,
7221 static const DWORD srgb_data[] =
7223 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
7224 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
7225 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
7226 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
7228 static const BYTE a8_data[] =
7230 0x00, 0x10, 0x20, 0x30,
7231 0x40, 0x50, 0x60, 0x70,
7232 0x80, 0x90, 0xa0, 0xb0,
7233 0xc0, 0xd0, 0xe0, 0xf0,
7235 static const BYTE bc1_data[] =
7237 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
7238 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
7239 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
7240 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
7242 static const BYTE bc2_data[] =
7244 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
7245 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
7246 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
7247 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
7249 static const BYTE bc3_data[] =
7251 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
7252 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
7253 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
7254 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
7256 static const BYTE bc4_data[] =
7258 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
7259 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
7260 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
7261 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
7263 static const BYTE bc5_data[] =
7265 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
7266 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
7267 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
7268 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
7270 static const BYTE bc6h_u_data[] =
7272 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7273 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7274 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7275 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7277 static const BYTE bc6h_s_data[] =
7279 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7280 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7281 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7282 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7284 static const BYTE bc7_data[] =
7286 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7287 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7288 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7289 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
7291 static const float r32_float[] =
7293 0.0f, 1.0f, 0.5f, 0.50f,
7294 1.0f, 0.0f, 0.0f, 0.75f,
7295 0.0f, 1.0f, 0.5f, 0.25f,
7296 1.0f, 0.0f, 0.0f, 0.75f,
7298 static const DWORD r32_uint[] =
7300 0, 1, 2, 3,
7301 100, 200, 255, 128,
7302 40, 30, 20, 10,
7303 250, 210, 155, 190,
7305 static const DWORD r9g9b9e5_data[] =
7307 0x80000100, 0x80020000, 0x84000000, 0x84000100,
7308 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
7309 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
7310 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
7312 static const struct texture rgba_texture =
7314 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
7316 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
7317 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
7318 {rgba_level_2, sizeof(*rgba_level_2), 0},
7321 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
7322 {{srgb_data, 4 * sizeof(*srgb_data)}}};
7323 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
7324 {{srgb_data, 4 * sizeof(*srgb_data)}}};
7325 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
7326 {{a8_data, 4 * sizeof(*a8_data)}}};
7327 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
7328 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
7329 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
7330 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
7331 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
7332 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
7333 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
7334 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
7335 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
7336 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
7337 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
7338 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
7339 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
7340 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
7341 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
7342 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
7343 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
7344 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
7345 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
7346 static const struct texture array_2d_texture =
7348 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
7350 {red_data, 6 * sizeof(*red_data)},
7351 {green_data, 4 * sizeof(*green_data)},
7352 {blue_data, 5 * sizeof(*blue_data)},
7355 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
7356 {{r32_float, 4 * sizeof(*r32_float)}}};
7357 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
7358 {{r32_uint, 4 * sizeof(*r32_uint)}}};
7359 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
7360 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
7361 static const DWORD red_colors[] =
7363 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7364 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7365 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7366 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7368 static const DWORD blue_colors[] =
7370 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7371 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7372 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7373 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7375 static const DWORD level_1_colors[] =
7377 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
7378 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
7379 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
7380 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
7382 static const DWORD lerp_1_2_colors[] =
7384 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
7385 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
7386 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
7387 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
7389 static const DWORD level_2_colors[] =
7391 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7392 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7393 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7394 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7396 static const DWORD srgb_colors[] =
7398 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
7399 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
7400 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
7401 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
7403 static const DWORD a8_colors[] =
7405 0x00000000, 0x10000000, 0x20000000, 0x30000000,
7406 0x40000000, 0x50000000, 0x60000000, 0x70000000,
7407 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
7408 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
7410 static const DWORD bc_colors[] =
7412 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
7413 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
7414 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
7415 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
7417 static const DWORD bc4_colors[] =
7419 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
7420 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
7421 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
7422 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
7424 static const DWORD bc5_colors[] =
7426 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
7427 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
7428 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
7429 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
7431 static const DWORD bc7_colors[] =
7433 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
7434 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
7435 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
7436 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
7438 static const DWORD sint8_colors[] =
7440 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
7441 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
7442 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
7443 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
7445 static const DWORD r32f_colors[] =
7447 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
7448 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
7449 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
7450 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
7452 static const DWORD r32u_colors[16] =
7454 0x01000000, 0x01000001, 0x01000002, 0x01000003,
7455 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
7456 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
7457 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
7459 static const DWORD r9g9b9e5_colors[16] =
7461 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
7462 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
7463 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
7464 0xff000033, 0xff003300, 0xff330000, 0xff333333,
7466 static const DWORD zero_colors[4 * 4] = {0};
7467 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7469 static const struct texture_test
7471 const struct shader *ps;
7472 const struct texture *texture;
7473 D3D11_FILTER filter;
7474 float lod_bias;
7475 float min_lod;
7476 float max_lod;
7477 float ps_constant;
7478 const DWORD *expected_colors;
7480 texture_tests[] =
7482 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
7483 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
7484 #define MIP_MAX D3D11_FLOAT32_MAX
7485 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7486 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
7487 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
7488 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
7489 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
7490 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7491 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7492 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7493 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7494 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7495 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7496 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7497 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7498 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7499 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
7500 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
7501 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7502 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7503 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
7504 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
7505 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
7506 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7507 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7508 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
7509 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7510 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7511 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7512 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7513 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
7514 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
7515 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7516 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7517 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
7518 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
7519 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7520 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7521 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7522 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
7523 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
7524 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
7525 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
7526 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7527 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7528 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7529 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
7530 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
7531 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
7532 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
7533 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
7534 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
7535 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
7536 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
7537 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
7538 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7539 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7540 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7541 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
7542 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
7543 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7544 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
7545 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
7546 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
7547 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
7548 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
7549 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
7550 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
7551 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
7552 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
7553 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
7554 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
7555 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
7556 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
7557 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
7558 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
7559 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
7560 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
7561 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
7562 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
7563 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
7564 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
7565 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
7566 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
7567 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
7568 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
7569 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
7570 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
7571 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
7572 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
7573 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
7574 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
7575 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
7576 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
7577 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
7578 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
7579 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
7580 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
7581 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
7582 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
7583 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
7584 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7585 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7586 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
7587 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7588 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
7589 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
7590 #undef POINT
7591 #undef POINT_LINEAR
7592 #undef MIP_MAX
7594 static const struct srv_test
7596 const struct shader *ps;
7597 const struct texture *texture;
7598 struct srv_desc srv_desc;
7599 float ps_constant;
7600 const DWORD *expected_colors;
7602 srv_tests[] =
7604 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
7605 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
7606 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
7607 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
7608 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
7609 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
7610 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
7611 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
7612 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
7613 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
7614 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
7615 #define R32_UINT DXGI_FORMAT_R32_UINT
7616 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
7617 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
7618 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
7619 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
7620 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
7621 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
7622 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
7623 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
7624 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
7625 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
7626 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
7627 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
7628 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
7629 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
7630 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
7631 #undef TEX_2D
7632 #undef TEX_2D_ARRAY
7633 #undef BC1_UNORM
7634 #undef BC1_UNORM_SRGB
7635 #undef BC2_UNORM
7636 #undef BC2_UNORM_SRGB
7637 #undef BC3_UNORM
7638 #undef BC3_UNORM_SRGB
7639 #undef R8G8B8A8_UNORM_SRGB
7640 #undef R8G8B8A8_UNORM
7641 #undef R32_FLOAT
7642 #undef R32_UINT
7643 #undef FMT_UNKNOWN
7646 if (!init_test_context(&test_context, NULL))
7647 return;
7649 device = test_context.device;
7650 context = test_context.immediate_context;
7651 feature_level = ID3D11Device_GetFeatureLevel(device);
7653 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
7655 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7657 texture_desc.SampleDesc.Count = 1;
7658 texture_desc.SampleDesc.Quality = 0;
7659 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7660 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
7661 texture_desc.CPUAccessFlags = 0;
7662 texture_desc.MiscFlags = 0;
7664 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7665 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7666 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7667 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7668 sampler_desc.MipLODBias = 0.0f;
7669 sampler_desc.MaxAnisotropy = 0;
7670 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7671 sampler_desc.BorderColor[0] = 0.0f;
7672 sampler_desc.BorderColor[1] = 0.0f;
7673 sampler_desc.BorderColor[2] = 0.0f;
7674 sampler_desc.BorderColor[3] = 0.0f;
7675 sampler_desc.MinLOD = 0.0f;
7676 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
7678 ps = NULL;
7679 srv = NULL;
7680 sampler = NULL;
7681 texture = NULL;
7682 current_ps = NULL;
7683 current_texture = NULL;
7684 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
7686 const struct texture_test *test = &texture_tests[i];
7688 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
7689 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
7690 && feature_level < D3D_FEATURE_LEVEL_11_0)
7692 skip("Feature level >= 11.0 is required for BC7 tests.\n");
7693 continue;
7696 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
7697 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
7698 && feature_level < D3D_FEATURE_LEVEL_11_0)
7700 skip("Feature level >= 11.0 is required for BC6H tests.\n");
7701 continue;
7704 if (current_ps != test->ps)
7706 if (ps)
7707 ID3D11PixelShader_Release(ps);
7709 current_ps = test->ps;
7711 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
7712 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7714 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7717 if (current_texture != test->texture)
7719 if (texture)
7720 ID3D11Texture2D_Release(texture);
7721 if (srv)
7722 ID3D11ShaderResourceView_Release(srv);
7724 current_texture = test->texture;
7726 if (current_texture)
7728 texture_desc.Width = current_texture->width;
7729 texture_desc.Height = current_texture->height;
7730 texture_desc.MipLevels = current_texture->miplevel_count;
7731 texture_desc.ArraySize = current_texture->array_size;
7732 texture_desc.Format = current_texture->format;
7734 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
7735 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7737 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
7738 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7740 else
7742 texture = NULL;
7743 srv = NULL;
7746 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7749 if (!sampler || (sampler_desc.Filter != test->filter
7750 || sampler_desc.MipLODBias != test->lod_bias
7751 || sampler_desc.MinLOD != test->min_lod
7752 || sampler_desc.MaxLOD != test->max_lod))
7754 if (sampler)
7755 ID3D11SamplerState_Release(sampler);
7757 sampler_desc.Filter = test->filter;
7758 sampler_desc.MipLODBias = test->lod_bias;
7759 sampler_desc.MinLOD = test->min_lod;
7760 sampler_desc.MaxLOD = test->max_lod;
7762 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
7763 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
7765 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7768 ps_constant.x = test->ps_constant;
7769 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
7771 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7773 draw_quad(&test_context);
7775 get_texture_readback(test_context.backbuffer, 0, &rb);
7776 for (y = 0; y < 4; ++y)
7778 for (x = 0; x < 4; ++x)
7780 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
7781 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
7782 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
7785 release_resource_readback(&rb);
7787 if (srv)
7788 ID3D11ShaderResourceView_Release(srv);
7789 ID3D11SamplerState_Release(sampler);
7790 if (texture)
7791 ID3D11Texture2D_Release(texture);
7792 ID3D11PixelShader_Release(ps);
7794 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
7796 win_skip("SRV tests are broken on WARP.\n");
7797 ID3D11Buffer_Release(cb);
7798 release_test_context(&test_context);
7799 return;
7802 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7803 sampler_desc.MipLODBias = 0.0f;
7804 sampler_desc.MinLOD = 0.0f;
7805 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
7807 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
7808 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7810 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7812 ps = NULL;
7813 srv = NULL;
7814 texture = NULL;
7815 current_ps = NULL;
7816 current_texture = NULL;
7817 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
7819 const struct srv_test *test = &srv_tests[i];
7821 if (current_ps != test->ps)
7823 if (ps)
7824 ID3D11PixelShader_Release(ps);
7826 current_ps = test->ps;
7828 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
7829 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7831 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7834 if (current_texture != test->texture)
7836 if (texture)
7837 ID3D11Texture2D_Release(texture);
7839 current_texture = test->texture;
7841 texture_desc.Width = current_texture->width;
7842 texture_desc.Height = current_texture->height;
7843 texture_desc.MipLevels = current_texture->miplevel_count;
7844 texture_desc.ArraySize = current_texture->array_size;
7845 texture_desc.Format = current_texture->format;
7847 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
7848 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7851 if (srv)
7852 ID3D11ShaderResourceView_Release(srv);
7854 get_srv_desc(&srv_desc, &test->srv_desc);
7855 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
7856 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7858 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7860 ps_constant.x = test->ps_constant;
7861 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
7863 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7865 draw_quad(&test_context);
7867 get_texture_readback(test_context.backbuffer, 0, &rb);
7868 for (y = 0; y < 4; ++y)
7870 for (x = 0; x < 4; ++x)
7872 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
7873 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
7874 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
7877 release_resource_readback(&rb);
7879 ID3D11PixelShader_Release(ps);
7880 ID3D11Texture2D_Release(texture);
7881 ID3D11ShaderResourceView_Release(srv);
7882 ID3D11SamplerState_Release(sampler);
7884 ID3D11Buffer_Release(cb);
7885 release_test_context(&test_context);
7888 static void test_cube_maps(void)
7890 struct shader
7892 const DWORD *code;
7893 size_t size;
7896 unsigned int i, j, sub_resource_idx, sub_resource_count;
7897 struct d3d11_test_context test_context;
7898 D3D11_TEXTURE2D_DESC texture_desc;
7899 const struct shader *current_ps;
7900 D3D_FEATURE_LEVEL feature_level;
7901 ID3D11ShaderResourceView *srv;
7902 ID3D11DeviceContext *context;
7903 ID3D11Texture2D *rtv_texture;
7904 ID3D11RenderTargetView *rtv;
7905 struct vec4 expected_result;
7906 ID3D11Resource *texture;
7907 ID3D11PixelShader *ps;
7908 ID3D11Device *device;
7909 float data[64 * 64];
7910 ID3D11Buffer *cb;
7911 HRESULT hr;
7912 RECT rect;
7913 struct
7915 unsigned int face;
7916 unsigned int level;
7917 unsigned int cube;
7918 unsigned int padding;
7919 } constant;
7921 static const DWORD ps_cube_code[] =
7923 #if 0
7924 TextureCube t;
7925 SamplerState s;
7927 uint face;
7928 uint level;
7930 float4 main(float4 position : SV_POSITION) : SV_Target
7932 float2 p;
7933 p.x = position.x / 640.0f;
7934 p.y = position.y / 480.0f;
7936 float3 coord;
7937 switch (face)
7939 case 0:
7940 coord = float3(1.0f, p.x, p.y);
7941 break;
7942 case 1:
7943 coord = float3(-1.0f, p.x, p.y);
7944 break;
7945 case 2:
7946 coord = float3(p.x, 1.0f, p.y);
7947 break;
7948 case 3:
7949 coord = float3(p.x, -1.0f, p.y);
7950 break;
7951 case 4:
7952 coord = float3(p.x, p.y, 1.0f);
7953 break;
7954 case 5:
7955 default:
7956 coord = float3(p.x, p.y, -1.0f);
7957 break;
7959 return t.SampleLevel(s, coord, level);
7961 #endif
7962 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
7963 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7964 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7965 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7966 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
7967 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
7968 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7969 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
7970 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
7971 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
7972 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
7973 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
7974 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
7975 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
7976 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
7977 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
7978 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
7979 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
7980 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
7981 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
7982 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7983 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
7984 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
7985 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
7986 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
7988 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
7989 static const DWORD ps_cube_array_code[] =
7991 #if 0
7992 TextureCubeArray t;
7993 SamplerState s;
7995 uint face;
7996 uint level;
7997 uint cube;
7999 float4 main(float4 position : SV_POSITION) : SV_Target
8001 float2 p;
8002 p.x = position.x / 640.0f;
8003 p.y = position.y / 480.0f;
8005 float3 coord;
8006 switch (face)
8008 case 0:
8009 coord = float3(1.0f, p.x, p.y);
8010 break;
8011 case 1:
8012 coord = float3(-1.0f, p.x, p.y);
8013 break;
8014 case 2:
8015 coord = float3(p.x, 1.0f, p.y);
8016 break;
8017 case 3:
8018 coord = float3(p.x, -1.0f, p.y);
8019 break;
8020 case 4:
8021 coord = float3(p.x, p.y, 1.0f);
8022 break;
8023 case 5:
8024 default:
8025 coord = float3(p.x, p.y, -1.0f);
8026 break;
8028 return t.SampleLevel(s, float4(coord, cube), level);
8030 #endif
8031 0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
8032 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8033 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8034 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8035 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
8036 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
8037 0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
8038 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
8039 0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
8040 0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
8041 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
8042 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
8043 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
8044 0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
8045 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
8046 0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
8047 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
8048 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
8049 0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8050 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
8051 0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
8052 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
8053 0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
8054 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
8055 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
8056 0x00000001, 0x0100003e,
8058 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
8059 static const struct ps_test
8061 const struct shader *ps;
8062 unsigned int miplevel_count;
8063 unsigned int array_size;
8065 ps_tests[] =
8067 {&ps_cube, 1, 6},
8068 {&ps_cube, 2, 6},
8069 {&ps_cube, 3, 6},
8070 {&ps_cube, 0, 6},
8072 {&ps_cube_array, 1, 12},
8073 {&ps_cube_array, 2, 12},
8074 {&ps_cube_array, 3, 12},
8075 {&ps_cube_array, 0, 12},
8078 if (!init_test_context(&test_context, NULL))
8079 return;
8081 device = test_context.device;
8082 context = test_context.immediate_context;
8083 feature_level = ID3D11Device_GetFeatureLevel(device);
8085 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8086 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8087 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
8088 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8089 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
8090 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8092 memset(&constant, 0, sizeof(constant));
8093 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
8095 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8096 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8098 ps = NULL;
8099 current_ps = NULL;
8100 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
8102 const struct ps_test *test = &ps_tests[i];
8104 if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
8106 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
8107 continue;
8110 if (current_ps != test->ps)
8112 if (ps)
8113 ID3D11PixelShader_Release(ps);
8115 current_ps = test->ps;
8117 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
8118 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
8119 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8122 if (!test->miplevel_count)
8124 srv = NULL;
8125 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8127 memset(&expected_result, 0, sizeof(expected_result));
8129 memset(&constant, 0, sizeof(constant));
8130 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8131 draw_quad(&test_context);
8132 check_texture_vec4(rtv_texture, &expected_result, 0);
8133 constant.level = 1;
8134 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8135 draw_quad(&test_context);
8136 check_texture_vec4(rtv_texture, &expected_result, 0);
8137 continue;
8140 texture_desc.Width = 64;
8141 texture_desc.Height = 64;
8142 texture_desc.MipLevels = test->miplevel_count;
8143 texture_desc.ArraySize = test->array_size;
8144 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
8145 texture_desc.SampleDesc.Count = 1;
8146 texture_desc.SampleDesc.Quality = 0;
8147 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8148 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
8149 texture_desc.CPUAccessFlags = 0;
8150 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
8151 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
8152 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
8154 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
8155 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
8156 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8158 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
8159 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
8161 for (j = 0; j < ARRAY_SIZE(data); ++j)
8162 data[j] = sub_resource_idx;
8163 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, sub_resource_idx, NULL,
8164 data, texture_desc.Width * sizeof(*data), 0);
8167 expected_result.y = expected_result.z = 0.0f;
8168 expected_result.w = 1.0f;
8169 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
8171 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
8172 constant.level = sub_resource_idx % texture_desc.MipLevels;
8173 constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
8174 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8176 draw_quad(&test_context);
8177 expected_result.x = sub_resource_idx;
8178 /* Avoid testing values affected by seamless cube map filtering. */
8179 SetRect(&rect, 100, 100, 540, 380);
8180 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
8183 ID3D11Resource_Release(texture);
8184 ID3D11ShaderResourceView_Release(srv);
8186 ID3D11PixelShader_Release(ps);
8188 ID3D11Buffer_Release(cb);
8189 ID3D11RenderTargetView_Release(rtv);
8190 ID3D11Texture2D_Release(rtv_texture);
8191 release_test_context(&test_context);
8194 static void test_depth_stencil_sampling(void)
8196 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
8197 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
8198 ID3D11SamplerState *cmp_sampler, *sampler;
8199 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8200 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
8201 struct d3d11_test_context test_context;
8202 ID3D11Texture2D *texture, *rt_texture;
8203 D3D11_TEXTURE2D_DESC texture_desc;
8204 D3D11_SAMPLER_DESC sampler_desc;
8205 ID3D11DeviceContext *context;
8206 ID3D11DepthStencilView *dsv;
8207 ID3D11RenderTargetView *rtv;
8208 struct vec4 ps_constant;
8209 ID3D11Device *device;
8210 ID3D11Buffer *cb;
8211 unsigned int i;
8212 HRESULT hr;
8214 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
8215 static const DWORD ps_compare_code[] =
8217 #if 0
8218 Texture2D t;
8219 SamplerComparisonState s;
8221 float ref;
8223 float4 main(float4 position : SV_Position) : SV_Target
8225 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
8227 #endif
8228 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
8229 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8230 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
8231 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8232 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
8233 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
8234 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
8235 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
8236 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
8237 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
8238 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
8239 0x0100003e,
8241 static const DWORD ps_sample_code[] =
8243 #if 0
8244 Texture2D t;
8245 SamplerState s;
8247 float4 main(float4 position : SV_Position) : SV_Target
8249 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
8251 #endif
8252 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
8253 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8254 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
8255 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8256 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
8257 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
8258 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
8259 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8260 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
8261 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
8263 static const DWORD ps_stencil_code[] =
8265 #if 0
8266 Texture2D<uint4> t;
8268 float4 main(float4 position : SV_Position) : SV_Target
8270 float2 s;
8271 t.GetDimensions(s.x, s.y);
8272 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
8274 #endif
8275 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
8276 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8277 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
8278 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8279 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
8280 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
8281 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
8282 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
8283 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
8284 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
8285 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
8286 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8287 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
8289 static const DWORD ps_depth_stencil_code[] =
8291 #if 0
8292 SamplerState samp;
8293 Texture2D depth_tex;
8294 Texture2D<uint4> stencil_tex;
8296 float main(float4 position: SV_Position) : SV_Target
8298 float2 s, p;
8299 float depth, stencil;
8300 depth_tex.GetDimensions(s.x, s.y);
8301 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
8302 depth = depth_tex.Sample(samp, p).r;
8303 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
8304 return depth + stencil;
8306 #endif
8307 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
8308 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8309 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
8310 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8311 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
8312 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
8313 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
8314 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
8315 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
8316 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
8317 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
8318 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
8319 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
8320 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
8321 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
8322 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
8324 static const struct test
8326 DXGI_FORMAT typeless_format;
8327 DXGI_FORMAT dsv_format;
8328 DXGI_FORMAT depth_view_format;
8329 DXGI_FORMAT stencil_view_format;
8331 tests[] =
8333 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
8334 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
8335 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
8336 DXGI_FORMAT_R32_FLOAT},
8337 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
8338 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
8339 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
8340 DXGI_FORMAT_R16_UNORM},
8343 if (!init_test_context(&test_context, NULL))
8344 return;
8346 device = test_context.device;
8347 context = test_context.immediate_context;
8349 if (is_amd_device(device))
8351 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
8352 win_skip("Some AMD drivers have a bug affecting the test.\n");
8353 release_test_context(&test_context);
8354 return;
8357 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
8358 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8359 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8360 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8361 sampler_desc.MipLODBias = 0.0f;
8362 sampler_desc.MaxAnisotropy = 0;
8363 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
8364 sampler_desc.BorderColor[0] = 0.0f;
8365 sampler_desc.BorderColor[1] = 0.0f;
8366 sampler_desc.BorderColor[2] = 0.0f;
8367 sampler_desc.BorderColor[3] = 0.0f;
8368 sampler_desc.MinLOD = 0.0f;
8369 sampler_desc.MaxLOD = 0.0f;
8370 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
8371 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8373 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8374 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8375 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
8376 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8378 texture_desc.Width = 640;
8379 texture_desc.Height = 480;
8380 texture_desc.MipLevels = 1;
8381 texture_desc.ArraySize = 1;
8382 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
8383 texture_desc.SampleDesc.Count = 1;
8384 texture_desc.SampleDesc.Quality = 0;
8385 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8386 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8387 texture_desc.CPUAccessFlags = 0;
8388 texture_desc.MiscFlags = 0;
8389 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
8390 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8391 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
8392 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
8393 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8395 memset(&ps_constant, 0, sizeof(ps_constant));
8396 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
8397 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8399 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
8400 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8401 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
8402 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8403 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
8404 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8405 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
8406 &ps_depth_stencil);
8407 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8409 for (i = 0; i < ARRAY_SIZE(tests); ++i)
8411 texture_desc.Format = tests[i].typeless_format;
8412 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
8413 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8414 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
8415 texture_desc.Format, hr);
8417 dsv_desc.Format = tests[i].dsv_format;
8418 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
8419 dsv_desc.Flags = 0;
8420 U(dsv_desc).Texture2D.MipSlice = 0;
8421 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
8422 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
8423 dsv_desc.Format, hr);
8425 srv_desc.Format = tests[i].depth_view_format;
8426 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
8427 U(srv_desc).Texture2D.MostDetailedMip = 0;
8428 U(srv_desc).Texture2D.MipLevels = 1;
8429 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
8430 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
8431 srv_desc.Format, hr);
8433 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
8434 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
8435 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
8437 ps_constant.x = 0.5f;
8438 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
8439 NULL, &ps_constant, 0, 0);
8441 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8442 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
8443 draw_quad(&test_context);
8444 check_texture_float(rt_texture, 0.0f, 2);
8446 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
8447 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
8448 draw_quad(&test_context);
8449 check_texture_float(rt_texture, 1.0f, 2);
8451 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
8452 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
8453 draw_quad(&test_context);
8454 check_texture_float(rt_texture, 0.0f, 2);
8456 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
8457 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
8458 draw_quad(&test_context);
8459 check_texture_float(rt_texture, 0.0f, 2);
8461 ps_constant.x = 0.7f;
8462 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
8463 NULL, &ps_constant, 0, 0);
8465 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
8466 draw_quad(&test_context);
8467 check_texture_float(rt_texture, 1.0f, 2);
8469 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
8470 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
8472 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8473 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
8474 draw_quad(&test_context);
8475 check_texture_float(rt_texture, 1.0f, 2);
8477 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
8478 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
8479 draw_quad(&test_context);
8480 check_texture_float(rt_texture, 0.2f, 2);
8482 if (!tests[i].stencil_view_format)
8484 ID3D11DepthStencilView_Release(dsv);
8485 ID3D11ShaderResourceView_Release(depth_srv);
8486 ID3D11Texture2D_Release(texture);
8487 continue;
8490 srv_desc.Format = tests[i].stencil_view_format;
8491 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
8492 if (hr == E_OUTOFMEMORY)
8494 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
8495 ID3D11DepthStencilView_Release(dsv);
8496 ID3D11ShaderResourceView_Release(depth_srv);
8497 ID3D11Texture2D_Release(texture);
8498 continue;
8500 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
8501 srv_desc.Format, hr);
8503 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
8504 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
8506 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
8507 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
8508 draw_quad(&test_context);
8509 check_texture_float(rt_texture, 0.0f, 0);
8511 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
8512 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
8513 draw_quad(&test_context);
8514 check_texture_float(rt_texture, 100.0f, 0);
8516 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
8517 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
8518 draw_quad(&test_context);
8519 check_texture_float(rt_texture, 255.0f, 0);
8521 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
8522 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
8523 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
8525 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
8526 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
8527 draw_quad(&test_context);
8528 check_texture_float(rt_texture, 3.3f, 2);
8530 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
8531 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
8532 draw_quad(&test_context);
8533 check_texture_float(rt_texture, 4.0f, 2);
8535 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
8536 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
8537 draw_quad(&test_context);
8538 check_texture_float(rt_texture, 0.0f, 2);
8540 ID3D11DepthStencilView_Release(dsv);
8541 ID3D11ShaderResourceView_Release(depth_srv);
8542 ID3D11ShaderResourceView_Release(stencil_srv);
8543 ID3D11Texture2D_Release(texture);
8546 ID3D11Buffer_Release(cb);
8547 ID3D11PixelShader_Release(ps_cmp);
8548 ID3D11PixelShader_Release(ps_depth);
8549 ID3D11PixelShader_Release(ps_depth_stencil);
8550 ID3D11PixelShader_Release(ps_stencil);
8551 ID3D11RenderTargetView_Release(rtv);
8552 ID3D11SamplerState_Release(cmp_sampler);
8553 ID3D11SamplerState_Release(sampler);
8554 ID3D11Texture2D_Release(rt_texture);
8555 release_test_context(&test_context);
8558 static void test_sample_c_lz(void)
8560 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8561 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
8562 struct d3d11_test_context test_context;
8563 ID3D11Texture2D *texture, *rt_texture;
8564 D3D11_TEXTURE2D_DESC texture_desc;
8565 D3D11_SAMPLER_DESC sampler_desc;
8566 ID3D11ShaderResourceView *srv;
8567 ID3D11DeviceContext *context;
8568 ID3D11DepthStencilView *dsv;
8569 ID3D11RenderTargetView *rtv;
8570 ID3D11SamplerState *sampler;
8571 struct vec4 ps_constant;
8572 ID3D11PixelShader *ps;
8573 ID3D11Device *device;
8574 ID3D11Buffer *cb;
8575 unsigned int i;
8576 HRESULT hr;
8577 RECT rect;
8579 static const float clear_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
8580 static const DWORD ps_array_code[] =
8582 #if 0
8583 Texture2DArray t;
8584 SamplerComparisonState s;
8586 float ref;
8587 float layer;
8589 float4 main(float4 position : SV_Position) : SV_Target
8591 return t.SampleCmpLevelZero(s, float3(position.x / 640.0f, position.y / 480.0f, layer), ref);
8593 #endif
8594 0x43425844, 0xfe28b3c3, 0xdd7ef404, 0x8d5874a1, 0x984ff182, 0x00000001, 0x00000180, 0x00000003,
8595 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8596 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
8597 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8598 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000e4, 0x00000041,
8599 0x00000039, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
8600 0x00000000, 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
8601 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
8602 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
8603 0x06000036, 0x00100042, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0c000047, 0x00100012,
8604 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000, 0x0020800a,
8605 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
8607 static const DWORD ps_cube_code[] =
8609 #if 0
8610 TextureCube t;
8611 SamplerComparisonState s;
8613 float ref;
8614 float face;
8616 float4 main(float4 position : SV_Position) : SV_Target
8618 float2 p;
8619 p.x = position.x / 640.0f;
8620 p.y = position.y / 480.0f;
8622 float3 coord;
8623 switch ((uint)face)
8625 case 0:
8626 coord = float3(1.0f, p.x, p.y);
8627 break;
8628 case 1:
8629 coord = float3(-1.0f, p.x, p.y);
8630 break;
8631 case 2:
8632 coord = float3(p.x, 1.0f, p.y);
8633 break;
8634 case 3:
8635 coord = float3(p.x, -1.0f, p.y);
8636 break;
8637 case 4:
8638 coord = float3(p.x, p.y, 1.0f);
8639 break;
8640 case 5:
8641 default:
8642 coord = float3(p.x, p.y, -1.0f);
8643 break;
8646 return t.SampleCmpLevelZero(s, coord, ref);
8648 #endif
8649 0x43425844, 0xde5655e5, 0x1b116fa1, 0xfce9e757, 0x41c28aac, 0x00000001, 0x00000328, 0x00000003,
8650 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8651 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
8652 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8653 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
8654 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
8655 0x00000000, 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
8656 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600001c, 0x00100012,
8657 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0300004c, 0x0010000a, 0x00000000, 0x03000006,
8658 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x3f800000, 0x0a000038,
8659 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889,
8660 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, 0x00100012, 0x00000000,
8661 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
8662 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000002,
8663 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000,
8664 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
8665 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
8666 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
8667 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, 0x0a000038, 0x00100032,
8668 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
8669 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x0100000a, 0x0a000038,
8670 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000,
8671 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x01000017,
8672 0x0c000047, 0x00100012, 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000,
8673 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006,
8674 0x00000000, 0x0100003e,
8676 static const float depth_values[] = {1.0f, 0.0f, 0.5f, 0.6f, 0.4f, 0.1f};
8677 static const struct
8679 unsigned int layer;
8680 float d_ref;
8681 float expected;
8683 tests[] =
8685 {0, 0.5f, 0.0f},
8686 {1, 0.5f, 1.0f},
8687 {2, 0.5f, 0.0f},
8688 {3, 0.5f, 0.0f},
8689 {4, 0.5f, 1.0f},
8690 {5, 0.5f, 1.0f},
8692 {0, 0.0f, 0.0f},
8693 {1, 0.0f, 0.0f},
8694 {2, 0.0f, 0.0f},
8695 {3, 0.0f, 0.0f},
8696 {4, 0.0f, 0.0f},
8697 {5, 0.0f, 0.0f},
8699 {0, 1.0f, 0.0f},
8700 {1, 1.0f, 1.0f},
8701 {2, 1.0f, 1.0f},
8702 {3, 1.0f, 1.0f},
8703 {4, 1.0f, 1.0f},
8704 {5, 1.0f, 1.0f},
8707 if (!init_test_context(&test_context, NULL))
8708 return;
8710 device = test_context.device;
8711 context = test_context.immediate_context;
8713 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
8714 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8715 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8716 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8717 sampler_desc.MipLODBias = 0.0f;
8718 sampler_desc.MaxAnisotropy = 0;
8719 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
8720 sampler_desc.BorderColor[0] = 0.0f;
8721 sampler_desc.BorderColor[1] = 0.0f;
8722 sampler_desc.BorderColor[2] = 0.0f;
8723 sampler_desc.BorderColor[3] = 0.0f;
8724 sampler_desc.MinLOD = 0.0f;
8725 sampler_desc.MaxLOD = 10.0f;
8726 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
8727 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8729 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8730 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
8731 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
8732 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8733 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
8734 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8735 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8737 memset(&ps_constant, 0, sizeof(ps_constant));
8738 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
8740 /* 2D array texture */
8741 texture_desc.Width = 32;
8742 texture_desc.Height = 32;
8743 texture_desc.MipLevels = 2;
8744 texture_desc.ArraySize = ARRAY_SIZE(depth_values);
8745 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
8746 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
8747 texture_desc.MiscFlags = 0;
8748 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8749 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8751 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
8753 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
8754 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
8755 dsv_desc.Flags = 0;
8756 U(dsv_desc).Texture2DArray.MipSlice = 0;
8757 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
8758 U(dsv_desc).Texture2DArray.ArraySize = 1;
8760 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
8761 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8762 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
8763 ID3D11DepthStencilView_Release(dsv);
8765 U(dsv_desc).Texture2DArray.MipSlice = 1;
8766 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
8767 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8768 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8769 ID3D11DepthStencilView_Release(dsv);
8772 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
8773 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
8774 U(srv_desc).Texture2DArray.MostDetailedMip = 0;
8775 U(srv_desc).Texture2DArray.MipLevels = ~0u;
8776 U(srv_desc).Texture2DArray.FirstArraySlice = 0;
8777 U(srv_desc).Texture2DArray.ArraySize = ~0u;
8778 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
8779 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8781 hr = ID3D11Device_CreatePixelShader(device, ps_array_code, sizeof(ps_array_code), NULL, &ps);
8782 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8784 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8785 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8786 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
8787 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8789 for (i = 0; i < ARRAY_SIZE(tests); ++i)
8791 ps_constant.x = tests[i].d_ref;
8792 ps_constant.y = tests[i].layer;
8793 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
8794 NULL, &ps_constant, 0, 0);
8795 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
8796 draw_quad(&test_context);
8797 check_texture_float(rt_texture, tests[i].expected, 2);
8800 ID3D11Texture2D_Release(texture);
8801 ID3D11ShaderResourceView_Release(srv);
8802 ID3D11PixelShader_Release(ps);
8804 /* cube texture */
8805 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
8806 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8807 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8809 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
8811 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
8812 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
8813 dsv_desc.Flags = 0;
8814 U(dsv_desc).Texture2DArray.MipSlice = 0;
8815 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
8816 U(dsv_desc).Texture2DArray.ArraySize = 1;
8818 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
8819 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8820 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
8821 ID3D11DepthStencilView_Release(dsv);
8823 U(dsv_desc).Texture2DArray.MipSlice = 1;
8824 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
8825 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8826 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8827 ID3D11DepthStencilView_Release(dsv);
8830 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
8831 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
8832 U(srv_desc).TextureCube.MostDetailedMip = 0;
8833 U(srv_desc).TextureCube.MipLevels = ~0u;
8834 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
8835 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8837 hr = ID3D11Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), NULL, &ps);
8838 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8840 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8841 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8842 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
8843 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8845 for (i = 0; i < ARRAY_SIZE(tests); ++i)
8847 ps_constant.x = tests[i].d_ref;
8848 ps_constant.y = tests[i].layer;
8849 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
8850 NULL, &ps_constant, 0, 0);
8851 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
8852 draw_quad(&test_context);
8853 /* Avoid testing values affected by seamless cube map filtering. */
8854 SetRect(&rect, 100, 100, 540, 380);
8855 check_texture_sub_resource_float(rt_texture, 0, &rect, tests[i].expected, 2);
8858 ID3D11Texture2D_Release(texture);
8859 ID3D11ShaderResourceView_Release(srv);
8861 ID3D11Buffer_Release(cb);
8862 ID3D11PixelShader_Release(ps);
8863 ID3D11RenderTargetView_Release(rtv);
8864 ID3D11SamplerState_Release(sampler);
8865 ID3D11Texture2D_Release(rt_texture);
8866 release_test_context(&test_context);
8869 static void test_multiple_render_targets(void)
8871 ID3D11RenderTargetView *rtv[4], *tmp_rtv[4];
8872 D3D11_TEXTURE2D_DESC texture_desc;
8873 ID3D11InputLayout *input_layout;
8874 unsigned int stride, offset, i;
8875 ID3D11DeviceContext *context;
8876 ID3D11Texture2D *rt[4];
8877 ID3D11VertexShader *vs;
8878 ID3D11PixelShader *ps;
8879 ID3D11Device *device;
8880 ID3D11Buffer *vb;
8881 ULONG refcount;
8882 HRESULT hr;
8884 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8886 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8888 static const DWORD vs_code[] =
8890 #if 0
8891 float4 main(float4 position : POSITION) : SV_POSITION
8893 return position;
8895 #endif
8896 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
8897 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8898 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8899 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8900 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
8901 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
8902 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8904 static const DWORD ps_code[] =
8906 #if 0
8907 struct output
8909 float4 t1 : SV_TARGET0;
8910 float4 t2 : SV_Target1;
8911 float4 t3 : SV_TARGET2;
8912 float4 t4 : SV_Target3;
8915 output main(float4 position : SV_POSITION)
8917 struct output o;
8918 o.t1 = (float4)1.0f;
8919 o.t2 = (float4)0.5f;
8920 o.t3 = (float4)0.2f;
8921 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
8922 return o;
8924 #endif
8925 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
8926 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8927 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
8928 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
8929 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8930 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
8931 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
8932 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
8933 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
8934 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
8935 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
8936 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
8937 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
8938 0x3f800000, 0x0100003e,
8940 static const struct vec2 quad[] =
8942 {-1.0f, -1.0f},
8943 {-1.0f, 1.0f},
8944 { 1.0f, -1.0f},
8945 { 1.0f, 1.0f},
8947 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
8949 if (!(device = create_device(NULL)))
8951 skip("Failed to create device.\n");
8952 return;
8955 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8956 vs_code, sizeof(vs_code), &input_layout);
8957 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8959 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
8961 texture_desc.Width = 640;
8962 texture_desc.Height = 480;
8963 texture_desc.MipLevels = 1;
8964 texture_desc.ArraySize = 1;
8965 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8966 texture_desc.SampleDesc.Count = 1;
8967 texture_desc.SampleDesc.Quality = 0;
8968 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8969 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8970 texture_desc.CPUAccessFlags = 0;
8971 texture_desc.MiscFlags = 0;
8973 for (i = 0; i < ARRAY_SIZE(rt); ++i)
8975 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
8976 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
8978 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
8979 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
8982 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
8983 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8984 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8985 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8987 ID3D11Device_GetImmediateContext(device, &context);
8989 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
8990 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
8991 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8992 stride = sizeof(*quad);
8993 offset = 0;
8994 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
8995 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
8996 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8998 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
9000 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
9001 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
9002 ID3D11DeviceContext_Draw(context, 4, 0);
9003 check_texture_color(rt[0], 0xffffffff, 2);
9004 check_texture_color(rt[1], 0x7f7f7f7f, 2);
9005 check_texture_color(rt[2], 0x33333333, 2);
9006 check_texture_color(rt[3], 0xff7f3300, 2);
9008 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
9009 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
9010 for (i = 0; i < ARRAY_SIZE(tmp_rtv); ++i)
9012 memset(tmp_rtv, 0, sizeof(tmp_rtv));
9013 tmp_rtv[i] = rtv[i];
9014 ID3D11DeviceContext_OMSetRenderTargets(context, 4, tmp_rtv, NULL);
9015 ID3D11DeviceContext_Draw(context, 4, 0);
9017 check_texture_color(rt[0], 0xffffffff, 2);
9018 check_texture_color(rt[1], 0x7f7f7f7f, 2);
9019 check_texture_color(rt[2], 0x33333333, 2);
9020 check_texture_color(rt[3], 0xff7f3300, 2);
9022 ID3D11Buffer_Release(vb);
9023 ID3D11PixelShader_Release(ps);
9024 ID3D11VertexShader_Release(vs);
9025 ID3D11InputLayout_Release(input_layout);
9026 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
9028 ID3D11RenderTargetView_Release(rtv[i]);
9029 ID3D11Texture2D_Release(rt[i]);
9031 ID3D11DeviceContext_Release(context);
9032 refcount = ID3D11Device_Release(device);
9033 ok(!refcount, "Device has %u references left.\n", refcount);
9036 static void test_render_target_views(void)
9038 struct texture
9040 UINT miplevel_count;
9041 UINT array_size;
9044 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
9045 static struct test
9047 struct texture texture;
9048 struct rtv_desc rtv;
9049 DWORD expected_colors[4];
9051 tests[] =
9053 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
9054 {0xff0000ff, 0x00000000}},
9055 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
9056 {0x00000000, 0xff0000ff}},
9057 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
9058 {0xff0000ff, 0x00000000}},
9059 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
9060 {0x00000000, 0xff0000ff}},
9061 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
9062 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
9063 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
9064 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
9065 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
9066 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
9067 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
9068 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
9069 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
9070 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
9071 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
9072 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
9073 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
9074 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
9075 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
9076 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
9077 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
9078 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
9079 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
9080 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
9081 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
9082 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
9084 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
9085 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
9086 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
9087 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
9088 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
9089 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
9090 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
9091 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
9092 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
9093 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
9094 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
9095 static const struct
9097 struct
9099 D3D11_RTV_DIMENSION dimension;
9100 unsigned int miplevel_count;
9101 unsigned int depth_or_array_size;
9102 DXGI_FORMAT format;
9103 } texture;
9104 struct rtv_desc rtv_desc;
9106 invalid_desc_tests[] =
9108 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
9109 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
9110 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
9111 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
9112 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
9113 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
9114 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
9115 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
9116 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
9117 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
9118 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
9119 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
9120 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
9121 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
9122 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
9123 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}},
9124 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
9125 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
9126 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
9127 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
9128 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
9129 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
9130 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
9131 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
9132 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
9133 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
9134 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
9135 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
9136 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
9137 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
9138 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
9139 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
9140 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
9141 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
9142 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
9143 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
9144 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
9146 #undef FMT_UNKNOWN
9147 #undef RGBA8_UNORM
9148 #undef RGBA8_SRGB
9149 #undef RGBA8_UINT
9150 #undef RGBA8_TL
9151 #undef DIM_UNKNOWN
9152 #undef TEX_1D
9153 #undef TEX_1D_ARRAY
9154 #undef TEX_2D
9155 #undef TEX_2D_ARRAY
9156 #undef TEX_3D
9158 struct d3d11_test_context test_context;
9159 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
9160 D3D11_TEXTURE3D_DESC texture3d_desc;
9161 D3D11_TEXTURE2D_DESC texture_desc;
9162 ID3D11DeviceContext *context;
9163 ID3D11RenderTargetView *rtv;
9164 ID3D11Texture3D *texture3d;
9165 ID3D11Texture2D *texture;
9166 ID3D11Resource *resource;
9167 ID3D11Device *device;
9168 unsigned int i, j, k;
9169 void *data;
9170 HRESULT hr;
9172 if (!init_test_context(&test_context, NULL))
9173 return;
9175 device = test_context.device;
9176 context = test_context.immediate_context;
9178 texture_desc.Width = 32;
9179 texture_desc.Height = 32;
9180 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9181 texture_desc.SampleDesc.Count = 1;
9182 texture_desc.SampleDesc.Quality = 0;
9183 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9184 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9185 texture_desc.CPUAccessFlags = 0;
9186 texture_desc.MiscFlags = 0;
9188 data = heap_alloc_zero(texture_desc.Width * texture_desc.Height * 4);
9189 ok(!!data, "Failed to allocate memory.\n");
9191 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9193 const struct test *test = &tests[i];
9194 unsigned int sub_resource_count;
9196 texture_desc.MipLevels = test->texture.miplevel_count;
9197 texture_desc.ArraySize = test->texture.array_size;
9199 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9200 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
9202 get_rtv_desc(&rtv_desc, &test->rtv);
9203 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
9204 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
9206 for (j = 0; j < texture_desc.ArraySize; ++j)
9208 for (k = 0; k < texture_desc.MipLevels; ++k)
9210 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
9211 ID3D11DeviceContext_UpdateSubresource(context,
9212 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
9215 check_texture_color(texture, 0, 0);
9217 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9218 draw_color_quad(&test_context, &red);
9220 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
9221 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
9222 for (j = 0; j < sub_resource_count; ++j)
9223 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
9225 ID3D11RenderTargetView_Release(rtv);
9226 ID3D11Texture2D_Release(texture);
9229 texture3d_desc.Width = 32;
9230 texture3d_desc.Height = 32;
9231 texture3d_desc.Depth = 32;
9232 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9233 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
9234 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9235 texture3d_desc.CPUAccessFlags = 0;
9236 texture3d_desc.MiscFlags = 0;
9238 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
9240 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
9241 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
9243 if (invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
9245 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
9246 texture_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
9247 texture_desc.Format = invalid_desc_tests[i].texture.format;
9248 texture_desc.MiscFlags = 0;
9250 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9251 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
9252 resource = (ID3D11Resource *)texture;
9254 else
9256 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
9257 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
9258 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
9260 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
9261 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
9262 resource = (ID3D11Resource *)texture3d;
9265 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
9266 hr = ID3D11Device_CreateRenderTargetView(device, resource, &rtv_desc, &rtv);
9267 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
9269 ID3D11Resource_Release(resource);
9272 heap_free(data);
9273 release_test_context(&test_context);
9276 static void test_layered_rendering(void)
9278 struct
9280 unsigned int layer_offset;
9281 unsigned int draw_id;
9282 unsigned int padding[2];
9283 } constant;
9284 struct d3d11_test_context test_context;
9285 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
9286 unsigned int i, sub_resource_count;
9287 D3D11_TEXTURE2D_DESC texture_desc;
9288 ID3D11DeviceContext *context;
9289 ID3D11RenderTargetView *rtv;
9290 ID3D11Texture2D *texture;
9291 ID3D11GeometryShader *gs;
9292 ID3D11PixelShader *ps;
9293 ID3D11Device *device;
9294 ID3D11Buffer *cb;
9295 HRESULT hr;
9296 BOOL warp;
9298 static const DWORD gs_5_code[] =
9300 #if 0
9301 uint layer_offset;
9303 struct gs_in
9305 float4 pos : SV_Position;
9308 struct gs_out
9310 float4 pos : SV_Position;
9311 uint layer : SV_RenderTargetArrayIndex;
9314 [instance(4)]
9315 [maxvertexcount(3)]
9316 void main(triangle gs_in vin[3], in uint instance_id : SV_GSInstanceID,
9317 inout TriangleStream<gs_out> vout)
9319 gs_out o;
9320 o.layer = layer_offset + instance_id;
9321 for (uint i = 0; i < 3; ++i)
9323 o.pos = vin[i].pos;
9324 vout.Append(o);
9327 #endif
9328 0x43425844, 0xb52da162, 0x9a13d8ee, 0xf7c30b50, 0xe80bc2e7, 0x00000001, 0x00000218, 0x00000003,
9329 0x0000002c, 0x00000060, 0x000000d0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9330 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
9331 0x3547534f, 0x00000068, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
9332 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000004, 0x00000001,
9333 0x00000001, 0x00000e01, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472,
9334 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x58454853, 0x00000140, 0x00020050, 0x00000050,
9335 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
9336 0x00000000, 0x00000001, 0x0200005f, 0x00025000, 0x02000068, 0x00000001, 0x020000ce, 0x00000004,
9337 0x0100185d, 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
9338 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x00000003, 0x0700001e,
9339 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0002500a, 0x05000036, 0x00100022,
9340 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a,
9341 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000, 0x07000036, 0x001020f2,
9342 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001,
9343 0x0010000a, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x0700001e, 0x00100022, 0x00000000,
9344 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
9346 static const DWORD gs_4_code[] =
9348 #if 0
9349 uint layer_offset;
9351 struct gs_in
9353 float4 pos : SV_Position;
9356 struct gs_out
9358 float4 pos : SV_Position;
9359 uint layer : SV_RenderTargetArrayIndex;
9362 [maxvertexcount(12)]
9363 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
9365 gs_out o;
9366 for (uint instance_id = 0; instance_id < 4; ++instance_id)
9368 o.layer = layer_offset + instance_id;
9369 for (uint i = 0; i < 3; ++i)
9371 o.pos = vin[i].pos;
9372 vout.Append(o);
9374 vout.RestartStrip();
9377 #endif
9378 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
9379 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9380 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
9381 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9382 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
9383 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
9384 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
9385 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
9386 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
9387 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
9388 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
9389 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
9390 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
9391 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
9392 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
9393 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
9394 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
9395 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
9396 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
9398 static const DWORD ps_code[] =
9400 #if 0
9401 uint layer_offset;
9402 uint draw_id;
9404 float4 main(in float4 pos : SV_Position,
9405 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
9407 return float4(layer, draw_id, 0, 0);
9409 #endif
9410 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
9411 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
9412 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
9413 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
9414 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
9415 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
9416 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
9417 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
9418 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
9419 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
9420 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
9422 static const struct vec4 expected_values[] =
9424 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
9425 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
9426 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
9427 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
9430 if (!init_test_context(&test_context, NULL))
9431 return;
9433 device = test_context.device;
9434 context = test_context.immediate_context;
9436 warp = is_warp_device(device);
9438 memset(&constant, 0, sizeof(constant));
9439 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
9440 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
9441 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9443 /* Geometry shader instancing seems broken on WARP. */
9444 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0 || warp)
9446 hr = ID3D11Device_CreateGeometryShader(device, gs_4_code, sizeof(gs_4_code), NULL, &gs);
9447 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
9449 else
9451 hr = ID3D11Device_CreateGeometryShader(device, gs_5_code, sizeof(gs_5_code), NULL, &gs);
9452 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
9454 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
9456 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9457 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9458 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9460 texture_desc.Width = 32;
9461 texture_desc.Height = 32;
9462 texture_desc.MipLevels = 3;
9463 texture_desc.ArraySize = 8;
9464 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9465 texture_desc.SampleDesc.Count = 1;
9466 texture_desc.SampleDesc.Quality = 0;
9467 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9468 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9469 texture_desc.CPUAccessFlags = 0;
9470 texture_desc.MiscFlags = 0;
9471 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9472 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9474 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
9475 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9476 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9477 constant.layer_offset = 0;
9478 constant.draw_id = 0;
9479 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
9480 draw_quad(&test_context);
9481 constant.layer_offset = 4;
9482 constant.draw_id = 1;
9483 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
9484 draw_quad(&test_context);
9485 ID3D11RenderTargetView_Release(rtv);
9487 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
9488 rtv_desc.Format = texture_desc.Format;
9489 U(rtv_desc).Texture2DArray.MipSlice = 0;
9490 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
9491 U(rtv_desc).Texture2DArray.ArraySize = 1;
9492 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
9493 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9494 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9495 constant.layer_offset = 1;
9496 constant.draw_id = 2;
9497 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
9498 draw_quad(&test_context);
9499 ID3D11RenderTargetView_Release(rtv);
9501 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
9502 U(rtv_desc).Texture2DArray.MipSlice = 1;
9503 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
9504 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
9505 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
9506 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9507 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9508 constant.layer_offset = 0;
9509 constant.draw_id = 3;
9510 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
9511 draw_quad(&test_context);
9512 constant.layer_offset = 4;
9513 constant.draw_id = 3;
9514 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
9515 draw_quad(&test_context);
9516 ID3D11RenderTargetView_Release(rtv);
9518 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
9519 U(rtv_desc).Texture2DArray.MipSlice = 2;
9520 U(rtv_desc).Texture2DArray.ArraySize = 1;
9521 for (i = 0; i < texture_desc.ArraySize; ++i)
9523 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
9524 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
9525 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9526 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9527 constant.layer_offset = 0;
9528 constant.draw_id = 4 + i;
9529 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
9530 draw_quad(&test_context);
9531 ID3D11RenderTargetView_Release(rtv);
9534 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
9535 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
9536 for (i = 0; i < sub_resource_count; ++i)
9538 if (warp && (i == 3 || i == 4)) /* Broken on WARP. */
9539 continue;
9540 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
9543 ID3D11Texture2D_Release(texture);
9545 ID3D11Buffer_Release(cb);
9546 ID3D11GeometryShader_Release(gs);
9547 ID3D11PixelShader_Release(ps);
9548 release_test_context(&test_context);
9551 static void test_scissor(void)
9553 struct d3d11_test_context test_context;
9554 ID3D11DeviceContext *immediate_context;
9555 D3D11_RASTERIZER_DESC rs_desc;
9556 ID3D11RasterizerState *rs;
9557 D3D11_RECT scissor_rect;
9558 ID3D11Device *device;
9559 DWORD color;
9560 HRESULT hr;
9562 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
9563 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
9565 if (!init_test_context(&test_context, NULL))
9566 return;
9568 device = test_context.device;
9569 immediate_context = test_context.immediate_context;
9571 rs_desc.FillMode = D3D11_FILL_SOLID;
9572 rs_desc.CullMode = D3D11_CULL_BACK;
9573 rs_desc.FrontCounterClockwise = FALSE;
9574 rs_desc.DepthBias = 0;
9575 rs_desc.DepthBiasClamp = 0.0f;
9576 rs_desc.SlopeScaledDepthBias = 0.0f;
9577 rs_desc.DepthClipEnable = TRUE;
9578 rs_desc.ScissorEnable = TRUE;
9579 rs_desc.MultisampleEnable = FALSE;
9580 rs_desc.AntialiasedLineEnable = FALSE;
9581 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
9582 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
9584 scissor_rect.left = 160;
9585 scissor_rect.top = 120;
9586 scissor_rect.right = 480;
9587 scissor_rect.bottom = 360;
9588 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
9590 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
9591 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
9593 draw_color_quad(&test_context, &green);
9594 color = get_texture_color(test_context.backbuffer, 320, 60);
9595 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9596 color = get_texture_color(test_context.backbuffer, 80, 240);
9597 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9598 color = get_texture_color(test_context.backbuffer, 320, 240);
9599 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9600 color = get_texture_color(test_context.backbuffer, 560, 240);
9601 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9602 color = get_texture_color(test_context.backbuffer, 320, 420);
9603 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9605 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
9606 ID3D11DeviceContext_RSSetState(immediate_context, rs);
9607 draw_color_quad(&test_context, &green);
9608 color = get_texture_color(test_context.backbuffer, 320, 60);
9609 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9610 color = get_texture_color(test_context.backbuffer, 80, 240);
9611 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9612 color = get_texture_color(test_context.backbuffer, 320, 240);
9613 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9614 color = get_texture_color(test_context.backbuffer, 560, 240);
9615 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9616 color = get_texture_color(test_context.backbuffer, 320, 420);
9617 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9619 ID3D11RasterizerState_Release(rs);
9620 release_test_context(&test_context);
9623 static void test_clear_state(void)
9625 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
9626 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9628 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
9630 #if 0
9631 float4 main(float4 pos : POSITION) : POSITION
9633 return pos;
9635 #endif
9636 static const DWORD simple_vs[] =
9638 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
9639 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9640 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
9641 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9642 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
9643 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
9644 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
9646 #if 0
9647 struct data
9649 float4 position : SV_Position;
9652 struct patch_constant_data
9654 float edges[3] : SV_TessFactor;
9655 float inside : SV_InsideTessFactor;
9658 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
9660 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
9661 output.inside = 1.0f;
9664 [domain("tri")]
9665 [outputcontrolpoints(3)]
9666 [partitioning("integer")]
9667 [outputtopology("triangle_ccw")]
9668 [patchconstantfunc("patch_constant")]
9669 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
9671 return input[i];
9674 [domain("tri")]
9675 void ds_main(patch_constant_data input,
9676 float3 tess_coord : SV_DomainLocation,
9677 const OutputPatch<data, 3> patch,
9678 out data output)
9680 output.position = tess_coord.x * patch[0].position
9681 + tess_coord.y * patch[1].position
9682 + tess_coord.z * patch[2].position;
9684 #endif
9685 static const DWORD simple_hs[] =
9687 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
9688 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
9689 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
9690 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
9691 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
9692 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
9693 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
9694 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
9695 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
9696 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
9697 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
9698 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
9699 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
9700 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
9701 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
9702 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
9703 0x00004001, 0x3f800000, 0x0100003e,
9705 static const DWORD simple_ds[] =
9707 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
9708 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
9709 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
9710 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
9711 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
9712 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
9713 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
9714 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
9715 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
9716 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
9717 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
9718 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
9719 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
9720 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
9721 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
9723 #if 0
9724 struct gs_out
9726 float4 pos : SV_POSITION;
9729 [maxvertexcount(4)]
9730 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
9732 float offset = 0.1 * vin[0].w;
9733 gs_out v;
9735 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
9736 vout.Append(v);
9737 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
9738 vout.Append(v);
9739 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
9740 vout.Append(v);
9741 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
9742 vout.Append(v);
9744 #endif
9745 static const DWORD simple_gs[] =
9747 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
9748 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9749 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
9750 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
9751 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
9752 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
9753 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
9754 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
9755 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
9756 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
9757 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
9758 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
9759 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
9760 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
9761 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
9762 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
9763 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
9764 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
9766 #if 0
9767 float4 main(float4 color : COLOR) : SV_TARGET
9769 return color;
9771 #endif
9772 static const DWORD simple_ps[] =
9774 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
9775 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
9776 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
9777 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9778 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
9779 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
9780 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
9782 #if 0
9783 [numthreads(1, 1, 1)]
9784 void main() { }
9785 #endif
9786 static const DWORD simple_cs[] =
9788 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
9789 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9790 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
9791 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
9794 D3D11_VIEWPORT tmp_viewport[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
9795 ID3D11ShaderResourceView *tmp_srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
9796 ID3D11ShaderResourceView *srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
9797 ID3D11RenderTargetView *tmp_rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
9798 RECT tmp_rect[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
9799 ID3D11SamplerState *tmp_sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
9800 ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
9801 ID3D11Texture2D *rt_texture[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
9802 ID3D11Buffer *cb[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
9803 ID3D11Buffer *tmp_buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
9804 ID3D11SamplerState *sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
9805 ID3D11UnorderedAccessView *tmp_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
9806 ID3D11UnorderedAccessView *cs_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
9807 ID3D11Buffer *buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
9808 ID3D11Buffer *cs_uav_buffer[D3D11_PS_CS_UAV_REGISTER_COUNT];
9809 UINT offset[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
9810 UINT stride[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
9811 ID3D11Buffer *so_buffer[D3D11_SO_BUFFER_SLOT_COUNT];
9812 ID3D11InputLayout *tmp_input_layout, *input_layout;
9813 ID3D11DepthStencilState *tmp_ds_state, *ds_state;
9814 ID3D11BlendState *tmp_blend_state, *blend_state;
9815 ID3D11RasterizerState *tmp_rs_state, *rs_state;
9816 ID3D11Predicate *tmp_predicate, *predicate;
9817 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
9818 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
9819 ID3D11DepthStencilView *tmp_dsv, *dsv;
9820 ID3D11UnorderedAccessView *ps_uav;
9821 D3D11_PRIMITIVE_TOPOLOGY topology;
9822 D3D11_TEXTURE2D_DESC texture_desc;
9823 ID3D11GeometryShader *tmp_gs, *gs;
9824 ID3D11ComputeShader *tmp_cs, *cs;
9825 D3D11_DEPTH_STENCIL_DESC ds_desc;
9826 ID3D11VertexShader *tmp_vs, *vs;
9827 ID3D11DomainShader *tmp_ds, *ds;
9828 D3D11_SAMPLER_DESC sampler_desc;
9829 D3D11_QUERY_DESC predicate_desc;
9830 struct device_desc device_desc;
9831 ID3D11PixelShader *tmp_ps, *ps;
9832 ID3D11HullShader *tmp_hs, *hs;
9833 D3D11_RASTERIZER_DESC rs_desc;
9834 ID3D11DeviceContext *context;
9835 D3D11_BLEND_DESC blend_desc;
9836 ID3D11Texture2D *ds_texture;
9837 ID3D11Buffer *ps_uav_buffer;
9838 float blend_factor[4];
9839 ID3D11Device *device;
9840 BOOL predicate_value;
9841 UINT instance_count;
9842 DXGI_FORMAT format;
9843 UINT sample_mask;
9844 UINT stencil_ref;
9845 ULONG refcount;
9846 UINT count, i;
9847 HRESULT hr;
9849 device_desc.feature_level = &feature_level;
9850 device_desc.flags = 0;
9851 if (!(device = create_device(&device_desc)))
9853 skip("Failed to create device.\n");
9854 return;
9857 ID3D11Device_GetImmediateContext(device, &context);
9859 /* Verify the initial state after device creation. */
9861 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9862 tmp_buffer);
9863 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9865 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9867 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9868 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9870 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9872 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9873 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9875 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9877 instance_count = 100;
9878 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, &instance_count);
9879 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
9880 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
9882 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9883 tmp_buffer);
9884 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9886 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9888 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9889 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9891 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9893 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9894 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9896 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9898 instance_count = 100;
9899 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, &instance_count);
9900 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
9901 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
9903 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9904 tmp_buffer);
9905 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9907 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9909 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9910 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9912 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9914 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9915 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9917 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9919 instance_count = 100;
9920 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, &instance_count);
9921 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
9922 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
9924 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9925 tmp_buffer);
9926 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9928 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9930 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9931 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9933 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9935 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9936 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9938 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9940 instance_count = 100;
9941 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, &instance_count);
9942 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
9943 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
9945 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9946 tmp_buffer);
9947 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9949 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9951 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
9952 tmp_srv);
9953 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9955 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9957 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9958 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9960 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9962 instance_count = 100;
9963 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, &instance_count);
9964 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
9965 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
9967 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9968 tmp_buffer);
9969 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9971 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9973 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
9974 tmp_srv);
9975 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9977 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9979 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9980 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9982 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9984 instance_count = 100;
9985 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, &instance_count);
9986 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
9987 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
9988 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9989 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9991 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9994 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
9995 tmp_buffer, stride, offset);
9996 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9998 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
9999 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
10000 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
10002 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
10003 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
10004 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
10005 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
10006 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
10007 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
10008 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
10009 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
10011 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
10012 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
10013 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
10014 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
10015 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
10016 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
10017 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
10018 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
10019 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
10020 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
10021 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
10022 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
10024 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
10026 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
10027 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
10028 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
10029 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
10030 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
10032 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
10034 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
10035 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
10037 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
10040 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
10041 ok(!count, "Got unexpected scissor rect count %u.\n", count);
10042 memset(tmp_rect, 0x55, sizeof(tmp_rect));
10043 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
10044 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
10045 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
10047 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
10048 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
10050 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
10051 ok(!count, "Got unexpected viewport count %u.\n", count);
10052 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
10053 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
10054 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
10055 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
10057 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
10058 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
10059 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
10060 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
10061 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
10063 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
10064 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
10066 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
10067 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
10069 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
10072 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
10073 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
10074 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
10076 /* Create resources. */
10078 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10079 cb[i] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 1024, NULL);
10081 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
10083 buffer[i] = create_buffer(device,
10084 D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_SHADER_RESOURCE,
10085 1024, NULL);
10087 stride[i] = (i + 1) * 4;
10088 offset[i] = (i + 1) * 16;
10091 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
10092 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
10094 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10095 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
10096 U(srv_desc).Buffer.ElementOffset = 0;
10097 U(srv_desc).Buffer.ElementWidth = 64;
10099 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10101 hr = ID3D11Device_CreateShaderResourceView(device,
10102 (ID3D11Resource *)buffer[i % D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
10103 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10106 uav_desc.Format = DXGI_FORMAT_R32_UINT;
10107 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
10108 U(uav_desc).Buffer.FirstElement = 0;
10109 U(uav_desc).Buffer.NumElements = 8;
10110 U(uav_desc).Buffer.Flags = 0;
10112 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
10114 cs_uav_buffer[i] = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
10115 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_uav_buffer[i],
10116 &uav_desc, &cs_uav[i]);
10117 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
10120 ps_uav_buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
10121 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_uav_buffer,
10122 &uav_desc, &ps_uav);
10123 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
10125 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
10126 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10127 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10128 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10129 sampler_desc.MipLODBias = 0.0f;
10130 sampler_desc.MaxAnisotropy = 16;
10131 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
10132 sampler_desc.BorderColor[0] = 0.0f;
10133 sampler_desc.BorderColor[1] = 0.0f;
10134 sampler_desc.BorderColor[2] = 0.0f;
10135 sampler_desc.BorderColor[3] = 0.0f;
10136 sampler_desc.MinLOD = 0.0f;
10137 sampler_desc.MaxLOD = 16.0f;
10139 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10141 sampler_desc.MinLOD = (float)i;
10143 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
10144 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10147 hr = ID3D11Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
10148 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10150 hr = ID3D11Device_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
10151 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
10153 hr = ID3D11Device_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
10154 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
10156 hr = ID3D11Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
10157 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
10159 hr = ID3D11Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
10160 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10162 hr = ID3D11Device_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
10163 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
10165 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10166 simple_vs, sizeof(simple_vs), &input_layout);
10167 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10169 memset(&blend_desc, 0, sizeof(blend_desc));
10170 blend_desc.AlphaToCoverageEnable = FALSE;
10171 blend_desc.IndependentBlendEnable = FALSE;
10172 blend_desc.RenderTarget[0].BlendEnable = TRUE;
10173 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
10174 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
10175 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
10176 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
10177 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
10178 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
10179 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
10181 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
10182 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
10184 ds_desc.DepthEnable = TRUE;
10185 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
10186 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
10187 ds_desc.StencilEnable = FALSE;
10188 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
10189 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
10190 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
10191 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
10192 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
10193 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
10194 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
10195 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
10196 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
10197 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
10199 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
10200 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
10202 texture_desc.Width = 512;
10203 texture_desc.Height = 512;
10204 texture_desc.MipLevels = 1;
10205 texture_desc.ArraySize = 1;
10206 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10207 texture_desc.SampleDesc.Count = 1;
10208 texture_desc.SampleDesc.Quality = 0;
10209 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10210 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10211 texture_desc.CPUAccessFlags = 0;
10212 texture_desc.MiscFlags = 0;
10214 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
10216 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
10217 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10220 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
10221 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
10223 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
10224 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10226 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
10228 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture[i], NULL, &rtv[i]);
10229 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10232 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)ds_texture, NULL, &dsv);
10233 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
10235 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
10237 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
10239 tmp_viewport[i].TopLeftX = i * 3;
10240 tmp_viewport[i].TopLeftY = i * 4;
10241 tmp_viewport[i].Width = 3;
10242 tmp_viewport[i].Height = 4;
10243 tmp_viewport[i].MinDepth = i * 0.01f;
10244 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
10247 rs_desc.FillMode = D3D11_FILL_SOLID;
10248 rs_desc.CullMode = D3D11_CULL_BACK;
10249 rs_desc.FrontCounterClockwise = FALSE;
10250 rs_desc.DepthBias = 0;
10251 rs_desc.DepthBiasClamp = 0.0f;
10252 rs_desc.SlopeScaledDepthBias = 0.0f;
10253 rs_desc.DepthClipEnable = TRUE;
10254 rs_desc.ScissorEnable = FALSE;
10255 rs_desc.MultisampleEnable = FALSE;
10256 rs_desc.AntialiasedLineEnable = FALSE;
10258 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs_state);
10259 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
10261 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
10262 predicate_desc.MiscFlags = 0;
10264 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
10265 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
10267 /* Setup state. */
10269 /* Some versions of Windows AMD drivers hang while the device is being
10270 * released, if the total number of used resource slots exceeds some limit.
10271 * Do not use all constant buffers slots in order to not trigger this
10272 * driver bug. */
10273 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb[0]);
10274 ID3D11DeviceContext_VSSetConstantBuffers(context, 7, 1, &cb[7]);
10275 ID3D11DeviceContext_VSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
10276 ID3D11DeviceContext_VSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
10277 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
10279 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb[0]);
10280 ID3D11DeviceContext_HSSetConstantBuffers(context, 7, 1, &cb[7]);
10281 ID3D11DeviceContext_HSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
10282 ID3D11DeviceContext_HSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
10283 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
10285 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
10286 ID3D11DeviceContext_DSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
10287 ID3D11DeviceContext_DSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
10288 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
10290 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
10291 ID3D11DeviceContext_GSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
10292 ID3D11DeviceContext_GSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
10293 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
10295 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
10296 ID3D11DeviceContext_PSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
10297 ID3D11DeviceContext_PSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
10298 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10300 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
10301 ID3D11DeviceContext_CSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
10302 ID3D11DeviceContext_CSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
10303 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
10304 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, cs_uav, NULL);
10306 ID3D11DeviceContext_IASetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
10307 buffer, stride, offset);
10308 ID3D11DeviceContext_IASetIndexBuffer(context, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
10309 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
10310 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10312 blend_factor[0] = 0.1f;
10313 blend_factor[1] = 0.2f;
10314 blend_factor[2] = 0.3f;
10315 blend_factor[3] = 0.4f;
10316 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, 0xff00ff00);
10317 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 3);
10318 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
10319 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, rtv, dsv,
10320 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, 1, &ps_uav, NULL);
10322 ID3D11DeviceContext_RSSetScissorRects(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
10323 tmp_rect);
10324 ID3D11DeviceContext_RSSetViewports(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
10325 tmp_viewport);
10326 ID3D11DeviceContext_RSSetState(context, rs_state);
10328 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
10330 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
10332 /* Verify the set state. */
10334 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10335 tmp_buffer);
10336 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10338 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
10339 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
10340 tmp_buffer[i], i, expected_cb);
10341 if (tmp_buffer[i])
10342 ID3D11Buffer_Release(tmp_buffer[i]);
10344 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10345 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10347 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
10348 tmp_srv[i], i, srv[i]);
10349 ID3D11ShaderResourceView_Release(tmp_srv[i]);
10351 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10352 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10354 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
10355 tmp_sampler[i], i, sampler[i]);
10356 ID3D11SamplerState_Release(tmp_sampler[i]);
10358 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
10359 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
10360 ID3D11VertexShader_Release(tmp_vs);
10362 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10363 tmp_buffer);
10364 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10366 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
10367 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
10368 tmp_buffer[i], i, expected_cb);
10369 if (tmp_buffer[i])
10370 ID3D11Buffer_Release(tmp_buffer[i]);
10372 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10373 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10375 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
10376 tmp_srv[i], i, srv[i]);
10377 ID3D11ShaderResourceView_Release(tmp_srv[i]);
10379 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10380 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10382 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
10383 tmp_sampler[i], i, sampler[i]);
10384 ID3D11SamplerState_Release(tmp_sampler[i]);
10386 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
10387 ok(tmp_hs == hs, "Got unexpected hull shader %p, expected %p.\n", tmp_hs, hs);
10388 ID3D11HullShader_Release(tmp_hs);
10390 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10391 tmp_buffer);
10392 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10394 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
10395 tmp_buffer[i], i, cb[i]);
10396 ID3D11Buffer_Release(tmp_buffer[i]);
10398 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10399 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10401 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
10402 tmp_srv[i], i, srv[i]);
10403 ID3D11ShaderResourceView_Release(tmp_srv[i]);
10405 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10406 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10408 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
10409 tmp_sampler[i], i, sampler[i]);
10410 ID3D11SamplerState_Release(tmp_sampler[i]);
10412 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
10413 ok(tmp_ds == ds, "Got unexpected domain shader %p, expected %p.\n", tmp_ds, ds);
10414 ID3D11DomainShader_Release(tmp_ds);
10416 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10417 tmp_buffer);
10418 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10420 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
10421 tmp_buffer[i], i, cb[i]);
10422 ID3D11Buffer_Release(tmp_buffer[i]);
10424 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10425 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10427 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
10428 tmp_srv[i], i, srv[i]);
10429 ID3D11ShaderResourceView_Release(tmp_srv[i]);
10431 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10432 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10434 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
10435 tmp_sampler[i], i, sampler[i]);
10436 ID3D11SamplerState_Release(tmp_sampler[i]);
10438 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
10439 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
10440 ID3D11GeometryShader_Release(tmp_gs);
10442 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10443 tmp_buffer);
10444 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10446 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
10447 tmp_buffer[i], i, cb[i]);
10448 ID3D11Buffer_Release(tmp_buffer[i]);
10450 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10451 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10453 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
10454 tmp_srv[i], i, srv[i]);
10455 ID3D11ShaderResourceView_Release(tmp_srv[i]);
10457 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10458 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10460 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
10461 tmp_sampler[i], i, sampler[i]);
10462 ID3D11SamplerState_Release(tmp_sampler[i]);
10464 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
10465 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
10466 ID3D11PixelShader_Release(tmp_ps);
10468 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10469 tmp_buffer);
10470 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10472 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
10473 tmp_buffer[i], i, cb[i]);
10474 ID3D11Buffer_Release(tmp_buffer[i]);
10476 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10477 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10479 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
10480 tmp_srv[i], i, srv[i]);
10481 ID3D11ShaderResourceView_Release(tmp_srv[i]);
10483 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10484 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10486 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
10487 tmp_sampler[i], i, sampler[i]);
10488 ID3D11SamplerState_Release(tmp_sampler[i]);
10490 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
10491 ok(tmp_cs == cs, "Got unexpected compute shader %p, expected %p.\n", tmp_cs, cs);
10492 ID3D11ComputeShader_Release(tmp_cs);
10493 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
10494 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
10496 ok(tmp_uav[i] == cs_uav[i], "Got unexpected unordered access view %p in slot %u, expected %p.\n",
10497 tmp_uav[i], i, cs_uav[i]);
10498 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
10501 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
10502 tmp_buffer, stride, offset);
10503 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
10505 todo_wine_if(i >= D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
10507 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
10508 tmp_buffer[i], i, buffer[i]);
10509 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
10510 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
10512 if (tmp_buffer[i])
10513 ID3D11Buffer_Release(tmp_buffer[i]);
10515 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
10516 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
10517 ID3D11Buffer_Release(tmp_buffer[0]);
10518 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
10519 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
10520 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
10521 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
10522 tmp_input_layout, input_layout);
10523 ID3D11InputLayout_Release(tmp_input_layout);
10524 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
10525 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
10527 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
10528 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
10529 ID3D11BlendState_Release(tmp_blend_state);
10530 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
10531 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
10532 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
10533 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
10534 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
10535 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
10536 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
10537 ID3D11DepthStencilState_Release(tmp_ds_state);
10538 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
10539 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
10540 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
10542 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
10543 tmp_rtv[i], i, rtv[i]);
10544 ID3D11RenderTargetView_Release(tmp_rtv[i]);
10546 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
10547 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
10548 ID3D11DepthStencilView_Release(tmp_dsv);
10549 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
10550 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
10551 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
10552 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
10554 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
10555 tmp_rtv[i], i, rtv[i]);
10556 ID3D11RenderTargetView_Release(tmp_rtv[i]);
10558 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
10559 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
10560 ID3D11DepthStencilView_Release(tmp_dsv);
10561 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT - 1; ++i)
10563 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
10565 ok(tmp_uav[i] == ps_uav, "Got unexpected unordered access view %p in slot %u, expected %p.\n",
10566 tmp_uav[i], i, ps_uav);
10567 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
10569 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
10570 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
10571 "Got unexpected scissor rect count %u.\n", count);
10572 memset(tmp_rect, 0x55, sizeof(tmp_rect));
10573 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
10574 for (i = 0; i < count; ++i)
10576 ok(tmp_rect[i].left == i
10577 && tmp_rect[i].top == i * 2
10578 && tmp_rect[i].right == i + 1
10579 && tmp_rect[i].bottom == (i + 1) * 2,
10580 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
10582 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
10583 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
10584 "Got unexpected viewport count %u.\n", count);
10585 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
10586 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
10587 for (i = 0; i < count; ++i)
10589 ok(tmp_viewport[i].TopLeftX == i * 3
10590 && tmp_viewport[i].TopLeftY == i * 4
10591 && tmp_viewport[i].Width == 3
10592 && tmp_viewport[i].Height == 4
10593 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
10594 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
10595 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
10596 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
10597 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
10599 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
10600 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
10601 ID3D11RasterizerState_Release(tmp_rs_state);
10603 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
10604 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
10606 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
10607 tmp_buffer[i], i, so_buffer[i]);
10608 ID3D11Buffer_Release(tmp_buffer[i]);
10611 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
10612 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
10613 ID3D11Predicate_Release(tmp_predicate);
10614 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
10616 /* Verify ClearState(). */
10618 ID3D11DeviceContext_ClearState(context);
10620 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10621 tmp_buffer);
10622 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10624 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
10626 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10627 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10629 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
10631 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10632 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10634 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
10636 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
10637 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
10639 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10640 tmp_buffer);
10641 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10643 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
10645 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10646 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10648 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
10650 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10651 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10653 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
10655 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
10656 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
10658 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10659 tmp_buffer);
10660 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10662 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
10664 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10665 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10667 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
10669 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10670 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10672 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
10674 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
10675 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
10677 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10678 tmp_buffer);
10679 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10681 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
10683 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10684 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10686 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
10688 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10689 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10691 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
10693 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
10694 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
10696 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10697 tmp_buffer);
10698 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10700 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
10702 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
10703 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10705 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
10707 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10708 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10710 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
10712 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
10713 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
10715 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
10716 tmp_buffer);
10717 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10719 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
10721 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
10722 tmp_srv);
10723 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10725 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
10727 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
10728 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10730 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
10732 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
10733 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
10734 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
10735 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
10737 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
10740 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
10741 tmp_buffer, stride, offset);
10742 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
10744 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
10745 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
10746 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
10748 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
10749 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
10750 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
10751 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
10752 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
10753 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
10754 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
10755 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
10757 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
10758 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
10759 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
10760 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
10761 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
10762 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
10763 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
10764 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
10765 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
10766 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
10767 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
10768 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
10770 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
10772 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
10773 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
10774 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
10775 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
10776 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
10778 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
10780 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
10781 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
10783 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
10786 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
10787 ok(!count, "Got unexpected scissor rect count %u.\n", count);
10788 memset(tmp_rect, 0x55, sizeof(tmp_rect));
10789 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
10790 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
10791 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
10793 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
10794 "Got unexpected scissor rect %s in slot %u.\n",
10795 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 /* Cleanup. */
10825 ID3D11Predicate_Release(predicate);
10826 ID3D11RasterizerState_Release(rs_state);
10827 ID3D11DepthStencilView_Release(dsv);
10828 ID3D11Texture2D_Release(ds_texture);
10830 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
10832 ID3D11RenderTargetView_Release(rtv[i]);
10833 ID3D11Texture2D_Release(rt_texture[i]);
10836 ID3D11DepthStencilState_Release(ds_state);
10837 ID3D11BlendState_Release(blend_state);
10838 ID3D11InputLayout_Release(input_layout);
10839 ID3D11VertexShader_Release(vs);
10840 ID3D11HullShader_Release(hs);
10841 ID3D11DomainShader_Release(ds);
10842 ID3D11GeometryShader_Release(gs);
10843 ID3D11PixelShader_Release(ps);
10844 ID3D11ComputeShader_Release(cs);
10846 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
10848 ID3D11SamplerState_Release(sampler[i]);
10851 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
10853 ID3D11ShaderResourceView_Release(srv[i]);
10856 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
10858 ID3D11UnorderedAccessView_Release(cs_uav[i]);
10859 ID3D11Buffer_Release(cs_uav_buffer[i]);
10861 ID3D11UnorderedAccessView_Release(ps_uav);
10862 ID3D11Buffer_Release(ps_uav_buffer);
10864 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
10866 ID3D11Buffer_Release(so_buffer[i]);
10869 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
10871 ID3D11Buffer_Release(buffer[i]);
10874 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
10876 ID3D11Buffer_Release(cb[i]);
10879 ID3D11DeviceContext_Release(context);
10880 refcount = ID3D11Device_Release(device);
10881 ok(!refcount, "Device has %u references left.\n", refcount);
10884 static void test_il_append_aligned(void)
10886 struct d3d11_test_context test_context;
10887 ID3D11InputLayout *input_layout;
10888 ID3D11DeviceContext *context;
10889 unsigned int stride, offset;
10890 ID3D11VertexShader *vs;
10891 ID3D11PixelShader *ps;
10892 ID3D11Device *device;
10893 ID3D11Buffer *vb[3];
10894 DWORD color;
10895 HRESULT hr;
10897 /* Semantic names are case-insensitive. */
10898 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
10900 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
10901 D3D11_INPUT_PER_INSTANCE_DATA, 2},
10902 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
10903 D3D11_INPUT_PER_INSTANCE_DATA, 1},
10904 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
10905 D3D11_INPUT_PER_VERTEX_DATA, 0},
10906 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
10907 D3D11_INPUT_PER_INSTANCE_DATA, 1},
10908 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
10909 D3D11_INPUT_PER_INSTANCE_DATA, 2},
10911 static const DWORD vs_code[] =
10913 #if 0
10914 struct vs_in
10916 float4 position : POSITION;
10917 float2 color_xy : COLOR0;
10918 float2 color_zw : COLOR1;
10919 unsigned int instance_id : SV_INSTANCEID;
10922 struct vs_out
10924 float4 position : SV_POSITION;
10925 float2 color_xy : COLOR0;
10926 float2 color_zw : COLOR1;
10929 struct vs_out main(struct vs_in i)
10931 struct vs_out o;
10933 o.position = i.position;
10934 o.position.x += i.instance_id * 0.5;
10935 o.color_xy = i.color_xy;
10936 o.color_zw = i.color_zw;
10938 return o;
10940 #endif
10941 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
10942 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
10943 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
10944 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
10945 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
10946 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
10947 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
10948 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
10949 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
10950 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
10951 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
10952 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
10953 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
10954 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
10955 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
10956 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
10957 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
10959 static const DWORD ps_code[] =
10961 #if 0
10962 struct vs_out
10964 float4 position : SV_POSITION;
10965 float2 color_xy : COLOR0;
10966 float2 color_zw : COLOR1;
10969 float4 main(struct vs_out i) : SV_TARGET
10971 return float4(i.color_xy.xy, i.color_zw.xy);
10973 #endif
10974 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
10975 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
10976 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
10977 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
10978 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
10979 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
10980 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
10981 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10982 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
10984 static const struct
10986 struct vec4 position;
10988 stream0[] =
10990 {{-1.0f, -1.0f, 0.0f, 1.0f}},
10991 {{-1.0f, 1.0f, 0.0f, 1.0f}},
10992 {{-0.5f, -1.0f, 0.0f, 1.0f}},
10993 {{-0.5f, 1.0f, 0.0f, 1.0f}},
10995 static const struct
10997 struct vec2 color2;
10998 struct vec2 color1;
11000 stream1[] =
11002 {{0.5f, 0.5f}, {0.0f, 1.0f}},
11003 {{0.5f, 0.5f}, {1.0f, 1.0f}},
11005 static const struct
11007 struct vec2 color3;
11008 struct vec2 color0;
11010 stream2[] =
11012 {{0.5f, 0.5f}, {1.0f, 0.0f}},
11013 {{0.5f, 0.5f}, {0.0f, 1.0f}},
11014 {{0.5f, 0.5f}, {0.0f, 0.0f}},
11015 {{0.5f, 0.5f}, {1.0f, 0.0f}},
11017 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
11019 if (!init_test_context(&test_context, NULL))
11020 return;
11022 device = test_context.device;
11023 context = test_context.immediate_context;
11025 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11026 vs_code, sizeof(vs_code), &input_layout);
11027 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11029 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
11030 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
11031 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
11033 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11034 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11035 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11036 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11038 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
11039 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11040 offset = 0;
11041 stride = sizeof(*stream0);
11042 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
11043 stride = sizeof(*stream1);
11044 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
11045 stride = sizeof(*stream2);
11046 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
11047 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11048 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11050 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
11052 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
11054 color = get_texture_color(test_context.backbuffer, 80, 240);
11055 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11056 color = get_texture_color(test_context.backbuffer, 240, 240);
11057 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11058 color = get_texture_color(test_context.backbuffer, 400, 240);
11059 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
11060 color = get_texture_color(test_context.backbuffer, 560, 240);
11061 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
11063 ID3D11PixelShader_Release(ps);
11064 ID3D11VertexShader_Release(vs);
11065 ID3D11Buffer_Release(vb[2]);
11066 ID3D11Buffer_Release(vb[1]);
11067 ID3D11Buffer_Release(vb[0]);
11068 ID3D11InputLayout_Release(input_layout);
11069 release_test_context(&test_context);
11072 static void test_instance_id(void)
11074 struct d3d11_test_context test_context;
11075 D3D11_TEXTURE2D_DESC texture_desc;
11076 ID3D11InputLayout *input_layout;
11077 ID3D11RenderTargetView *rtvs[2];
11078 ID3D11Texture2D *render_target;
11079 ID3D11DeviceContext *context;
11080 struct resource_readback rb;
11081 unsigned int stride, offset;
11082 ID3D11Buffer *args_buffer;
11083 ID3D11VertexShader *vs;
11084 ID3D11PixelShader *ps;
11085 ID3D11Device *device;
11086 ID3D11Buffer *vb[2];
11087 unsigned int i;
11088 HRESULT hr;
11090 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11092 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
11093 D3D11_INPUT_PER_VERTEX_DATA, 0},
11094 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT,
11095 D3D11_INPUT_PER_INSTANCE_DATA, 1},
11096 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
11097 D3D11_INPUT_PER_INSTANCE_DATA, 1},
11099 static const DWORD vs_code[] =
11101 #if 0
11102 struct vs_in
11104 float4 position : Position;
11105 float color : Color;
11106 float v_offset : V_Offset;
11107 uint instance_id : SV_InstanceId;
11110 struct vs_out
11112 float4 position : SV_Position;
11113 float color : Color;
11114 uint instance_id : InstanceId;
11117 void main(vs_in i, out vs_out o)
11119 o.position = i.position;
11120 o.position.x += i.v_offset;
11121 o.color = i.color;
11122 o.instance_id = i.instance_id;
11124 #endif
11125 0x43425844, 0xcde3cfbf, 0xe2e3d090, 0xe2eb1038, 0x7e5ad1cf, 0x00000001, 0x00000204, 0x00000003,
11126 0x0000002c, 0x000000c4, 0x0000013c, 0x4e475349, 0x00000090, 0x00000004, 0x00000008, 0x00000068,
11127 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
11128 0x00000003, 0x00000001, 0x00000101, 0x00000077, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
11129 0x00000101, 0x00000080, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x69736f50,
11130 0x6e6f6974, 0x6c6f4300, 0x5600726f, 0x66664f5f, 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e,
11131 0xabab0064, 0x4e47534f, 0x00000070, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
11132 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
11133 0x00000e01, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
11134 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
11135 0x000000c0, 0x00010040, 0x00000030, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
11136 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x04000060, 0x00101012, 0x00000003, 0x00000008,
11137 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
11138 0x00102012, 0x00000002, 0x07000000, 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x0010100a,
11139 0x00000002, 0x05000036, 0x001020e2, 0x00000000, 0x00101e56, 0x00000000, 0x05000036, 0x00102012,
11140 0x00000001, 0x0010100a, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000003,
11141 0x0100003e,
11143 static const DWORD ps_code[] =
11145 #if 0
11146 struct vs_out
11148 float4 position : SV_Position;
11149 float color : Color;
11150 uint instance_id : InstanceId;
11153 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
11155 o0 = float4(i.color, i.color, i.color, 1.0f);
11156 o1 = i.instance_id;
11158 #endif
11159 0x43425844, 0xda0ad0bb, 0x4743f5f5, 0xfbc6d0b1, 0x7c8e7df5, 0x00000001, 0x00000170, 0x00000003,
11160 0x0000002c, 0x000000a4, 0x000000f0, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
11161 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
11162 0x00000003, 0x00000001, 0x00000101, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002,
11163 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563,
11164 0xababab00, 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000,
11165 0x00000003, 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
11166 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000078, 0x00000040, 0x0000001e,
11167 0x03001062, 0x00101012, 0x00000001, 0x03000862, 0x00101012, 0x00000002, 0x03000065, 0x001020f2,
11168 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072, 0x00000000, 0x00101006,
11169 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x05000036, 0x001020f2,
11170 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
11172 static const struct vec4 stream0[] =
11174 {-1.00f, 0.0f, 0.0f, 1.0f},
11175 {-1.00f, 1.0f, 0.0f, 1.0f},
11176 {-0.75f, 0.0f, 0.0f, 1.0f},
11177 {-0.75f, 1.0f, 0.0f, 1.0f},
11178 /* indirect draws data */
11179 {-1.00f, -1.0f, 0.0f, 1.0f},
11180 {-1.00f, 0.0f, 0.0f, 1.0f},
11181 {-0.75f, -1.0f, 0.0f, 1.0f},
11182 {-0.75f, 0.0f, 0.0f, 1.0f},
11184 static const struct
11186 BYTE color;
11187 float v_offset;
11189 stream1[] =
11191 {0xf0, 0.00f},
11192 {0x80, 0.25f},
11193 {0x10, 0.50f},
11194 {0x40, 0.75f},
11196 {0xaa, 1.00f},
11197 {0xbb, 1.25f},
11198 {0xcc, 1.50f},
11199 {0x90, 1.75f},
11201 static const D3D11_DRAW_INSTANCED_INDIRECT_ARGS argument_data[] =
11203 {4, 4, 4, 0},
11204 {4, 4, 4, 4},
11206 static const struct
11208 RECT rect;
11209 unsigned int color;
11210 unsigned int instance_id;
11212 expected_results[] =
11214 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
11215 {{ 80, 0, 160, 240}, 0xff808080, 1},
11216 {{160, 0, 240, 240}, 0xff101010, 2},
11217 {{240, 0, 320, 240}, 0xff404040, 3},
11218 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
11219 {{400, 0, 480, 240}, 0xffbbbbbb, 1},
11220 {{480, 0, 560, 240}, 0xffcccccc, 2},
11221 {{560, 0, 640, 240}, 0xff909090, 3},
11222 /* indirect draws results */
11223 {{ 0, 240, 80, 480}, 0xfff0f0f0, 0},
11224 {{ 80, 240, 160, 480}, 0xff808080, 1},
11225 {{160, 240, 240, 480}, 0xff101010, 2},
11226 {{240, 240, 320, 480}, 0xff404040, 3},
11227 {{320, 240, 400, 480}, 0xffaaaaaa, 0},
11228 {{400, 240, 480, 480}, 0xffbbbbbb, 1},
11229 {{480, 240, 560, 480}, 0xffcccccc, 2},
11230 {{560, 240, 640, 480}, 0xff909090, 3},
11232 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11233 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11235 if (!init_test_context(&test_context, &feature_level))
11236 return;
11237 device = test_context.device;
11238 context = test_context.immediate_context;
11240 rtvs[0] = test_context.backbuffer_rtv;
11242 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11243 texture_desc.Format = DXGI_FORMAT_R32_UINT;
11244 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
11245 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11246 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtvs[1]);
11247 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11249 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11250 vs_code, sizeof(vs_code), &input_layout);
11251 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11253 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11254 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11255 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11256 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11258 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
11259 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
11261 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11262 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11263 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
11264 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11265 offset = 0;
11266 stride = sizeof(*stream0);
11267 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
11268 stride = sizeof(*stream1);
11269 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
11271 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
11272 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[1], white);
11274 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
11275 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
11276 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 4);
11278 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
11279 sizeof(argument_data), argument_data);
11281 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, 0);
11282 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, sizeof(*argument_data));
11284 get_texture_readback(test_context.backbuffer, 0, &rb);
11285 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
11286 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
11287 release_resource_readback(&rb);
11289 get_texture_readback(render_target, 0, &rb);
11290 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
11291 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
11292 release_resource_readback(&rb);
11294 ID3D11Buffer_Release(vb[0]);
11295 ID3D11Buffer_Release(vb[1]);
11296 ID3D11Buffer_Release(args_buffer);
11297 ID3D11RenderTargetView_Release(rtvs[1]);
11298 ID3D11Texture2D_Release(render_target);
11299 ID3D11VertexShader_Release(vs);
11300 ID3D11PixelShader_Release(ps);
11301 ID3D11InputLayout_Release(input_layout);
11302 release_test_context(&test_context);
11305 static void test_fragment_coords(void)
11307 struct d3d11_test_context test_context;
11308 ID3D11PixelShader *ps, *ps_frac;
11309 ID3D11DeviceContext *context;
11310 ID3D11Device *device;
11311 ID3D11Buffer *ps_cb;
11312 DWORD color;
11313 HRESULT hr;
11315 static const DWORD ps_code[] =
11317 #if 0
11318 float2 cutoff;
11320 float4 main(float4 position : SV_POSITION) : SV_TARGET
11322 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
11324 if (position.x > cutoff.x)
11325 ret.y = 1.0;
11326 if (position.y > cutoff.y)
11327 ret.z = 1.0;
11329 return ret;
11331 #endif
11332 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
11333 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11334 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
11335 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11336 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
11337 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
11338 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
11339 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
11340 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
11341 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
11342 0x0100003e,
11344 static const DWORD ps_frac_code[] =
11346 #if 0
11347 float4 main(float4 position : SV_POSITION) : SV_TARGET
11349 return float4(frac(position.xy), 0.0, 1.0);
11351 #endif
11352 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
11353 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11354 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
11355 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11356 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
11357 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11358 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
11359 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
11361 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
11362 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
11364 if (!init_test_context(&test_context, NULL))
11365 return;
11367 device = test_context.device;
11368 context = test_context.immediate_context;
11370 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
11372 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11373 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11374 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
11375 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11377 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
11378 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11380 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
11382 draw_quad(&test_context);
11384 color = get_texture_color(test_context.backbuffer, 319, 239);
11385 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
11386 color = get_texture_color(test_context.backbuffer, 320, 239);
11387 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11388 color = get_texture_color(test_context.backbuffer, 319, 240);
11389 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
11390 color = get_texture_color(test_context.backbuffer, 320, 240);
11391 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
11393 ID3D11Buffer_Release(ps_cb);
11394 cutoff.x = 16.0f;
11395 cutoff.y = 16.0f;
11396 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
11397 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
11399 draw_quad(&test_context);
11401 color = get_texture_color(test_context.backbuffer, 14, 14);
11402 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
11403 color = get_texture_color(test_context.backbuffer, 18, 14);
11404 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11405 color = get_texture_color(test_context.backbuffer, 14, 18);
11406 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
11407 color = get_texture_color(test_context.backbuffer, 18, 18);
11408 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
11410 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
11411 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
11413 ID3D11DeviceContext_Draw(context, 4, 0);
11415 color = get_texture_color(test_context.backbuffer, 14, 14);
11416 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
11418 ID3D11Buffer_Release(ps_cb);
11419 ID3D11PixelShader_Release(ps_frac);
11420 ID3D11PixelShader_Release(ps);
11421 release_test_context(&test_context);
11424 static void test_update_subresource(void)
11426 struct d3d11_test_context test_context;
11427 D3D11_SUBRESOURCE_DATA resource_data;
11428 D3D11_TEXTURE2D_DESC texture_desc;
11429 ID3D11SamplerState *sampler_state;
11430 ID3D11ShaderResourceView *ps_srv;
11431 D3D11_SAMPLER_DESC sampler_desc;
11432 ID3D11DeviceContext *context;
11433 struct resource_readback rb;
11434 ID3D11Texture2D *texture;
11435 ID3D11PixelShader *ps;
11436 ID3D11Device *device;
11437 unsigned int i, j;
11438 D3D11_BOX box;
11439 DWORD color;
11440 HRESULT hr;
11442 static const DWORD ps_code[] =
11444 #if 0
11445 Texture2D t;
11446 SamplerState s;
11448 float4 main(float4 position : SV_POSITION) : SV_Target
11450 float2 p;
11452 p.x = position.x / 640.0f;
11453 p.y = position.y / 480.0f;
11454 return t.Sample(s, p);
11456 #endif
11457 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
11458 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11459 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
11460 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11461 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
11462 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
11463 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
11464 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
11465 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
11466 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
11468 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
11469 static const DWORD initial_data[16] = {0};
11470 static const DWORD bitmap_data[] =
11472 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
11473 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
11474 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
11475 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
11477 static const DWORD expected_colors[] =
11479 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
11480 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
11481 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
11482 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
11485 if (!init_test_context(&test_context, NULL))
11486 return;
11488 device = test_context.device;
11489 context = test_context.immediate_context;
11491 texture_desc.Width = 4;
11492 texture_desc.Height = 4;
11493 texture_desc.MipLevels = 1;
11494 texture_desc.ArraySize = 1;
11495 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11496 texture_desc.SampleDesc.Count = 1;
11497 texture_desc.SampleDesc.Quality = 0;
11498 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11499 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
11500 texture_desc.CPUAccessFlags = 0;
11501 texture_desc.MiscFlags = 0;
11503 resource_data.pSysMem = initial_data;
11504 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
11505 resource_data.SysMemSlicePitch = 0;
11507 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
11508 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
11510 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
11511 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11513 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
11514 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
11515 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
11516 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
11517 sampler_desc.MipLODBias = 0.0f;
11518 sampler_desc.MaxAnisotropy = 0;
11519 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
11520 sampler_desc.BorderColor[0] = 0.0f;
11521 sampler_desc.BorderColor[1] = 0.0f;
11522 sampler_desc.BorderColor[2] = 0.0f;
11523 sampler_desc.BorderColor[3] = 0.0f;
11524 sampler_desc.MinLOD = 0.0f;
11525 sampler_desc.MaxLOD = 0.0f;
11527 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
11528 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
11530 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11531 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11533 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
11534 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
11535 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11537 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
11538 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
11540 draw_quad(&test_context);
11541 check_texture_color(test_context.backbuffer, 0x00000000, 0);
11543 set_box(&box, 1, 1, 0, 3, 3, 1);
11544 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
11545 bitmap_data, 4 * sizeof(*bitmap_data), 0);
11546 set_box(&box, 0, 3, 0, 3, 4, 1);
11547 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
11548 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
11549 set_box(&box, 0, 0, 0, 4, 1, 1);
11550 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
11551 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
11552 set_box(&box, 0, 1, 0, 1, 3, 1);
11553 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
11554 &bitmap_data[2], sizeof(*bitmap_data), 0);
11555 set_box(&box, 4, 4, 0, 3, 1, 1);
11556 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
11557 bitmap_data, sizeof(*bitmap_data), 0);
11558 set_box(&box, 0, 0, 0, 4, 4, 0);
11559 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
11560 bitmap_data, 4 * sizeof(*bitmap_data), 0);
11561 draw_quad(&test_context);
11562 get_texture_readback(test_context.backbuffer, 0, &rb);
11563 for (i = 0; i < 4; ++i)
11565 for (j = 0; j < 4; ++j)
11567 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
11568 ok(compare_color(color, expected_colors[j + i * 4], 1),
11569 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
11570 color, j, i, expected_colors[j + i * 4]);
11573 release_resource_readback(&rb);
11575 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
11576 bitmap_data, 4 * sizeof(*bitmap_data), 0);
11577 draw_quad(&test_context);
11578 get_texture_readback(test_context.backbuffer, 0, &rb);
11579 for (i = 0; i < 4; ++i)
11581 for (j = 0; j < 4; ++j)
11583 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
11584 ok(compare_color(color, bitmap_data[j + i * 4], 1),
11585 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
11586 color, j, i, bitmap_data[j + i * 4]);
11589 release_resource_readback(&rb);
11591 ID3D11PixelShader_Release(ps);
11592 ID3D11SamplerState_Release(sampler_state);
11593 ID3D11ShaderResourceView_Release(ps_srv);
11594 ID3D11Texture2D_Release(texture);
11595 release_test_context(&test_context);
11598 static void test_copy_subresource_region(void)
11600 ID3D11Texture2D *dst_texture, *src_texture;
11601 struct d3d11_test_context test_context;
11602 ID3D11Buffer *dst_buffer, *src_buffer;
11603 D3D11_SUBRESOURCE_DATA resource_data;
11604 D3D11_TEXTURE2D_DESC texture_desc;
11605 ID3D11SamplerState *sampler_state;
11606 ID3D11ShaderResourceView *ps_srv;
11607 D3D11_SAMPLER_DESC sampler_desc;
11608 ID3D11DeviceContext1 *context1;
11609 ID3D11DeviceContext *context;
11610 struct vec4 float_colors[16];
11611 struct resource_readback rb;
11612 ID3D11PixelShader *ps;
11613 ID3D11Device *device;
11614 unsigned int i, j;
11615 D3D11_BOX box;
11616 DWORD color;
11617 HRESULT hr;
11619 static const DWORD ps_code[] =
11621 #if 0
11622 Texture2D t;
11623 SamplerState s;
11625 float4 main(float4 position : SV_POSITION) : SV_Target
11627 float2 p;
11629 p.x = position.x / 640.0f;
11630 p.y = position.y / 480.0f;
11631 return t.Sample(s, p);
11633 #endif
11634 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
11635 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11636 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
11637 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11638 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
11639 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
11640 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
11641 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
11642 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
11643 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
11645 static const DWORD ps_buffer_code[] =
11647 #if 0
11648 float4 buffer[16];
11650 float4 main(float4 position : SV_POSITION) : SV_TARGET
11652 float2 p = (float2)4;
11653 p *= float2(position.x / 640.0f, position.y / 480.0f);
11654 return buffer[(int)p.y * 4 + (int)p.x];
11656 #endif
11657 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
11658 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11659 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
11660 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11661 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
11662 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
11663 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
11664 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
11665 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
11666 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
11667 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
11668 0x0010000a, 0x00000000, 0x0100003e,
11670 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
11671 static const DWORD initial_data[16] = {0};
11672 static const DWORD bitmap_data[] =
11674 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
11675 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
11676 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
11677 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
11679 static const DWORD expected_colors[] =
11681 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
11682 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
11683 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
11684 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
11687 if (!init_test_context(&test_context, NULL))
11688 return;
11690 device = test_context.device;
11691 context = test_context.immediate_context;
11693 texture_desc.Width = 4;
11694 texture_desc.Height = 4;
11695 texture_desc.MipLevels = 1;
11696 texture_desc.ArraySize = 1;
11697 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11698 texture_desc.SampleDesc.Count = 1;
11699 texture_desc.SampleDesc.Quality = 0;
11700 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11701 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
11702 texture_desc.CPUAccessFlags = 0;
11703 texture_desc.MiscFlags = 0;
11705 resource_data.pSysMem = initial_data;
11706 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
11707 resource_data.SysMemSlicePitch = 0;
11709 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
11710 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
11712 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
11714 resource_data.pSysMem = bitmap_data;
11715 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
11716 resource_data.SysMemSlicePitch = 0;
11718 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
11719 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
11721 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
11722 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11724 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
11725 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
11726 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
11727 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
11728 sampler_desc.MipLODBias = 0.0f;
11729 sampler_desc.MaxAnisotropy = 0;
11730 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
11731 sampler_desc.BorderColor[0] = 0.0f;
11732 sampler_desc.BorderColor[1] = 0.0f;
11733 sampler_desc.BorderColor[2] = 0.0f;
11734 sampler_desc.BorderColor[3] = 0.0f;
11735 sampler_desc.MinLOD = 0.0f;
11736 sampler_desc.MaxLOD = 0.0f;
11738 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
11739 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
11741 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11742 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11744 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
11745 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
11746 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11748 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
11750 set_box(&box, 0, 0, 0, 2, 2, 1);
11751 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
11752 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
11753 set_box(&box, 1, 2, 0, 4, 3, 1);
11754 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
11755 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
11756 set_box(&box, 0, 3, 0, 4, 4, 1);
11757 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
11758 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
11759 set_box(&box, 3, 0, 0, 4, 2, 1);
11760 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
11761 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
11762 set_box(&box, 3, 1, 0, 4, 2, 1);
11763 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
11764 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
11765 set_box(&box, 0, 0, 0, 4, 4, 0);
11766 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
11767 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
11768 draw_quad(&test_context);
11769 get_texture_readback(test_context.backbuffer, 0, &rb);
11770 for (i = 0; i < 4; ++i)
11772 for (j = 0; j < 4; ++j)
11774 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
11775 ok(compare_color(color, expected_colors[j + i * 4], 1),
11776 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
11777 color, j, i, expected_colors[j + i * 4]);
11780 release_resource_readback(&rb);
11782 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
11783 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
11784 draw_quad(&test_context);
11785 get_texture_readback(test_context.backbuffer, 0, &rb);
11786 for (i = 0; i < 4; ++i)
11788 for (j = 0; j < 4; ++j)
11790 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
11791 ok(compare_color(color, bitmap_data[j + i * 4], 1),
11792 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
11793 color, j, i, bitmap_data[j + i * 4]);
11796 release_resource_readback(&rb);
11798 hr = ID3D11DeviceContext_QueryInterface(context, &IID_ID3D11DeviceContext1, (void **)&context1);
11799 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
11800 "Failed to query ID3D11DeviceContext1, hr %#x.\n", hr);
11802 if (SUCCEEDED(hr))
11804 ID3D11DeviceContext1_ClearRenderTargetView(context1, test_context.backbuffer_rtv, red);
11805 check_texture_color(test_context.backbuffer, 0x800000ff, 2);
11807 memset(float_colors, 0, sizeof(float_colors));
11808 ID3D11DeviceContext1_UpdateSubresource1(context1, (ID3D11Resource *)dst_texture, 0, NULL,
11809 float_colors, 0, 0, 0);
11810 draw_quad(&test_context);
11811 check_texture_color(test_context.backbuffer, 0x00000000, 1);
11813 ID3D11DeviceContext1_CopySubresourceRegion1(context1, (ID3D11Resource *)dst_texture, 0,
11814 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL, 0);
11815 draw_quad(&test_context);
11817 get_texture_readback(test_context.backbuffer, 0, &rb);
11818 for (i = 0; i < 4; ++i)
11820 for (j = 0; j < 4; ++j)
11822 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
11823 ok(compare_color(color, bitmap_data[j + i * 4], 1),
11824 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
11825 color, j, i, bitmap_data[j + i * 4]);
11828 release_resource_readback(&rb);
11830 ID3D11DeviceContext1_Release(context1);
11834 ID3D11PixelShader_Release(ps);
11835 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
11836 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11838 ID3D11ShaderResourceView_Release(ps_srv);
11839 ps_srv = NULL;
11841 ID3D11SamplerState_Release(sampler_state);
11842 sampler_state = NULL;
11844 ID3D11Texture2D_Release(dst_texture);
11845 ID3D11Texture2D_Release(src_texture);
11847 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
11848 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
11849 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11851 memset(float_colors, 0, sizeof(float_colors));
11852 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
11853 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
11855 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
11857 for (i = 0; i < 4; ++i)
11859 for (j = 0; j < 4; ++j)
11861 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
11862 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
11863 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
11864 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
11867 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
11868 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
11870 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
11871 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
11872 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
11873 draw_quad(&test_context);
11874 check_texture_color(test_context.backbuffer, 0x00000000, 0);
11876 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
11877 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
11878 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
11879 draw_quad(&test_context);
11880 check_texture_color(test_context.backbuffer, 0x00000000, 0);
11882 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
11883 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
11884 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
11885 draw_quad(&test_context);
11886 check_texture_color(test_context.backbuffer, 0x00000000, 0);
11888 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
11889 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
11890 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
11891 draw_quad(&test_context);
11892 get_texture_readback(test_context.backbuffer, 0, &rb);
11893 for (i = 0; i < 4; ++i)
11895 for (j = 0; j < 4; ++j)
11897 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
11898 ok(compare_color(color, bitmap_data[j + i * 4], 1),
11899 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
11900 color, j, i, bitmap_data[j + i * 4]);
11903 release_resource_readback(&rb);
11905 ID3D11Buffer_Release(dst_buffer);
11906 ID3D11Buffer_Release(src_buffer);
11907 ID3D11PixelShader_Release(ps);
11908 release_test_context(&test_context);
11911 static void test_copy_subresource_region_1d(void)
11913 D3D11_SUBRESOURCE_DATA resource_data[4];
11914 struct d3d11_test_context test_context;
11915 D3D11_TEXTURE1D_DESC texture1d_desc;
11916 D3D11_TEXTURE2D_DESC texture2d_desc;
11917 ID3D11DeviceContext *context;
11918 struct resource_readback rb;
11919 ID3D11Texture1D *texture1d;
11920 ID3D11Texture2D *texture2d;
11921 ID3D11Device *device;
11922 unsigned int i, j;
11923 D3D11_BOX box;
11924 DWORD color;
11925 HRESULT hr;
11927 static const DWORD bitmap_data[] =
11929 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
11930 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
11931 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
11932 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
11935 if (!init_test_context(&test_context, NULL))
11936 return;
11937 device = test_context.device;
11938 context = test_context.immediate_context;
11940 texture1d_desc.Width = 4;
11941 texture1d_desc.MipLevels = 1;
11942 texture1d_desc.ArraySize = 4;
11943 texture1d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11944 texture1d_desc.Usage = D3D11_USAGE_DEFAULT;
11945 texture1d_desc.BindFlags = 0;
11946 texture1d_desc.CPUAccessFlags = 0;
11947 texture1d_desc.MiscFlags = 0;
11949 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
11951 resource_data[i].pSysMem = &bitmap_data[4 * i];
11952 resource_data[i].SysMemPitch = texture1d_desc.Width * sizeof(bitmap_data);
11953 resource_data[i].SysMemSlicePitch = 0;
11956 hr = ID3D11Device_CreateTexture1D(device, &texture1d_desc, resource_data, &texture1d);
11957 ok(hr == S_OK, "Failed to create 1d texture, hr %#x.\n", hr);
11959 texture2d_desc.Width = 4;
11960 texture2d_desc.Height = 4;
11961 texture2d_desc.MipLevels = 1;
11962 texture2d_desc.ArraySize = 1;
11963 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11964 texture2d_desc.SampleDesc.Count = 1;
11965 texture2d_desc.SampleDesc.Quality = 0;
11966 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
11967 texture2d_desc.BindFlags = 0;
11968 texture2d_desc.CPUAccessFlags = 0;
11969 texture2d_desc.MiscFlags = 0;
11971 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
11972 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
11974 set_box(&box, 0, 0, 0, 4, 1, 1);
11975 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
11977 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2d, 0,
11978 0, i, 0, (ID3D11Resource *)texture1d, i, &box);
11981 get_texture_readback(texture2d, 0, &rb);
11982 for (i = 0; i < 4; ++i)
11984 for (j = 0; j < 4; ++j)
11986 color = get_readback_color(&rb, j, i, 0);
11987 ok(compare_color(color, bitmap_data[j + i * 4], 1),
11988 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
11989 color, j, i, bitmap_data[j + i * 4]);
11992 release_resource_readback(&rb);
11994 ID3D11Texture1D_Release(texture1d);
11995 ID3D11Texture2D_Release(texture2d);
11996 release_test_context(&test_context);
11999 static void test_copy_subresource_region_3d(void)
12001 ID3D11ShaderResourceView *dst_srv, *src_srv;
12002 ID3D11Texture3D *dst_texture, *src_texture;
12003 D3D11_SUBRESOURCE_DATA resource_data[4];
12004 struct d3d11_test_context test_context;
12005 D3D11_TEXTURE2D_DESC texture2d_desc;
12006 D3D11_TEXTURE3D_DESC texture3d_desc;
12007 ID3D11SamplerState *sampler_state;
12008 D3D11_SAMPLER_DESC sampler_desc;
12009 ID3D11DeviceContext *context;
12010 struct resource_readback rb;
12011 ID3D11Texture2D *texture2d;
12012 ID3D11PixelShader *ps;
12013 ID3D11Device *device;
12014 unsigned int i, j;
12015 DWORD data[4][16];
12016 D3D11_BOX box;
12017 DWORD color;
12018 HRESULT hr;
12020 static const DWORD ps_code[] =
12022 #if 0
12023 Texture3D t;
12024 SamplerState s;
12026 float4 main(float4 position : SV_POSITION) : SV_Target
12028 return t.Sample(s, position.xyz / float3(640, 480, 1));
12030 #endif
12031 0x43425844, 0x27b15ae8, 0xbebf46f7, 0x6cd88d8d, 0x5118de51, 0x00000001, 0x00000134, 0x00000003,
12032 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12033 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000070f, 0x505f5653, 0x5449534f, 0x004e4f49,
12034 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12035 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
12036 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
12037 0x04002064, 0x00101072, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12038 0x00000001, 0x0a000038, 0x00100072, 0x00000000, 0x00101246, 0x00000000, 0x00004002, 0x3acccccd,
12039 0x3b088889, 0x3f800000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
12040 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
12042 static const DWORD bitmap_data[] =
12044 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
12045 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
12046 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
12047 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
12050 if (!init_test_context(&test_context, NULL))
12051 return;
12052 device = test_context.device;
12053 context = test_context.immediate_context;
12055 texture3d_desc.Width = 4;
12056 texture3d_desc.Height = 4;
12057 texture3d_desc.Depth = 4;
12058 texture3d_desc.MipLevels = 1;
12059 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12060 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
12061 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
12062 texture3d_desc.CPUAccessFlags = 0;
12063 texture3d_desc.MiscFlags = 0;
12065 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &src_texture);
12066 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
12067 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &dst_texture);
12068 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
12070 texture2d_desc.Width = 4;
12071 texture2d_desc.Height = 4;
12072 texture2d_desc.MipLevels = 1;
12073 texture2d_desc.ArraySize = 4;
12074 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12075 texture2d_desc.SampleDesc.Count = 1;
12076 texture2d_desc.SampleDesc.Quality = 0;
12077 texture2d_desc.Usage = D3D11_USAGE_IMMUTABLE;
12078 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
12079 texture2d_desc.CPUAccessFlags = 0;
12080 texture2d_desc.MiscFlags = 0;
12082 for (i = 0; i < ARRAY_SIZE(*data); ++i)
12084 data[0][i] = 0xff0000ff;
12085 data[1][i] = bitmap_data[i];
12086 data[2][i] = 0xff00ff00;
12087 data[3][i] = 0xffff00ff;
12090 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
12092 resource_data[i].pSysMem = data[i];
12093 resource_data[i].SysMemPitch = texture2d_desc.Width * sizeof(data[0][0]);
12094 resource_data[i].SysMemSlicePitch = 0;
12097 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, resource_data, &texture2d);
12098 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
12100 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)src_texture, NULL, &src_srv);
12101 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
12102 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &dst_srv);
12103 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
12105 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
12106 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
12107 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
12108 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
12109 sampler_desc.MipLODBias = 0.0f;
12110 sampler_desc.MaxAnisotropy = 0;
12111 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
12112 sampler_desc.BorderColor[0] = 0.0f;
12113 sampler_desc.BorderColor[1] = 0.0f;
12114 sampler_desc.BorderColor[2] = 0.0f;
12115 sampler_desc.BorderColor[3] = 0.0f;
12116 sampler_desc.MinLOD = 0.0f;
12117 sampler_desc.MaxLOD = 0.0f;
12119 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
12120 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
12122 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12123 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
12125 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &src_srv);
12126 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
12127 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12129 set_box(&box, 0, 0, 0, 4, 4, 1);
12130 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
12132 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
12133 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
12135 draw_quad(&test_context);
12136 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
12137 draw_quad_z(&test_context, 0.25f);
12138 get_texture_readback(test_context.backbuffer, 0, &rb);
12139 for (i = 0; i < 4; ++i)
12141 for (j = 0; j < 4; ++j)
12143 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
12144 ok(compare_color(color, bitmap_data[j + i * 4], 1),
12145 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
12146 color, j, i, bitmap_data[j + i * 4]);
12149 release_resource_readback(&rb);
12150 draw_quad_z(&test_context, 0.5f);
12151 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
12152 draw_quad_z(&test_context, 1.0f);
12153 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
12155 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &dst_srv);
12157 set_box(&box, 0, 0, 0, 4, 4, 2);
12158 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
12159 0, 0, 2, (ID3D11Resource *)src_texture, 0, &box);
12160 set_box(&box, 0, 0, 2, 4, 4, 4);
12161 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
12162 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
12164 set_box(&box, 0, 0, 0, 4, 4, 1);
12165 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
12167 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
12168 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
12170 draw_quad(&test_context);
12171 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
12172 draw_quad_z(&test_context, 0.25f);
12173 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
12174 draw_quad_z(&test_context, 0.5f);
12175 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
12176 draw_quad_z(&test_context, 1.0f);
12177 get_texture_readback(test_context.backbuffer, 0, &rb);
12178 for (i = 0; i < 4; ++i)
12180 for (j = 0; j < 4; ++j)
12182 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
12183 ok(compare_color(color, bitmap_data[j + i * 4], 1),
12184 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
12185 color, j, i, bitmap_data[j + i * 4]);
12188 release_resource_readback(&rb);
12190 ID3D11PixelShader_Release(ps);
12191 ID3D11SamplerState_Release(sampler_state);
12192 ID3D11ShaderResourceView_Release(dst_srv);
12193 ID3D11ShaderResourceView_Release(src_srv);
12194 ID3D11Texture2D_Release(texture2d);
12195 ID3D11Texture3D_Release(dst_texture);
12196 ID3D11Texture3D_Release(src_texture);
12197 release_test_context(&test_context);
12200 static void test_resource_map(void)
12202 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
12203 D3D11_TEXTURE3D_DESC texture3d_desc;
12204 D3D11_TEXTURE2D_DESC texture2d_desc;
12205 D3D11_BUFFER_DESC buffer_desc;
12206 ID3D11DeviceContext *context;
12207 ID3D11Texture3D *texture3d;
12208 ID3D11Texture2D *texture2d;
12209 ID3D11Buffer *buffer;
12210 ID3D11Device *device;
12211 ULONG refcount;
12212 HRESULT hr;
12213 DWORD data;
12215 if (!(device = create_device(NULL)))
12217 skip("Failed to create device.\n");
12218 return;
12221 ID3D11Device_GetImmediateContext(device, &context);
12223 buffer_desc.ByteWidth = 1024;
12224 buffer_desc.Usage = D3D11_USAGE_STAGING;
12225 buffer_desc.BindFlags = 0;
12226 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
12227 buffer_desc.MiscFlags = 0;
12228 buffer_desc.StructureByteStride = 0;
12230 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
12231 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
12233 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
12234 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12236 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
12237 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
12238 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
12239 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
12240 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
12241 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
12242 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
12244 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
12245 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
12246 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
12247 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
12248 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
12249 data = *((DWORD *)mapped_subresource.pData);
12250 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
12251 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
12253 refcount = ID3D11Buffer_Release(buffer);
12254 ok(!refcount, "Buffer has %u references left.\n", refcount);
12256 texture2d_desc.Width = 512;
12257 texture2d_desc.Height = 512;
12258 texture2d_desc.MipLevels = 1;
12259 texture2d_desc.ArraySize = 1;
12260 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12261 texture2d_desc.SampleDesc.Count = 1;
12262 texture2d_desc.SampleDesc.Quality = 0;
12263 texture2d_desc.Usage = D3D11_USAGE_STAGING;
12264 texture2d_desc.BindFlags = 0;
12265 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
12266 texture2d_desc.MiscFlags = 0;
12268 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
12269 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
12271 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
12272 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12274 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
12275 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
12276 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
12277 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
12278 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
12279 mapped_subresource.DepthPitch);
12280 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
12281 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
12283 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
12284 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
12285 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
12286 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
12287 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
12288 mapped_subresource.DepthPitch);
12289 data = *((DWORD *)mapped_subresource.pData);
12290 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
12291 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
12293 refcount = ID3D11Texture2D_Release(texture2d);
12294 ok(!refcount, "2D texture has %u references left.\n", refcount);
12296 texture3d_desc.Width = 64;
12297 texture3d_desc.Height = 64;
12298 texture3d_desc.Depth = 64;
12299 texture3d_desc.MipLevels = 1;
12300 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12301 texture3d_desc.Usage = D3D11_USAGE_STAGING;
12302 texture3d_desc.BindFlags = 0;
12303 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
12304 texture3d_desc.MiscFlags = 0;
12306 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
12307 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
12309 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
12310 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12312 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
12313 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
12314 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
12315 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
12316 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
12317 mapped_subresource.DepthPitch);
12318 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
12319 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
12321 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
12322 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
12323 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
12324 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
12325 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
12326 mapped_subresource.DepthPitch);
12327 data = *((DWORD *)mapped_subresource.pData);
12328 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
12329 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
12331 refcount = ID3D11Texture3D_Release(texture3d);
12332 ok(!refcount, "3D texture has %u references left.\n", refcount);
12334 ID3D11DeviceContext_Release(context);
12336 refcount = ID3D11Device_Release(device);
12337 ok(!refcount, "Device has %u references left.\n", refcount);
12340 #define check_resource_cpu_access(a, b, c, d, e) check_resource_cpu_access_(__LINE__, a, b, c, d, e)
12341 static void check_resource_cpu_access_(unsigned int line, ID3D11DeviceContext *context,
12342 ID3D11Resource *resource, D3D11_USAGE usage, UINT bind_flags, UINT cpu_access)
12344 BOOL cpu_write = cpu_access & D3D11_CPU_ACCESS_WRITE;
12345 BOOL cpu_read = cpu_access & D3D11_CPU_ACCESS_READ;
12346 BOOL dynamic = usage == D3D11_USAGE_DYNAMIC;
12347 D3D11_MAPPED_SUBRESOURCE map_desc;
12348 HRESULT hr, expected_hr;
12349 ID3D11Device *device;
12351 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
12352 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ, 0, &map_desc);
12353 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
12354 if (SUCCEEDED(hr))
12355 ID3D11DeviceContext_Unmap(context, resource, 0);
12357 /* WRITE_DISCARD and WRITE_NO_OVERWRITE are the only allowed options for dynamic resources. */
12358 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
12359 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE, 0, &map_desc);
12360 todo_wine_if(dynamic && cpu_write)
12361 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
12362 if (SUCCEEDED(hr))
12363 ID3D11DeviceContext_Unmap(context, resource, 0);
12365 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
12366 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
12367 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
12368 if (SUCCEEDED(hr))
12369 ID3D11DeviceContext_Unmap(context, resource, 0);
12371 expected_hr = dynamic ? S_OK : E_INVALIDARG;
12372 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
12373 todo_wine_if(!dynamic && cpu_write)
12374 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
12375 if (SUCCEEDED(hr))
12376 ID3D11DeviceContext_Unmap(context, resource, 0);
12378 if (!dynamic)
12379 return;
12381 ID3D11DeviceContext_GetDevice(context, &device);
12383 /* WRITE_NO_OVERWRITE is supported only for buffers. */
12384 expected_hr = is_buffer(resource) ? S_OK : E_INVALIDARG;
12385 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
12386 /* D3D11.1 is required for constant and shader buffers. */
12387 todo_wine_if(expected_hr != S_OK)
12388 ok_(__FILE__, line)(hr == expected_hr
12389 || broken(bind_flags & (D3D11_BIND_CONSTANT_BUFFER | D3D11_BIND_SHADER_RESOURCE)),
12390 "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
12391 if (SUCCEEDED(hr))
12392 ID3D11DeviceContext_Unmap(context, resource, 0);
12394 ID3D11Device_Release(device);
12397 static void test_resource_access(const D3D_FEATURE_LEVEL feature_level)
12399 D3D11_TEXTURE2D_DESC texture_desc;
12400 struct device_desc device_desc;
12401 D3D11_BUFFER_DESC buffer_desc;
12402 ID3D11DeviceContext *context;
12403 D3D11_SUBRESOURCE_DATA data;
12404 ID3D11Resource *resource;
12405 BOOL required_cpu_access;
12406 BOOL cpu_write, cpu_read;
12407 HRESULT hr, expected_hr;
12408 UINT allowed_cpu_access;
12409 BOOL broken_validation;
12410 ID3D11Device *device;
12411 unsigned int i;
12412 ULONG refcount;
12414 static const struct
12416 D3D11_USAGE usage;
12417 UINT bind_flags;
12418 BOOL is_valid;
12419 UINT allowed_cpu_access;
12421 tests[] =
12423 /* Default resources cannot be written by CPU. */
12424 {D3D11_USAGE_DEFAULT, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
12425 {D3D11_USAGE_DEFAULT, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
12426 {D3D11_USAGE_DEFAULT, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
12427 {D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
12428 {D3D11_USAGE_DEFAULT, D3D11_BIND_STREAM_OUTPUT, TRUE, 0},
12429 {D3D11_USAGE_DEFAULT, D3D11_BIND_RENDER_TARGET, TRUE, 0},
12430 {D3D11_USAGE_DEFAULT, D3D11_BIND_DEPTH_STENCIL, TRUE, 0},
12431 {D3D11_USAGE_DEFAULT, D3D11_BIND_UNORDERED_ACCESS, TRUE, 0},
12433 /* Immutable resources cannot be written by CPU and GPU. */
12434 {D3D11_USAGE_IMMUTABLE, 0, FALSE, 0},
12435 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
12436 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
12437 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
12438 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
12439 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
12440 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_RENDER_TARGET, FALSE, 0},
12441 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
12442 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
12444 /* Dynamic resources cannot be written by GPU. */
12445 {D3D11_USAGE_DYNAMIC, 0, FALSE, D3D11_CPU_ACCESS_WRITE},
12446 {D3D11_USAGE_DYNAMIC, D3D11_BIND_VERTEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
12447 {D3D11_USAGE_DYNAMIC, D3D11_BIND_INDEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
12448 {D3D11_USAGE_DYNAMIC, D3D11_BIND_CONSTANT_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
12449 {D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE, TRUE, D3D11_CPU_ACCESS_WRITE},
12450 {D3D11_USAGE_DYNAMIC, D3D11_BIND_STREAM_OUTPUT, FALSE, D3D11_CPU_ACCESS_WRITE},
12451 {D3D11_USAGE_DYNAMIC, D3D11_BIND_RENDER_TARGET, FALSE, D3D11_CPU_ACCESS_WRITE},
12452 {D3D11_USAGE_DYNAMIC, D3D11_BIND_DEPTH_STENCIL, FALSE, D3D11_CPU_ACCESS_WRITE},
12453 {D3D11_USAGE_DYNAMIC, D3D11_BIND_UNORDERED_ACCESS, FALSE, D3D11_CPU_ACCESS_WRITE},
12455 /* Staging resources support only data transfer. */
12456 {D3D11_USAGE_STAGING, 0, TRUE, D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ},
12457 {D3D11_USAGE_STAGING, D3D11_BIND_VERTEX_BUFFER, FALSE, 0},
12458 {D3D11_USAGE_STAGING, D3D11_BIND_INDEX_BUFFER, FALSE, 0},
12459 {D3D11_USAGE_STAGING, D3D11_BIND_CONSTANT_BUFFER, FALSE, 0},
12460 {D3D11_USAGE_STAGING, D3D11_BIND_SHADER_RESOURCE, FALSE, 0},
12461 {D3D11_USAGE_STAGING, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
12462 {D3D11_USAGE_STAGING, D3D11_BIND_RENDER_TARGET, FALSE, 0},
12463 {D3D11_USAGE_STAGING, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
12464 {D3D11_USAGE_STAGING, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
12467 device_desc.feature_level = &feature_level;
12468 device_desc.flags = 0;
12469 if (!(device = create_device(&device_desc)))
12471 skip("Failed to create device for feature level %#x.\n", feature_level);
12472 return;
12474 ID3D11Device_GetImmediateContext(device, &context);
12476 data.SysMemPitch = 0;
12477 data.SysMemSlicePitch = 0;
12478 data.pSysMem = heap_alloc(10240);
12479 ok(!!data.pSysMem, "Failed to allocate memory.\n");
12481 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12483 switch (tests[i].bind_flags)
12485 case D3D11_BIND_DEPTH_STENCIL:
12486 continue;
12488 case D3D11_BIND_SHADER_RESOURCE:
12489 case D3D11_BIND_STREAM_OUTPUT:
12490 case D3D11_BIND_RENDER_TARGET:
12491 if (feature_level < D3D_FEATURE_LEVEL_10_0)
12492 continue;
12493 break;
12495 case D3D11_BIND_UNORDERED_ACCESS:
12496 if (feature_level < D3D_FEATURE_LEVEL_11_0)
12497 continue;
12498 break;
12500 default:
12501 break;
12504 allowed_cpu_access = tests[i].allowed_cpu_access;
12505 if (feature_level >= D3D_FEATURE_LEVEL_11_0 && is_d3d11_2_runtime(device)
12506 && tests[i].usage == D3D11_USAGE_DEFAULT
12507 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
12508 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS))
12509 allowed_cpu_access |= D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
12511 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
12512 cpu_write = allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
12513 cpu_read = allowed_cpu_access & D3D11_CPU_ACCESS_READ;
12515 buffer_desc.ByteWidth = 1024;
12516 buffer_desc.Usage = tests[i].usage;
12517 buffer_desc.BindFlags = tests[i].bind_flags;
12518 buffer_desc.MiscFlags = 0;
12519 buffer_desc.StructureByteStride = 0;
12521 buffer_desc.CPUAccessFlags = 0;
12522 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
12523 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
12524 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
12525 if (SUCCEEDED(hr))
12527 check_resource_cpu_access(context, resource,
12528 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
12529 ID3D11Resource_Release(resource);
12532 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
12533 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
12534 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
12535 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
12536 if (SUCCEEDED(hr))
12538 check_resource_cpu_access(context, resource,
12539 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
12540 ID3D11Resource_Release(resource);
12543 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
12544 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
12545 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
12546 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
12547 if (SUCCEEDED(hr))
12549 check_resource_cpu_access(context, resource,
12550 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
12551 ID3D11Resource_Release(resource);
12554 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
12555 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
12556 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
12557 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
12558 if (SUCCEEDED(hr))
12560 check_resource_cpu_access(context, resource,
12561 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
12562 ID3D11Resource_Release(resource);
12566 data.SysMemPitch = 16;
12568 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12570 switch (tests[i].bind_flags)
12572 case D3D11_BIND_VERTEX_BUFFER:
12573 case D3D11_BIND_INDEX_BUFFER:
12574 case D3D11_BIND_CONSTANT_BUFFER:
12575 case D3D11_BIND_STREAM_OUTPUT:
12576 continue;
12578 case D3D11_BIND_UNORDERED_ACCESS:
12579 if (feature_level < D3D_FEATURE_LEVEL_11_0)
12580 continue;
12581 break;
12583 default:
12584 break;
12587 broken_validation = tests[i].usage == D3D11_USAGE_DEFAULT
12588 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
12589 || tests[i].bind_flags == D3D11_BIND_RENDER_TARGET
12590 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS);
12592 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
12593 cpu_write = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
12594 cpu_read = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_READ;
12596 texture_desc.Width = 4;
12597 texture_desc.Height = 4;
12598 texture_desc.MipLevels = 1;
12599 texture_desc.ArraySize = 1;
12600 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12601 texture_desc.SampleDesc.Count = 1;
12602 texture_desc.SampleDesc.Quality = 0;
12603 texture_desc.Usage = tests[i].usage;
12604 texture_desc.BindFlags = tests[i].bind_flags;
12605 texture_desc.MiscFlags = 0;
12606 if (tests[i].bind_flags == D3D11_BIND_DEPTH_STENCIL)
12607 texture_desc.Format = DXGI_FORMAT_D16_UNORM;
12609 texture_desc.CPUAccessFlags = 0;
12610 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
12611 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
12612 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
12613 if (SUCCEEDED(hr))
12615 check_resource_cpu_access(context, resource,
12616 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
12617 ID3D11Resource_Release(resource);
12620 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
12621 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
12622 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
12623 ok(hr == expected_hr || (hr == S_OK && broken_validation),
12624 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
12625 if (SUCCEEDED(hr))
12627 if (broken_validation)
12628 texture_desc.CPUAccessFlags = 0;
12629 check_resource_cpu_access(context, resource,
12630 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
12631 ID3D11Resource_Release(resource);
12634 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
12635 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
12636 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
12637 ok(hr == expected_hr || (hr == S_OK && broken_validation),
12638 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
12639 if (SUCCEEDED(hr))
12641 if (broken_validation)
12642 texture_desc.CPUAccessFlags = 0;
12643 check_resource_cpu_access(context, resource,
12644 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
12645 ID3D11Resource_Release(resource);
12648 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
12649 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
12650 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
12651 ok(hr == expected_hr || (hr == S_OK && broken_validation),
12652 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
12653 if (SUCCEEDED(hr))
12655 if (broken_validation)
12656 texture_desc.CPUAccessFlags = 0;
12657 check_resource_cpu_access(context, resource,
12658 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
12659 ID3D11Resource_Release(resource);
12663 heap_free((void *)data.pSysMem);
12665 ID3D11DeviceContext_Release(context);
12666 refcount = ID3D11Device_Release(device);
12667 ok(!refcount, "Device has %u references left.\n", refcount);
12670 static void test_check_multisample_quality_levels(void)
12672 ID3D11Device *device;
12673 UINT quality_levels;
12674 ULONG refcount;
12675 HRESULT hr;
12677 if (!(device = create_device(NULL)))
12679 skip("Failed to create device.\n");
12680 return;
12683 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
12684 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
12685 if (!quality_levels)
12687 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
12688 goto done;
12691 quality_levels = 0xdeadbeef;
12692 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
12693 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
12694 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
12695 quality_levels = 0xdeadbeef;
12696 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
12697 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12698 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
12700 quality_levels = 0xdeadbeef;
12701 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
12702 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12703 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
12704 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
12705 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
12707 quality_levels = 0xdeadbeef;
12708 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
12709 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12710 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
12711 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
12712 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
12714 quality_levels = 0xdeadbeef;
12715 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
12716 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12717 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
12718 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
12719 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
12721 /* We assume 15 samples multisampling is never supported in practice. */
12722 quality_levels = 0xdeadbeef;
12723 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
12724 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
12725 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
12726 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
12727 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
12728 quality_levels = 0xdeadbeef;
12729 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
12730 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
12731 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
12732 quality_levels = 0xdeadbeef;
12733 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
12734 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
12735 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
12737 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
12738 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
12739 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
12741 done:
12742 refcount = ID3D11Device_Release(device);
12743 ok(!refcount, "Device has %u references left.\n", refcount);
12746 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
12748 DXGI_SWAP_CHAIN_DESC swapchain_desc;
12749 struct device_desc device_desc;
12750 IDXGISwapChain *swapchain;
12751 IDXGIDevice *dxgi_device;
12752 HRESULT hr, expected_hr;
12753 IDXGIAdapter *adapter;
12754 IDXGIFactory *factory;
12755 ID3D11Device *device;
12756 unsigned int i;
12757 ULONG refcount;
12759 swapchain_desc.BufferDesc.Width = 800;
12760 swapchain_desc.BufferDesc.Height = 600;
12761 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
12762 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
12763 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
12764 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
12765 swapchain_desc.SampleDesc.Count = 1;
12766 swapchain_desc.SampleDesc.Quality = 0;
12767 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
12768 swapchain_desc.BufferCount = 1;
12769 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
12770 swapchain_desc.Windowed = TRUE;
12771 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
12772 swapchain_desc.Flags = 0;
12774 device_desc.feature_level = &feature_level;
12775 device_desc.flags = 0;
12776 if (!(device = create_device(&device_desc)))
12778 skip("Failed to create device for feature level %#x.\n", feature_level);
12779 return;
12782 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
12783 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
12784 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
12785 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
12786 IDXGIDevice_Release(dxgi_device);
12787 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
12788 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
12789 IDXGIAdapter_Release(adapter);
12791 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
12792 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
12793 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
12794 hr, feature_level);
12795 if (SUCCEEDED(hr))
12796 IDXGISwapChain_Release(swapchain);
12798 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
12800 DXGI_FORMAT format = display_format_support[i].format;
12801 BOOL todo = FALSE;
12803 if (display_format_support[i].fl_required <= feature_level)
12805 expected_hr = S_OK;
12806 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
12807 todo = TRUE;
12809 else if (!display_format_support[i].fl_optional
12810 || display_format_support[i].fl_optional > feature_level)
12812 expected_hr = E_INVALIDARG;
12813 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
12814 todo = TRUE;
12816 else
12818 continue;
12821 swapchain_desc.BufferDesc.Format = format;
12822 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
12823 todo_wine_if(todo)
12824 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
12825 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
12826 hr, expected_hr, feature_level, format);
12827 if (FAILED(hr))
12828 continue;
12829 refcount = IDXGISwapChain_Release(swapchain);
12830 ok(!refcount, "Swapchain has %u references left.\n", refcount);
12833 refcount = ID3D11Device_Release(device);
12834 ok(!refcount, "Device has %u references left.\n", refcount);
12835 refcount = IDXGIFactory_Release(factory);
12836 ok(!refcount, "Factory has %u references left.\n", refcount);
12837 DestroyWindow(swapchain_desc.OutputWindow);
12840 static void test_swapchain_views(void)
12842 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
12843 struct d3d11_test_context test_context;
12844 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
12845 ID3D11ShaderResourceView *srv;
12846 ID3D11DeviceContext *context;
12847 ID3D11RenderTargetView *rtv;
12848 ID3D11Device *device;
12849 ULONG refcount;
12850 HRESULT hr;
12852 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
12854 if (!init_test_context(&test_context, NULL))
12855 return;
12857 device = test_context.device;
12858 context = test_context.immediate_context;
12860 refcount = get_refcount(test_context.backbuffer);
12861 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12863 draw_color_quad(&test_context, &color);
12864 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
12866 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
12867 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
12868 U(rtv_desc).Texture2D.MipSlice = 0;
12869 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
12870 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12871 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
12873 refcount = get_refcount(test_context.backbuffer);
12874 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12876 draw_color_quad(&test_context, &color);
12877 todo_wine check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
12879 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
12880 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
12881 U(srv_desc).Texture2D.MostDetailedMip = 0;
12882 U(srv_desc).Texture2D.MipLevels = 1;
12883 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
12884 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12885 if (SUCCEEDED(hr))
12886 ID3D11ShaderResourceView_Release(srv);
12888 ID3D11RenderTargetView_Release(rtv);
12889 release_test_context(&test_context);
12892 static void test_swapchain_flip(void)
12894 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
12895 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
12896 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
12897 D3D11_TEXTURE2D_DESC texture_desc;
12898 ID3D11InputLayout *input_layout;
12899 ID3D11DeviceContext *context;
12900 unsigned int stride, offset;
12901 struct swapchain_desc desc;
12902 IDXGISwapChain *swapchain;
12903 ID3D11VertexShader *vs;
12904 ID3D11PixelShader *ps;
12905 ID3D11Device *device;
12906 ID3D11Buffer *vb;
12907 ULONG refcount;
12908 DWORD color;
12909 HWND window;
12910 HRESULT hr;
12911 RECT rect;
12913 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12915 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12917 static const DWORD vs_code[] =
12919 #if 0
12920 float4 main(float4 position : POSITION) : SV_POSITION
12922 return position;
12924 #endif
12925 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
12926 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12927 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
12928 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
12929 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
12930 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
12931 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
12934 static const DWORD ps_code[] =
12936 #if 0
12937 Texture2D t0, t1;
12938 SamplerState s;
12940 float4 main(float4 position : SV_POSITION) : SV_Target
12942 float2 p;
12944 p.x = 0.5;
12945 p.y = 0.5;
12946 if (position.x < 320)
12947 return t0.Sample(s, p);
12948 return t1.Sample(s, p);
12950 #endif
12951 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
12952 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12953 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
12954 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12955 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
12956 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
12957 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
12958 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
12959 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
12960 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
12961 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
12962 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
12963 0x00000000, 0x0100003e,
12965 static const struct vec2 quad[] =
12967 {-1.0f, -1.0f},
12968 {-1.0f, 1.0f},
12969 { 1.0f, -1.0f},
12970 { 1.0f, 1.0f},
12972 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
12973 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
12974 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
12976 if (!(device = create_device(NULL)))
12978 skip("Failed to create device, skipping tests.\n");
12979 return;
12981 SetRect(&rect, 0, 0, 640, 480);
12982 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
12983 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12984 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
12985 desc.buffer_count = 3;
12986 desc.width = desc.height = 0;
12987 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
12988 desc.windowed = TRUE;
12989 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
12990 swapchain = create_swapchain(device, window, &desc);
12992 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
12993 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
12994 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
12995 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
12996 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
12997 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
12999 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
13000 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13001 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
13002 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13003 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
13004 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13006 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
13007 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
13008 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
13009 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
13010 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
13012 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
13013 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
13014 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
13015 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
13016 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
13018 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
13019 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13020 if (SUCCEEDED(hr))
13021 ID3D11RenderTargetView_Release(offscreen_rtv);
13023 ID3D11Device_GetImmediateContext(device, &context);
13025 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
13026 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
13028 texture_desc.Width = 640;
13029 texture_desc.Height = 480;
13030 texture_desc.MipLevels = 1;
13031 texture_desc.ArraySize = 1;
13032 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13033 texture_desc.SampleDesc.Count = 1;
13034 texture_desc.SampleDesc.Quality = 0;
13035 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13036 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
13037 texture_desc.CPUAccessFlags = 0;
13038 texture_desc.MiscFlags = 0;
13039 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
13040 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
13041 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
13042 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13043 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
13044 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
13046 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
13048 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13049 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13050 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13051 vs_code, sizeof(vs_code), &input_layout);
13052 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13053 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13054 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13055 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13056 stride = sizeof(*quad);
13057 offset = 0;
13058 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
13060 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13061 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13062 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13064 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
13066 ID3D11DeviceContext_Draw(context, 4, 0);
13067 color = get_texture_color(offscreen, 120, 240);
13068 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
13070 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
13071 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
13072 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
13074 * What is this good for? I don't know. Ad-hoc tests suggest that
13075 * Present() always waits for the next V-sync interval, even if there are
13076 * still untouched buffers. Buffer 0 is the buffer that is shown on the
13077 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
13078 * rendering finishes before the V-sync interval is over. I haven't found
13079 * any productive use for more than one buffer. */
13080 IDXGISwapChain_Present(swapchain, 0, 0);
13082 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
13084 ID3D11DeviceContext_Draw(context, 4, 0);
13085 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
13086 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13087 /* Buffer 1 is still untouched. */
13089 color = get_texture_color(backbuffer_0, 320, 240); /* green */
13090 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13091 color = get_texture_color(backbuffer_2, 320, 240); /* red */
13092 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
13094 IDXGISwapChain_Present(swapchain, 0, 0);
13096 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
13098 ID3D11DeviceContext_Draw(context, 4, 0);
13099 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
13100 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
13101 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
13102 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
13104 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
13105 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
13106 color = get_texture_color(backbuffer_1, 320, 240); /* red */
13107 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
13108 color = get_texture_color(backbuffer_2, 320, 240); /* green */
13109 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13111 ID3D11VertexShader_Release(vs);
13112 ID3D11PixelShader_Release(ps);
13113 ID3D11Buffer_Release(vb);
13114 ID3D11InputLayout_Release(input_layout);
13115 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
13116 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
13117 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
13118 ID3D11RenderTargetView_Release(offscreen_rtv);
13119 ID3D11Texture2D_Release(offscreen);
13120 ID3D11Texture2D_Release(backbuffer_0);
13121 ID3D11Texture2D_Release(backbuffer_1);
13122 ID3D11Texture2D_Release(backbuffer_2);
13123 IDXGISwapChain_Release(swapchain);
13125 ID3D11DeviceContext_Release(context);
13126 refcount = ID3D11Device_Release(device);
13127 ok(!refcount, "Device has %u references left.\n", refcount);
13128 DestroyWindow(window);
13131 static void test_clear_render_target_view_1d(void)
13133 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
13134 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
13136 struct d3d11_test_context test_context;
13137 D3D11_TEXTURE1D_DESC texture_desc;
13138 ID3D11DeviceContext *context;
13139 ID3D11RenderTargetView *rtv;
13140 ID3D11Texture1D *texture;
13141 ID3D11Device *device;
13142 HRESULT hr;
13144 if (!init_test_context(&test_context, NULL))
13145 return;
13147 device = test_context.device;
13148 context = test_context.immediate_context;
13150 texture_desc.Width = 64;
13151 texture_desc.MipLevels = 1;
13152 texture_desc.ArraySize = 1;
13153 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13154 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13155 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
13156 texture_desc.CPUAccessFlags = 0;
13157 texture_desc.MiscFlags = 0;
13158 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, NULL, &texture);
13159 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13161 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13162 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13164 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
13165 check_texture1d_color(texture, 0xbf4c7f19, 1);
13167 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
13168 check_texture1d_color(texture, 0x8000ff00, 1);
13170 ID3D11RenderTargetView_Release(rtv);
13171 ID3D11Texture1D_Release(texture);
13172 release_test_context(&test_context);
13175 static void test_clear_render_target_view_2d(void)
13177 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
13178 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
13179 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
13181 ID3D11Texture2D *texture, *srgb_texture;
13182 struct d3d11_test_context test_context;
13183 ID3D11RenderTargetView *rtv, *srgb_rtv;
13184 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
13185 D3D11_TEXTURE2D_DESC texture_desc;
13186 ID3D11DeviceContext *context;
13187 struct resource_readback rb;
13188 ID3D11Device *device;
13189 unsigned int i, j;
13190 HRESULT hr;
13192 if (!init_test_context(&test_context, NULL))
13193 return;
13195 device = test_context.device;
13196 context = test_context.immediate_context;
13198 texture_desc.Width = 640;
13199 texture_desc.Height = 480;
13200 texture_desc.MipLevels = 1;
13201 texture_desc.ArraySize = 1;
13202 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13203 texture_desc.SampleDesc.Count = 1;
13204 texture_desc.SampleDesc.Quality = 0;
13205 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13206 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
13207 texture_desc.CPUAccessFlags = 0;
13208 texture_desc.MiscFlags = 0;
13209 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13210 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13212 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
13213 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
13214 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13216 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13217 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13219 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
13220 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13222 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
13223 check_texture_color(test_context.backbuffer, expected_color, 1);
13225 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
13226 check_texture_color(texture, expected_color, 1);
13228 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
13229 check_texture_color(texture, expected_color, 1);
13231 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
13232 check_texture_color(srgb_texture, expected_srgb_color, 1);
13234 ID3D11RenderTargetView_Release(srgb_rtv);
13235 ID3D11RenderTargetView_Release(rtv);
13236 ID3D11Texture2D_Release(srgb_texture);
13237 ID3D11Texture2D_Release(texture);
13239 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
13240 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13241 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13243 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
13244 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
13245 U(rtv_desc).Texture2D.MipSlice = 0;
13246 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
13247 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13249 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13250 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
13251 U(rtv_desc).Texture2D.MipSlice = 0;
13252 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
13253 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13255 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
13256 check_texture_color(texture, expected_color, 1);
13258 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
13259 get_texture_readback(texture, 0, &rb);
13260 for (i = 0; i < 4; ++i)
13262 for (j = 0; j < 4; ++j)
13264 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
13265 DWORD color = get_readback_color(&rb, 80 + i * 160, 60 + j * 120, 0);
13266 ok(compare_color(color, expected_srgb_color, 1)
13267 || broken(compare_color(color, expected_color, 1) && broken_device),
13268 "Got unexpected color 0x%08x.\n", color);
13271 release_resource_readback(&rb);
13273 ID3D11RenderTargetView_Release(srgb_rtv);
13274 ID3D11RenderTargetView_Release(rtv);
13275 ID3D11Texture2D_Release(texture);
13276 release_test_context(&test_context);
13279 static void test_clear_render_target_view_3d(void)
13281 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
13282 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
13284 struct d3d11_test_context test_context;
13285 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
13286 D3D11_TEXTURE3D_DESC texture_desc;
13287 ID3D11DeviceContext *context;
13288 ID3D11RenderTargetView *rtv;
13289 ID3D11Texture3D *texture;
13290 ID3D11Device *device;
13291 HRESULT hr;
13293 if (!init_test_context(&test_context, NULL))
13294 return;
13295 device = test_context.device;
13296 context = test_context.immediate_context;
13298 texture_desc.Width = 8;
13299 texture_desc.Height = 8;
13300 texture_desc.Depth = 4;
13301 texture_desc.MipLevels = 1;
13302 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13303 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13304 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
13305 texture_desc.CPUAccessFlags = 0;
13306 texture_desc.MiscFlags = 0;
13307 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
13308 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13310 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13311 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13313 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
13314 check_texture3d_color(texture, 0xbf4c7f19, 1);
13315 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
13316 check_texture3d_color(texture, 0x8000ff00, 1);
13318 ID3D11RenderTargetView_Release(rtv);
13319 ID3D11Texture3D_Release(texture);
13321 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
13322 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
13323 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13325 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
13326 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
13327 U(rtv_desc).Texture3D.MipSlice = 0;
13328 U(rtv_desc).Texture3D.FirstWSlice = 0;
13329 U(rtv_desc).Texture3D.WSize = ~0u;
13330 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
13331 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13333 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
13334 check_texture3d_color(texture, 0xbf95bc59, 1);
13335 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
13336 check_texture3d_color(texture, 0x8000ff00, 1);
13338 ID3D11RenderTargetView_Release(rtv);
13339 ID3D11Texture3D_Release(texture);
13340 release_test_context(&test_context);
13343 static void test_clear_depth_stencil_view(void)
13345 D3D11_TEXTURE2D_DESC texture_desc;
13346 ID3D11Texture2D *depth_texture;
13347 ID3D11DeviceContext *context;
13348 ID3D11DepthStencilView *dsv;
13349 ID3D11Device *device;
13350 ULONG refcount;
13351 HRESULT hr;
13353 if (!(device = create_device(NULL)))
13355 skip("Failed to create device.\n");
13356 return;
13359 ID3D11Device_GetImmediateContext(device, &context);
13361 texture_desc.Width = 640;
13362 texture_desc.Height = 480;
13363 texture_desc.MipLevels = 1;
13364 texture_desc.ArraySize = 1;
13365 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
13366 texture_desc.SampleDesc.Count = 1;
13367 texture_desc.SampleDesc.Quality = 0;
13368 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13369 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
13370 texture_desc.CPUAccessFlags = 0;
13371 texture_desc.MiscFlags = 0;
13372 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
13373 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
13375 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
13376 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
13378 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
13379 check_texture_float(depth_texture, 1.0f, 0);
13381 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
13382 check_texture_float(depth_texture, 0.25f, 0);
13384 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
13385 check_texture_float(depth_texture, 0.25f, 0);
13387 ID3D11Texture2D_Release(depth_texture);
13388 ID3D11DepthStencilView_Release(dsv);
13390 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
13391 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
13392 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
13394 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
13395 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
13397 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
13398 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
13400 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
13401 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
13403 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
13404 check_texture_color(depth_texture, 0xffffffff, 0);
13406 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
13407 check_texture_color(depth_texture, 0x00000000, 0);
13409 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
13410 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
13412 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
13413 check_texture_color(depth_texture, 0xffffffff, 0);
13415 ID3D11Texture2D_Release(depth_texture);
13416 ID3D11DepthStencilView_Release(dsv);
13418 ID3D11DeviceContext_Release(context);
13420 refcount = ID3D11Device_Release(device);
13421 ok(!refcount, "Device has %u references left.\n", refcount);
13424 static unsigned int to_sint8(unsigned int x)
13426 union
13428 signed int s;
13429 unsigned int u;
13430 } bits;
13431 bits.u = x;
13432 return min(max(bits.s, -128), 127) & 0xff;
13435 #define check_rgba_sint8(data, uvec) check_rgba_sint8_(__LINE__, data, uvec)
13436 static void check_rgba_sint8_(unsigned int line, DWORD data, const struct uvec4 *v)
13438 unsigned int x = to_sint8(v->x);
13439 unsigned int y = to_sint8(v->y);
13440 unsigned int z = to_sint8(v->z);
13441 unsigned int w = to_sint8(v->w);
13442 DWORD expected[] =
13444 /* Windows 7 - Nvidia, WARP */
13445 (v->x & 0xff) | (v->y & 0xff) << 8 | (v->z & 0xff) << 16 | (v->w & 0xff) << 24,
13446 /* Windows 10 - AMD */
13447 x | y << 8 | z << 16 | w << 24,
13448 /* Windows 10 - Intel */
13449 x | x << 8 | x << 16 | x << 24,
13452 ok_(__FILE__, line)(data == expected[0] || data == expected[1] || broken(data == expected[2]),
13453 "Got %#x, expected %#x or %#x at %u, uvec4 %#x, %#x, %#x, %#x.\n",
13454 data, expected[0], expected[1], x, v->x, v->y, v->z, v->w);
13457 static void test_clear_buffer_unordered_access_view(void)
13459 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
13460 ID3D11UnorderedAccessView *uav, *uav2;
13461 struct device_desc device_desc;
13462 D3D11_BUFFER_DESC buffer_desc;
13463 ID3D11DeviceContext *context;
13464 struct resource_readback rb;
13465 ID3D11Buffer *buffer;
13466 ID3D11Device *device;
13467 struct uvec4 uvec4;
13468 unsigned int i, x;
13469 ULONG refcount;
13470 HRESULT hr;
13472 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13473 static const struct uvec4 fe_uvec4 = {0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe};
13474 static const struct uvec4 uvec4_data[] =
13476 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
13478 {0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
13479 {0xffffffff, 0x00000000, 0x00000000, 0x00000000},
13480 {0x00000000, 0xffffffff, 0x00000000, 0x00000000},
13481 {0x00000000, 0x00000000, 0xffffffff, 0x00000000},
13482 {0x00000000, 0x00000000, 0x00000000, 0xffffffff},
13484 {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff},
13485 {0x80000000, 0x80000000, 0x80000000, 0x80000000},
13486 {0x000000ff, 0x00000080, 0x80000080, 0x00000080},
13487 {0x000000ff, 0x0000007f, 0x000000ef, 0x000000fe},
13488 {0x800000ff, 0x8000007f, 0x800000ef, 0x800000fe},
13489 {0xfefefefe, 0xf0f0f0f0, 0xefefefef, 0x0f0f0f0f},
13490 {0xaaaaaaaa, 0xdeadbeef, 0xdeadbabe, 0xdeadf00d},
13492 {0x00000001, 0x00000002, 0x00000003, 0x00000004},
13493 {0x000000ff, 0x000000fe, 0x000000fd, 0x000000fc},
13494 {0x000000f2, 0x000000f1, 0x000000f0, 0x000000ef},
13495 {0x0000000a, 0x0000000d, 0x0000000e, 0x0000000f},
13496 {0x0000001a, 0x0000002d, 0x0000003e, 0x0000004f},
13497 {0x00000050, 0x00000060, 0x00000070, 0x00000080},
13498 {0x00000090, 0x000000a0, 0x000000b0, 0x000000c0},
13499 {0x000000d0, 0x000000e0, 0x000000f0, 0x000000ff},
13500 {0x00000073, 0x00000077, 0x0000007a, 0x0000007b},
13501 {0x0000007c, 0x0000007d, 0x0000007e, 0x0000007f},
13503 {0x80000001, 0x80000002, 0x80000003, 0x80000004},
13504 {0x800000ff, 0x800000fe, 0x800000fd, 0x800000fc},
13505 {0x800000f2, 0x800000f1, 0x800000f0, 0x800000ef},
13506 {0x8000000a, 0x0000000d, 0x8000000e, 0x8000000f},
13507 {0x8000001a, 0x8000002d, 0x8000003e, 0x8000004f},
13508 {0x80000050, 0x80000060, 0x80000070, 0x00000080},
13509 {0x80000090, 0x800000a0, 0x800000b0, 0x800000c0},
13510 {0x800000d0, 0x800000e0, 0x800000f0, 0x800000ff},
13511 {0x80000073, 0x80000077, 0x8000007a, 0x8000007b},
13512 {0x8000007c, 0x8000007d, 0x8000007e, 0x8000007f},
13514 {0x7fffff01, 0x7fffff02, 0x7fffff03, 0x7fffff04},
13515 {0x7fffffff, 0x7ffffffe, 0x7ffffffd, 0x7ffffffc},
13516 {0x7ffffff2, 0x7ffffff1, 0x7ffffff0, 0x7fffffef},
13517 {0x7fffff0a, 0x7fffff0d, 0x7fffff0e, 0x7fffff0f},
13518 {0x7fffff1a, 0x7fffff2d, 0x7fffff3e, 0x7fffff4f},
13519 {0x7fffff50, 0x7fffff60, 0x7fffff70, 0x7fffff80},
13520 {0x8fffff90, 0x7fffffa0, 0x7fffffb0, 0x7fffffc0},
13521 {0x7fffffd0, 0x7fffffe0, 0x7ffffff0, 0x7fffffff},
13522 {0x7fffff73, 0x7fffff77, 0x7fffff7a, 0x7fffff7b},
13523 {0x7fffff7c, 0x7fffff7d, 0x7fffff7e, 0x7fffff7f},
13525 {0xffffff01, 0xffffff02, 0xffffff03, 0xffffff04},
13526 {0xffffffff, 0xfffffffe, 0xfffffffd, 0xfffffffc},
13527 {0xfffffff2, 0xfffffff1, 0xfffffff0, 0xffffffef},
13528 {0xffffff0a, 0xffffff0d, 0xffffff0e, 0xffffff0f},
13529 {0xffffff1a, 0xffffff2d, 0xffffff3e, 0xffffff4f},
13530 {0xffffff50, 0xffffff60, 0xffffff70, 0xffffff80},
13531 {0xffffff90, 0xffffffa0, 0xffffffb0, 0xffffffc0},
13532 {0xffffffd0, 0xffffffe0, 0xfffffff0, 0xffffffff},
13533 {0xffffff73, 0xffffff77, 0xffffff7a, 0xffffff7b},
13534 {0xffffff7c, 0xffffff7d, 0xffffff7e, 0xffffff7f},
13537 device_desc.feature_level = &feature_level;
13538 device_desc.flags = 0;
13539 if (!(device = create_device(&device_desc)))
13541 skip("Failed to create device for feature level %#x.\n", feature_level);
13542 return;
13545 ID3D11Device_GetImmediateContext(device, &context);
13547 /* Structured buffer views */
13548 buffer_desc.ByteWidth = 64;
13549 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
13550 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
13551 buffer_desc.CPUAccessFlags = 0;
13552 buffer_desc.MiscFlags = 0;
13553 buffer_desc.StructureByteStride = 0;
13554 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
13555 buffer_desc.StructureByteStride = 4;
13556 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
13557 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
13559 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
13560 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13562 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
13563 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
13564 U(uav_desc).Buffer.FirstElement = 0;
13565 U(uav_desc).Buffer.NumElements = 4;
13566 U(uav_desc).Buffer.Flags = 0;
13567 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
13568 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13570 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
13572 uvec4 = uvec4_data[i];
13573 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
13574 get_buffer_readback(buffer, &rb);
13575 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
13577 DWORD data = get_readback_color(&rb, x, 0, 0);
13578 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
13580 release_resource_readback(&rb);
13582 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
13583 get_buffer_readback(buffer, &rb);
13584 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
13586 DWORD data = get_readback_color(&rb, x, 0, 0);
13587 uvec4 = x < U(uav_desc).Buffer.NumElements ? fe_uvec4 : uvec4_data[i];
13588 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
13590 release_resource_readback(&rb);
13593 ID3D11Buffer_Release(buffer);
13594 ID3D11UnorderedAccessView_Release(uav);
13595 ID3D11UnorderedAccessView_Release(uav2);
13597 /* Raw buffer views */
13598 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
13599 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
13600 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
13602 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
13603 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
13604 U(uav_desc).Buffer.FirstElement = 0;
13605 U(uav_desc).Buffer.NumElements = 16;
13606 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
13607 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
13608 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13609 U(uav_desc).Buffer.FirstElement = 8;
13610 U(uav_desc).Buffer.NumElements = 8;
13611 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
13612 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13614 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
13616 uvec4 = uvec4_data[i];
13617 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
13618 get_buffer_readback(buffer, &rb);
13619 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
13621 DWORD data = get_readback_color(&rb, x, 0, 0);
13622 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
13624 release_resource_readback(&rb);
13626 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
13627 get_buffer_readback(buffer, &rb);
13628 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
13630 DWORD data = get_readback_color(&rb, x, 0, 0);
13631 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
13632 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
13634 release_resource_readback(&rb);
13637 ID3D11Buffer_Release(buffer);
13638 ID3D11UnorderedAccessView_Release(uav);
13639 ID3D11UnorderedAccessView_Release(uav2);
13641 /* Typed buffer views */
13642 buffer_desc.MiscFlags = 0;
13643 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
13644 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
13646 uav_desc.Format = DXGI_FORMAT_R32_SINT;
13647 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
13648 U(uav_desc).Buffer.FirstElement = 0;
13649 U(uav_desc).Buffer.NumElements = 16;
13650 U(uav_desc).Buffer.Flags = 0;
13651 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
13652 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13653 U(uav_desc).Buffer.FirstElement = 9;
13654 U(uav_desc).Buffer.NumElements = 7;
13655 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
13656 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13658 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
13660 uvec4 = uvec4_data[i];
13661 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
13662 get_buffer_readback(buffer, &rb);
13663 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
13665 DWORD data = get_readback_color(&rb, x, 0, 0);
13666 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
13668 release_resource_readback(&rb);
13670 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
13671 get_buffer_readback(buffer, &rb);
13672 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
13674 DWORD data = get_readback_color(&rb, x, 0, 0);
13675 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
13676 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
13678 release_resource_readback(&rb);
13681 ID3D11UnorderedAccessView_Release(uav);
13682 ID3D11UnorderedAccessView_Release(uav2);
13684 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
13685 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
13686 U(uav_desc).Buffer.FirstElement = 0;
13687 U(uav_desc).Buffer.NumElements = 4;
13688 U(uav_desc).Buffer.Flags = 0;
13689 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
13690 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13691 U(uav_desc).Buffer.FirstElement = 2;
13692 U(uav_desc).Buffer.NumElements = 2;
13693 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
13694 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13696 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
13698 uvec4 = uvec4_data[i];
13699 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
13700 get_buffer_readback(buffer, &rb);
13701 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
13703 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
13704 const struct uvec4 broken_result = {uvec4.x, uvec4.x, uvec4.x, uvec4.x}; /* Intel */
13705 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
13706 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
13707 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
13709 release_resource_readback(&rb);
13711 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
13712 get_buffer_readback(buffer, &rb);
13713 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
13715 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
13716 struct uvec4 broken_result;
13717 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
13718 broken_result.x = broken_result.y = broken_result.z = broken_result.w = uvec4.x;
13719 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
13720 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
13721 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
13723 release_resource_readback(&rb);
13726 uvec4.x = uvec4.y = uvec4.z = uvec4.w = 0xdeadbeef;
13727 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
13728 ID3D11UnorderedAccessView_Release(uav);
13729 ID3D11UnorderedAccessView_Release(uav2);
13731 uav_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT;
13732 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
13733 U(uav_desc).Buffer.FirstElement = 0;
13734 U(uav_desc).Buffer.NumElements = 16;
13735 U(uav_desc).Buffer.Flags = 0;
13736 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
13737 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13738 U(uav_desc).Buffer.FirstElement = 8;
13739 U(uav_desc).Buffer.NumElements = 8;
13740 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
13741 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13743 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
13745 uvec4 = uvec4_data[i];
13746 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
13747 get_buffer_readback(buffer, &rb);
13748 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
13749 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0, 0), &uvec4);
13750 release_resource_readback(&rb);
13752 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
13753 get_buffer_readback(buffer, &rb);
13754 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
13756 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
13757 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0, 0), &uvec4);
13759 release_resource_readback(&rb);
13762 ID3D11UnorderedAccessView_Release(uav);
13763 ID3D11UnorderedAccessView_Release(uav2);
13765 ID3D11Buffer_Release(buffer);
13767 ID3D11DeviceContext_Release(context);
13768 refcount = ID3D11Device_Release(device);
13769 ok(!refcount, "Device has %u references left.\n", refcount);
13772 static void test_initial_depth_stencil_state(void)
13774 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
13775 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
13776 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13777 struct d3d11_test_context test_context;
13778 D3D11_TEXTURE2D_DESC texture_desc;
13779 ID3D11DeviceContext *context;
13780 ID3D11DepthStencilView *dsv;
13781 ID3D11Texture2D *texture;
13782 ID3D11Device *device;
13783 unsigned int count;
13784 D3D11_VIEWPORT vp;
13785 HRESULT hr;
13787 if (!init_test_context(&test_context, NULL))
13788 return;
13790 device = test_context.device;
13791 context = test_context.immediate_context;
13793 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13794 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
13795 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
13796 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13797 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13799 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
13800 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
13802 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
13804 count = 1;
13805 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
13807 /* check if depth function is D3D11_COMPARISON_LESS */
13808 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
13809 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
13810 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.4f);
13811 draw_color_quad(&test_context, &green);
13812 draw_color_quad(&test_context, &red);
13813 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.6f, 0.6f);
13814 draw_color_quad(&test_context, &red);
13815 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
13816 check_texture_float(texture, 0.4f, 1);
13818 ID3D11DepthStencilView_Release(dsv);
13819 ID3D11Texture2D_Release(texture);
13820 release_test_context(&test_context);
13823 static void test_draw_depth_only(void)
13825 struct d3d11_test_context test_context;
13826 ID3D11PixelShader *ps_color, *ps_depth;
13827 D3D11_TEXTURE2D_DESC texture_desc;
13828 ID3D11DeviceContext *context;
13829 ID3D11DepthStencilView *dsv;
13830 struct resource_readback rb;
13831 ID3D11Texture2D *texture;
13832 ID3D11Device *device;
13833 unsigned int i, j;
13834 struct vec4 depth;
13835 ID3D11Buffer *cb;
13836 HRESULT hr;
13838 static const DWORD ps_color_code[] =
13840 #if 0
13841 float4 main(float4 position : SV_POSITION) : SV_Target
13843 return float4(0.0, 1.0, 0.0, 1.0);
13845 #endif
13846 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
13847 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13848 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
13849 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13850 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
13851 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
13852 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
13854 static const DWORD ps_depth_code[] =
13856 #if 0
13857 float depth;
13859 float main() : SV_Depth
13861 return depth;
13863 #endif
13864 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
13865 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13866 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
13867 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
13868 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
13869 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
13872 if (!init_test_context(&test_context, NULL))
13873 return;
13875 device = test_context.device;
13876 context = test_context.immediate_context;
13878 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
13880 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13881 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
13882 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
13883 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13884 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13886 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
13887 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
13889 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
13890 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13891 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
13892 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13894 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13895 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
13896 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
13898 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
13899 check_texture_float(texture, 1.0f, 1);
13900 draw_quad(&test_context);
13901 check_texture_float(texture, 0.0f, 1);
13903 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
13905 depth.x = 0.7f;
13906 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
13907 draw_quad(&test_context);
13908 check_texture_float(texture, 0.0f, 1);
13909 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
13910 check_texture_float(texture, 1.0f, 1);
13911 draw_quad(&test_context);
13912 check_texture_float(texture, 0.7f, 1);
13913 depth.x = 0.8f;
13914 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
13915 draw_quad(&test_context);
13916 check_texture_float(texture, 0.7f, 1);
13917 depth.x = 0.5f;
13918 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
13919 draw_quad(&test_context);
13920 check_texture_float(texture, 0.5f, 1);
13922 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
13923 for (i = 0; i < 4; ++i)
13925 for (j = 0; j < 4; ++j)
13927 depth.x = 1.0f / 16.0f * (j + 4 * i);
13928 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
13930 set_viewport(context, 160.0f * j, 120.0f * i, 160.0f, 120.0f, 0.0f, 1.0f);
13932 draw_quad(&test_context);
13935 get_texture_readback(texture, 0, &rb);
13936 for (i = 0; i < 4; ++i)
13938 for (j = 0; j < 4; ++j)
13940 float obtained_depth, expected_depth;
13942 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
13943 expected_depth = 1.0f / 16.0f * (j + 4 * i);
13944 ok(compare_float(obtained_depth, expected_depth, 1),
13945 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
13946 obtained_depth, j, i, expected_depth);
13949 release_resource_readback(&rb);
13951 ID3D11Buffer_Release(cb);
13952 ID3D11PixelShader_Release(ps_color);
13953 ID3D11PixelShader_Release(ps_depth);
13954 ID3D11DepthStencilView_Release(dsv);
13955 ID3D11Texture2D_Release(texture);
13956 release_test_context(&test_context);
13959 static void test_draw_uav_only(void)
13961 struct d3d11_test_context test_context;
13962 D3D11_TEXTURE2D_DESC texture_desc;
13963 ID3D11UnorderedAccessView *uav;
13964 ID3D11DeviceContext *context;
13965 ID3D11Texture2D *texture;
13966 ID3D11PixelShader *ps;
13967 ID3D11Device *device;
13968 HRESULT hr;
13970 static const DWORD ps_code[] =
13972 #if 0
13973 RWTexture2D<int> u;
13975 void main()
13977 InterlockedAdd(u[uint2(0, 0)], 1);
13979 #endif
13980 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
13981 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13982 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
13983 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
13984 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
13986 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13987 static const UINT values[4] = {0};
13989 if (!init_test_context(&test_context, &feature_level))
13990 return;
13992 device = test_context.device;
13993 context = test_context.immediate_context;
13995 texture_desc.Width = 1;
13996 texture_desc.Height = 1;
13997 texture_desc.MipLevels = 1;
13998 texture_desc.ArraySize = 1;
13999 texture_desc.Format = DXGI_FORMAT_R32_SINT;
14000 texture_desc.SampleDesc.Count = 1;
14001 texture_desc.SampleDesc.Quality = 0;
14002 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14003 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14004 texture_desc.CPUAccessFlags = 0;
14005 texture_desc.MiscFlags = 0;
14007 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14008 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14010 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
14011 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
14013 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14014 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14016 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14017 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
14018 0, 1, &uav, NULL);
14020 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
14021 set_viewport(context, 0.0f, 0.0f, 10.0f, 10.0f, 0.0f, 0.0f);
14022 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
14023 draw_quad(&test_context);
14024 check_texture_color(texture, 100, 1);
14026 draw_quad(&test_context);
14027 draw_quad(&test_context);
14028 draw_quad(&test_context);
14029 draw_quad(&test_context);
14030 check_texture_color(texture, 500, 1);
14032 ID3D11PixelShader_Release(ps);
14033 ID3D11Texture2D_Release(texture);
14034 ID3D11UnorderedAccessView_Release(uav);
14035 release_test_context(&test_context);
14038 static void test_cb_relative_addressing(void)
14040 struct d3d11_test_context test_context;
14041 ID3D11Buffer *colors_cb, *index_cb;
14042 unsigned int i, index[4] = {0};
14043 ID3D11DeviceContext *context;
14044 ID3D11PixelShader *ps;
14045 ID3D11Device *device;
14046 HRESULT hr;
14048 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
14050 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
14052 static const DWORD vs_code[] =
14054 #if 0
14055 int color_index;
14057 cbuffer colors
14059 float4 colors[8];
14062 struct vs_in
14064 float4 position : POSITION;
14067 struct vs_out
14069 float4 position : SV_POSITION;
14070 float4 color : COLOR;
14073 vs_out main(const vs_in v)
14075 vs_out o;
14077 o.position = v.position;
14078 o.color = colors[color_index];
14080 return o;
14082 #endif
14083 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
14084 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14085 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
14086 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
14087 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
14088 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
14089 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
14090 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
14091 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
14092 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
14093 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
14094 0x0100003e,
14096 static const DWORD ps_code[] =
14098 #if 0
14099 struct ps_in
14101 float4 position : SV_POSITION;
14102 float4 color : COLOR;
14105 float4 main(const ps_in v) : SV_TARGET
14107 return v.color;
14109 #endif
14110 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
14111 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14112 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14113 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14114 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14115 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
14116 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14117 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
14119 static const struct
14121 float color[4];
14123 colors[10] =
14125 {{0.0f, 0.0f, 0.0f, 1.0f}},
14126 {{0.0f, 0.0f, 1.0f, 0.0f}},
14127 {{0.0f, 0.0f, 1.0f, 1.0f}},
14128 {{0.0f, 1.0f, 0.0f, 0.0f}},
14129 {{0.0f, 1.0f, 0.0f, 1.0f}},
14130 {{0.0f, 1.0f, 1.0f, 0.0f}},
14131 {{0.0f, 1.0f, 1.0f, 1.0f}},
14132 {{1.0f, 0.0f, 0.0f, 0.0f}},
14133 {{1.0f, 0.0f, 0.0f, 1.0f}},
14134 {{1.0f, 0.0f, 1.0f, 0.0f}},
14136 static const struct
14138 unsigned int index;
14139 DWORD expected;
14141 test_data[] =
14143 {0, 0xff000000},
14144 {1, 0x00ff0000},
14145 {2, 0xffff0000},
14146 {3, 0x0000ff00},
14147 {4, 0xff00ff00},
14148 {5, 0x00ffff00},
14149 {6, 0xffffff00},
14150 {7, 0x000000ff},
14152 {8, 0xff0000ff},
14153 {9, 0x00ff00ff},
14155 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
14156 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
14158 if (!init_test_context(&test_context, &feature_level))
14159 return;
14161 device = test_context.device;
14162 context = test_context.immediate_context;
14164 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
14165 vs_code, sizeof(vs_code), &test_context.input_layout);
14166 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
14168 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
14169 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
14171 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14172 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14174 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
14175 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
14176 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14178 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
14180 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
14182 index[0] = test_data[i].index;
14183 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
14185 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
14186 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
14189 ID3D11Buffer_Release(index_cb);
14190 ID3D11Buffer_Release(colors_cb);
14191 ID3D11PixelShader_Release(ps);
14193 release_test_context(&test_context);
14196 static void test_vs_input_relative_addressing(void)
14198 struct d3d11_test_context test_context;
14199 ID3D11DeviceContext *context;
14200 unsigned int offset, stride;
14201 unsigned int index[4] = {0};
14202 ID3D11PixelShader *ps;
14203 ID3D11Buffer *vb, *cb;
14204 ID3D11Device *device;
14205 unsigned int i;
14206 HRESULT hr;
14208 static const DWORD vs_code[] =
14210 #if 0
14211 struct vertex
14213 float4 position : POSITION;
14214 float4 colors[4] : COLOR;
14217 uint index;
14219 void main(vertex vin, out float4 position : SV_Position,
14220 out float4 color : COLOR)
14222 position = vin.position;
14223 color = vin.colors[index];
14225 #endif
14226 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003,
14227 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080,
14228 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000,
14229 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
14230 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089,
14231 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300,
14232 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
14233 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
14234 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4,
14235 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2,
14236 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f,
14237 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000,
14238 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2,
14239 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036,
14240 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001,
14241 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
14243 static const DWORD ps_code[] =
14245 #if 0
14246 struct vs_out
14248 float4 position : SV_POSITION;
14249 float4 color : COLOR;
14252 float4 main(struct vs_out i) : SV_TARGET
14254 return i.color;
14256 #endif
14257 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
14258 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14259 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14260 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14261 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14262 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
14263 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
14264 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
14266 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
14268 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
14269 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1},
14270 {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D11_INPUT_PER_INSTANCE_DATA, 1},
14271 {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D11_INPUT_PER_INSTANCE_DATA, 1},
14272 {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D11_INPUT_PER_INSTANCE_DATA, 1},
14274 static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f};
14275 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
14277 if (!init_test_context(&test_context, NULL))
14278 return;
14279 device = test_context.device;
14280 context = test_context.immediate_context;
14282 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
14283 vs_code, sizeof(vs_code), &test_context.input_layout);
14284 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
14286 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
14287 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
14289 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(colors), colors);
14290 stride = sizeof(colors);
14291 offset = 0;
14292 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
14294 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14295 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14296 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14298 for (i = 0; i < ARRAY_SIZE(colors); ++i)
14300 *index = i;
14301 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
14302 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
14303 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
14304 check_texture_color(test_context.backbuffer, colors[i], 1);
14307 ID3D11Buffer_Release(cb);
14308 ID3D11Buffer_Release(vb);
14309 ID3D11PixelShader_Release(ps);
14310 release_test_context(&test_context);
14313 static void test_getdc(void)
14315 static const struct
14317 const char *name;
14318 DXGI_FORMAT format;
14319 BOOL getdc_supported;
14321 testdata[] =
14323 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
14324 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
14325 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
14326 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
14327 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
14328 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
14330 struct device_desc device_desc;
14331 D3D11_TEXTURE2D_DESC desc;
14332 ID3D11Texture2D *texture;
14333 IDXGISurface1 *surface;
14334 ID3D11Device *device;
14335 unsigned int i;
14336 ULONG refcount;
14337 HRESULT hr;
14338 HDC dc;
14340 device_desc.feature_level = NULL;
14341 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
14342 if (!(device = create_device(&device_desc)))
14344 skip("Failed to create device.\n");
14345 return;
14348 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
14349 desc.Width = 512;
14350 desc.Height = 512;
14351 desc.MipLevels = 1;
14352 desc.ArraySize = 1;
14353 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
14354 desc.SampleDesc.Count = 1;
14355 desc.SampleDesc.Quality = 0;
14356 desc.Usage = D3D11_USAGE_DEFAULT;
14357 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
14358 desc.CPUAccessFlags = 0;
14359 desc.MiscFlags = 0;
14360 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
14361 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14363 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
14364 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
14366 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
14367 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
14369 IDXGISurface1_Release(surface);
14370 ID3D11Texture2D_Release(texture);
14372 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
14373 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
14374 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14376 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
14377 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
14379 hr = IDXGISurface1_ReleaseDC(surface, NULL);
14380 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
14382 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
14383 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
14385 hr = IDXGISurface1_ReleaseDC(surface, NULL);
14386 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
14388 IDXGISurface1_Release(surface);
14389 ID3D11Texture2D_Release(texture);
14391 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
14393 static const unsigned int bit_count = 32;
14394 unsigned int width_bytes;
14395 DIBSECTION dib;
14396 HBITMAP bitmap;
14397 DWORD type;
14398 int size;
14400 desc.Width = 64;
14401 desc.Height = 64;
14402 desc.MipLevels = 1;
14403 desc.ArraySize = 1;
14404 desc.Format = testdata[i].format;
14405 desc.SampleDesc.Count = 1;
14406 desc.SampleDesc.Quality = 0;
14407 desc.Usage = D3D11_USAGE_STAGING;
14408 desc.BindFlags = 0;
14409 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
14410 desc.MiscFlags = 0;
14412 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
14413 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14414 ID3D11Texture2D_Release(texture);
14416 /* STAGING usage, requesting GDI compatibility mode. */
14417 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
14418 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
14419 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
14421 desc.Usage = D3D11_USAGE_DEFAULT;
14422 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
14423 desc.CPUAccessFlags = 0;
14424 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
14425 if (testdata[i].getdc_supported)
14426 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
14427 else
14428 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
14430 if (FAILED(hr))
14431 continue;
14433 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
14434 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
14436 dc = (void *)0x1234;
14437 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
14438 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
14440 if (FAILED(hr))
14442 IDXGISurface1_Release(surface);
14443 ID3D11Texture2D_Release(texture);
14444 continue;
14447 type = GetObjectType(dc);
14448 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
14449 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
14450 type = GetObjectType(bitmap);
14451 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
14453 size = GetObjectA(bitmap, sizeof(dib), &dib);
14454 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
14455 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
14457 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
14458 dib.dsBm.bmType, testdata[i].name);
14459 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
14460 dib.dsBm.bmWidth, testdata[i].name);
14461 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
14462 dib.dsBm.bmHeight, testdata[i].name);
14463 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
14464 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
14465 dib.dsBm.bmWidthBytes, testdata[i].name);
14466 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
14467 dib.dsBm.bmPlanes, testdata[i].name);
14468 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
14469 dib.dsBm.bmBitsPixel, testdata[i].name);
14471 if (size == sizeof(dib))
14472 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
14473 dib.dsBm.bmBits, testdata[i].name);
14474 else
14475 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
14476 dib.dsBm.bmBits, testdata[i].name);
14478 if (size == sizeof(dib))
14480 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
14481 dib.dsBmih.biSize, testdata[i].name);
14482 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
14483 dib.dsBmih.biHeight, testdata[i].name);
14484 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
14485 dib.dsBmih.biHeight, testdata[i].name);
14486 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
14487 dib.dsBmih.biPlanes, testdata[i].name);
14488 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
14489 dib.dsBmih.biBitCount, testdata[i].name);
14490 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
14491 dib.dsBmih.biCompression, testdata[i].name);
14492 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
14493 dib.dsBmih.biSizeImage, testdata[i].name);
14494 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
14495 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
14496 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
14497 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
14498 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
14499 dib.dsBmih.biClrUsed, testdata[i].name);
14500 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
14501 dib.dsBmih.biClrImportant, testdata[i].name);
14502 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
14503 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
14504 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
14505 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
14506 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
14509 hr = IDXGISurface1_ReleaseDC(surface, NULL);
14510 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
14512 IDXGISurface1_Release(surface);
14513 ID3D11Texture2D_Release(texture);
14516 refcount = ID3D11Device_Release(device);
14517 ok(!refcount, "Device has %u references left.\n", refcount);
14520 static void test_shader_stage_input_output_matching(void)
14522 struct d3d11_test_context test_context;
14523 D3D11_TEXTURE2D_DESC texture_desc;
14524 ID3D11Texture2D *render_target;
14525 ID3D11RenderTargetView *rtv[2];
14526 ID3D11DeviceContext *context;
14527 ID3D11VertexShader *vs;
14528 ID3D11PixelShader *ps;
14529 ID3D11Device *device;
14530 HRESULT hr;
14532 static const DWORD vs_code[] =
14534 #if 0
14535 struct output
14537 float4 position : SV_PoSiTion;
14538 float4 color0 : COLOR0;
14539 float4 color1 : COLOR1;
14542 void main(uint id : SV_VertexID, out output o)
14544 float2 coords = float2((id << 1) & 2, id & 2);
14545 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
14546 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
14547 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
14549 #endif
14550 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
14551 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14552 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
14553 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
14554 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
14555 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
14556 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
14557 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
14558 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
14559 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
14560 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
14561 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
14562 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
14563 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
14564 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
14565 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
14566 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
14567 0x0100003e,
14569 static const DWORD ps_code[] =
14571 #if 0
14572 struct input
14574 float4 position : SV_PoSiTiOn;
14575 float4 color1 : COLOR1;
14576 float4 color0 : COLOR0;
14579 struct output
14581 float4 target0 : SV_Target0;
14582 float4 target1 : SV_Target1;
14585 void main(const in input i, out output o)
14587 o.target0 = i.color0;
14588 o.target1 = i.color1;
14590 #endif
14591 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
14592 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
14593 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
14594 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
14595 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
14596 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
14597 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
14598 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
14599 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
14600 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
14601 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
14604 if (!init_test_context(&test_context, NULL))
14605 return;
14607 device = test_context.device;
14608 context = test_context.immediate_context;
14610 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
14611 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
14612 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14613 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14615 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14616 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
14617 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14619 rtv[0] = test_context.backbuffer_rtv;
14620 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
14621 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14623 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
14624 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14625 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
14626 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
14627 ID3D11DeviceContext_Draw(context, 3, 0);
14629 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
14630 check_texture_color(render_target, 0xff0000ff, 0);
14632 ID3D11RenderTargetView_Release(rtv[1]);
14633 ID3D11Texture2D_Release(render_target);
14634 ID3D11PixelShader_Release(ps);
14635 ID3D11VertexShader_Release(vs);
14636 release_test_context(&test_context);
14639 static void test_shader_interstage_interface(void)
14641 struct d3d11_test_context test_context;
14642 D3D11_TEXTURE2D_DESC texture_desc;
14643 ID3D11InputLayout *input_layout;
14644 ID3D11Texture2D *render_target;
14645 ID3D11DeviceContext *context;
14646 ID3D11RenderTargetView *rtv;
14647 ID3D11VertexShader *vs;
14648 ID3D11PixelShader *ps;
14649 ID3D11Device *device;
14650 UINT stride, offset;
14651 ID3D11Buffer *vb;
14652 unsigned int i;
14653 HRESULT hr;
14655 static const DWORD vs_code[] =
14657 #if 0
14658 struct vertex
14660 float4 position : SV_Position;
14661 float2 t0 : TEXCOORD0;
14662 nointerpolation float t1 : TEXCOORD1;
14663 uint t2 : TEXCOORD2;
14664 uint t3 : TEXCOORD3;
14665 float t4 : TEXCOORD4;
14668 void main(in vertex vin, out vertex vout)
14670 vout = vin;
14672 #endif
14673 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
14674 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
14675 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
14676 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
14677 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
14678 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
14679 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
14680 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
14681 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
14682 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
14683 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
14684 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
14685 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
14686 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
14687 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
14688 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
14689 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
14690 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
14691 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
14692 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
14693 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
14694 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
14696 static const DWORD ps_code[] =
14698 #if 0
14699 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
14700 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
14701 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
14703 o.x = t0.y + t1;
14704 o.y = t2 + t3;
14705 o.z = t4;
14706 o.w = t0.x;
14708 #endif
14709 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
14710 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
14711 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
14712 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
14713 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
14714 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
14715 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
14716 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
14717 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
14718 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
14719 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
14720 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
14721 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
14722 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
14723 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
14725 static const DWORD ps_partial_input_code[] =
14727 #if 0
14728 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
14729 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
14730 uint t3 : TEXCOORD3, out float4 o : SV_Target)
14732 o.x = t0.y + t1;
14733 o.y = t2 + t3;
14734 o.z = 0.0f;
14735 o.w = t0.x;
14737 #endif
14738 0x43425844, 0x5b1db356, 0xaa5a5e9d, 0xb916a081, 0x61e6dcb1, 0x00000001, 0x000001cc, 0x00000003,
14739 0x0000002c, 0x000000cc, 0x00000100, 0x4e475349, 0x00000098, 0x00000005, 0x00000008, 0x00000080,
14740 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
14741 0x00000003, 0x00000001, 0x00000303, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
14742 0x00000101, 0x0000008c, 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x0000008c,
14743 0x00000003, 0x00000000, 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
14744 0x43584554, 0x44524f4f, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14745 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
14746 0x52444853, 0x000000c4, 0x00000040, 0x00000031, 0x03001062, 0x00101032, 0x00000001, 0x03000862,
14747 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042, 0x00000002,
14748 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012, 0x00000000,
14749 0x0010102a, 0x00000002, 0x0010101a, 0x00000002, 0x05000056, 0x00102022, 0x00000000, 0x0010000a,
14750 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a, 0x00000002,
14751 0x05000036, 0x00102042, 0x00000000, 0x00004001, 0x00000000, 0x05000036, 0x00102082, 0x00000000,
14752 0x0010100a, 0x00000001, 0x0100003e,
14754 static const DWORD ps_single_input_code[] =
14756 #if 0
14757 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0, out float4 o : SV_Target)
14759 o.x = t0.x;
14760 o.y = t0.y;
14761 o.z = 1.0f;
14762 o.w = 2.0f;
14764 #endif
14765 0x43425844, 0x7cc601b6, 0xc65b8bdb, 0x54d0f606, 0x9cc74d3d, 0x00000001, 0x00000118, 0x00000003,
14766 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
14767 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14768 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
14769 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
14770 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058,
14771 0x00000040, 0x00000016, 0x03001062, 0x00101032, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14772 0x05000036, 0x00102032, 0x00000000, 0x00101046, 0x00000001, 0x08000036, 0x001020c2, 0x00000000,
14773 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x40000000, 0x0100003e,
14775 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
14777 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
14778 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
14779 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
14780 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
14781 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
14782 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
14784 static const struct
14786 struct vec2 position;
14787 struct vec2 t0;
14788 float t1;
14789 unsigned int t2;
14790 unsigned int t3;
14791 float t4;
14793 quad[] =
14795 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
14796 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
14797 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
14798 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
14800 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
14801 static const struct
14803 const DWORD *ps_code;
14804 size_t ps_size;
14805 struct vec4 expected_result;
14807 tests[] =
14809 {ps_code, sizeof(ps_code), {10.0f, 8.0f, 7.0f, 3.0f}},
14810 {ps_partial_input_code, sizeof(ps_partial_input_code), {10.0f, 8.0f, 0.0f, 3.0f}},
14811 {ps_single_input_code, sizeof(ps_single_input_code), {3.0f, 5.0f, 1.0f, 2.0f}},
14814 if (!init_test_context(&test_context, NULL))
14815 return;
14817 device = test_context.device;
14818 context = test_context.immediate_context;
14820 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
14821 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
14823 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14824 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14825 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
14826 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14828 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
14829 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14831 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
14832 vs_code, sizeof(vs_code), &input_layout);
14833 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
14835 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
14837 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
14839 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14840 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
14841 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
14842 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
14843 offset = 0;
14844 stride = sizeof(*quad);
14845 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
14847 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14849 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_size, NULL, &ps);
14850 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
14851 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14852 ID3D11DeviceContext_Draw(context, 4, 0);
14853 check_texture_vec4(render_target, &tests[i].expected_result, 0);
14854 ID3D11PixelShader_Release(ps);
14857 ID3D11InputLayout_Release(input_layout);
14858 ID3D11RenderTargetView_Release(rtv);
14859 ID3D11Texture2D_Release(render_target);
14860 ID3D11VertexShader_Release(vs);
14861 ID3D11Buffer_Release(vb);
14862 release_test_context(&test_context);
14865 static void test_sm4_if_instruction(void)
14867 struct d3d11_test_context test_context;
14868 ID3D11PixelShader *ps_if_nz, *ps_if_z;
14869 ID3D11DeviceContext *context;
14870 ID3D11Device *device;
14871 unsigned int bits[4];
14872 DWORD expected_color;
14873 ID3D11Buffer *cb;
14874 unsigned int i;
14875 HRESULT hr;
14877 static const DWORD ps_if_nz_code[] =
14879 #if 0
14880 uint bits;
14882 float4 main() : SV_TARGET
14884 if (bits)
14885 return float4(0.0f, 1.0f, 0.0f, 1.0f);
14886 else
14887 return float4(1.0f, 0.0f, 0.0f, 1.0f);
14889 #endif
14890 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
14891 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14892 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14893 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
14894 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
14895 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
14896 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
14897 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
14899 static const DWORD ps_if_z_code[] =
14901 #if 0
14902 uint bits;
14904 float4 main() : SV_TARGET
14906 if (!bits)
14907 return float4(0.0f, 1.0f, 0.0f, 1.0f);
14908 else
14909 return float4(1.0f, 0.0f, 0.0f, 1.0f);
14911 #endif
14912 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
14913 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14914 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14915 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
14916 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
14917 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
14918 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
14919 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
14921 static unsigned int bit_patterns[] =
14923 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
14926 if (!init_test_context(&test_context, NULL))
14927 return;
14929 device = test_context.device;
14930 context = test_context.immediate_context;
14932 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
14933 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
14934 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
14935 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
14937 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
14938 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14940 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
14942 *bits = bit_patterns[i];
14943 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
14945 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
14946 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
14947 draw_quad(&test_context);
14948 check_texture_color(test_context.backbuffer, expected_color, 0);
14950 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
14951 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
14952 draw_quad(&test_context);
14953 check_texture_color(test_context.backbuffer, expected_color, 0);
14956 ID3D11Buffer_Release(cb);
14957 ID3D11PixelShader_Release(ps_if_z);
14958 ID3D11PixelShader_Release(ps_if_nz);
14959 release_test_context(&test_context);
14962 static void test_sm4_breakc_instruction(void)
14964 struct d3d11_test_context test_context;
14965 ID3D11DeviceContext *context;
14966 ID3D11PixelShader *ps;
14967 ID3D11Device *device;
14968 HRESULT hr;
14970 static const DWORD ps_breakc_nz_code[] =
14972 #if 0
14973 float4 main() : SV_TARGET
14975 uint counter = 0;
14977 for (uint i = 0; i < 255; ++i)
14978 ++counter;
14980 if (counter == 255)
14981 return float4(0.0f, 1.0f, 0.0f, 1.0f);
14982 else
14983 return float4(1.0f, 0.0f, 0.0f, 1.0f);
14985 #endif
14986 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
14987 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14988 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14989 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
14990 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
14991 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
14992 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
14993 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
14994 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
14995 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
14996 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
14997 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
14998 0x01000015, 0x0100003e,
15000 static const DWORD ps_breakc_z_code[] =
15002 #if 0
15003 float4 main() : SV_TARGET
15005 uint counter = 0;
15007 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
15008 ++counter;
15010 if (counter == 255)
15011 return float4(0.0f, 1.0f, 0.0f, 1.0f);
15012 else
15013 return float4(1.0f, 0.0f, 0.0f, 1.0f);
15015 #endif
15016 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
15017 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15018 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15019 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
15020 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
15021 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
15022 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
15023 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
15024 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
15025 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
15026 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
15027 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
15028 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
15029 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
15032 if (!init_test_context(&test_context, NULL))
15033 return;
15035 device = test_context.device;
15036 context = test_context.immediate_context;
15038 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
15039 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
15040 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15041 draw_quad(&test_context);
15042 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15043 ID3D11PixelShader_Release(ps);
15045 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
15046 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
15047 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15048 draw_quad(&test_context);
15049 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15050 ID3D11PixelShader_Release(ps);
15052 release_test_context(&test_context);
15055 static void test_sm4_continuec_instruction(void)
15057 struct d3d11_test_context test_context;
15058 ID3D11DeviceContext *context;
15059 ID3D11PixelShader *ps;
15060 ID3D11Device *device;
15061 HRESULT hr;
15063 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
15064 * with a normal continue inside, the shaders have been compiled with
15065 * the /Gfa flag. */
15066 static const DWORD ps_continuec_nz_code[] =
15068 #if 0
15069 float4 main() : SV_TARGET
15071 uint counter = 0;
15072 int i = -1;
15074 while (i < 255) {
15075 ++i;
15077 if (i != 0)
15078 continue;
15080 ++counter;
15083 if (counter == 1)
15084 return float4(0.0f, 1.0f, 0.0f, 1.0f);
15085 else
15086 return float4(1.0f, 0.0f, 0.0f, 1.0f);
15088 #endif
15089 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
15090 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15091 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15092 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
15093 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
15094 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
15095 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
15096 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
15097 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
15098 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
15099 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
15100 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
15101 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
15102 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
15103 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
15104 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
15105 0x3f800000, 0x0100003e,
15108 static const DWORD ps_continuec_z_code[] =
15110 #if 0
15111 float4 main() : SV_TARGET
15113 uint counter = 0;
15114 int i = -1;
15116 while (i < 255) {
15117 ++i;
15119 if (i == 0)
15120 continue;
15122 ++counter;
15125 if (counter == 255)
15126 return float4(0.0f, 1.0f, 0.0f, 1.0f);
15127 else
15128 return float4(1.0f, 0.0f, 0.0f, 1.0f);
15130 #endif
15131 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
15132 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15133 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15134 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
15135 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
15136 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
15137 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
15138 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
15139 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
15140 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
15141 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
15142 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
15143 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
15144 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
15145 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
15148 if (!init_test_context(&test_context, NULL))
15149 return;
15151 device = test_context.device;
15152 context = test_context.immediate_context;
15154 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), NULL, &ps);
15155 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
15156 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15157 draw_quad(&test_context);
15158 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15159 ID3D11PixelShader_Release(ps);
15161 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), NULL, &ps);
15162 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
15163 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15164 draw_quad(&test_context);
15165 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15166 ID3D11PixelShader_Release(ps);
15168 release_test_context(&test_context);
15171 static void test_sm4_discard_instruction(void)
15173 ID3D11PixelShader *ps_discard_nz, *ps_discard_z;
15174 struct d3d11_test_context test_context;
15175 ID3D11DeviceContext *context;
15176 ID3D11Device *device;
15177 ID3D11Buffer *cb;
15178 unsigned int i;
15179 HRESULT hr;
15181 static const DWORD ps_discard_nz_code[] =
15183 #if 0
15184 uint data;
15186 float4 main() : SV_Target
15188 if (data)
15189 discard;
15190 return float4(0.0f, 0.5f, 0.0f, 1.0f);
15192 #endif
15193 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
15194 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15195 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15196 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
15197 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
15198 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
15199 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
15201 static const DWORD ps_discard_z_code[] =
15203 #if 0
15204 uint data;
15206 float4 main() : SV_Target
15208 if (!data)
15209 discard;
15210 return float4(0.0f, 1.0f, 0.0f, 1.0f);
15212 #endif
15213 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
15214 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15215 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15216 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
15217 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
15218 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
15219 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
15221 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
15222 static const struct uvec4 values[] =
15224 {0x0000000},
15225 {0x0000001},
15226 {0x8000000},
15227 {0xfffffff},
15230 if (!init_test_context(&test_context, NULL))
15231 return;
15233 device = test_context.device;
15234 context = test_context.immediate_context;
15236 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
15237 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
15239 hr = ID3D11Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code),
15240 NULL, &ps_discard_nz);
15241 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
15242 hr = ID3D11Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code),
15243 NULL, &ps_discard_z);
15244 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
15246 for (i = 0; i < ARRAY_SIZE(values); ++i)
15248 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &values[i], 0, 0);
15250 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
15251 ID3D11DeviceContext_PSSetShader(context, ps_discard_nz, NULL, 0);
15252 draw_quad(&test_context);
15253 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
15255 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
15256 ID3D11DeviceContext_PSSetShader(context, ps_discard_z, NULL, 0);
15257 draw_quad(&test_context);
15258 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
15261 ID3D11Buffer_Release(cb);
15262 ID3D11PixelShader_Release(ps_discard_nz);
15263 ID3D11PixelShader_Release(ps_discard_z);
15264 release_test_context(&test_context);
15267 static void test_sm5_swapc_instruction(void)
15269 struct input
15271 struct uvec4 src0;
15272 struct uvec4 src1;
15273 struct uvec4 src2;
15276 struct d3d11_test_context test_context;
15277 D3D11_TEXTURE2D_DESC texture_desc;
15278 ID3D11DeviceContext *context;
15279 ID3D11RenderTargetView *rtv;
15280 ID3D11Texture2D *texture;
15281 ID3D11PixelShader *ps[6];
15282 ID3D11Device *device;
15283 ID3D11Buffer *cb;
15284 unsigned int i;
15285 HRESULT hr;
15287 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15288 static const DWORD ps_swapc0_code[] =
15290 #if 0
15291 ps_5_0
15292 dcl_globalFlags refactoringAllowed
15293 dcl_constantbuffer cb0[3], immediateIndexed
15294 dcl_output o0.xyzw
15295 dcl_temps 2
15296 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
15297 mov o0.xyzw, r0.xyzw
15299 #endif
15300 0x43425844, 0x9e089246, 0x9f8b5cbe, 0xbac66faf, 0xaef23488, 0x00000001, 0x000000f8, 0x00000003,
15301 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15302 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
15303 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
15304 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
15305 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
15306 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
15307 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
15309 static const DWORD ps_swapc1_code[] =
15311 #if 0
15312 ps_5_0
15313 dcl_globalFlags refactoringAllowed
15314 dcl_constantbuffer cb0[3], immediateIndexed
15315 dcl_output o0.xyzw
15316 dcl_temps 2
15317 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
15318 mov o0.xyzw, r1.xyzw
15320 #endif
15321 0x43425844, 0xf2daed61, 0xede211f7, 0x7300dbea, 0x573ed49f, 0x00000001, 0x000000f8, 0x00000003,
15322 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15323 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
15324 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
15325 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
15326 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
15327 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
15328 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
15330 static const DWORD ps_swapc2_code[] =
15332 #if 0
15333 ps_5_0
15334 dcl_globalFlags refactoringAllowed
15335 dcl_constantbuffer cb0[3], immediateIndexed
15336 dcl_output o0.xyzw
15337 dcl_temps 2
15338 mov r0.xyzw, cb0[1].xyzw
15339 mov r1.xyzw, cb0[2].xyzw
15340 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
15341 mov o0.xyzw, r0.xyzw
15343 #endif
15344 0x43425844, 0x230fcb22, 0x70d99148, 0x65814d89, 0x97473498, 0x00000001, 0x00000120, 0x00000003,
15345 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15346 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
15347 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
15348 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
15349 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
15350 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
15351 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
15352 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
15354 static const DWORD ps_swapc3_code[] =
15356 #if 0
15357 ps_5_0
15358 dcl_globalFlags refactoringAllowed
15359 dcl_constantbuffer cb0[3], immediateIndexed
15360 dcl_output o0.xyzw
15361 dcl_temps 2
15362 mov r0.xyzw, cb0[1].xyzw
15363 mov r1.xyzw, cb0[2].xyzw
15364 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
15365 mov o0.xyzw, r1.xyzw
15367 #endif
15368 0x43425844, 0xce595d62, 0x98305541, 0xb04e74c8, 0xfc010f3a, 0x00000001, 0x00000120, 0x00000003,
15369 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15370 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
15371 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
15372 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
15373 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
15374 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
15375 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
15376 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
15378 static const DWORD ps_swapc4_code[] =
15380 #if 0
15381 ps_5_0
15382 dcl_globalFlags refactoringAllowed
15383 dcl_constantbuffer cb0[3], immediateIndexed
15384 dcl_output o0.xyzw
15385 dcl_temps 2
15386 mov r0.xyzw, cb0[0].xyzw
15387 swapc r0.xyzw, r1.xyzw, r0.xyzw, cb0[1].xyzw, cb0[2].xyzw
15388 mov o0.xyzw, r0.xyzw
15390 #endif
15391 0x43425844, 0x72067c48, 0xb53572a0, 0x9dd9e0fd, 0x903e37e3, 0x00000001, 0x0000010c, 0x00000003,
15392 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15393 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
15394 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
15395 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
15396 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
15397 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000000, 0x00208e46,
15398 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
15399 0x00100e46, 0x00000000, 0x0100003e,
15401 static const DWORD ps_swapc5_code[] =
15403 #if 0
15404 ps_5_0
15405 dcl_globalFlags refactoringAllowed
15406 dcl_constantbuffer cb0[3], immediateIndexed
15407 dcl_output o0.xyzw
15408 dcl_temps 2
15409 mov r1.xyzw, cb0[0].xyzw
15410 swapc r0.xyzw, r1.xyzw, r1.xyzw, cb0[1].xyzw, cb0[2].xyzw
15411 mov o0.xyzw, r1.xyzw
15413 #endif
15414 0x43425844, 0x7078fb08, 0xdd24cd44, 0x469d3258, 0x9e33a0bc, 0x00000001, 0x0000010c, 0x00000003,
15415 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15416 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
15417 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
15418 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
15419 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000,
15420 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001, 0x00208e46,
15421 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
15422 0x00100e46, 0x00000001, 0x0100003e,
15424 static const struct
15426 struct input input;
15427 struct uvec4 dst0;
15428 struct uvec4 dst1;
15430 tests[] =
15433 {{0, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
15434 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}
15437 {{1, 1, 1, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
15438 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
15441 {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
15442 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
15443 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
15446 {{1, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
15447 {0xaaaa, 0xc0de, 0xcccc, 0xeeee}, {0xdead, 0xbbbb, 0xffff, 0xdddd},
15450 {{1, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
15451 {0xaaaa, 0xc0de, 0xffff, 0xdddd}, {0xdead, 0xbbbb, 0xcccc, 0xeeee},
15454 {{1, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
15455 {0xaaaa, 0xc0de, 0xffff, 0xeeee}, {0xdead, 0xbbbb, 0xcccc, 0xdddd}
15458 {{0, 1, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
15459 {0xdead, 0xbbbb, 0xffff, 0xeeee}, {0xaaaa, 0xc0de, 0xcccc, 0xdddd}
15462 {{0, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
15463 {0xdead, 0xc0de, 0xcccc, 0xeeee}, {0xaaaa, 0xbbbb, 0xffff, 0xdddd}
15466 {{0, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
15467 {0xdead, 0xc0de, 0xffff, 0xdddd}, {0xaaaa, 0xbbbb, 0xcccc, 0xeeee},
15471 if (!init_test_context(&test_context, &feature_level))
15472 return;
15474 device = test_context.device;
15475 context = test_context.immediate_context;
15477 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
15478 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
15479 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15480 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15482 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15483 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15485 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15487 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct input), NULL);
15488 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
15490 hr = ID3D11Device_CreatePixelShader(device, ps_swapc0_code, sizeof(ps_swapc0_code), NULL, &ps[0]);
15491 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15492 hr = ID3D11Device_CreatePixelShader(device, ps_swapc1_code, sizeof(ps_swapc1_code), NULL, &ps[1]);
15493 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15494 hr = ID3D11Device_CreatePixelShader(device, ps_swapc2_code, sizeof(ps_swapc2_code), NULL, &ps[2]);
15495 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15496 hr = ID3D11Device_CreatePixelShader(device, ps_swapc3_code, sizeof(ps_swapc3_code), NULL, &ps[3]);
15497 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15498 hr = ID3D11Device_CreatePixelShader(device, ps_swapc4_code, sizeof(ps_swapc4_code), NULL, &ps[4]);
15499 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15500 hr = ID3D11Device_CreatePixelShader(device, ps_swapc5_code, sizeof(ps_swapc5_code), NULL, &ps[5]);
15501 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15503 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15505 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &tests[i].input, 0, 0);
15507 ID3D11DeviceContext_PSSetShader(context, ps[0], NULL, 0);
15508 draw_quad(&test_context);
15509 check_texture_uvec4(texture, &tests[i].dst0);
15511 ID3D11DeviceContext_PSSetShader(context, ps[1], NULL, 0);
15512 draw_quad(&test_context);
15513 check_texture_uvec4(texture, &tests[i].dst1);
15515 ID3D11DeviceContext_PSSetShader(context, ps[2], NULL, 0);
15516 draw_quad(&test_context);
15517 check_texture_uvec4(texture, &tests[i].dst0);
15519 ID3D11DeviceContext_PSSetShader(context, ps[3], NULL, 0);
15520 draw_quad(&test_context);
15521 check_texture_uvec4(texture, &tests[i].dst1);
15523 ID3D11DeviceContext_PSSetShader(context, ps[4], NULL, 0);
15524 draw_quad(&test_context);
15525 check_texture_uvec4(texture, &tests[i].dst0);
15527 ID3D11DeviceContext_PSSetShader(context, ps[5], NULL, 0);
15528 draw_quad(&test_context);
15529 check_texture_uvec4(texture, &tests[i].dst1);
15532 for (i = 0; i < ARRAY_SIZE(ps); ++i)
15533 ID3D11PixelShader_Release(ps[i]);
15534 ID3D11RenderTargetView_Release(rtv);
15535 ID3D11Texture2D_Release(texture);
15536 ID3D11Buffer_Release(cb);
15537 release_test_context(&test_context);
15540 static void test_create_input_layout(void)
15542 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
15544 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15546 ULONG refcount, expected_refcount;
15547 ID3D11InputLayout *input_layout;
15548 ID3D11Device *device;
15549 unsigned int i;
15550 HRESULT hr;
15552 static const DWORD vs_code[] =
15554 #if 0
15555 float4 main(float4 position : POSITION) : SV_POSITION
15557 return position;
15559 #endif
15560 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
15561 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15562 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
15563 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
15564 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
15565 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
15566 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
15568 static const DXGI_FORMAT vertex_formats[] =
15570 DXGI_FORMAT_R32G32_FLOAT,
15571 DXGI_FORMAT_R32G32_UINT,
15572 DXGI_FORMAT_R32G32_SINT,
15573 DXGI_FORMAT_R16G16_FLOAT,
15574 DXGI_FORMAT_R16G16_UINT,
15575 DXGI_FORMAT_R16G16_SINT,
15576 DXGI_FORMAT_R32_FLOAT,
15577 DXGI_FORMAT_R32_UINT,
15578 DXGI_FORMAT_R32_SINT,
15579 DXGI_FORMAT_R16_UINT,
15580 DXGI_FORMAT_R16_SINT,
15581 DXGI_FORMAT_R8_UINT,
15582 DXGI_FORMAT_R8_SINT,
15585 if (!(device = create_device(NULL)))
15587 skip("Failed to create device.\n");
15588 return;
15591 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
15593 expected_refcount = get_refcount(device) + 1;
15594 layout_desc->Format = vertex_formats[i];
15595 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15596 vs_code, sizeof(vs_code), &input_layout);
15597 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
15598 vertex_formats[i], hr);
15599 refcount = get_refcount(device);
15600 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
15601 refcount, expected_refcount);
15602 ID3D11InputLayout_Release(input_layout);
15605 refcount = ID3D11Device_Release(device);
15606 ok(!refcount, "Device has %u references left.\n", refcount);
15609 static void test_input_assembler(void)
15611 enum layout_id
15613 LAYOUT_FLOAT32,
15614 LAYOUT_UINT16,
15615 LAYOUT_SINT16,
15616 LAYOUT_UNORM16,
15617 LAYOUT_SNORM16,
15618 LAYOUT_UINT8,
15619 LAYOUT_SINT8,
15620 LAYOUT_UNORM8,
15621 LAYOUT_SNORM8,
15622 LAYOUT_UNORM10_2,
15623 LAYOUT_UINT10_2,
15625 LAYOUT_COUNT,
15628 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
15630 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15631 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15633 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
15634 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
15635 ID3D11Buffer *vb_position, *vb_attribute;
15636 struct d3d11_test_context test_context;
15637 D3D11_TEXTURE2D_DESC texture_desc;
15638 unsigned int i, j, stride, offset;
15639 ID3D11Texture2D *render_target;
15640 ID3D11DeviceContext *context;
15641 ID3D11RenderTargetView *rtv;
15642 ID3D11PixelShader *ps;
15643 ID3D11Device *device;
15644 HRESULT hr;
15646 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
15648 DXGI_FORMAT_R32G32B32A32_FLOAT,
15649 DXGI_FORMAT_R16G16B16A16_UINT,
15650 DXGI_FORMAT_R16G16B16A16_SINT,
15651 DXGI_FORMAT_R16G16B16A16_UNORM,
15652 DXGI_FORMAT_R16G16B16A16_SNORM,
15653 DXGI_FORMAT_R8G8B8A8_UINT,
15654 DXGI_FORMAT_R8G8B8A8_SINT,
15655 DXGI_FORMAT_R8G8B8A8_UNORM,
15656 DXGI_FORMAT_R8G8B8A8_SNORM,
15657 DXGI_FORMAT_R10G10B10A2_UNORM,
15658 DXGI_FORMAT_R10G10B10A2_UINT,
15660 static const struct vec2 quad[] =
15662 {-1.0f, -1.0f},
15663 {-1.0f, 1.0f},
15664 { 1.0f, -1.0f},
15665 { 1.0f, 1.0f},
15667 static const DWORD ps_code[] =
15669 #if 0
15670 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
15672 return color;
15674 #endif
15675 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
15676 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
15677 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
15678 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
15679 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15680 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
15681 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
15682 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
15684 static const DWORD vs_float_code[] =
15686 #if 0
15687 struct output
15689 float4 position : SV_Position;
15690 float4 color : COLOR;
15693 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
15695 o.position = position;
15696 o.color = color;
15698 #endif
15699 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
15700 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15701 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
15702 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
15703 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15704 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15705 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
15706 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
15707 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
15708 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
15709 0x0100003e,
15711 static const DWORD vs_uint_code[] =
15713 #if 0
15714 struct output
15716 float4 position : SV_Position;
15717 float4 color : COLOR;
15720 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
15722 o.position = position;
15723 o.color = color;
15725 #endif
15726 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
15727 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15728 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
15729 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
15730 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15731 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15732 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
15733 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
15734 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
15735 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
15736 0x0100003e,
15738 static const DWORD vs_sint_code[] =
15740 #if 0
15741 struct output
15743 float4 position : SV_Position;
15744 float4 color : COLOR;
15747 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
15749 o.position = position;
15750 o.color = color;
15752 #endif
15753 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
15754 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15755 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
15756 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
15757 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15758 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15759 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
15760 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
15761 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
15762 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
15763 0x0100003e,
15765 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
15766 static const unsigned short uint16_data[] = {6, 8, 55, 777};
15767 static const short sint16_data[] = {-1, 33, 8, -77};
15768 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
15769 static const short snorm16_data[] = {-32768, 0, 32767, 0};
15770 static const unsigned char uint8_data[] = {0, 64, 128, 255};
15771 static const signed char sint8_data[] = {-128, 0, 127, 64};
15772 static const unsigned int uint32_zero = 0;
15773 static const unsigned int uint32_max = 0xffffffff;
15774 static const unsigned int unorm10_2_data= 0xa00003ff;
15775 static const unsigned int g10_data = 0x000ffc00;
15776 static const unsigned int a2_data = 0xc0000000;
15777 static const struct
15779 enum layout_id layout_id;
15780 unsigned int stride;
15781 const void *data;
15782 struct vec4 expected_color;
15783 BOOL todo;
15785 tests[] =
15787 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
15788 {1.0f, 2.0f, 3.0f, 4.0f}},
15789 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
15790 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
15791 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
15792 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
15793 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
15794 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
15795 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
15796 {-1.0f, 0.0f, 1.0f, 0.0f}},
15797 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
15798 {0.0f, 0.0f, 0.0f, 0.0f}},
15799 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
15800 {255.0f, 255.0f, 255.0f, 255.0f}},
15801 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
15802 {0.0f, 64.0f, 128.0f, 255.0f}},
15803 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
15804 {0.0f, 0.0f, 0.0f, 0.0f}},
15805 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
15806 {-1.0f, -1.0f, -1.0f, -1.0f}},
15807 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
15808 {-128.0f, 0.0f, 127.0f, 64.0f}},
15809 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
15810 {0.0f, 0.0f, 0.0f, 0.0f}},
15811 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
15812 {1.0f, 1.0f, 1.0f, 1.0f}},
15813 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
15814 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
15815 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
15816 {0.0f, 0.0f, 0.0f, 0.0f}},
15817 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
15818 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
15819 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
15820 {0.0f, 0.0f, 0.0f, 0.0f}},
15821 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
15822 {1.0f, 1.0f, 1.0f, 1.0f}},
15823 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
15824 {0.0f, 1.0f, 0.0f, 0.0f}},
15825 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
15826 {0.0f, 0.0f, 0.0f, 1.0f}},
15827 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
15828 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
15829 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
15830 {0.0f, 0.0f, 0.0f, 0.0f}},
15831 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
15832 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
15833 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
15834 {0.0f, 1023.0f, 0.0f, 0.0f}},
15835 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
15836 {0.0f, 0.0f, 0.0f, 3.0f}},
15837 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
15838 {1023.0f, 0.0f, 512.0f, 2.0f}},
15841 if (!init_test_context(&test_context, NULL))
15842 return;
15844 device = test_context.device;
15845 context = test_context.immediate_context;
15847 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15848 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15850 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
15851 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
15852 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
15853 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
15854 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
15855 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
15857 for (i = 0; i < LAYOUT_COUNT; ++i)
15859 input_layout_desc[1].Format = layout_formats[i];
15860 input_layout[i] = NULL;
15861 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
15862 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
15863 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
15864 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
15867 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
15868 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
15870 texture_desc.Width = 640;
15871 texture_desc.Height = 480;
15872 texture_desc.MipLevels = 1;
15873 texture_desc.ArraySize = 1;
15874 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
15875 texture_desc.SampleDesc.Count = 1;
15876 texture_desc.SampleDesc.Quality = 0;
15877 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15878 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15879 texture_desc.CPUAccessFlags = 0;
15880 texture_desc.MiscFlags = 0;
15882 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
15883 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
15885 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
15886 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15888 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
15889 offset = 0;
15890 stride = sizeof(*quad);
15891 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
15892 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15893 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15895 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15897 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
15899 if (tests[i].layout_id == LAYOUT_UINT10_2)
15900 continue;
15902 assert(tests[i].layout_id < LAYOUT_COUNT);
15903 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
15905 assert(4 * tests[i].stride <= 1024);
15906 box.right = tests[i].stride;
15907 for (j = 0; j < 4; ++j)
15909 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
15910 &box, tests[i].data, 0, 0);
15911 box.left += tests[i].stride;
15912 box.right += tests[i].stride;
15915 stride = tests[i].stride;
15916 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
15918 switch (layout_formats[tests[i].layout_id])
15920 case DXGI_FORMAT_R16G16B16A16_UINT:
15921 case DXGI_FORMAT_R10G10B10A2_UINT:
15922 case DXGI_FORMAT_R8G8B8A8_UINT:
15923 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
15924 break;
15925 case DXGI_FORMAT_R16G16B16A16_SINT:
15926 case DXGI_FORMAT_R8G8B8A8_SINT:
15927 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
15928 break;
15930 default:
15931 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
15932 /* Fall through. */
15933 case DXGI_FORMAT_R32G32B32A32_FLOAT:
15934 case DXGI_FORMAT_R16G16B16A16_UNORM:
15935 case DXGI_FORMAT_R16G16B16A16_SNORM:
15936 case DXGI_FORMAT_R10G10B10A2_UNORM:
15937 case DXGI_FORMAT_R8G8B8A8_UNORM:
15938 case DXGI_FORMAT_R8G8B8A8_SNORM:
15939 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
15940 break;
15943 ID3D11DeviceContext_Draw(context, 4, 0);
15944 check_texture_vec4(render_target, &tests[i].expected_color, 2);
15947 ID3D11Texture2D_Release(render_target);
15948 ID3D11RenderTargetView_Release(rtv);
15949 ID3D11Buffer_Release(vb_attribute);
15950 ID3D11Buffer_Release(vb_position);
15951 for (i = 0; i < LAYOUT_COUNT; ++i)
15953 if (input_layout[i])
15954 ID3D11InputLayout_Release(input_layout[i]);
15956 ID3D11PixelShader_Release(ps);
15957 ID3D11VertexShader_Release(vs_float);
15958 ID3D11VertexShader_Release(vs_uint);
15959 ID3D11VertexShader_Release(vs_sint);
15960 release_test_context(&test_context);
15963 static void test_null_sampler(void)
15965 struct d3d11_test_context test_context;
15966 D3D11_TEXTURE2D_DESC texture_desc;
15967 ID3D11ShaderResourceView *srv;
15968 ID3D11DeviceContext *context;
15969 ID3D11RenderTargetView *rtv;
15970 ID3D11SamplerState *sampler;
15971 ID3D11Texture2D *texture;
15972 ID3D11PixelShader *ps;
15973 ID3D11Device *device;
15974 HRESULT hr;
15976 static const DWORD ps_code[] =
15978 #if 0
15979 Texture2D t;
15980 SamplerState s;
15982 float4 main(float4 position : SV_POSITION) : SV_Target
15984 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
15986 #endif
15987 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
15988 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15989 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
15990 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15991 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
15992 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
15993 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
15994 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
15995 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
15996 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
15998 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
16000 if (!init_test_context(&test_context, NULL))
16001 return;
16003 device = test_context.device;
16004 context = test_context.immediate_context;
16006 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16007 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16009 texture_desc.Width = 64;
16010 texture_desc.Height = 64;
16011 texture_desc.MipLevels = 1;
16012 texture_desc.ArraySize = 1;
16013 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
16014 texture_desc.SampleDesc.Count = 1;
16015 texture_desc.SampleDesc.Quality = 0;
16016 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16017 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
16018 texture_desc.CPUAccessFlags = 0;
16019 texture_desc.MiscFlags = 0;
16021 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16022 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16024 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
16025 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
16027 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
16028 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
16030 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
16032 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16033 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
16034 sampler = NULL;
16035 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
16036 draw_quad(&test_context);
16037 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
16039 ID3D11ShaderResourceView_Release(srv);
16040 ID3D11RenderTargetView_Release(rtv);
16041 ID3D11Texture2D_Release(texture);
16042 ID3D11PixelShader_Release(ps);
16043 release_test_context(&test_context);
16046 static void test_check_feature_support(void)
16048 D3D11_FEATURE_DATA_THREADING threading[2];
16049 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
16050 D3D11_FEATURE_DATA_ARCHITECTURE_INFO archinfo;
16051 ID3D11Device *device;
16052 ULONG refcount;
16053 HRESULT hr;
16055 if (!(device = create_device(NULL)))
16057 skip("Failed to create device.\n");
16058 return;
16061 memset(threading, 0xef, sizeof(threading));
16063 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
16064 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16065 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
16066 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16067 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
16068 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16069 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
16070 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16071 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
16072 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16073 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
16074 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16076 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
16077 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
16078 ok(threading[0].DriverCommandLists == 0xefefefef,
16079 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
16080 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
16081 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
16082 ok(threading[1].DriverCommandLists == 0xefefefef,
16083 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
16085 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
16086 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
16087 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
16088 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
16089 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
16090 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
16092 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
16093 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16094 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
16095 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16096 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
16097 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16098 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
16099 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16100 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
16101 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16102 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
16103 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16105 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
16106 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
16107 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
16109 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo));
16110 ok(hr == S_OK || broken(hr == E_INVALIDARG) /* Not available on all Windows versions. */,
16111 "Got unexpected hr %#x.\n", hr);
16112 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo)*2);
16113 ok(hr == E_INVALIDARG /* Not available on all Windows versions but they will return E_INVALIDARG anyways. */,
16114 "Got unexpected hr %#x.\n", hr);
16116 refcount = ID3D11Device_Release(device);
16117 ok(!refcount, "Device has %u references left.\n", refcount);
16120 static void test_create_unordered_access_view(void)
16122 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16123 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16124 D3D11_TEXTURE3D_DESC texture3d_desc;
16125 D3D11_TEXTURE2D_DESC texture2d_desc;
16126 ULONG refcount, expected_refcount;
16127 D3D11_SUBRESOURCE_DATA data = {0};
16128 ID3D11UnorderedAccessView *uav;
16129 struct device_desc device_desc;
16130 D3D11_BUFFER_DESC buffer_desc;
16131 ID3D11Device *device, *tmp;
16132 ID3D11Texture3D *texture3d;
16133 ID3D11Texture2D *texture2d;
16134 ID3D11Resource *texture;
16135 ID3D11Buffer *buffer;
16136 unsigned int i;
16137 HRESULT hr;
16139 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
16140 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
16141 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
16142 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
16143 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
16144 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
16145 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
16146 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
16147 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
16148 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
16149 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
16150 static const struct
16152 struct
16154 unsigned int miplevel_count;
16155 unsigned int depth_or_array_size;
16156 DXGI_FORMAT format;
16157 } texture;
16158 struct uav_desc uav_desc;
16159 struct uav_desc expected_uav_desc;
16161 tests[] =
16163 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
16164 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
16165 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
16166 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
16167 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
16168 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
16169 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
16170 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
16171 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
16172 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
16173 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
16174 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
16175 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
16176 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
16177 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
16178 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
16179 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
16180 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
16181 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
16182 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
16183 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
16184 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
16185 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
16186 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
16187 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
16188 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
16189 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
16190 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
16191 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
16192 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
16193 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
16194 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
16195 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
16196 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
16197 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
16198 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
16200 static const struct
16202 struct
16204 D3D11_UAV_DIMENSION dimension;
16205 unsigned int miplevel_count;
16206 unsigned int depth_or_array_size;
16207 DXGI_FORMAT format;
16208 } texture;
16209 struct uav_desc uav_desc;
16211 invalid_desc_tests[] =
16213 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
16214 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
16215 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
16216 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
16217 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
16218 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
16219 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
16220 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
16221 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
16222 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
16223 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
16224 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
16225 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
16226 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
16227 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
16228 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}},
16229 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
16230 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
16231 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
16232 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
16233 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
16234 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
16235 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
16236 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
16237 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
16238 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
16239 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
16240 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
16241 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
16242 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
16243 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
16244 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
16245 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
16246 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
16247 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
16248 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
16249 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
16251 #undef FMT_UNKNOWN
16252 #undef RGBA8_UNORM
16253 #undef RGBA8_SRGB
16254 #undef RGBA8_UINT
16255 #undef RGBA8_TL
16256 #undef DIM_UNKNOWN
16257 #undef TEX_1D
16258 #undef TEX_1D_ARRAY
16259 #undef TEX_2D
16260 #undef TEX_2D_ARRAY
16261 #undef TEX_3D
16263 device_desc.feature_level = &feature_level;
16264 device_desc.flags = 0;
16265 if (!(device = create_device(&device_desc)))
16267 skip("Failed to create device.\n");
16268 return;
16271 buffer_desc.ByteWidth = 1024;
16272 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
16273 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16274 buffer_desc.CPUAccessFlags = 0;
16275 buffer_desc.MiscFlags = 0;
16276 buffer_desc.StructureByteStride = 0;
16278 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
16279 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16281 expected_refcount = get_refcount(device) + 1;
16282 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16283 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
16284 refcount = get_refcount(device);
16285 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
16286 tmp = NULL;
16287 expected_refcount = refcount + 1;
16288 ID3D11Buffer_GetDevice(buffer, &tmp);
16289 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
16290 refcount = get_refcount(device);
16291 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
16292 ID3D11Device_Release(tmp);
16294 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
16295 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16296 U(uav_desc).Buffer.FirstElement = 0;
16297 U(uav_desc).Buffer.NumElements = 64;
16298 U(uav_desc).Buffer.Flags = 0;
16300 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
16301 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16303 expected_refcount = get_refcount(device) + 1;
16304 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16305 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16306 refcount = get_refcount(device);
16307 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
16308 tmp = NULL;
16309 expected_refcount = refcount + 1;
16310 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
16311 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
16312 refcount = get_refcount(device);
16313 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
16314 ID3D11Device_Release(tmp);
16316 ID3D11UnorderedAccessView_Release(uav);
16317 ID3D11Buffer_Release(buffer);
16319 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
16320 buffer_desc.StructureByteStride = 4;
16322 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16323 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
16325 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
16326 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
16328 memset(&uav_desc, 0, sizeof(uav_desc));
16329 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
16331 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
16332 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
16333 uav_desc.ViewDimension);
16334 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
16335 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
16336 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
16338 ID3D11UnorderedAccessView_Release(uav);
16339 ID3D11Buffer_Release(buffer);
16341 texture2d_desc.Width = 512;
16342 texture2d_desc.Height = 512;
16343 texture2d_desc.SampleDesc.Count = 1;
16344 texture2d_desc.SampleDesc.Quality = 0;
16345 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
16346 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16347 texture2d_desc.CPUAccessFlags = 0;
16348 texture2d_desc.MiscFlags = 0;
16350 texture3d_desc.Width = 64;
16351 texture3d_desc.Height = 64;
16352 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
16353 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16354 texture3d_desc.CPUAccessFlags = 0;
16355 texture3d_desc.MiscFlags = 0;
16357 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16359 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
16361 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
16363 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
16364 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
16365 texture2d_desc.Format = tests[i].texture.format;
16367 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
16368 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
16369 texture = (ID3D11Resource *)texture2d;
16371 else
16373 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
16374 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
16375 texture3d_desc.Format = tests[i].texture.format;
16377 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
16378 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
16379 texture = (ID3D11Resource *)texture3d;
16382 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
16384 current_desc = NULL;
16386 else
16388 current_desc = &uav_desc;
16389 get_uav_desc(current_desc, &tests[i].uav_desc);
16392 expected_refcount = get_refcount(texture);
16393 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
16394 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
16395 refcount = get_refcount(texture);
16396 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
16398 memset(&uav_desc, 0, sizeof(uav_desc));
16399 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
16400 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
16402 ID3D11UnorderedAccessView_Release(uav);
16403 ID3D11Resource_Release(texture);
16406 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
16408 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
16409 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
16411 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
16413 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
16414 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
16415 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
16417 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
16418 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
16419 texture = (ID3D11Resource *)texture2d;
16421 else
16423 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
16424 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
16425 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
16427 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
16428 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
16429 texture = (ID3D11Resource *)texture3d;
16432 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
16433 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
16434 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
16436 ID3D11Resource_Release(texture);
16439 refcount = ID3D11Device_Release(device);
16440 ok(!refcount, "Device has %u references left.\n", refcount);
16443 static void test_immediate_constant_buffer(void)
16445 struct d3d11_test_context test_context;
16446 D3D11_TEXTURE2D_DESC texture_desc;
16447 ID3D11DeviceContext *context;
16448 ID3D11RenderTargetView *rtv;
16449 unsigned int index[4] = {0};
16450 ID3D11Texture2D *texture;
16451 ID3D11PixelShader *ps;
16452 ID3D11Device *device;
16453 ID3D11Buffer *cb;
16454 unsigned int i;
16455 HRESULT hr;
16457 static const DWORD ps_code[] =
16459 #if 0
16460 uint index;
16462 static const int int_array[6] =
16464 310, 111, 212, -513, -318, 0,
16467 static const uint uint_array[6] =
16469 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
16472 static const float float_array[6] =
16474 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
16477 float4 main() : SV_Target
16479 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
16481 #endif
16482 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
16483 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16484 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16485 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
16486 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
16487 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
16488 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
16489 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
16490 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
16491 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
16492 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
16493 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
16494 0x0100003e,
16496 static struct vec4 expected_result[] =
16498 { 310.0f, 2.0f, 76.00f, 1.0f},
16499 { 111.0f, 7.0f, 83.50f, 1.0f},
16500 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
16501 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
16502 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
16503 { 0.0f, 0.0f, 0.0f, 1.0f},
16506 if (!init_test_context(&test_context, NULL))
16507 return;
16509 device = test_context.device;
16510 context = test_context.immediate_context;
16512 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16513 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16514 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16516 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
16517 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16519 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16520 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
16521 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16522 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16524 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
16525 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
16526 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
16528 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
16530 *index = i;
16531 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
16533 draw_quad(&test_context);
16534 check_texture_vec4(texture, &expected_result[i], 0);
16537 ID3D11Buffer_Release(cb);
16538 ID3D11PixelShader_Release(ps);
16539 ID3D11Texture2D_Release(texture);
16540 ID3D11RenderTargetView_Release(rtv);
16541 release_test_context(&test_context);
16544 static void test_fp_specials(void)
16546 struct d3d11_test_context test_context;
16547 D3D11_TEXTURE2D_DESC texture_desc;
16548 ID3D11DeviceContext *context;
16549 ID3D11RenderTargetView *rtv;
16550 ID3D11Texture2D *texture;
16551 ID3D11PixelShader *ps;
16552 ID3D11Device *device;
16553 HRESULT hr;
16555 static const DWORD ps_code[] =
16557 #if 0
16558 float4 main() : SV_Target
16560 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
16562 #endif
16563 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
16564 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16565 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16566 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
16567 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
16568 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
16570 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
16572 if (!init_test_context(&test_context, NULL))
16573 return;
16575 device = test_context.device;
16576 context = test_context.immediate_context;
16578 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16579 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16580 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16582 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16583 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
16584 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16585 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16587 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
16588 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
16590 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
16592 draw_quad(&test_context);
16593 check_texture_uvec4(texture, &expected_result);
16595 ID3D11PixelShader_Release(ps);
16596 ID3D11Texture2D_Release(texture);
16597 ID3D11RenderTargetView_Release(rtv);
16598 release_test_context(&test_context);
16601 static void test_uint_shader_instructions(void)
16603 struct shader
16605 const DWORD *code;
16606 size_t size;
16607 D3D_FEATURE_LEVEL required_feature_level;
16610 struct d3d11_test_context test_context;
16611 D3D11_TEXTURE2D_DESC texture_desc;
16612 D3D_FEATURE_LEVEL feature_level;
16613 ID3D11DeviceContext *context;
16614 ID3D11RenderTargetView *rtv;
16615 ID3D11Texture2D *texture;
16616 ID3D11PixelShader *ps;
16617 ID3D11Device *device;
16618 ID3D11Buffer *cb;
16619 unsigned int i;
16620 HRESULT hr;
16622 static const DWORD ps_bfi_code[] =
16624 #if 0
16625 uint bits, offset, insert, base;
16627 uint4 main() : SV_Target
16629 uint mask = ((1 << bits) - 1) << offset;
16630 return ((insert << offset) & mask) | (base & ~mask);
16632 #endif
16633 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
16634 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16635 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16636 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
16637 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16638 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
16639 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
16641 static const DWORD ps_bfi2_code[] =
16643 #if 0
16644 ps_5_0
16645 dcl_globalFlags refactoringAllowed
16646 dcl_constantbuffer cb0[1], immediateIndexed
16647 dcl_output o0.xyzw
16648 dcl_temps 1
16649 mov r0.xyzw, cb0[0].xyzw
16650 bfi r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz, r0.wwww
16651 mov o0.xyzw, r0.xyzw
16653 #endif
16654 0x43425844, 0x900f86b6, 0x73f4dabf, 0xea1b1106, 0x591ac790, 0x00000001, 0x00000104, 0x00000003,
16655 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16656 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16657 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000008c, 0x00000050, 0x00000023,
16658 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16659 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
16660 0x0b00008c, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
16661 0x00000000, 0x00100ff6, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
16662 0x0100003e,
16664 static const DWORD ps_ibfe_code[] =
16666 #if 0
16667 ps_5_0
16668 dcl_globalFlags refactoringAllowed
16669 dcl_constantbuffer cb0[1], immediateIndexed
16670 dcl_output o0.xyzw
16671 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
16673 #endif
16674 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
16675 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16676 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16677 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
16678 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16679 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
16680 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
16682 static const DWORD ps_ibfe2_code[] =
16684 #if 0
16685 ps_5_0
16686 dcl_globalFlags refactoringAllowed
16687 dcl_constantbuffer cb0[1], immediateIndexed
16688 dcl_output o0.xyzw
16689 dcl_temps 1
16690 mov r0.xyzw, cb0[0].xyzw
16691 ibfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
16692 mov o0.xyzw, r0.xyzw
16694 #endif
16695 0x43425844, 0x347a9c0e, 0x3eff39a4, 0x3dd41cc5, 0xff87ec8d, 0x00000001, 0x000000fc, 0x00000003,
16696 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16697 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16698 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
16699 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16700 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
16701 0x0900008b, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
16702 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
16704 static const DWORD ps_ubfe_code[] =
16706 #if 0
16707 uint u;
16709 uint4 main() : SV_Target
16711 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
16713 #endif
16714 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
16715 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16716 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16717 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
16718 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16719 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
16720 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
16721 0x0100003e,
16723 static const DWORD ps_ubfe2_code[] =
16725 #if 0
16726 ps_5_0
16727 dcl_globalFlags refactoringAllowed
16728 dcl_constantbuffer cb0[1], immediateIndexed
16729 dcl_output o0.xyzw
16730 dcl_temps 1
16731 mov r0.xyzw, cb0[0].xyzw
16732 ubfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
16733 mov o0.xyzw, r0.xyzw
16735 #endif
16736 0x43425844, 0xf377b7fc, 0x1e4cb9e7, 0xb9b1020d, 0xde484388, 0x00000001, 0x000000fc, 0x00000003,
16737 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16738 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16739 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
16740 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16741 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
16742 0x0900008a, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
16743 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
16745 static const DWORD ps_bfrev_code[] =
16747 #if 0
16748 uint bits;
16750 uint4 main() : SV_Target
16752 return uint4(reversebits(bits), reversebits(reversebits(bits)),
16753 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
16755 #endif
16756 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
16757 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16758 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16759 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
16760 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16761 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
16762 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
16763 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
16764 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
16765 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
16766 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16768 static const DWORD ps_bits_code[] =
16770 #if 0
16771 uint u;
16772 int i;
16774 uint4 main() : SV_Target
16776 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
16778 #endif
16779 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
16780 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16781 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16782 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
16783 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16784 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
16785 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
16786 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
16787 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
16788 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
16789 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
16790 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
16791 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
16792 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
16794 static const DWORD ps_ftou_code[] =
16796 #if 0
16797 float f;
16799 uint4 main() : SV_Target
16801 return uint4(f, -f, 0, 0);
16803 #endif
16804 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
16805 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16806 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16807 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
16808 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
16809 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
16810 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
16811 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
16813 static const DWORD ps_f16tof32_code[] =
16815 #if 0
16816 uint4 hf;
16818 uint4 main() : SV_Target
16820 return f16tof32(hf);
16822 #endif
16823 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
16824 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16825 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16826 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
16827 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16828 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
16829 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
16831 static const DWORD ps_f32tof16_code[] =
16833 #if 0
16834 float4 f;
16836 uint4 main() : SV_Target
16838 return f32tof16(f);
16840 #endif
16841 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
16842 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16843 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16844 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
16845 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16846 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
16848 static const DWORD ps_not_code[] =
16850 #if 0
16851 uint2 bits;
16853 uint4 main() : SV_Target
16855 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
16857 #endif
16858 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
16859 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16860 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16861 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
16862 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
16863 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
16864 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
16865 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
16867 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
16868 static const struct shader ps_bfi2 = {ps_bfi2_code, sizeof(ps_bfi2_code), D3D_FEATURE_LEVEL_11_0};
16869 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
16870 static const struct shader ps_ibfe2 = {ps_ibfe2_code, sizeof(ps_ibfe2_code), D3D_FEATURE_LEVEL_11_0};
16871 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
16872 static const struct shader ps_ubfe2 = {ps_ubfe2_code, sizeof(ps_ubfe2_code), D3D_FEATURE_LEVEL_11_0};
16873 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
16874 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
16875 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
16876 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
16877 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
16878 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
16879 static const struct
16881 const struct shader *ps;
16882 unsigned int bits[4];
16883 struct uvec4 expected_result;
16885 tests[] =
16887 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
16888 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
16889 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
16890 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
16891 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
16892 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
16893 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
16894 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
16895 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
16896 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
16897 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
16898 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
16899 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
16900 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
16901 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
16902 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
16903 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
16904 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
16905 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
16907 {&ps_bfi2, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
16908 {&ps_bfi2, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
16909 {&ps_bfi2, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
16910 {&ps_bfi2, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
16912 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
16913 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
16914 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
16915 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
16916 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
16917 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
16918 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
16919 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
16920 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
16921 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
16922 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
16923 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
16924 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
16925 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
16926 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
16927 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
16928 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
16929 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
16930 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
16931 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
16932 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
16933 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
16934 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
16935 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
16936 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
16937 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
16939 {&ps_ibfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
16941 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
16942 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
16943 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
16944 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
16945 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
16946 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
16947 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
16949 {&ps_ubfe2, { 4, 4, 0x7fffffff}, {0x0000000f, 0x0000000f, 0x0000000f, 0x0000000f}},
16950 {&ps_ubfe2, {23, 8, 0xffffffff}, {0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff}},
16951 {&ps_ubfe2, {30, 1, 0xffffffff}, {0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff}},
16952 {&ps_ubfe2, {15, 15, 0x7fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
16953 {&ps_ubfe2, {15, 15, 0xffff00ff}, {0x00007ffe, 0x00007ffe, 0x00007ffe, 0x00007ffe}},
16954 {&ps_ubfe2, {16, 15, 0xffffffff}, {0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff}},
16955 {&ps_ubfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
16956 {&ps_ubfe2, {20, 15, 0xffffffff}, {0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff}},
16957 {&ps_ubfe2, {31, 31, 0xffffffff}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
16958 {&ps_ubfe2, {31, 31, 0x80000000}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
16959 {&ps_ubfe2, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
16961 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
16962 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
16963 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
16965 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
16966 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
16967 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
16968 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
16969 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
16970 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
16971 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
16972 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
16973 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
16974 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
16975 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
16976 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
16978 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
16979 {&ps_ftou, {BITS_NAN}, { 0, 0}},
16980 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
16981 {&ps_ftou, {BITS_INF}, {~0u, 0}},
16982 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
16983 {&ps_ftou, {BITS_1_0}, { 1, 0}},
16985 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
16986 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
16987 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
16988 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
16990 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
16992 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
16993 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
16996 if (!init_test_context(&test_context, NULL))
16997 return;
16999 device = test_context.device;
17000 context = test_context.immediate_context;
17001 feature_level = ID3D11Device_GetFeatureLevel(device);
17003 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
17004 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17006 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17007 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
17008 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17009 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17011 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
17012 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17014 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17016 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17018 if (feature_level < tests[i].ps->required_feature_level)
17019 continue;
17021 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
17022 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17023 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17025 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
17027 draw_quad(&test_context);
17028 check_texture_uvec4(texture, &tests[i].expected_result);
17030 ID3D11PixelShader_Release(ps);
17033 ID3D11Buffer_Release(cb);
17034 ID3D11Texture2D_Release(texture);
17035 ID3D11RenderTargetView_Release(rtv);
17036 release_test_context(&test_context);
17039 static void test_index_buffer_offset(void)
17041 ID3D11Buffer *vb, *ib, *so_buffer, *args_buffer;
17042 struct d3d11_test_context test_context;
17043 ID3D11InputLayout *input_layout;
17044 ID3D11DeviceContext *context;
17045 struct resource_readback rb;
17046 ID3D11GeometryShader *gs;
17047 const struct vec4 *data;
17048 ID3D11VertexShader *vs;
17049 ID3D11Device *device;
17050 UINT stride, offset;
17051 unsigned int i;
17052 HRESULT hr;
17054 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17055 static const DWORD vs_code[] =
17057 #if 0
17058 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
17059 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
17061 out_position = position;
17062 out_attrib = attrib;
17064 #endif
17065 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
17066 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17067 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
17068 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
17069 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
17070 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
17071 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
17072 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
17073 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
17074 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
17075 0x0100003e,
17077 static const DWORD gs_code[] =
17079 #if 0
17080 struct vertex
17082 float4 position : SV_POSITION;
17083 float4 attrib : ATTRIB;
17086 [maxvertexcount(1)]
17087 void main(point vertex input[1], inout PointStream<vertex> output)
17089 output.Append(input[0]);
17090 output.RestartStrip();
17092 #endif
17093 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
17094 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17095 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
17096 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
17097 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
17098 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
17099 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
17100 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
17101 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
17102 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
17103 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
17104 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
17106 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
17108 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17109 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
17111 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
17113 {0, "SV_Position", 0, 0, 4, 0},
17114 {0, "ATTRIB", 0, 0, 4, 0},
17116 static const struct
17118 struct vec4 position;
17119 struct vec4 attrib;
17121 vertices[] =
17123 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
17124 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
17125 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
17126 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
17128 static const unsigned int indices[] =
17130 0, 1, 2, 3,
17131 3, 2, 1, 0,
17132 1, 3, 2, 0,
17134 static const struct vec4 expected_data[] =
17136 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
17137 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
17138 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
17139 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
17141 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
17142 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
17143 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
17144 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
17146 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
17147 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
17148 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
17149 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
17151 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
17152 static const D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS argument_data[] =
17154 {4, 1, 0, 0, 0},
17157 if (!init_test_context(&test_context, &feature_level))
17158 return;
17160 device = test_context.device;
17161 context = test_context.immediate_context;
17163 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
17164 vs_code, sizeof(vs_code), &input_layout);
17165 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17167 stride = 32;
17168 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
17169 so_declaration, ARRAY_SIZE(so_declaration),
17170 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
17171 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
17173 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17174 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17176 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
17177 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
17178 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
17180 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17181 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
17183 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
17184 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
17185 stride = sizeof(*vertices);
17186 offset = 0;
17187 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
17189 offset = 0;
17190 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
17192 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
17193 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
17195 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
17196 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
17198 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
17199 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
17201 get_buffer_readback(so_buffer, &rb);
17202 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
17204 data = get_readback_vec4(&rb, i, 0);
17205 ok(compare_vec4(data, &expected_data[i], 0)
17206 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
17207 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
17208 data->x, data->y, data->z, data->w, i);
17210 release_resource_readback(&rb);
17212 /* indirect draws */
17213 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
17214 sizeof(argument_data), argument_data);
17216 offset = 0;
17217 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
17219 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
17220 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
17222 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
17223 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
17225 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
17226 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
17228 get_buffer_readback(so_buffer, &rb);
17229 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
17231 data = get_readback_vec4(&rb, i, 0);
17232 todo_wine_if(i >= 8 && i != 20 && i != 21)
17233 ok(compare_vec4(data, &expected_data[i], 0)
17234 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
17235 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
17236 data->x, data->y, data->z, data->w, i);
17238 release_resource_readback(&rb);
17240 ID3D11Buffer_Release(so_buffer);
17241 ID3D11Buffer_Release(args_buffer);
17242 ID3D11Buffer_Release(ib);
17243 ID3D11Buffer_Release(vb);
17244 ID3D11VertexShader_Release(vs);
17245 ID3D11GeometryShader_Release(gs);
17246 ID3D11InputLayout_Release(input_layout);
17247 release_test_context(&test_context);
17250 static void test_face_culling(void)
17252 struct d3d11_test_context test_context;
17253 D3D11_RASTERIZER_DESC rasterizer_desc;
17254 ID3D11RasterizerState *state;
17255 ID3D11DeviceContext *context;
17256 ID3D11Buffer *cw_vb, *ccw_vb;
17257 ID3D11Device *device;
17258 BOOL broken_warp;
17259 unsigned int i;
17260 HRESULT hr;
17262 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
17263 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
17264 static const DWORD ps_code[] =
17266 #if 0
17267 float4 main(uint front : SV_IsFrontFace) : SV_Target
17269 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
17271 #endif
17272 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
17273 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
17274 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
17275 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
17276 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
17277 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
17278 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
17279 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
17280 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
17281 0x3f800000, 0x0100003e,
17283 static const struct vec3 ccw_quad[] =
17285 {-1.0f, 1.0f, 0.0f},
17286 {-1.0f, -1.0f, 0.0f},
17287 { 1.0f, 1.0f, 0.0f},
17288 { 1.0f, -1.0f, 0.0f},
17290 static const struct
17292 D3D11_CULL_MODE cull_mode;
17293 BOOL front_ccw;
17294 BOOL expected_cw;
17295 BOOL expected_ccw;
17297 tests[] =
17299 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
17300 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
17301 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
17302 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
17303 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
17304 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
17307 if (!init_test_context(&test_context, NULL))
17308 return;
17310 device = test_context.device;
17311 context = test_context.immediate_context;
17313 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
17314 draw_color_quad(&test_context, &green);
17315 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17317 cw_vb = test_context.vb;
17318 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
17320 test_context.vb = ccw_vb;
17321 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
17322 draw_color_quad(&test_context, &green);
17323 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
17325 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
17326 rasterizer_desc.CullMode = D3D11_CULL_BACK;
17327 rasterizer_desc.FrontCounterClockwise = FALSE;
17328 rasterizer_desc.DepthBias = 0;
17329 rasterizer_desc.DepthBiasClamp = 0.0f;
17330 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
17331 rasterizer_desc.DepthClipEnable = TRUE;
17332 rasterizer_desc.ScissorEnable = FALSE;
17333 rasterizer_desc.MultisampleEnable = FALSE;
17334 rasterizer_desc.AntialiasedLineEnable = FALSE;
17336 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17338 rasterizer_desc.CullMode = tests[i].cull_mode;
17339 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
17340 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
17341 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
17343 ID3D11DeviceContext_RSSetState(context, state);
17345 test_context.vb = cw_vb;
17346 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
17347 draw_color_quad(&test_context, &green);
17348 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
17350 test_context.vb = ccw_vb;
17351 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
17352 draw_color_quad(&test_context, &green);
17353 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
17355 ID3D11RasterizerState_Release(state);
17358 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0;
17360 /* Test SV_IsFrontFace. */
17361 ID3D11PixelShader_Release(test_context.ps);
17362 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
17363 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17365 rasterizer_desc.CullMode = D3D11_CULL_NONE;
17366 rasterizer_desc.FrontCounterClockwise = FALSE;
17367 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
17368 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
17369 ID3D11DeviceContext_RSSetState(context, state);
17371 test_context.vb = cw_vb;
17372 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
17373 draw_color_quad(&test_context, &green);
17374 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17375 test_context.vb = ccw_vb;
17376 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
17377 draw_color_quad(&test_context, &green);
17378 if (!broken_warp)
17379 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
17380 else
17381 win_skip("Broken WARP.\n");
17383 ID3D11RasterizerState_Release(state);
17385 rasterizer_desc.CullMode = D3D11_CULL_NONE;
17386 rasterizer_desc.FrontCounterClockwise = TRUE;
17387 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
17388 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
17389 ID3D11DeviceContext_RSSetState(context, state);
17391 test_context.vb = cw_vb;
17392 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
17393 draw_color_quad(&test_context, &green);
17394 if (!broken_warp)
17395 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
17396 else
17397 win_skip("Broken WARP.\n");
17398 test_context.vb = ccw_vb;
17399 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
17400 draw_color_quad(&test_context, &green);
17401 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17403 ID3D11RasterizerState_Release(state);
17405 test_context.vb = cw_vb;
17406 ID3D11Buffer_Release(ccw_vb);
17407 release_test_context(&test_context);
17410 static void test_line_antialiasing_blending(void)
17412 ID3D11RasterizerState *rasterizer_state;
17413 struct d3d11_test_context test_context;
17414 D3D11_RASTERIZER_DESC rasterizer_desc;
17415 ID3D11BlendState *blend_state;
17416 ID3D11DeviceContext *context;
17417 D3D11_BLEND_DESC blend_desc;
17418 ID3D11Device *device;
17419 HRESULT hr;
17421 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
17422 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
17424 if (!init_test_context(&test_context, NULL))
17425 return;
17427 device = test_context.device;
17428 context = test_context.immediate_context;
17430 memset(&blend_desc, 0, sizeof(blend_desc));
17431 blend_desc.AlphaToCoverageEnable = FALSE;
17432 blend_desc.IndependentBlendEnable = FALSE;
17433 blend_desc.RenderTarget[0].BlendEnable = TRUE;
17434 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
17435 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
17436 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
17437 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
17438 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
17439 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
17440 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
17442 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
17443 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
17444 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
17446 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
17447 draw_color_quad(&test_context, &green);
17448 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
17450 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
17451 draw_color_quad(&test_context, &red);
17452 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
17454 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
17455 ID3D11BlendState_Release(blend_state);
17457 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
17458 draw_color_quad(&test_context, &green);
17459 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
17461 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
17462 draw_color_quad(&test_context, &red);
17463 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
17465 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
17466 rasterizer_desc.CullMode = D3D11_CULL_BACK;
17467 rasterizer_desc.FrontCounterClockwise = FALSE;
17468 rasterizer_desc.DepthBias = 0;
17469 rasterizer_desc.DepthBiasClamp = 0.0f;
17470 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
17471 rasterizer_desc.DepthClipEnable = TRUE;
17472 rasterizer_desc.ScissorEnable = FALSE;
17473 rasterizer_desc.MultisampleEnable = FALSE;
17474 rasterizer_desc.AntialiasedLineEnable = TRUE;
17476 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
17477 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
17478 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
17480 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
17481 draw_color_quad(&test_context, &green);
17482 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
17484 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
17485 draw_color_quad(&test_context, &red);
17486 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
17488 ID3D11RasterizerState_Release(rasterizer_state);
17489 release_test_context(&test_context);
17492 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
17493 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
17494 const char *feature_name)
17496 unsigned int i;
17498 for (i = 0; i < format_count; ++i)
17500 DXGI_FORMAT format = formats[i].format;
17501 unsigned int supported = format_support[format] & feature_flag;
17503 if (formats[i].fl_required <= feature_level)
17505 todo_wine ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
17506 format, feature_name, feature_level, format_support[format]);
17507 continue;
17510 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
17512 if (supported)
17513 trace("Optional format %#x - %s supported, feature level %#x.\n",
17514 format, feature_name, feature_level);
17515 continue;
17518 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
17519 format, feature_name, feature_level, format_support[format]);
17523 static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
17525 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
17526 struct device_desc device_desc;
17527 ID3D11Device *device;
17528 DXGI_FORMAT format;
17529 ULONG refcount;
17530 UINT support;
17531 HRESULT hr;
17533 static const struct format_support index_buffers[] =
17535 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
17536 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
17539 device_desc.feature_level = &feature_level;
17540 device_desc.flags = 0;
17541 if (!(device = create_device(&device_desc)))
17543 skip("Failed to create device for feature level %#x.\n", feature_level);
17544 return;
17547 support = 0xdeadbeef;
17548 hr = ID3D11Device_CheckFormatSupport(device, ~0u, &support);
17549 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
17550 ok(!support, "Got unexpected format support %#x.\n", support);
17552 memset(format_support, 0, sizeof(format_support));
17553 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
17555 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
17556 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
17557 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
17558 format, hr, format_support[format]);
17561 check_format_support(format_support, feature_level,
17562 index_buffers, ARRAY_SIZE(index_buffers),
17563 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
17565 check_format_support(format_support, feature_level,
17566 display_format_support, ARRAY_SIZE(display_format_support),
17567 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
17569 refcount = ID3D11Device_Release(device);
17570 ok(!refcount, "Device has %u references left.\n", refcount);
17573 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
17575 struct d3d11_test_context test_context;
17576 D3D11_SUBRESOURCE_DATA resource_data;
17577 D3D11_TEXTURE2D_DESC texture_desc;
17578 ID3D11ShaderResourceView *srv;
17579 ID3D11DeviceContext *context;
17580 ID3D11Texture2D *texture;
17581 ID3D11PixelShader *ps;
17582 ID3D11Device *device;
17583 HRESULT hr;
17585 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
17586 static const DWORD ps_code[] =
17588 #if 0
17589 float4 main() : SV_TARGET
17591 return float4(1.0f, 0.0f, 0.0f, 0.5f);
17593 #endif
17594 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
17595 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
17596 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
17597 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
17598 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
17599 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
17600 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
17601 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
17602 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
17603 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
17604 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
17605 0x45475241, 0xabab0054,
17607 static const DWORD ps_texture_code[] =
17609 #if 0
17610 Texture2D t;
17611 SamplerState s;
17613 float4 main() : SV_TARGET
17615 return t.Sample(s, (float2)0);
17617 #endif
17618 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
17619 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
17620 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
17621 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
17622 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
17623 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
17624 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
17625 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
17626 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
17627 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
17628 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
17629 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
17630 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
17631 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17632 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
17634 static const DWORD texture_data[] = {0xffffff00};
17636 if (!init_test_context(&test_context, &feature_level))
17637 return;
17639 device = test_context.device;
17640 context = test_context.immediate_context;
17642 texture_desc.Width = 1;
17643 texture_desc.Height = 1;
17644 texture_desc.MipLevels = 0;
17645 texture_desc.ArraySize = 1;
17646 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
17647 texture_desc.SampleDesc.Count = 1;
17648 texture_desc.SampleDesc.Quality = 0;
17649 texture_desc.Usage = D3D11_USAGE_DEFAULT;
17650 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
17651 texture_desc.CPUAccessFlags = 0;
17652 texture_desc.MiscFlags = 0;
17653 resource_data.pSysMem = texture_data;
17654 resource_data.SysMemPitch = sizeof(texture_data);
17655 resource_data.SysMemSlicePitch = 0;
17656 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
17657 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
17658 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
17659 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
17661 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17662 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
17663 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17664 draw_quad(&test_context);
17665 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
17666 ID3D11PixelShader_Release(ps);
17668 draw_color_quad(&test_context, &color);
17669 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
17671 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
17672 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
17673 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17674 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
17675 draw_quad(&test_context);
17676 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
17677 ID3D11PixelShader_Release(ps);
17679 ID3D11ShaderResourceView_Release(srv);
17680 ID3D11Texture2D_Release(texture);
17681 release_test_context(&test_context);
17684 static void queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
17685 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
17687 static const D3D_FEATURE_LEVEL feature_levels[] =
17689 D3D_FEATURE_LEVEL_11_1,
17690 D3D_FEATURE_LEVEL_11_0,
17691 D3D_FEATURE_LEVEL_10_1,
17692 D3D_FEATURE_LEVEL_10_0,
17693 D3D_FEATURE_LEVEL_9_3,
17694 D3D_FEATURE_LEVEL_9_2,
17695 D3D_FEATURE_LEVEL_9_1
17697 unsigned int i;
17699 assert(begin <= end);
17700 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
17702 if (begin <= feature_levels[i] && feature_levels[i] <= end)
17703 queue_test_fl(test_func, feature_levels[i]);
17707 static void queue_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
17709 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
17710 D3D_FEATURE_LEVEL_11_1, test_func);
17713 static void queue_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
17715 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
17716 D3D_FEATURE_LEVEL_9_3, test_func);
17719 static void test_ddy(void)
17721 static const struct
17723 struct vec4 position;
17724 unsigned int color;
17726 quad[] =
17728 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
17729 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
17730 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
17731 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
17733 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17735 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17736 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
17738 #if 0
17739 struct vs_data
17741 float4 pos : SV_POSITION;
17742 float4 color : COLOR;
17745 void main(in struct vs_data vs_input, out struct vs_data vs_output)
17747 vs_output.pos = vs_input.pos;
17748 vs_output.color = vs_input.color;
17750 #endif
17751 static const DWORD vs_code[] =
17753 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
17754 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17755 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
17756 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
17757 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
17758 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
17759 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
17760 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
17761 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
17762 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
17763 0x0100003e,
17765 #if 0
17766 struct ps_data
17768 float4 pos : SV_POSITION;
17769 float4 color : COLOR;
17772 float4 main(struct ps_data ps_input) : SV_Target
17774 return ddy(ps_input.color) * 240.0 + 0.5;
17776 #endif
17777 static const DWORD ps_code_ddy[] =
17779 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
17780 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17781 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17782 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
17783 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17784 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
17785 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
17786 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
17787 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
17788 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
17790 #if 0
17791 struct ps_data
17793 float4 pos : SV_POSITION;
17794 float4 color : COLOR;
17797 float4 main(struct ps_data ps_input) : SV_Target
17799 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
17801 #endif
17802 static const DWORD ps_code_ddy_coarse[] =
17804 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
17805 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17806 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17807 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
17808 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17809 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
17810 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17811 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
17812 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
17813 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
17815 #if 0
17816 struct ps_data
17818 float4 pos : SV_POSITION;
17819 float4 color : COLOR;
17822 float4 main(struct ps_data ps_input) : SV_Target
17824 return ddy_fine(ps_input.color) * 240.0 + 0.5;
17826 #endif
17827 static const DWORD ps_code_ddy_fine[] =
17829 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
17830 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17831 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17832 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
17833 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17834 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
17835 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17836 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
17837 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
17838 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
17840 static const struct
17842 D3D_FEATURE_LEVEL min_feature_level;
17843 const DWORD *ps_code;
17844 unsigned int ps_code_size;
17846 tests[] =
17848 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
17849 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
17850 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
17852 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
17853 struct d3d11_test_context test_context;
17854 D3D11_TEXTURE2D_DESC texture_desc;
17855 D3D_FEATURE_LEVEL feature_level;
17856 ID3D11InputLayout *input_layout;
17857 ID3D11DeviceContext *context;
17858 unsigned int stride, offset;
17859 struct resource_readback rb;
17860 ID3D11RenderTargetView *rtv;
17861 ID3D11Texture2D *texture;
17862 ID3D11VertexShader *vs;
17863 ID3D11PixelShader *ps;
17864 ID3D11Device *device;
17865 ID3D11Buffer *vb;
17866 unsigned int i;
17867 DWORD color;
17868 HRESULT hr;
17870 if (!init_test_context(&test_context, NULL))
17871 return;
17873 device = test_context.device;
17874 context = test_context.immediate_context;
17875 feature_level = ID3D11Device_GetFeatureLevel(device);
17877 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17878 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17879 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17881 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
17882 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17884 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17885 vs_code, sizeof(vs_code), &input_layout);
17886 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17888 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
17890 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17891 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17893 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
17894 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
17895 stride = sizeof(*quad);
17896 offset = 0;
17897 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
17898 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17900 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17902 if (feature_level < tests[i].min_feature_level)
17904 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
17905 feature_level, tests[i].min_feature_level);
17906 continue;
17909 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
17910 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17912 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17914 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17915 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
17916 ID3D11DeviceContext_Draw(context, 4, 0);
17918 get_texture_readback(texture, 0, &rb);
17919 color = get_readback_color(&rb, 320, 190, 0);
17920 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
17921 color = get_readback_color(&rb, 255, 240, 0);
17922 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
17923 color = get_readback_color(&rb, 320, 240, 0);
17924 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
17925 color = get_readback_color(&rb, 385, 240, 0);
17926 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
17927 color = get_readback_color(&rb, 320, 290, 0);
17928 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
17929 release_resource_readback(&rb);
17931 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
17932 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
17933 ID3D11DeviceContext_Draw(context, 4, 0);
17935 get_texture_readback(test_context.backbuffer, 0, &rb);
17936 color = get_readback_color(&rb, 320, 190, 0);
17937 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
17938 color = get_readback_color(&rb, 255, 240, 0);
17939 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
17940 color = get_readback_color(&rb, 320, 240, 0);
17941 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
17942 color = get_readback_color(&rb, 385, 240, 0);
17943 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
17944 color = get_readback_color(&rb, 320, 290, 0);
17945 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
17946 release_resource_readback(&rb);
17948 ID3D11PixelShader_Release(ps);
17951 ID3D11VertexShader_Release(vs);
17952 ID3D11Buffer_Release(vb);
17953 ID3D11InputLayout_Release(input_layout);
17954 ID3D11Texture2D_Release(texture);
17955 ID3D11RenderTargetView_Release(rtv);
17956 release_test_context(&test_context);
17959 static void test_shader_input_registers_limits(void)
17961 struct d3d11_test_context test_context;
17962 D3D11_SUBRESOURCE_DATA resource_data;
17963 D3D11_TEXTURE2D_DESC texture_desc;
17964 D3D11_SAMPLER_DESC sampler_desc;
17965 ID3D11ShaderResourceView *srv;
17966 ID3D11DeviceContext *context;
17967 ID3D11SamplerState *sampler;
17968 ID3D11Texture2D *texture;
17969 ID3D11PixelShader *ps;
17970 ID3D11Device *device;
17971 HRESULT hr;
17973 static const DWORD ps_last_register_code[] =
17975 #if 0
17976 Texture2D t : register(t127);
17977 SamplerState s : register(s15);
17979 void main(out float4 target : SV_Target)
17981 target = t.Sample(s, float2(0, 0));
17983 #endif
17984 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
17985 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17986 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17987 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
17988 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
17989 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
17990 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
17992 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17993 static const DWORD texture_data[] = {0xff00ff00};
17995 if (!init_test_context(&test_context, NULL))
17996 return;
17998 device = test_context.device;
17999 context = test_context.immediate_context;
18001 texture_desc.Width = 1;
18002 texture_desc.Height = 1;
18003 texture_desc.MipLevels = 0;
18004 texture_desc.ArraySize = 1;
18005 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
18006 texture_desc.SampleDesc.Count = 1;
18007 texture_desc.SampleDesc.Quality = 0;
18008 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18009 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18010 texture_desc.CPUAccessFlags = 0;
18011 texture_desc.MiscFlags = 0;
18013 resource_data.pSysMem = texture_data;
18014 resource_data.SysMemPitch = sizeof(texture_data);
18015 resource_data.SysMemSlicePitch = 0;
18017 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
18018 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
18020 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
18021 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
18023 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
18024 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
18025 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
18026 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
18027 sampler_desc.MipLODBias = 0.0f;
18028 sampler_desc.MaxAnisotropy = 0;
18029 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
18030 sampler_desc.BorderColor[0] = 0.0f;
18031 sampler_desc.BorderColor[1] = 0.0f;
18032 sampler_desc.BorderColor[2] = 0.0f;
18033 sampler_desc.BorderColor[3] = 0.0f;
18034 sampler_desc.MinLOD = 0.0f;
18035 sampler_desc.MaxLOD = 0.0f;
18037 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
18038 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
18040 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
18041 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18042 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18044 ID3D11DeviceContext_PSSetShaderResources(context,
18045 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
18046 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
18047 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
18048 draw_quad(&test_context);
18049 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
18051 ID3D11PixelShader_Release(ps);
18052 ID3D11SamplerState_Release(sampler);
18053 ID3D11ShaderResourceView_Release(srv);
18054 ID3D11Texture2D_Release(texture);
18055 release_test_context(&test_context);
18058 static void test_unbind_shader_resource_view(void)
18060 struct d3d11_test_context test_context;
18061 D3D11_SUBRESOURCE_DATA resource_data;
18062 ID3D11ShaderResourceView *srv, *srv2;
18063 D3D11_TEXTURE2D_DESC texture_desc;
18064 ID3D11DeviceContext *context;
18065 ID3D11Texture2D *texture;
18066 ID3D11PixelShader *ps;
18067 ID3D11Device *device;
18068 HRESULT hr;
18070 static const DWORD ps_code[] =
18072 #if 0
18073 Texture2D t0;
18074 Texture2D t1;
18075 SamplerState s;
18077 float4 main() : SV_Target
18079 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
18081 #endif
18082 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
18083 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18084 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18085 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
18086 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
18087 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
18088 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
18089 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
18090 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
18091 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
18092 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
18093 0x3f800000, 0x0100003e,
18095 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
18096 static const DWORD texture_data[] = {0xff00ff00};
18098 if (!init_test_context(&test_context, NULL))
18099 return;
18101 device = test_context.device;
18102 context = test_context.immediate_context;
18104 texture_desc.Width = 1;
18105 texture_desc.Height = 1;
18106 texture_desc.MipLevels = 0;
18107 texture_desc.ArraySize = 1;
18108 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
18109 texture_desc.SampleDesc.Count = 1;
18110 texture_desc.SampleDesc.Quality = 0;
18111 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18112 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18113 texture_desc.CPUAccessFlags = 0;
18114 texture_desc.MiscFlags = 0;
18116 resource_data.pSysMem = texture_data;
18117 resource_data.SysMemPitch = sizeof(texture_data);
18118 resource_data.SysMemSlicePitch = 0;
18120 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
18121 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
18122 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
18123 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
18124 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18125 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18126 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18128 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18129 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
18130 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
18131 draw_quad(&test_context);
18132 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
18134 srv2 = NULL;
18135 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
18136 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
18137 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
18138 draw_quad(&test_context);
18139 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
18141 ID3D11PixelShader_Release(ps);
18142 ID3D11ShaderResourceView_Release(srv);
18143 ID3D11Texture2D_Release(texture);
18144 release_test_context(&test_context);
18147 static void test_stencil_separate(void)
18149 struct d3d11_test_context test_context;
18150 D3D11_TEXTURE2D_DESC texture_desc;
18151 D3D11_DEPTH_STENCIL_DESC ds_desc;
18152 ID3D11DepthStencilState *ds_state;
18153 ID3D11DepthStencilView *ds_view;
18154 D3D11_RASTERIZER_DESC rs_desc;
18155 ID3D11DeviceContext *context;
18156 ID3D11RasterizerState *rs;
18157 ID3D11Texture2D *texture;
18158 ID3D11Device *device;
18159 HRESULT hr;
18161 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
18162 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
18163 static const struct vec3 ccw_quad[] =
18165 {-1.0f, -1.0f, 0.0f},
18166 { 1.0f, -1.0f, 0.0f},
18167 {-1.0f, 1.0f, 0.0f},
18168 { 1.0f, 1.0f, 0.0f},
18171 if (!init_test_context(&test_context, NULL))
18172 return;
18174 device = test_context.device;
18175 context = test_context.immediate_context;
18177 texture_desc.Width = 640;
18178 texture_desc.Height = 480;
18179 texture_desc.MipLevels = 1;
18180 texture_desc.ArraySize = 1;
18181 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
18182 texture_desc.SampleDesc.Count = 1;
18183 texture_desc.SampleDesc.Quality = 0;
18184 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18185 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
18186 texture_desc.CPUAccessFlags = 0;
18187 texture_desc.MiscFlags = 0;
18188 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18189 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18190 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
18191 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
18193 ds_desc.DepthEnable = TRUE;
18194 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
18195 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
18196 ds_desc.StencilEnable = TRUE;
18197 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
18198 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
18199 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
18200 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
18201 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
18202 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
18203 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
18204 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
18205 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
18206 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
18207 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
18208 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
18210 rs_desc.FillMode = D3D11_FILL_SOLID;
18211 rs_desc.CullMode = D3D11_CULL_NONE;
18212 rs_desc.FrontCounterClockwise = FALSE;
18213 rs_desc.DepthBias = 0;
18214 rs_desc.DepthBiasClamp = 0.0f;
18215 rs_desc.SlopeScaledDepthBias = 0.0f;
18216 rs_desc.DepthClipEnable = TRUE;
18217 rs_desc.ScissorEnable = FALSE;
18218 rs_desc.MultisampleEnable = FALSE;
18219 rs_desc.AntialiasedLineEnable = FALSE;
18220 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
18221 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
18223 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
18224 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
18225 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
18226 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
18227 ID3D11DeviceContext_RSSetState(context, rs);
18229 draw_color_quad(&test_context, &green);
18230 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
18232 ID3D11Buffer_Release(test_context.vb);
18233 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
18235 draw_color_quad(&test_context, &green);
18236 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
18238 ID3D11RasterizerState_Release(rs);
18239 rs_desc.FrontCounterClockwise = TRUE;
18240 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
18241 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
18242 ID3D11DeviceContext_RSSetState(context, rs);
18244 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
18245 draw_color_quad(&test_context, &green);
18246 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
18248 ID3D11DepthStencilState_Release(ds_state);
18249 ID3D11DepthStencilView_Release(ds_view);
18250 ID3D11RasterizerState_Release(rs);
18251 ID3D11Texture2D_Release(texture);
18252 release_test_context(&test_context);
18255 static void test_uav_load(void)
18257 struct shader
18259 const DWORD *code;
18260 size_t size;
18262 struct texture
18264 UINT width;
18265 UINT height;
18266 UINT miplevel_count;
18267 UINT array_size;
18268 DXGI_FORMAT format;
18269 D3D11_SUBRESOURCE_DATA data[3];
18272 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
18273 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18274 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
18275 struct d3d11_test_context test_context;
18276 const struct texture *current_texture;
18277 ID3D11Texture2D *texture, *rt_texture;
18278 D3D11_TEXTURE2D_DESC texture_desc;
18279 const struct shader *current_ps;
18280 ID3D11UnorderedAccessView *uav;
18281 ID3D11DeviceContext *context;
18282 struct resource_readback rb;
18283 ID3D11PixelShader *ps;
18284 ID3D11Device *device;
18285 unsigned int i, x, y;
18286 ID3D11Buffer *cb;
18287 HRESULT hr;
18289 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
18290 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18291 static const DWORD ps_ld_2d_float_code[] =
18293 #if 0
18294 RWTexture2D<float> u;
18296 float main(float4 position : SV_Position) : SV_Target
18298 float2 s;
18299 u.GetDimensions(s.x, s.y);
18300 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
18302 #endif
18303 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
18304 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18305 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
18306 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18307 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
18308 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
18309 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
18310 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
18311 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
18312 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
18313 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
18314 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
18315 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
18317 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
18318 static const DWORD ps_ld_2d_uint_code[] =
18320 #if 0
18321 RWTexture2D<uint> u;
18323 uint main(float4 position : SV_Position) : SV_Target
18325 float2 s;
18326 u.GetDimensions(s.x, s.y);
18327 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
18329 #endif
18330 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
18331 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18332 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
18333 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
18334 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
18335 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
18336 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
18337 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
18338 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
18339 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
18340 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
18341 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
18342 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
18344 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
18345 static const DWORD ps_ld_2d_int_code[] =
18347 #if 0
18348 RWTexture2D<int> u;
18350 int main(float4 position : SV_Position) : SV_Target
18352 float2 s;
18353 u.GetDimensions(s.x, s.y);
18354 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
18356 #endif
18357 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
18358 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18359 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
18360 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
18361 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
18362 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
18363 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
18364 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
18365 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
18366 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
18367 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
18368 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
18369 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
18371 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
18372 static const DWORD ps_ld_2d_uint_arr_code[] =
18374 #if 0
18375 RWTexture2DArray<uint> u;
18377 uint layer;
18379 uint main(float4 position : SV_Position) : SV_Target
18381 float3 s;
18382 u.GetDimensions(s.x, s.y, s.z);
18383 s.z = layer;
18384 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
18386 #endif
18387 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
18388 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18389 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
18390 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
18391 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
18392 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
18393 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
18394 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
18395 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
18396 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
18397 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
18398 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
18399 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
18400 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
18402 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
18403 static const float float_data[] =
18405 0.50f, 0.25f, 1.00f, 0.00f,
18406 -1.00f, -2.00f, -3.00f, -4.00f,
18407 -0.50f, -0.25f, -1.00f, -0.00f,
18408 1.00f, 2.00f, 3.00f, 4.00f,
18410 static const unsigned int uint_data[] =
18412 0x00, 0x10, 0x20, 0x30,
18413 0x40, 0x50, 0x60, 0x70,
18414 0x80, 0x90, 0xa0, 0xb0,
18415 0xc0, 0xd0, 0xe0, 0xf0,
18417 static const unsigned int uint_data2[] =
18419 0xffff, 0xffff, 0xffff, 0xffff,
18420 0xffff, 0xc000, 0xc000, 0xffff,
18421 0xffff, 0xc000, 0xc000, 0xffff,
18422 0xffff, 0xffff, 0xffff, 0xffff,
18424 static const unsigned int uint_data3[] =
18426 0xaa, 0xaa, 0xcc, 0xcc,
18427 0xaa, 0xaa, 0xdd, 0xdd,
18428 0xbb, 0xbb, 0xee, 0xee,
18429 0xbb, 0xbb, 0xff, 0xff,
18431 static const int int_data[] =
18433 -1, 0x10, 0x20, 0x30,
18434 0x40, 0x50, 0x60, -777,
18435 -666, 0x90, -555, 0xb0,
18436 0xc0, 0xd0, 0xe0, -101,
18438 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
18439 {{float_data, 4 * sizeof(*float_data), 0}}};
18440 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
18441 {{uint_data, 4 * sizeof(*uint_data), 0}}};
18442 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
18443 {{uint_data, 4 * sizeof(*uint_data), 0},
18444 {uint_data2, 4 * sizeof(*uint_data2), 0},
18445 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
18446 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
18447 {{int_data, 4 * sizeof(*int_data), 0}}};
18449 static const struct test
18451 const struct shader *ps;
18452 const struct texture *texture;
18453 struct uav_desc uav_desc;
18454 struct uvec4 constant;
18455 const DWORD *expected_colors;
18457 tests[] =
18459 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
18460 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
18461 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
18462 #define R32_UINT DXGI_FORMAT_R32_UINT
18463 #define R32_SINT DXGI_FORMAT_R32_SINT
18464 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {}, (const DWORD *)float_data},
18465 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {}, (const DWORD *)uint_data},
18466 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {}, (const DWORD *)int_data},
18467 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
18468 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
18469 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
18470 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
18471 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
18472 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
18473 #undef TEX_2D
18474 #undef TEX_2D_ARRAY
18475 #undef R32_FLOAT
18476 #undef R32_UINT
18477 #undef R32_SINT
18480 if (!init_test_context(&test_context, &feature_level))
18481 return;
18483 device = test_context.device;
18484 context = test_context.immediate_context;
18486 texture_desc.Width = 640;
18487 texture_desc.Height = 480;
18488 texture_desc.MipLevels = 1;
18489 texture_desc.ArraySize = 1;
18490 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
18491 texture_desc.SampleDesc.Count = 1;
18492 texture_desc.SampleDesc.Quality = 0;
18493 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18494 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
18495 texture_desc.CPUAccessFlags = 0;
18496 texture_desc.MiscFlags = 0;
18497 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
18498 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18500 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
18501 U(rtv_desc).Texture2D.MipSlice = 0;
18503 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
18504 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
18505 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18507 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
18508 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
18509 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18511 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
18512 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
18513 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18515 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
18517 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
18518 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18520 ps = NULL;
18521 uav = NULL;
18522 texture = NULL;
18523 current_ps = NULL;
18524 current_texture = NULL;
18525 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18527 const struct test *test = &tests[i];
18528 ID3D11RenderTargetView *current_rtv;
18530 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18531 NULL, &test->constant, 0, 0);
18533 if (current_ps != test->ps)
18535 if (ps)
18536 ID3D11PixelShader_Release(ps);
18538 current_ps = test->ps;
18540 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
18541 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
18543 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18546 if (current_texture != test->texture)
18548 if (texture)
18549 ID3D11Texture2D_Release(texture);
18551 current_texture = test->texture;
18553 texture_desc.Width = current_texture->width;
18554 texture_desc.Height = current_texture->height;
18555 texture_desc.MipLevels = current_texture->miplevel_count;
18556 texture_desc.ArraySize = current_texture->array_size;
18557 texture_desc.Format = current_texture->format;
18559 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
18560 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
18563 if (uav)
18564 ID3D11UnorderedAccessView_Release(uav);
18566 get_uav_desc(&uav_desc, &test->uav_desc);
18567 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
18568 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
18570 switch (uav_desc.Format)
18572 case DXGI_FORMAT_R32_FLOAT:
18573 current_rtv = rtv_float;
18574 break;
18575 case DXGI_FORMAT_R32_UINT:
18576 current_rtv = rtv_uint;
18577 break;
18578 case DXGI_FORMAT_R32_SINT:
18579 current_rtv = rtv_sint;
18580 break;
18581 default:
18582 trace("Unhandled format %#x.\n", uav_desc.Format);
18583 current_rtv = NULL;
18584 break;
18587 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
18589 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
18590 1, 1, &uav, NULL);
18592 draw_quad(&test_context);
18594 get_texture_readback(rt_texture, 0, &rb);
18595 for (y = 0; y < 4; ++y)
18597 for (x = 0; x < 4; ++x)
18599 DWORD expected = test->expected_colors[y * 4 + x];
18600 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
18601 ok(compare_color(color, expected, 0),
18602 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
18603 i, color, expected, x, y);
18606 release_resource_readback(&rb);
18608 ID3D11PixelShader_Release(ps);
18609 ID3D11Texture2D_Release(texture);
18610 ID3D11UnorderedAccessView_Release(uav);
18612 ID3D11Buffer_Release(cb);
18613 ID3D11RenderTargetView_Release(rtv_float);
18614 ID3D11RenderTargetView_Release(rtv_sint);
18615 ID3D11RenderTargetView_Release(rtv_uint);
18616 ID3D11Texture2D_Release(rt_texture);
18617 release_test_context(&test_context);
18620 static void test_cs_uav_store(void)
18622 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18623 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18624 static const float zero[4] = {0.0f};
18625 D3D11_TEXTURE2D_DESC texture_desc;
18626 ID3D11UnorderedAccessView *uav;
18627 struct device_desc device_desc;
18628 ID3D11DeviceContext *context;
18629 struct vec4 input = {1.0f};
18630 ID3D11Texture2D *texture;
18631 ID3D11ComputeShader *cs;
18632 ID3D11Device *device;
18633 ID3D11Buffer *cb;
18634 ULONG refcount;
18635 HRESULT hr;
18636 RECT rect;
18638 static const DWORD cs_1_thread_code[] =
18640 #if 0
18641 RWTexture2D<float> u;
18643 float value;
18645 [numthreads(1, 1, 1)]
18646 void main()
18648 uint x, y, width, height;
18649 u.GetDimensions(width, height);
18650 for (y = 0; y < height; ++y)
18652 for (x = 0; x < width; ++x)
18653 u[uint2(x, y)] = value;
18656 #endif
18657 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
18658 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18659 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
18660 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
18661 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
18662 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
18663 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
18664 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
18665 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
18666 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
18667 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
18668 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
18669 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
18670 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
18671 0x01000016, 0x0100003e,
18673 static const DWORD cs_1_group_code[] =
18675 #if 0
18676 RWTexture2D<float> u;
18678 float value;
18680 [numthreads(16, 16, 1)]
18681 void main(uint3 threadID : SV_GroupThreadID)
18683 uint2 count, size ;
18684 u.GetDimensions(size.x, size.y);
18685 count = size / (uint2)16;
18686 for (uint y = 0; y < count.y; ++y)
18687 for (uint x = 0; x < count.x; ++x)
18688 u[count * threadID.xy + uint2(x, y)] = value;
18690 #endif
18691 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
18692 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18693 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
18694 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
18695 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
18696 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
18697 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
18698 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
18699 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
18700 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
18701 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
18702 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
18703 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
18704 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
18705 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
18706 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
18707 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
18709 static const DWORD cs_1_store_code[] =
18711 #if 0
18712 RWTexture2D<float> u;
18714 float value;
18716 [numthreads(1, 1, 1)]
18717 void main(uint3 groupID : SV_GroupID)
18719 u[groupID.xy] = value;
18721 #endif
18722 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
18723 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18724 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
18725 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
18726 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
18727 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
18729 static const DWORD cs_dispatch_id_code[] =
18731 #if 0
18732 RWTexture2D<float> u;
18734 float value;
18736 [numthreads(4, 4, 1)]
18737 void main(uint3 id : SV_DispatchThreadID)
18739 u[id.xy] = value;
18741 #endif
18742 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
18743 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18744 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
18745 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
18746 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
18747 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
18749 static const DWORD cs_group_index_code[] =
18751 #if 0
18752 RWTexture2D<float> u;
18754 float value;
18756 [numthreads(32, 1, 1)]
18757 void main(uint index : SV_GroupIndex)
18759 uint2 size;
18760 u.GetDimensions(size.x, size.y);
18761 uint count = size.x * size.y / 32;
18762 index *= count;
18763 for (uint i = 0; i < count; ++i, ++index)
18764 u[uint2(index % size.x, index / size.x)] = value;
18766 #endif
18767 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
18768 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18769 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
18770 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
18771 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
18772 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
18773 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
18774 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
18775 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
18776 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
18777 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
18778 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
18779 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
18780 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
18781 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
18782 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
18785 device_desc.feature_level = &feature_level;
18786 device_desc.flags = 0;
18787 if (!(device = create_device(&device_desc)))
18789 skip("Failed to create device for feature level %#x.\n", feature_level);
18790 return;
18793 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
18795 texture_desc.Width = 64;
18796 texture_desc.Height = 64;
18797 texture_desc.MipLevels = 1;
18798 texture_desc.ArraySize = 1;
18799 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
18800 texture_desc.SampleDesc.Count = 1;
18801 texture_desc.SampleDesc.Quality = 0;
18802 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18803 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
18804 texture_desc.CPUAccessFlags = 0;
18805 texture_desc.MiscFlags = 0;
18807 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18808 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18810 uav_desc.Format = texture_desc.Format;
18811 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
18812 U(uav_desc).Texture2D.MipSlice = 0;
18814 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
18815 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18817 ID3D11Device_GetImmediateContext(device, &context);
18819 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
18820 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
18822 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
18823 check_texture_float(texture, 0.0f, 2);
18825 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
18826 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18827 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18829 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18830 check_texture_float(texture, 1.0f, 2);
18832 input.x = 0.5f;
18833 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
18834 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18835 check_texture_float(texture, 0.5f, 2);
18837 ID3D11ComputeShader_Release(cs);
18839 input.x = 2.0f;
18840 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
18841 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
18842 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18843 check_texture_float(texture, 0.5f, 2);
18845 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
18846 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18847 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18849 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18850 check_texture_float(texture, 2.0f, 2);
18852 input.x = 4.0f;
18853 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
18854 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18855 check_texture_float(texture, 4.0f, 2);
18857 ID3D11ComputeShader_Release(cs);
18859 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
18860 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18861 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18863 input.x = 1.0f;
18864 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
18865 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
18866 check_texture_float(texture, 1.0f, 2);
18868 input.x = 0.5f;
18869 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
18870 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
18871 SetRect(&rect, 0, 0, 16, 32);
18872 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
18873 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
18874 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
18875 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
18876 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
18878 ID3D11ComputeShader_Release(cs);
18880 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
18881 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18882 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18884 input.x = 0.6f;
18885 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
18886 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
18887 SetRect(&rect, 0, 0, 60, 60);
18888 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
18889 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
18890 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
18891 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
18892 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
18894 input.x = 0.7f;
18895 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
18896 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
18897 check_texture_float(texture, 0.7f, 2);
18899 ID3D11ComputeShader_Release(cs);
18901 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
18902 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18903 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18905 input.x = 0.3f;
18906 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
18907 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18908 check_texture_float(texture, 0.3f, 2);
18910 input.x = 0.1f;
18911 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
18912 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
18913 check_texture_float(texture, 0.1f, 2);
18915 ID3D11ComputeShader_Release(cs);
18917 ID3D11Buffer_Release(cb);
18918 ID3D11Texture2D_Release(texture);
18919 ID3D11UnorderedAccessView_Release(uav);
18920 ID3D11DeviceContext_Release(context);
18921 refcount = ID3D11Device_Release(device);
18922 ok(!refcount, "Device has %u references left.\n", refcount);
18925 static void test_uav_store_immediate_constant(void)
18927 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18928 struct d3d11_test_context test_context;
18929 D3D11_TEXTURE2D_DESC texture_desc;
18930 ID3D11UnorderedAccessView *uav;
18931 ID3D11DeviceContext *context;
18932 struct resource_readback rb;
18933 ID3D11Texture2D *texture;
18934 ID3D11ComputeShader *cs;
18935 unsigned int uint_data;
18936 ID3D11Device *device;
18937 ID3D11Buffer *buffer;
18938 float float_data;
18939 int int_data;
18940 HRESULT hr;
18942 static const DWORD cs_store_int_code[] =
18944 #if 0
18945 RWBuffer<int> u;
18947 [numthreads(1, 1, 1)]
18948 void main()
18950 u[0] = 42;
18952 #endif
18953 0x43425844, 0x7246d785, 0x3f4ccbd6, 0x6a7cdbc0, 0xe2b58c72, 0x00000001, 0x000000b8, 0x00000003,
18954 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18955 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
18956 0x0400089c, 0x0011e000, 0x00000000, 0x00003333, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
18957 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
18958 0x00004002, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, 0x0100003e,
18960 static const DWORD cs_store_float_code[] =
18962 #if 0
18963 RWBuffer<float> u;
18965 [numthreads(1, 1, 1)]
18966 void main()
18968 u[0] = 1.0;
18970 #endif
18971 0x43425844, 0x525eea68, 0xc4cd5716, 0xc588f9c4, 0x0da27c5a, 0x00000001, 0x000000b8, 0x00000003,
18972 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18973 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
18974 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
18975 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
18976 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e,
18978 static const DWORD cs_store_unorm_code[] =
18980 #if 0
18981 RWTexture2D<unorm float> u;
18983 [numthreads(1, 1, 1)]
18984 void main()
18986 u[uint2(0, 0)] = 0.5f;
18988 #endif
18989 0x43425844, 0x3623f1de, 0xe847109e, 0x8e3da13f, 0xb6787b06, 0x00000001, 0x000000b8, 0x00000003,
18990 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18991 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
18992 0x0400189c, 0x0011e000, 0x00000000, 0x00001111, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
18993 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
18994 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
18996 static const DWORD cs_store_snorm_code[] =
18998 #if 0
18999 RWTexture2D<snorm float> u;
19001 [numthreads(1, 1, 1)]
19002 void main()
19004 u[uint2(0, 0)] = -0.5f;
19006 #endif
19007 0x43425844, 0xce5397fc, 0x7464bc06, 0xc79aa56c, 0x881bd7ef, 0x00000001, 0x000000b8, 0x00000003,
19008 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19009 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
19010 0x0400189c, 0x0011e000, 0x00000000, 0x00002222, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
19011 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
19012 0x00004002, 0xbf000000, 0xbf000000, 0xbf000000, 0xbf000000, 0x0100003e,
19014 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19015 static const unsigned int zero[4] = {0};
19017 if (!init_test_context(&test_context, &feature_level))
19018 return;
19020 device = test_context.device;
19021 context = test_context.immediate_context;
19023 buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
19025 uav_desc.Format = DXGI_FORMAT_R32_SINT;
19026 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19027 U(uav_desc).Buffer.FirstElement = 0;
19028 U(uav_desc).Buffer.NumElements = 1;
19029 U(uav_desc).Buffer.Flags = 0;
19030 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19031 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19032 hr = ID3D11Device_CreateComputeShader(device, cs_store_int_code, sizeof(cs_store_int_code), NULL, &cs);
19033 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19035 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19036 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19037 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19038 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19039 get_buffer_readback(buffer, &rb);
19040 int_data = get_readback_color(&rb, 0, 0, 0);
19041 ok(int_data == 42, "Got unexpected value %u.\n", int_data);
19042 release_resource_readback(&rb);
19044 ID3D11ComputeShader_Release(cs);
19045 ID3D11UnorderedAccessView_Release(uav);
19046 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
19047 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19048 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19049 hr = ID3D11Device_CreateComputeShader(device, cs_store_float_code, sizeof(cs_store_float_code), NULL, &cs);
19050 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19052 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19053 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19054 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19055 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19056 get_buffer_readback(buffer, &rb);
19057 float_data = get_readback_float(&rb, 0, 0);
19058 ok(float_data == 1.0f, "Got unexpected value %.8e.\n", float_data);
19059 release_resource_readback(&rb);
19061 texture_desc.Width = 64;
19062 texture_desc.Height = 64;
19063 texture_desc.MipLevels = 1;
19064 texture_desc.ArraySize = 1;
19065 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
19066 texture_desc.SampleDesc.Count = 1;
19067 texture_desc.SampleDesc.Quality = 0;
19068 texture_desc.Usage = D3D11_USAGE_DEFAULT;
19069 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19070 texture_desc.CPUAccessFlags = 0;
19071 texture_desc.MiscFlags = 0;
19072 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19073 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
19074 ID3D11UnorderedAccessView_Release(uav);
19075 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
19076 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
19078 ID3D11ComputeShader_Release(cs);
19079 hr = ID3D11Device_CreateComputeShader(device, cs_store_unorm_code, sizeof(cs_store_unorm_code), NULL, &cs);
19080 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
19081 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19082 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19083 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19084 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19085 get_texture_readback(texture, 0, &rb);
19086 uint_data = get_readback_color(&rb, 0, 0, 0);
19087 ok(compare_color(uint_data, 0x80808080, 1), "Got unexpected color 0x%08x.\n", uint_data);
19088 release_resource_readback(&rb);
19090 ID3D11Texture2D_Release(texture);
19091 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_SNORM;
19092 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19093 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
19094 ID3D11UnorderedAccessView_Release(uav);
19095 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
19096 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
19098 ID3D11ComputeShader_Release(cs);
19099 hr = ID3D11Device_CreateComputeShader(device, cs_store_snorm_code, sizeof(cs_store_snorm_code), NULL, &cs);
19100 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
19101 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19102 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19103 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19104 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19105 get_texture_readback(texture, 0, &rb);
19106 uint_data = get_readback_color(&rb, 0, 0, 0);
19107 ok(compare_color(uint_data, 0xc0c0c0c0, 1), "Got unexpected color 0x%08x.\n", uint_data);
19108 release_resource_readback(&rb);
19110 ID3D11Buffer_Release(buffer);
19111 ID3D11Texture2D_Release(texture);
19112 ID3D11ComputeShader_Release(cs);
19113 ID3D11UnorderedAccessView_Release(uav);
19114 release_test_context(&test_context);
19117 static void test_ps_cs_uav_binding(void)
19119 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19120 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
19121 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19122 ID3D11Texture2D *cs_texture, *ps_texture;
19123 struct d3d11_test_context test_context;
19124 static const float zero[4] = {0.0f};
19125 D3D11_TEXTURE2D_DESC texture_desc;
19126 ID3D11DeviceContext *context;
19127 ID3D11Buffer *cs_cb, *ps_cb;
19128 struct vec4 input = {1.0f};
19129 ID3D11ComputeShader *cs;
19130 ID3D11PixelShader *ps;
19131 ID3D11Device *device;
19132 HRESULT hr;
19134 static const DWORD cs_code[] =
19136 #if 0
19137 RWTexture2D<float> u;
19139 float value;
19141 [numthreads(1, 1, 1)]
19142 void main()
19144 uint x, y, width, height;
19145 u.GetDimensions(width, height);
19146 for (y = 0; y < height; ++y)
19148 for (x = 0; x < width; ++x)
19149 u[uint2(x, y)] = value;
19152 #endif
19153 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
19154 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19155 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
19156 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
19157 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
19158 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
19159 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
19160 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
19161 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
19162 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
19163 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
19164 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
19165 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
19166 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
19167 0x01000016, 0x0100003e,
19169 static const DWORD ps_code[] =
19171 #if 0
19172 RWTexture2D<float> u : register(u1);
19174 float value;
19176 void main()
19178 uint x, y, width, height;
19179 u.GetDimensions(width, height);
19180 for (y = 0; y < height; ++y)
19182 for (x = 0; x < width; ++x)
19183 u[uint2(x, y)] = value;
19186 #endif
19187 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
19188 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19189 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
19190 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
19191 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
19192 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
19193 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
19194 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
19195 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
19196 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
19197 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
19198 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
19199 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
19200 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
19203 if (!init_test_context(&test_context, &feature_level))
19204 return;
19206 device = test_context.device;
19207 context = test_context.immediate_context;
19209 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
19210 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
19212 texture_desc.Width = 64;
19213 texture_desc.Height = 64;
19214 texture_desc.MipLevels = 1;
19215 texture_desc.ArraySize = 1;
19216 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
19217 texture_desc.SampleDesc.Count = 1;
19218 texture_desc.SampleDesc.Quality = 0;
19219 texture_desc.Usage = D3D11_USAGE_DEFAULT;
19220 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19221 texture_desc.CPUAccessFlags = 0;
19222 texture_desc.MiscFlags = 0;
19223 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
19224 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19225 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
19226 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19228 uav_desc.Format = texture_desc.Format;
19229 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
19230 U(uav_desc).Texture2D.MipSlice = 0;
19231 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
19232 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19233 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
19234 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19236 ID3D11Device_GetImmediateContext(device, &context);
19238 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
19239 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
19240 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
19241 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
19242 0, NULL, NULL, 1, 1, &ps_uav, NULL);
19244 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
19245 check_texture_float(cs_texture, 0.0f, 2);
19246 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
19247 check_texture_float(ps_texture, 0.0f, 2);
19249 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
19250 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19251 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19252 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19253 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19254 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19256 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19257 check_texture_float(cs_texture, 1.0f, 2);
19258 check_texture_float(ps_texture, 0.0f, 2);
19259 draw_quad(&test_context);
19260 check_texture_float(cs_texture, 1.0f, 2);
19261 check_texture_float(ps_texture, 1.0f, 2);
19263 input.x = 0.5f;
19264 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
19265 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19266 check_texture_float(cs_texture, 0.5f, 2);
19267 check_texture_float(ps_texture, 1.0f, 2);
19268 input.x = 2.0f;
19269 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
19270 draw_quad(&test_context);
19271 check_texture_float(cs_texture, 0.5f, 2);
19272 check_texture_float(ps_texture, 2.0f, 2);
19274 input.x = 8.0f;
19275 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
19276 input.x = 4.0f;
19277 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
19278 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19279 check_texture_float(cs_texture, 8.0f, 2);
19280 check_texture_float(ps_texture, 2.0f, 2);
19281 draw_quad(&test_context);
19282 check_texture_float(cs_texture, 8.0f, 2);
19283 check_texture_float(ps_texture, 4.0f, 2);
19285 ID3D11ComputeShader_Release(cs);
19286 ID3D11PixelShader_Release(ps);
19287 ID3D11Buffer_Release(cs_cb);
19288 ID3D11Buffer_Release(ps_cb);
19289 ID3D11Texture2D_Release(cs_texture);
19290 ID3D11Texture2D_Release(ps_texture);
19291 ID3D11UnorderedAccessView_Release(cs_uav);
19292 ID3D11UnorderedAccessView_Release(ps_uav);
19293 ID3D11DeviceContext_Release(context);
19294 release_test_context(&test_context);
19297 static void test_atomic_instructions(void)
19299 ID3D11UnorderedAccessView *in_uav, *out_uav;
19300 ID3D11Buffer *cb, *in_buffer, *out_buffer;
19301 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19302 struct d3d11_test_context test_context;
19303 struct resource_readback rb, out_rb;
19304 D3D11_BUFFER_DESC buffer_desc;
19305 ID3D11DeviceContext *context;
19306 ID3D11ComputeShader *cs;
19307 ID3D11PixelShader *ps;
19308 ID3D11Device *device;
19309 unsigned int i, j;
19310 HRESULT hr;
19312 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19313 static const unsigned int zero[4] = {0, 0, 0, 0};
19314 static const DWORD ps_atomics_code[] =
19316 #if 0
19317 RWByteAddressBuffer u;
19319 uint4 v;
19320 int4 i;
19322 void main()
19324 u.InterlockedAnd(0 * 4, v.x);
19325 u.InterlockedCompareStore(1 * 4, v.y, v.x);
19326 u.InterlockedAdd(2 * 4, v.x);
19327 u.InterlockedOr(3 * 4, v.x);
19328 u.InterlockedMax(4 * 4, i.x);
19329 u.InterlockedMin(5 * 4, i.x);
19330 u.InterlockedMax(6 * 4, v.x);
19331 u.InterlockedMin(7 * 4, v.x);
19332 u.InterlockedXor(8 * 4, v.x);
19334 #endif
19335 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
19336 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19337 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
19338 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
19339 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
19340 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
19341 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
19342 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
19343 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
19344 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
19345 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
19346 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
19347 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
19348 0x00000000, 0x00000000, 0x0100003e,
19350 static const DWORD cs_atomics_code[] =
19352 #if 0
19353 RWByteAddressBuffer u;
19354 RWByteAddressBuffer u2;
19356 uint4 v;
19357 int4 i;
19359 [numthreads(1, 1, 1)]
19360 void main()
19362 uint r;
19363 u.InterlockedAnd(0 * 4, v.x, r);
19364 u2.Store(0 * 4, r);
19365 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
19366 u2.Store(1 * 4, r);
19367 u.InterlockedAdd(2 * 4, v.x, r);
19368 u2.Store(2 * 4, r);
19369 u.InterlockedOr(3 * 4, v.x, r);
19370 u2.Store(3 * 4, r);
19371 u.InterlockedMax(4 * 4, i.x, r);
19372 u2.Store(4 * 4, r);
19373 u.InterlockedMin(5 * 4, i.x, r);
19374 u2.Store(5 * 4, r);
19375 u.InterlockedMax(6 * 4, v.x, r);
19376 u2.Store(6 * 4, r);
19377 u.InterlockedMin(7 * 4, v.x, r);
19378 u2.Store(7 * 4, r);
19379 u.InterlockedXor(8 * 4, v.x, r);
19380 u2.Store(8 * 4, r);
19382 #endif
19383 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
19384 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19385 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
19386 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
19387 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
19388 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
19389 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
19390 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
19391 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
19392 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
19393 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
19394 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
19395 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
19396 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
19397 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
19398 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
19399 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
19400 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
19401 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
19402 0x0010000a, 0x00000000, 0x0100003e,
19405 static const char * const instructions[] =
19407 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
19408 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
19410 static const char * const imm_instructions[] =
19412 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
19413 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
19415 static const struct test
19417 struct uvec4 v;
19418 struct ivec4 i;
19419 unsigned int input[ARRAY_SIZE(instructions)];
19420 unsigned int expected_result[ARRAY_SIZE(instructions)];
19422 tests[] =
19424 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
19425 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
19428 if (!init_test_context(&test_context, &feature_level))
19429 return;
19431 device = test_context.device;
19432 context = test_context.immediate_context;
19434 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
19435 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
19436 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
19438 buffer_desc.ByteWidth = sizeof(tests->input);
19439 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19440 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19441 buffer_desc.CPUAccessFlags = 0;
19442 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
19443 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
19444 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19445 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
19446 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19448 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
19449 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19450 U(uav_desc).Buffer.FirstElement = 0;
19451 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
19452 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
19453 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
19454 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19455 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
19456 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19458 set_viewport(context, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f);
19460 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
19461 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19462 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19464 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
19465 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19466 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19468 for (i = 0; i < ARRAY_SIZE(tests); ++i)
19470 const struct test *test = &tests[i];
19472 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
19473 NULL, &test->v, 0, 0);
19475 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
19476 NULL, test->input, 0, 0);
19478 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
19479 0, 1, &in_uav, NULL);
19481 draw_quad(&test_context);
19482 get_buffer_readback(in_buffer, &rb);
19483 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
19485 unsigned int value = get_readback_color(&rb, j, 0, 0);
19486 unsigned int expected = test->expected_result[j];
19488 todo_wine_if(expected != test->input[j]
19489 && (!strcmp(instructions[j], "atomic_imax")
19490 || !strcmp(instructions[j], "atomic_imin")))
19491 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
19492 "with inputs (%u, %u), (%d), %#x (%d).\n",
19493 i, value, value, expected, expected, instructions[j],
19494 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
19496 release_resource_readback(&rb);
19498 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
19499 NULL, test->input, 0, 0);
19500 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
19502 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
19503 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
19505 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19506 get_buffer_readback(in_buffer, &rb);
19507 get_buffer_readback(out_buffer, &out_rb);
19508 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
19510 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
19511 || !strcmp(imm_instructions[j], "imm_atomic_imin");
19512 unsigned int out_value = get_readback_color(&out_rb, j, 0, 0);
19513 unsigned int value = get_readback_color(&rb, j, 0, 0);
19514 unsigned int expected = test->expected_result[j];
19516 todo_wine_if(expected != test->input[j] && todo_instruction)
19517 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
19518 "with inputs (%u, %u), (%d), %#x (%d).\n",
19519 i, value, value, expected, expected, imm_instructions[j],
19520 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
19522 todo_wine_if(todo_instruction && out_value != test->input[j])
19523 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
19524 out_value, test->input[j], imm_instructions[j]);
19526 release_resource_readback(&out_rb);
19527 release_resource_readback(&rb);
19530 ID3D11Buffer_Release(cb);
19531 ID3D11Buffer_Release(in_buffer);
19532 ID3D11Buffer_Release(out_buffer);
19533 ID3D11ComputeShader_Release(cs);
19534 ID3D11PixelShader_Release(ps);
19535 ID3D11UnorderedAccessView_Release(in_uav);
19536 ID3D11UnorderedAccessView_Release(out_uav);
19537 release_test_context(&test_context);
19540 static void test_sm4_ret_instruction(void)
19542 struct d3d11_test_context test_context;
19543 ID3D11DeviceContext *context;
19544 ID3D11PixelShader *ps;
19545 struct uvec4 constant;
19546 ID3D11Device *device;
19547 ID3D11Buffer *cb;
19548 HRESULT hr;
19550 static const DWORD ps_code[] =
19552 #if 0
19553 uint c;
19555 float4 main() : SV_TARGET
19557 if (c == 1)
19558 return float4(1, 0, 0, 1);
19559 if (c == 2)
19560 return float4(0, 1, 0, 1);
19561 if (c == 3)
19562 return float4(0, 0, 1, 1);
19563 return float4(1, 1, 1, 1);
19565 #endif
19566 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
19567 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19568 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19569 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
19570 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
19571 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
19572 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
19573 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
19574 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
19575 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
19576 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
19577 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
19578 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
19579 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
19580 0x0100003e,
19583 if (!init_test_context(&test_context, NULL))
19584 return;
19586 device = test_context.device;
19587 context = test_context.immediate_context;
19589 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19590 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
19591 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19592 memset(&constant, 0, sizeof(constant));
19593 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
19594 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
19596 draw_quad(&test_context);
19597 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
19599 constant.x = 1;
19600 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
19601 draw_quad(&test_context);
19602 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
19604 constant.x = 2;
19605 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
19606 draw_quad(&test_context);
19607 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
19609 constant.x = 3;
19610 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
19611 draw_quad(&test_context);
19612 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
19614 constant.x = 4;
19615 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
19616 draw_quad(&test_context);
19617 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
19619 ID3D11Buffer_Release(cb);
19620 ID3D11PixelShader_Release(ps);
19621 release_test_context(&test_context);
19624 static void test_primitive_restart(void)
19626 struct d3d11_test_context test_context;
19627 ID3D11Buffer *ib32, *ib16, *vb;
19628 ID3D11DeviceContext *context;
19629 unsigned int stride, offset;
19630 ID3D11InputLayout *layout;
19631 ID3D11VertexShader *vs;
19632 ID3D11PixelShader *ps;
19633 ID3D11Device *device;
19634 unsigned int i;
19635 HRESULT hr;
19636 RECT rect;
19638 static const DWORD ps_code[] =
19640 #if 0
19641 struct vs_out
19643 float4 position : SV_Position;
19644 float4 color : color;
19647 float4 main(vs_out input) : SV_TARGET
19649 return input.color;
19651 #endif
19652 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
19653 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19654 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
19655 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
19656 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19657 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
19658 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
19659 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
19661 static const DWORD vs_code[] =
19663 #if 0
19664 struct vs_out
19666 float4 position : SV_Position;
19667 float4 color : color;
19670 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
19672 output.position = position;
19673 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
19675 #endif
19676 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
19677 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
19678 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
19679 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
19680 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
19681 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
19682 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
19683 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
19684 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
19685 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
19686 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
19687 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
19688 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
19690 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
19692 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
19694 static const struct vec2 vertices[] =
19696 {-1.00f, -1.0f},
19697 {-1.00f, 1.0f},
19698 {-0.25f, -1.0f},
19699 {-0.25f, 1.0f},
19700 { 0.25f, -1.0f},
19701 { 0.25f, 1.0f},
19702 { 1.00f, -1.0f},
19703 { 1.00f, 1.0f},
19705 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
19706 static const unsigned short indices16[] =
19708 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
19710 static const unsigned int indices32[] =
19712 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
19715 if (!init_test_context(&test_context, NULL))
19716 return;
19718 device = test_context.device;
19719 context = test_context.immediate_context;
19721 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
19722 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
19723 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19724 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
19726 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
19727 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
19729 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
19730 vs_code, sizeof(vs_code), &layout);
19731 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
19733 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
19735 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
19736 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19738 ID3D11DeviceContext_IASetInputLayout(context, layout);
19739 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
19740 stride = sizeof(*vertices);
19741 offset = 0;
19742 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
19744 for (i = 0; i < 2; ++i)
19746 if (!i)
19747 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
19748 else
19749 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
19751 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
19752 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
19753 SetRect(&rect, 0, 0, 240, 480);
19754 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
19755 SetRect(&rect, 240, 0, 400, 480);
19756 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
19757 SetRect(&rect, 400, 0, 640, 480);
19758 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
19761 ID3D11Buffer_Release(ib16);
19762 ID3D11Buffer_Release(ib32);
19763 ID3D11Buffer_Release(vb);
19764 ID3D11InputLayout_Release(layout);
19765 ID3D11PixelShader_Release(ps);
19766 ID3D11VertexShader_Release(vs);
19767 release_test_context(&test_context);
19770 static void test_resinfo_instruction(void)
19772 struct shader
19774 const DWORD *code;
19775 size_t size;
19778 struct d3d11_test_context test_context;
19779 D3D11_TEXTURE3D_DESC texture3d_desc;
19780 D3D11_TEXTURE2D_DESC texture_desc;
19781 const struct shader *current_ps;
19782 D3D_FEATURE_LEVEL feature_level;
19783 ID3D11ShaderResourceView *srv;
19784 ID3D11DeviceContext *context;
19785 ID3D11Texture2D *rtv_texture;
19786 ID3D11RenderTargetView *rtv;
19787 ID3D11Resource *texture;
19788 struct uvec4 constant;
19789 ID3D11PixelShader *ps;
19790 ID3D11Device *device;
19791 unsigned int i, type;
19792 ID3D11Buffer *cb;
19793 HRESULT hr;
19795 static const DWORD ps_2d_code[] =
19797 #if 0
19798 Texture2D t;
19800 uint type;
19801 uint level;
19803 float4 main() : SV_TARGET
19805 if (!type)
19807 float width, height, miplevels;
19808 t.GetDimensions(level, width, height, miplevels);
19809 return float4(width, height, miplevels, 0);
19811 else
19813 uint width, height, miplevels;
19814 t.GetDimensions(level, width, height, miplevels);
19815 return float4(width, height, miplevels, 0);
19818 #endif
19819 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
19820 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19821 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19822 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
19823 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
19824 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
19825 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
19826 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
19827 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
19828 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
19829 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
19830 0x01000015, 0x0100003e,
19832 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
19833 static const DWORD ps_2d_array_code[] =
19835 #if 0
19836 Texture2DArray t;
19838 uint type;
19839 uint level;
19841 float4 main() : SV_TARGET
19843 if (!type)
19845 float width, height, elements, miplevels;
19846 t.GetDimensions(level, width, height, elements, miplevels);
19847 return float4(width, height, elements, miplevels);
19849 else
19851 uint width, height, elements, miplevels;
19852 t.GetDimensions(level, width, height, elements, miplevels);
19853 return float4(width, height, elements, miplevels);
19856 #endif
19857 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
19858 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19859 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19860 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
19861 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
19862 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
19863 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
19864 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
19865 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
19866 0x0100003e, 0x01000015, 0x0100003e,
19868 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
19869 static const DWORD ps_3d_code[] =
19871 #if 0
19872 Texture3D t;
19874 uint type;
19875 uint level;
19877 float4 main() : SV_TARGET
19879 if (!type)
19881 float width, height, depth, miplevels;
19882 t.GetDimensions(level, width, height, depth, miplevels);
19883 return float4(width, height, depth, miplevels);
19885 else
19887 uint width, height, depth, miplevels;
19888 t.GetDimensions(level, width, height, depth, miplevels);
19889 return float4(width, height, depth, miplevels);
19892 #endif
19893 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
19894 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19895 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19896 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
19897 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
19898 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
19899 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
19900 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
19901 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
19902 0x0100003e, 0x01000015, 0x0100003e,
19904 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
19905 static const DWORD ps_cube_code[] =
19907 #if 0
19908 TextureCube t;
19910 uint type;
19911 uint level;
19913 float4 main() : SV_TARGET
19915 if (!type)
19917 float width, height, miplevels;
19918 t.GetDimensions(level, width, height, miplevels);
19919 return float4(width, height, miplevels, 0);
19921 else
19923 uint width, height, miplevels;
19924 t.GetDimensions(level, width, height, miplevels);
19925 return float4(width, height, miplevels, 0);
19928 #endif
19929 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
19930 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19931 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19932 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
19933 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
19934 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
19935 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
19936 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
19937 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
19938 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
19939 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
19940 0x01000015, 0x0100003e,
19942 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
19943 static const DWORD ps_cube_array_code[] =
19945 #if 0
19946 TextureCubeArray t;
19948 uint type;
19949 uint level;
19951 float4 main() : SV_TARGET
19953 if (!type)
19955 float width, height, elements, miplevels;
19956 t.GetDimensions(level, width, height, elements, miplevels);
19957 return float4(width, height, miplevels, 0);
19959 else
19961 uint width, height, elements, miplevels;
19962 t.GetDimensions(level, width, height, elements, miplevels);
19963 return float4(width, height, miplevels, 0);
19966 #endif
19967 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
19968 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19969 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19970 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
19971 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
19972 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
19973 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
19974 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
19975 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
19976 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
19977 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
19978 0x0100003e, 0x01000015, 0x0100003e,
19980 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
19981 static const struct ps_test
19983 const struct shader *ps;
19984 struct
19986 unsigned int width;
19987 unsigned int height;
19988 unsigned int depth;
19989 unsigned int miplevel_count;
19990 unsigned int array_size;
19991 unsigned int cube_count;
19992 } texture_desc;
19993 unsigned int miplevel;
19994 struct vec4 expected_result;
19996 ps_tests[] =
19998 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
19999 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
20000 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
20001 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
20003 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
20004 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
20005 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
20006 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
20008 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
20009 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
20010 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
20011 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
20012 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
20013 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
20014 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
20015 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
20016 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
20018 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
20019 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
20020 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
20021 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
20022 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
20024 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
20025 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
20026 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
20029 if (!init_test_context(&test_context, NULL))
20030 return;
20032 device = test_context.device;
20033 context = test_context.immediate_context;
20034 feature_level = ID3D11Device_GetFeatureLevel(device);
20036 texture_desc.Width = 64;
20037 texture_desc.Height = 64;
20038 texture_desc.MipLevels = 1;
20039 texture_desc.ArraySize = 1;
20040 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
20041 texture_desc.SampleDesc.Count = 1;
20042 texture_desc.SampleDesc.Quality = 0;
20043 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20044 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
20045 texture_desc.CPUAccessFlags = 0;
20046 texture_desc.MiscFlags = 0;
20047 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
20048 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20049 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
20050 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
20052 memset(&constant, 0, sizeof(constant));
20053 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
20055 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
20056 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
20058 ps = NULL;
20059 current_ps = NULL;
20060 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
20062 const struct ps_test *test = &ps_tests[i];
20064 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
20066 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
20067 continue;
20070 if (current_ps != test->ps)
20072 if (ps)
20073 ID3D11PixelShader_Release(ps);
20075 current_ps = test->ps;
20077 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
20078 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
20079 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20082 if (test->texture_desc.depth != 1)
20084 texture3d_desc.Width = test->texture_desc.width;
20085 texture3d_desc.Height = test->texture_desc.height;
20086 texture3d_desc.Depth = test->texture_desc.depth;
20087 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
20088 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
20089 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
20090 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20091 texture3d_desc.CPUAccessFlags = 0;
20092 texture3d_desc.MiscFlags = 0;
20093 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
20094 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
20096 else
20098 texture_desc.Width = test->texture_desc.width;
20099 texture_desc.Height = test->texture_desc.height;
20100 texture_desc.MipLevels = test->texture_desc.miplevel_count;
20101 texture_desc.ArraySize = test->texture_desc.array_size;
20102 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
20103 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20104 texture_desc.MiscFlags = 0;
20105 if (test->texture_desc.cube_count)
20106 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
20107 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
20108 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
20111 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
20112 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
20113 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
20115 for (type = 0; type < 2; ++type)
20117 constant.x = type;
20118 constant.y = test->miplevel;
20119 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20121 draw_quad(&test_context);
20122 check_texture_vec4(rtv_texture, &test->expected_result, 0);
20125 ID3D11Resource_Release(texture);
20126 ID3D11ShaderResourceView_Release(srv);
20128 ID3D11PixelShader_Release(ps);
20130 ID3D11Buffer_Release(cb);
20131 ID3D11RenderTargetView_Release(rtv);
20132 ID3D11Texture2D_Release(rtv_texture);
20133 release_test_context(&test_context);
20136 static void test_sm5_bufinfo_instruction(void)
20138 struct shader
20140 const DWORD *code;
20141 size_t size;
20144 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
20145 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
20146 struct d3d11_test_context test_context;
20147 D3D11_TEXTURE2D_DESC texture_desc;
20148 const struct shader *current_ps;
20149 ID3D11UnorderedAccessView *uav;
20150 ID3D11ShaderResourceView *srv;
20151 D3D11_BUFFER_DESC buffer_desc;
20152 ID3D11DeviceContext *context;
20153 ID3D11RenderTargetView *rtv;
20154 ID3D11Texture2D *texture;
20155 ID3D11PixelShader *ps;
20156 ID3D11Buffer *buffer;
20157 ID3D11Device *device;
20158 unsigned int i;
20159 HRESULT hr;
20161 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20162 static const DWORD ps_uav_structured_code[] =
20164 #if 0
20165 struct s
20167 uint4 u;
20168 bool b;
20171 RWStructuredBuffer<s> b;
20173 uint4 main(void) : SV_Target
20175 uint count, stride;
20176 b.GetDimensions(count, stride);
20177 return uint4(count, stride, 0, 1);
20179 #endif
20180 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
20181 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20182 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
20183 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
20184 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
20185 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
20186 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
20187 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
20189 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
20190 static const DWORD ps_uav_structured32_code[] =
20192 #if 0
20193 struct s
20195 uint4 u;
20196 bool4 b;
20199 RWStructuredBuffer<s> b;
20201 uint4 main(void) : SV_Target
20203 uint count, stride;
20204 b.GetDimensions(count, stride);
20205 return uint4(count, stride, 0, 1);
20207 #endif
20208 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
20209 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20210 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
20211 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
20212 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
20213 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
20214 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
20215 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
20217 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
20218 static const DWORD ps_srv_structured_code[] =
20220 #if 0
20221 StructuredBuffer<bool> b;
20223 uint4 main(void) : SV_Target
20225 uint count, stride;
20226 b.GetDimensions(count, stride);
20227 return uint4(count, stride, 0, 1);
20229 #endif
20230 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
20231 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20232 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
20233 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
20234 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
20235 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
20236 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
20237 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
20239 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
20240 static const DWORD ps_uav_raw_code[] =
20242 #if 0
20243 RWByteAddressBuffer b;
20245 uint4 main(void) : SV_Target
20247 uint width;
20248 b.GetDimensions(width);
20249 return width;
20251 #endif
20252 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
20253 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20254 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
20255 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
20256 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
20257 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
20258 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
20260 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
20261 static const DWORD ps_srv_raw_code[] =
20263 #if 0
20264 ByteAddressBuffer b;
20266 uint4 main(void) : SV_Target
20268 uint width;
20269 b.GetDimensions(width);
20270 return width;
20272 #endif
20273 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
20274 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20275 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
20276 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
20277 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
20278 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
20279 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
20281 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
20282 static const DWORD ps_uav_typed_code[] =
20284 #if 0
20285 RWBuffer<float> b;
20287 uint4 main(void) : SV_Target
20289 uint width;
20290 b.GetDimensions(width);
20291 return width;
20293 #endif
20294 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
20295 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20296 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
20297 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
20298 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
20299 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
20300 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
20302 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
20303 static const DWORD ps_srv_typed_code[] =
20305 #if 0
20306 Buffer<float> b;
20308 uint4 main(void) : SV_Target
20310 uint width;
20311 b.GetDimensions(width);
20312 return width;
20314 #endif
20315 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
20316 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20317 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
20318 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
20319 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
20320 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
20321 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
20323 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
20324 static const struct test
20326 const struct shader *ps;
20327 BOOL uav;
20328 unsigned int buffer_size;
20329 unsigned int buffer_misc_flags;
20330 unsigned int buffer_structure_byte_stride;
20331 DXGI_FORMAT view_format;
20332 unsigned int view_element_idx;
20333 unsigned int view_element_count;
20334 struct uvec4 expected_result;
20336 tests[] =
20338 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
20339 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
20340 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
20341 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
20342 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
20343 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
20344 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
20345 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
20346 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
20347 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
20348 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
20349 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
20350 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
20351 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
20352 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
20353 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
20354 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
20355 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
20356 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
20357 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
20358 #undef RAW
20359 #undef STRUCTURED
20362 if (!init_test_context(&test_context, &feature_level))
20363 return;
20365 device = test_context.device;
20366 context = test_context.immediate_context;
20368 texture_desc.Width = 64;
20369 texture_desc.Height = 64;
20370 texture_desc.MipLevels = 1;
20371 texture_desc.ArraySize = 1;
20372 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
20373 texture_desc.SampleDesc.Count = 1;
20374 texture_desc.SampleDesc.Quality = 0;
20375 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20376 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
20377 texture_desc.CPUAccessFlags = 0;
20378 texture_desc.MiscFlags = 0;
20379 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
20380 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20381 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
20382 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
20384 ps = NULL;
20385 current_ps = NULL;
20386 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20388 const struct test *test = &tests[i];
20390 if (current_ps != test->ps)
20392 if (ps)
20393 ID3D11PixelShader_Release(ps);
20395 current_ps = test->ps;
20397 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
20398 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
20399 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20402 buffer_desc.ByteWidth = test->buffer_size;
20403 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
20404 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
20405 buffer_desc.CPUAccessFlags = 0;
20406 buffer_desc.MiscFlags = test->buffer_misc_flags;
20407 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
20408 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
20409 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
20411 if (test->uav)
20413 uav_desc.Format = test->view_format;
20414 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
20415 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
20416 U(uav_desc).Buffer.NumElements = test->view_element_count;
20417 U(uav_desc).Buffer.Flags = 0;
20418 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
20419 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
20420 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
20421 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
20422 srv = NULL;
20424 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
20425 1, 1, &uav, NULL);
20427 else
20429 srv_desc.Format = test->view_format;
20430 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
20431 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
20432 U(srv_desc).BufferEx.NumElements = test->view_element_count;
20433 U(srv_desc).BufferEx.Flags = 0;
20434 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
20435 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
20436 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
20437 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
20438 uav = NULL;
20440 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
20441 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
20444 draw_quad(&test_context);
20445 check_texture_uvec4(texture, &test->expected_result);
20447 if (srv)
20448 ID3D11ShaderResourceView_Release(srv);
20449 if (uav)
20450 ID3D11UnorderedAccessView_Release(uav);
20451 ID3D11Buffer_Release(buffer);
20453 ID3D11PixelShader_Release(ps);
20455 ID3D11RenderTargetView_Release(rtv);
20456 ID3D11Texture2D_Release(texture);
20457 release_test_context(&test_context);
20460 static void test_sampleinfo_instruction(void)
20462 ID3D11Texture2D *float_rt_texture, *uint_rt_texture;
20463 ID3D11RenderTargetView *float_rtv, *uint_rtv, *rtv;
20464 ID3D11PixelShader *ps_float, *ps_uint, *ps_rt;
20465 ID3D11Texture2D *texture, *readback_texture;
20466 struct d3d11_test_context test_context;
20467 unsigned int sample_count, quality;
20468 D3D11_TEXTURE2D_DESC texture_desc;
20469 ID3D11RenderTargetView *rtvs[2];
20470 ID3D11ShaderResourceView *srv;
20471 ID3D11DeviceContext *context;
20472 struct uvec4 expected_uint;
20473 struct vec4 expected_float;
20474 ID3D11Device *device;
20475 HRESULT hr;
20477 static const DWORD ps_uint_code[] =
20479 #if 0
20480 Texture2DMS<float> t;
20482 uint4 main() : SV_Target1
20484 uint width, height, sample_count;
20485 t.GetDimensions(width, height, sample_count);
20486 return sample_count;
20488 #endif
20489 0x43425844, 0x4342ad12, 0x19addd8c, 0x5cb87c48, 0xe604a242, 0x00000001, 0x000000d4, 0x00000003,
20490 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20491 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
20492 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
20493 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000001,
20494 0x02000068, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a, 0x00000000, 0x05000036,
20495 0x001020f2, 0x00000001, 0x00100006, 0x00000000, 0x0100003e,
20497 static const DWORD ps_float_code[] =
20499 #if 0
20500 Texture2DMS<float> t;
20502 float4 main() : SV_Target
20504 uint width, height, sample_count;
20505 t.GetDimensions(width, height, sample_count);
20506 return sample_count;
20508 #endif
20509 0x43425844, 0x2b8aea46, 0x34ceda6f, 0xf98d222b, 0x235ebc0b, 0x00000001, 0x000000b8, 0x00000003,
20510 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20511 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
20512 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000040, 0x00000050, 0x00000010,
20513 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
20514 0x0500006f, 0x001020f2, 0x00000000, 0x0010700a, 0x00000000, 0x0100003e,
20516 static const DWORD ps_rt_code[] =
20518 #if 0
20519 float4 main() : SV_Target
20521 return GetRenderTargetSampleCount();
20523 #endif
20524 0x43425844, 0x74404d37, 0xad6f88e4, 0xb006ea57, 0xf07d9e2a, 0x00000001, 0x000000a4, 0x00000003,
20525 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20526 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
20527 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000002c, 0x00000050, 0x0000000b,
20528 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x0400006f, 0x001020f2, 0x00000000, 0x0000e00a,
20529 0x0100003e,
20531 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20533 if (!init_test_context(&test_context, &feature_level))
20534 return;
20536 device = test_context.device;
20537 context = test_context.immediate_context;
20539 texture_desc.Width = 64;
20540 texture_desc.Height = 64;
20541 texture_desc.MipLevels = 1;
20542 texture_desc.ArraySize = 1;
20543 texture_desc.SampleDesc.Count = 1;
20544 texture_desc.SampleDesc.Quality = 0;
20545 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20546 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
20547 texture_desc.CPUAccessFlags = 0;
20548 texture_desc.MiscFlags = 0;
20550 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
20551 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &float_rt_texture);
20552 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
20553 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)float_rt_texture, NULL, &float_rtv);
20554 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
20555 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
20556 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &uint_rt_texture);
20557 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
20558 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)uint_rt_texture, NULL, &uint_rtv);
20559 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
20561 rtvs[0] = float_rtv;
20562 rtvs[1] = uint_rtv;
20563 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
20565 hr = ID3D11Device_CreatePixelShader(device, ps_float_code, sizeof(ps_float_code), NULL, &ps_float);
20566 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
20567 hr = ID3D11Device_CreatePixelShader(device, ps_uint_code, sizeof(ps_uint_code), NULL, &ps_uint);
20568 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
20570 for (sample_count = 2; sample_count <= 8; sample_count *= 2)
20572 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
20573 texture_desc.SampleDesc.Count = sample_count;
20574 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
20576 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
20577 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
20578 if (!quality)
20580 skip("Sample count %u not supported.\n", sample_count);
20581 continue;
20584 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
20585 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
20586 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
20587 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
20588 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
20590 ID3D11DeviceContext_PSSetShader(context, ps_float, NULL, 0);
20591 draw_quad(&test_context);
20592 ID3D11DeviceContext_PSSetShader(context, ps_uint, NULL, 0);
20593 draw_quad(&test_context);
20595 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
20596 check_texture_vec4(float_rt_texture, &expected_float, 0);
20597 expected_uint.x = expected_uint.y = expected_uint.z = expected_uint.w = sample_count;
20598 check_texture_uvec4(uint_rt_texture, &expected_uint);
20600 ID3D11Texture2D_Release(texture);
20601 ID3D11ShaderResourceView_Release(srv);
20604 hr = ID3D11Device_CreatePixelShader(device, ps_rt_code, sizeof(ps_rt_code), NULL, &ps_rt);
20605 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
20606 for (sample_count = 1; sample_count <= 8; sample_count *= 2)
20608 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
20609 texture_desc.SampleDesc.Count = sample_count;
20610 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
20612 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
20613 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
20614 if (!quality)
20616 skip("Sample count %u not supported.\n", sample_count);
20617 continue;
20620 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
20621 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
20622 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
20623 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
20624 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
20626 /* Some drivers (AMD Radeon HD 6310) return stale sample counts if we
20627 * don't rebind the pixel shader between runs with different sample
20628 * counts. */
20629 ID3D11DeviceContext_PSSetShader(context, NULL, NULL, 0);
20630 ID3D11DeviceContext_PSSetShader(context, ps_rt, NULL, 0);
20631 draw_quad(&test_context);
20633 if (sample_count != 1)
20635 texture_desc.SampleDesc.Count = 1;
20636 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
20637 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
20638 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
20639 (ID3D11Resource *)texture, 0, texture_desc.Format);
20641 else
20643 readback_texture = texture;
20644 ID3D11Texture2D_AddRef(readback_texture);
20647 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
20648 check_texture_vec4(readback_texture, &expected_float, 0);
20650 ID3D11Texture2D_Release(readback_texture);
20651 ID3D11Texture2D_Release(texture);
20652 ID3D11RenderTargetView_Release(rtv);
20655 ID3D11RenderTargetView_Release(float_rtv);
20656 ID3D11RenderTargetView_Release(uint_rtv);
20657 ID3D11Texture2D_Release(float_rt_texture);
20658 ID3D11Texture2D_Release(uint_rt_texture);
20659 ID3D11PixelShader_Release(ps_float);
20660 ID3D11PixelShader_Release(ps_uint);
20661 ID3D11PixelShader_Release(ps_rt);
20662 release_test_context(&test_context);
20665 static void test_render_target_device_mismatch(void)
20667 struct d3d11_test_context test_context;
20668 struct device_desc device_desc = {0};
20669 ID3D11DeviceContext *context;
20670 ID3D11RenderTargetView *rtv;
20671 ID3D11Device *device;
20672 ULONG refcount;
20674 if (!init_test_context(&test_context, NULL))
20675 return;
20677 device = create_device(&device_desc);
20678 ok(!!device, "Failed to create device.\n");
20680 ID3D11Device_GetImmediateContext(device, &context);
20682 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
20683 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
20684 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
20685 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
20686 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
20687 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
20688 ID3D11RenderTargetView_Release(rtv);
20690 rtv = NULL;
20691 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
20693 ID3D11DeviceContext_Release(context);
20694 refcount = ID3D11Device_Release(device);
20695 ok(!refcount, "Device has %u references left.\n", refcount);
20696 release_test_context(&test_context);
20699 static void test_buffer_srv(void)
20701 struct shader
20703 const DWORD *code;
20704 size_t size;
20705 BOOL requires_raw_and_structured_buffers;
20707 struct buffer
20709 unsigned int byte_count;
20710 unsigned int data_offset;
20711 const void *data;
20712 unsigned int structure_byte_stride;
20715 BOOL raw_and_structured_buffers_supported;
20716 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
20717 struct d3d11_test_context test_context;
20718 D3D11_SUBRESOURCE_DATA resource_data;
20719 const struct buffer *current_buffer;
20720 const struct shader *current_shader;
20721 ID3D11ShaderResourceView *srv;
20722 D3D11_BUFFER_DESC buffer_desc;
20723 ID3D11DeviceContext *context;
20724 DWORD color, expected_color;
20725 struct resource_readback rb;
20726 ID3D11Buffer *cb, *buffer;
20727 ID3D11PixelShader *ps;
20728 ID3D11Device *device;
20729 unsigned int i, x, y;
20730 struct vec4 cb_size;
20731 HRESULT hr;
20733 static const DWORD ps_float4_code[] =
20735 #if 0
20736 Buffer<float4> b;
20738 float2 size;
20740 float4 main(float4 position : SV_POSITION) : SV_Target
20742 float2 p;
20743 int2 coords;
20744 p.x = position.x / 640.0f;
20745 p.y = position.y / 480.0f;
20746 coords = int2(p.x * size.x, p.y * size.y);
20747 return b.Load(coords.y * size.x + coords.x);
20749 #endif
20750 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
20751 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
20752 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
20753 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20754 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
20755 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
20756 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
20757 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
20758 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
20759 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
20760 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
20761 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
20762 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
20764 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
20765 static const DWORD ps_structured_code[] =
20767 #if 0
20768 StructuredBuffer<float4> b;
20770 float2 size;
20772 float4 main(float4 position : SV_POSITION) : SV_Target
20774 float2 p;
20775 int2 coords;
20776 p.x = position.x / 640.0f;
20777 p.y = position.y / 480.0f;
20778 coords = int2(p.x * size.x, p.y * size.y);
20779 return b[coords.y * size.x + coords.x];
20781 #endif
20782 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
20783 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
20784 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
20785 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20786 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
20787 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
20788 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
20789 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
20790 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
20791 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
20792 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
20793 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
20794 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
20795 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
20797 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
20798 static const DWORD rgba16[] =
20800 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
20801 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
20802 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
20803 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
20805 static const DWORD rgba4[] =
20807 0xffffffff, 0xff0000ff,
20808 0xff000000, 0xff00ff00,
20810 static const BYTE r4[] =
20812 0xde, 0xad,
20813 0xba, 0xbe,
20815 static const struct vec4 rgba_float[] =
20817 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
20818 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
20820 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
20821 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
20822 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
20823 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
20824 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
20825 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
20826 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
20827 &rgba_float, sizeof(*rgba_float)};
20828 static const DWORD rgba16_colors2x2[] =
20830 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
20831 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
20832 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
20833 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
20835 static const DWORD rgba16_colors1x1[] =
20837 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
20838 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
20839 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
20840 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
20842 static const DWORD rgba4_colors[] =
20844 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
20845 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
20846 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
20847 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
20849 static const DWORD r4_colors[] =
20851 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
20852 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
20853 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
20854 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
20856 static const DWORD zero_colors[16] = {0};
20857 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
20859 static const struct test
20861 const struct shader *shader;
20862 const struct buffer *buffer;
20863 DXGI_FORMAT srv_format;
20864 unsigned int srv_first_element;
20865 unsigned int srv_element_count;
20866 struct vec2 size;
20867 const DWORD *expected_colors;
20869 tests[] =
20871 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
20872 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
20873 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
20874 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
20875 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
20876 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
20877 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
20878 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
20879 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
20880 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
20881 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
20884 if (!init_test_context(&test_context, NULL))
20885 return;
20887 device = test_context.device;
20888 context = test_context.immediate_context;
20889 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
20890 || check_compute_shaders_via_sm4_support(device);
20892 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
20893 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
20895 buffer_desc.ByteWidth = 256;
20896 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
20897 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20898 buffer_desc.CPUAccessFlags = 0;
20899 buffer_desc.MiscFlags = 0;
20900 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
20901 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
20902 srv_desc.Format = DXGI_FORMAT_R8_UNORM;
20903 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
20904 U(srv_desc).Buffer.FirstElement = 0;
20905 U(srv_desc).Buffer.NumElements = 0;
20906 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
20907 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
20908 ID3D11Buffer_Release(buffer);
20910 ps = NULL;
20911 srv = NULL;
20912 buffer = NULL;
20913 current_shader = NULL;
20914 current_buffer = NULL;
20915 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20917 const struct test *test = &tests[i];
20919 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
20921 skip("Test %u: Raw and structured buffers are not supported.\n", i);
20922 continue;
20924 /* Structured buffer views with an offset don't seem to work on WARP. */
20925 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
20926 && is_warp_device(device))
20928 skip("Test %u: Broken WARP.\n", i);
20929 continue;
20932 if (current_shader != test->shader)
20934 if (ps)
20935 ID3D11PixelShader_Release(ps);
20937 current_shader = test->shader;
20939 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
20940 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
20941 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20944 if (current_buffer != test->buffer)
20946 if (buffer)
20947 ID3D11Buffer_Release(buffer);
20949 current_buffer = test->buffer;
20950 if (current_buffer)
20952 BYTE *data = NULL;
20954 buffer_desc.ByteWidth = current_buffer->byte_count;
20955 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
20956 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20957 buffer_desc.CPUAccessFlags = 0;
20958 buffer_desc.MiscFlags = 0;
20959 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
20960 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
20961 resource_data.SysMemPitch = 0;
20962 resource_data.SysMemSlicePitch = 0;
20963 if (current_buffer->data_offset)
20965 data = heap_alloc_zero(current_buffer->byte_count);
20966 ok(!!data, "Failed to allocate memory.\n");
20967 memcpy(data + current_buffer->data_offset, current_buffer->data,
20968 current_buffer->byte_count - current_buffer->data_offset);
20969 resource_data.pSysMem = data;
20971 else
20973 resource_data.pSysMem = current_buffer->data;
20975 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
20976 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
20977 heap_free(data);
20979 else
20981 buffer = NULL;
20985 if (srv)
20986 ID3D11ShaderResourceView_Release(srv);
20987 if (current_buffer)
20989 srv_desc.Format = test->srv_format;
20990 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
20991 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
20992 U(srv_desc).Buffer.NumElements = test->srv_element_count;
20993 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
20994 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
20996 else
20998 srv = NULL;
21000 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
21002 cb_size.x = test->size.x;
21003 cb_size.y = test->size.y;
21004 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
21006 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
21007 draw_quad(&test_context);
21009 get_texture_readback(test_context.backbuffer, 0, &rb);
21010 for (y = 0; y < 4; ++y)
21012 for (x = 0; x < 4; ++x)
21014 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
21015 expected_color = test->expected_colors[y * 4 + x];
21016 ok(compare_color(color, expected_color, 1),
21017 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
21018 i, color, expected_color, x, y);
21021 release_resource_readback(&rb);
21023 if (srv)
21024 ID3D11ShaderResourceView_Release(srv);
21025 if (buffer)
21026 ID3D11Buffer_Release(buffer);
21028 ID3D11Buffer_Release(cb);
21029 ID3D11PixelShader_Release(ps);
21030 release_test_context(&test_context);
21033 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
21035 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21036 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
21037 struct d3d11_test_context test_context;
21038 D3D11_SUBRESOURCE_DATA resource_data;
21039 D3D11_TEXTURE2D_DESC texture_desc;
21040 ID3D11UnorderedAccessView *uav;
21041 ID3D11ShaderResourceView *srv;
21042 D3D11_BUFFER_DESC buffer_desc;
21043 ID3D11Buffer *cb, *raw_buffer;
21044 ID3D11DeviceContext *context;
21045 struct resource_readback rb;
21046 ID3D11RenderTargetView *rtv;
21047 ID3D11Texture2D *texture;
21048 ID3D11ComputeShader *cs;
21049 ID3D11PixelShader *ps;
21050 ID3D11Device *device;
21051 unsigned int i, data;
21052 struct uvec4 offset;
21053 HRESULT hr;
21055 static const unsigned int buffer_data[] =
21057 0xffffffff, 0x00000000,
21059 static const DWORD ps_code[] =
21061 #if 0
21062 ByteAddressBuffer buffer;
21064 uint offset;
21066 uint main() : SV_Target0
21068 return buffer.Load(offset);
21070 #endif
21071 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
21072 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
21073 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
21074 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
21075 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
21076 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
21077 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
21078 0x00000000,
21080 static const DWORD cs_code[] =
21082 #if 0
21083 RWByteAddressBuffer buffer;
21085 uint2 input;
21087 [numthreads(1, 1, 1)]
21088 void main()
21090 buffer.Store(input.x, input.y);
21092 #endif
21093 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
21094 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21095 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
21096 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
21097 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
21098 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
21100 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
21102 if (!init_test_context(&test_context, &feature_level))
21103 return;
21105 device = test_context.device;
21106 context = test_context.immediate_context;
21108 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
21110 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
21111 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
21112 if (SUCCEEDED(hr))
21113 ID3D11PixelShader_Release(ps);
21114 skip("Raw buffers are not supported.\n");
21115 release_test_context(&test_context);
21116 return;
21119 if (is_intel_device(device))
21121 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
21122 * This test checks what happens when offsets are not properly aligned.
21123 * The behavior seems to be undefined on Intel hardware. */
21124 win_skip("Skipping the test on Intel hardware.\n");
21125 release_test_context(&test_context);
21126 return;
21129 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
21130 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21132 memset(&offset, 0, sizeof(offset));
21133 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
21135 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
21136 texture_desc.Format = DXGI_FORMAT_R32_UINT;
21137 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21138 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21139 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
21140 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21142 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
21144 buffer_desc.ByteWidth = sizeof(buffer_data);
21145 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
21146 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
21147 buffer_desc.CPUAccessFlags = 0;
21148 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
21149 resource_data.pSysMem = buffer_data;
21150 resource_data.SysMemPitch = 0;
21151 resource_data.SysMemSlicePitch = 0;
21152 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
21153 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
21155 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
21156 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
21157 U(srv_desc).BufferEx.FirstElement = 0;
21158 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
21159 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
21160 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
21161 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
21163 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21164 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
21165 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
21167 offset.x = 0;
21168 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21169 NULL, &offset, 0, 0);
21170 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
21171 draw_quad(&test_context);
21172 check_texture_color(texture, buffer_data[0], 0);
21173 offset.x = 1;
21174 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21175 NULL, &offset, 0, 0);
21176 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
21177 draw_quad(&test_context);
21178 check_texture_color(texture, buffer_data[0], 0);
21179 offset.x = 2;
21180 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21181 NULL, &offset, 0, 0);
21182 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
21183 draw_quad(&test_context);
21184 check_texture_color(texture, buffer_data[0], 0);
21185 offset.x = 3;
21186 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21187 NULL, &offset, 0, 0);
21188 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
21189 draw_quad(&test_context);
21190 check_texture_color(texture, buffer_data[0], 0);
21192 offset.x = 4;
21193 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21194 NULL, &offset, 0, 0);
21195 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
21196 draw_quad(&test_context);
21197 check_texture_color(texture, buffer_data[1], 0);
21198 offset.x = 7;
21199 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21200 NULL, &offset, 0, 0);
21201 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
21202 draw_quad(&test_context);
21203 check_texture_color(texture, buffer_data[1], 0);
21205 if (feature_level < D3D_FEATURE_LEVEL_11_0)
21207 skip("Feature level 11_0 required for unaligned UAV test.\n");
21208 goto done;
21211 ID3D11Buffer_Release(raw_buffer);
21212 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21213 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
21214 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
21216 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
21217 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
21218 U(uav_desc).Buffer.FirstElement = 0;
21219 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
21220 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
21221 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
21222 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21224 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
21225 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21227 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21228 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
21229 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21231 offset.x = 0;
21232 offset.y = 0xffffffff;
21233 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21234 NULL, &offset, 0, 0);
21235 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
21236 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21237 get_buffer_readback(raw_buffer, &rb);
21238 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
21240 data = get_readback_color(&rb, i, 0, 0);
21241 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
21243 release_resource_readback(&rb);
21245 offset.x = 1;
21246 offset.y = 0xffffffff;
21247 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21248 NULL, &offset, 0, 0);
21249 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
21250 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21251 get_buffer_readback(raw_buffer, &rb);
21252 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
21254 data = get_readback_color(&rb, i, 0, 0);
21255 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
21257 release_resource_readback(&rb);
21259 offset.x = 2;
21260 offset.y = 0xffffffff;
21261 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21262 NULL, &offset, 0, 0);
21263 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
21264 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21265 get_buffer_readback(raw_buffer, &rb);
21266 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
21268 data = get_readback_color(&rb, i, 0, 0);
21269 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
21271 release_resource_readback(&rb);
21273 offset.x = 3;
21274 offset.y = 0xffffffff;
21275 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21276 NULL, &offset, 0, 0);
21277 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
21278 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21279 get_buffer_readback(raw_buffer, &rb);
21280 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
21282 data = get_readback_color(&rb, i, 0, 0);
21283 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
21285 release_resource_readback(&rb);
21287 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
21288 offset.x = 3;
21289 offset.y = 0xffff;
21290 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21291 NULL, &offset, 0, 0);
21292 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21293 offset.x = 4;
21294 offset.y = 0xa;
21295 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21296 NULL, &offset, 0, 0);
21297 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21298 get_buffer_readback(raw_buffer, &rb);
21299 data = get_readback_color(&rb, 0, 0, 0);
21300 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
21301 data = get_readback_color(&rb, 1, 0, 0);
21302 ok(data == 0xa, "Got unexpected result %#x.\n", data);
21303 release_resource_readback(&rb);
21305 ID3D11ComputeShader_Release(cs);
21306 ID3D11UnorderedAccessView_Release(uav);
21308 done:
21309 ID3D11Buffer_Release(cb);
21310 ID3D11Buffer_Release(raw_buffer);
21311 ID3D11PixelShader_Release(ps);
21312 ID3D11RenderTargetView_Release(rtv);
21313 ID3D11ShaderResourceView_Release(srv);
21314 ID3D11Texture2D_Release(texture);
21315 release_test_context(&test_context);
21318 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
21319 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
21321 D3D11_MAPPED_SUBRESOURCE map_desc;
21322 unsigned int counter;
21324 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
21326 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
21327 D3D11_MAP_READ, 0, &map_desc)))
21328 return 0xdeadbeef;
21329 counter = *(unsigned int *)map_desc.pData;
21330 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
21331 return counter;
21334 static int compare_id(const void *a, const void *b)
21336 return *(int *)a - *(int *)b;
21339 static void test_uav_counters(void)
21341 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
21342 ID3D11ComputeShader *cs_producer, *cs_consumer;
21343 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21344 struct d3d11_test_context test_context;
21345 ID3D11UnorderedAccessView *uav, *uav2;
21346 unsigned int data, id[128], i;
21347 D3D11_BUFFER_DESC buffer_desc;
21348 ID3D11DeviceContext *context;
21349 struct resource_readback rb;
21350 ID3D11Device *device;
21351 D3D11_BOX box;
21352 HRESULT hr;
21354 static const DWORD cs_producer_code[] =
21356 #if 0
21357 RWStructuredBuffer<uint> u;
21359 [numthreads(4, 1, 1)]
21360 void main(uint3 dispatch_id : SV_DispatchThreadID)
21362 uint counter = u.IncrementCounter();
21363 u[counter] = dispatch_id.x;
21365 #endif
21366 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
21367 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21368 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
21369 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
21370 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
21371 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
21372 0x0002000a, 0x0100003e,
21374 static const DWORD cs_consumer_code[] =
21376 #if 0
21377 RWStructuredBuffer<uint> u;
21378 RWStructuredBuffer<uint> u2;
21380 [numthreads(4, 1, 1)]
21381 void main()
21383 uint counter = u.DecrementCounter();
21384 u2[counter] = u[counter];
21386 #endif
21387 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
21388 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21389 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
21390 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
21391 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
21392 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
21393 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
21394 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
21396 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21398 if (!init_test_context(&test_context, &feature_level))
21399 return;
21401 device = test_context.device;
21402 context = test_context.immediate_context;
21404 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
21405 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21406 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
21407 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21409 memset(&buffer_desc, 0, sizeof(buffer_desc));
21410 buffer_desc.ByteWidth = sizeof(unsigned int);
21411 buffer_desc.Usage = D3D11_USAGE_STAGING;
21412 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
21413 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
21414 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
21416 buffer_desc.ByteWidth = 1024;
21417 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
21418 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21419 buffer_desc.CPUAccessFlags = 0;
21420 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
21421 buffer_desc.StructureByteStride = sizeof(unsigned int);
21422 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
21423 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
21424 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
21425 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
21426 U(uav_desc).Buffer.FirstElement = 0;
21427 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
21428 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
21429 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
21430 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21431 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
21432 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
21433 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
21434 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21436 data = read_uav_counter(context, staging_buffer, uav);
21437 ok(!data, "Got unexpected initial value %u.\n", data);
21438 data = 8;
21439 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
21440 data = read_uav_counter(context, staging_buffer, uav);
21441 ok(data == 8, "Got unexpected value %u.\n", data);
21442 data = ~0u;
21443 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
21444 data = read_uav_counter(context, staging_buffer, uav);
21445 ok(data == 8, "Got unexpected value %u.\n", data);
21446 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21447 data = read_uav_counter(context, staging_buffer, uav);
21448 ok(data == 8, "Got unexpected value %u.\n", data);
21450 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
21451 data = 0;
21452 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
21453 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
21454 data = read_uav_counter(context, staging_buffer, uav);
21455 ok(!data, "Got unexpected value %u.\n", data);
21457 /* produce */
21458 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
21459 data = read_uav_counter(context, staging_buffer, uav);
21460 ok(data == 64, "Got unexpected value %u.\n", data);
21461 get_buffer_readback(buffer, &rb);
21462 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
21463 release_resource_readback(&rb);
21464 qsort(id, 64, sizeof(*id), compare_id);
21465 for (i = 0; i < 64; ++i)
21467 if (id[i] != i)
21468 break;
21470 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
21472 /* consume */
21473 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
21474 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
21475 data = read_uav_counter(context, staging_buffer, uav);
21476 ok(!data, "Got unexpected value %u.\n", data);
21477 get_buffer_readback(buffer2, &rb);
21478 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
21479 release_resource_readback(&rb);
21480 qsort(id, 64, sizeof(*id), compare_id);
21481 for (i = 0; i < 64; ++i)
21483 if (id[i] != i)
21484 break;
21486 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
21488 /* produce on CPU */
21489 for (i = 0; i < 8; ++i)
21490 id[i] = 0xdeadbeef;
21491 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
21492 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
21493 data = 8;
21494 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
21495 data = read_uav_counter(context, staging_buffer, uav);
21496 ok(data == 8, "Got unexpected value %u.\n", data);
21498 /* consume */
21499 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21500 data = read_uav_counter(context, staging_buffer, uav);
21501 ok(data == 4, "Got unexpected value %u.\n", data);
21502 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21503 data = read_uav_counter(context, staging_buffer, uav);
21504 ok(!data, "Got unexpected value %u.\n", data);
21505 get_buffer_readback(buffer2, &rb);
21506 for (i = 0; i < 8; ++i)
21508 data = get_readback_color(&rb, i, 0, 0);
21509 ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
21511 release_resource_readback(&rb);
21513 ID3D11Buffer_Release(buffer);
21514 ID3D11Buffer_Release(buffer2);
21515 ID3D11Buffer_Release(staging_buffer);
21516 ID3D11ComputeShader_Release(cs_producer);
21517 ID3D11ComputeShader_Release(cs_consumer);
21518 ID3D11UnorderedAccessView_Release(uav);
21519 ID3D11UnorderedAccessView_Release(uav2);
21520 release_test_context(&test_context);
21523 static void test_dispatch_indirect(void)
21525 struct stats
21527 unsigned int dispatch_count;
21528 unsigned int thread_count;
21529 unsigned int max_x;
21530 unsigned int max_y;
21531 unsigned int max_z;
21534 ID3D11Buffer *append_buffer, *stats_buffer, *args_buffer, *staging_buffer;
21535 ID3D11UnorderedAccessView *uav, *stats_uav;
21536 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21537 ID3D11ComputeShader *cs_append, *cs_stats;
21538 struct d3d11_test_context test_context;
21539 D3D11_BUFFER_DESC buffer_desc;
21540 ID3D11DeviceContext *context;
21541 struct resource_readback rb;
21542 ID3D11Device *device;
21543 unsigned int data, i;
21544 struct stats *stats;
21545 HRESULT hr;
21547 static const DWORD cs_append_code[] =
21549 #if 0
21550 struct dispatch_args
21552 uint x, y, z;
21555 AppendStructuredBuffer<dispatch_args> u;
21557 [numthreads(1, 1, 1)]
21558 void main()
21560 dispatch_args args = {4, 2, 1};
21561 u.Append(args);
21562 args.y = 1;
21563 u.Append(args);
21564 args.x = 3;
21565 u.Append(args);
21567 #endif
21568 0x43425844, 0x954de75a, 0x8bb1b78b, 0x84ded464, 0x9d9532b7, 0x00000001, 0x00000158, 0x00000003,
21569 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21570 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000104, 0x00050050, 0x00000041, 0x0100086a,
21571 0x0400009e, 0x0011e000, 0x00000000, 0x0000000c, 0x02000068, 0x00000001, 0x0400009b, 0x00000001,
21572 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x0c0000a8,
21573 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002, 0x00000004,
21574 0x00000002, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000,
21575 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002,
21576 0x00000004, 0x00000001, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
21577 0x00000000, 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
21578 0x00004002, 0x00000003, 0x00000001, 0x00000001, 0x00000000, 0x0100003e,
21580 static const DWORD cs_stats_code[] =
21582 #if 0
21583 struct stats
21585 uint dispatch_count;
21586 uint thread_count;
21587 uint max_x;
21588 uint max_y;
21589 uint max_z;
21592 RWStructuredBuffer<stats> u;
21594 [numthreads(1, 1, 1)]
21595 void main(uint3 id : SV_DispatchThreadID)
21597 if (all(!id))
21598 InterlockedAdd(u[0].dispatch_count, 1);
21599 InterlockedAdd(u[0].thread_count, 1);
21600 InterlockedMax(u[0].max_x, id.x);
21601 InterlockedMax(u[0].max_y, id.y);
21602 InterlockedMax(u[0].max_z, id.z);
21604 #endif
21605 0x43425844, 0xbd3f2e4e, 0xb0f61ff7, 0xa8e10584, 0x2f61aec9, 0x00000001, 0x000001bc, 0x00000003,
21606 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21607 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000168, 0x00050050, 0x0000005a, 0x0100086a,
21608 0x0400009e, 0x0011e000, 0x00000000, 0x00000014, 0x0200005f, 0x00020072, 0x02000068, 0x00000001,
21609 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x09000020, 0x00100072, 0x00000000, 0x00020246,
21610 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000001, 0x00100012, 0x00000000,
21611 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00100012, 0x00000000, 0x0010002a,
21612 0x00000000, 0x0010000a, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x0a0000ad, 0x0011e000,
21613 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001,
21614 0x01000015, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000,
21615 0x00000000, 0x00004001, 0x00000001, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002, 0x00000000,
21616 0x00000008, 0x00000000, 0x00000000, 0x0002000a, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002,
21617 0x00000000, 0x0000000c, 0x00000000, 0x00000000, 0x0002001a, 0x090000b0, 0x0011e000, 0x00000000,
21618 0x00004002, 0x00000000, 0x00000010, 0x00000000, 0x00000000, 0x0002002a, 0x0100003e,
21620 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21621 static const unsigned int zero[4] = {0, 0, 0, 0};
21623 if (!init_test_context(&test_context, &feature_level))
21624 return;
21626 device = test_context.device;
21627 context = test_context.immediate_context;
21629 hr = ID3D11Device_CreateComputeShader(device, cs_append_code, sizeof(cs_append_code), NULL, &cs_append);
21630 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21631 hr = ID3D11Device_CreateComputeShader(device, cs_stats_code, sizeof(cs_stats_code), NULL, &cs_stats);
21632 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21634 memset(&buffer_desc, 0, sizeof(buffer_desc));
21635 buffer_desc.ByteWidth = sizeof(unsigned int);
21636 buffer_desc.Usage = D3D11_USAGE_STAGING;
21637 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
21638 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
21639 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
21641 buffer_desc.ByteWidth = 60;
21642 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
21643 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21644 buffer_desc.CPUAccessFlags = 0;
21645 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
21646 buffer_desc.StructureByteStride = 3 * sizeof(unsigned int);
21647 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &append_buffer);
21648 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
21649 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
21650 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
21651 U(uav_desc).Buffer.FirstElement = 0;
21652 U(uav_desc).Buffer.NumElements = 5;
21653 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
21654 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)append_buffer, &uav_desc, &uav);
21655 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21657 /* We use a separate buffer because D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
21658 * and D3D11_RESOURCE_MISC_BUFFER_STRUCTURED are mutually exclusive flags.
21660 buffer_desc.BindFlags = 0;
21661 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
21662 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &args_buffer);
21663 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
21665 buffer_desc.ByteWidth = sizeof(*stats);
21666 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21667 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
21668 buffer_desc.StructureByteStride = sizeof(*stats);
21669 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &stats_buffer);
21670 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
21671 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)stats_buffer, NULL, &stats_uav);
21672 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21674 data = read_uav_counter(context, staging_buffer, uav);
21675 ok(!data, "Got unexpected initial value %u.\n", data);
21676 data = 8;
21677 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
21678 data = read_uav_counter(context, staging_buffer, uav);
21679 ok(data == 8, "Got unexpected value %u.\n", data);
21681 ID3D11DeviceContext_CSSetShader(context, cs_append, NULL, 0);
21682 data = 0;
21683 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
21684 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21685 data = read_uav_counter(context, staging_buffer, uav);
21686 ok(data == 3, "Got unexpected value %u.\n", data);
21687 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)args_buffer, (ID3D11Resource *)append_buffer);
21689 ID3D11DeviceContext_CSSetShader(context, cs_stats, NULL, 0);
21690 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, stats_uav, zero);
21691 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &stats_uav, NULL);
21692 data = read_uav_counter(context, staging_buffer, uav);
21693 for (i = 0; i < data; ++i)
21694 ID3D11DeviceContext_DispatchIndirect(context, args_buffer, i * 3 * sizeof(unsigned int));
21695 get_buffer_readback(stats_buffer, &rb);
21696 stats = rb.map_desc.pData;
21697 ok(stats->dispatch_count == 3, "Got unexpected dispatch count %u.\n", stats->dispatch_count);
21698 ok(stats->thread_count == 15, "Got unexpected thread count %u.\n", stats->thread_count);
21699 ok(stats->max_x == 3, "Got unexpected max x %u.\n", stats->max_x);
21700 ok(stats->max_y == 1, "Got unexpected max y %u.\n", stats->max_y);
21701 ok(stats->max_z == 0, "Got unexpected max z %u.\n", stats->max_z);
21702 release_resource_readback(&rb);
21704 ID3D11Buffer_Release(append_buffer);
21705 ID3D11Buffer_Release(args_buffer);
21706 ID3D11Buffer_Release(staging_buffer);
21707 ID3D11Buffer_Release(stats_buffer);
21708 ID3D11ComputeShader_Release(cs_append);
21709 ID3D11ComputeShader_Release(cs_stats);
21710 ID3D11UnorderedAccessView_Release(uav);
21711 ID3D11UnorderedAccessView_Release(stats_uav);
21712 release_test_context(&test_context);
21715 static void test_compute_shader_registers(void)
21717 struct data
21719 unsigned int group_id[3];
21720 unsigned int group_index;
21721 unsigned int dispatch_id[3];
21722 unsigned int thread_id[3];
21725 struct d3d11_test_context test_context;
21726 unsigned int i, x, y, group_x, group_y;
21727 ID3D11UnorderedAccessView *uav;
21728 D3D11_BUFFER_DESC buffer_desc;
21729 ID3D11DeviceContext *context;
21730 struct resource_readback rb;
21731 ID3D11Buffer *cb, *buffer;
21732 struct uvec4 dimensions;
21733 ID3D11ComputeShader *cs;
21734 const struct data *data;
21735 ID3D11Device *device;
21736 HRESULT hr;
21738 static const DWORD cs_code[] =
21740 #if 0
21741 struct data
21743 uint3 group_id;
21744 uint group_index;
21745 uint3 dispatch_id;
21746 uint3 group_thread_id;
21749 RWStructuredBuffer<data> u;
21751 uint2 dim;
21753 [numthreads(3, 2, 1)]
21754 void main(uint3 group_id : SV_GroupID,
21755 uint group_index : SV_GroupIndex,
21756 uint3 dispatch_id : SV_DispatchThreadID,
21757 uint3 group_thread_id : SV_GroupThreadID)
21759 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
21760 u[i].group_id = group_id;
21761 u[i].group_index = group_index;
21762 u[i].dispatch_id = dispatch_id;
21763 u[i].group_thread_id = group_thread_id;
21765 #endif
21766 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
21767 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21768 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
21769 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
21770 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
21771 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
21772 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
21773 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
21774 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
21775 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
21776 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
21777 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
21778 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
21779 0x0100003e,
21781 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21783 if (!init_test_context(&test_context, &feature_level))
21784 return;
21786 device = test_context.device;
21787 context = test_context.immediate_context;
21789 buffer_desc.ByteWidth = 10240;
21790 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
21791 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21792 buffer_desc.CPUAccessFlags = 0;
21793 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
21794 buffer_desc.StructureByteStride = 40;
21795 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
21796 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
21797 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
21798 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
21799 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21801 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
21803 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
21804 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21806 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21807 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
21808 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21810 dimensions.x = 2;
21811 dimensions.y = 3;
21812 dimensions.z = 1;
21813 dimensions.w = 0;
21814 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21815 NULL, &dimensions, 0, 0);
21816 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
21818 get_buffer_readback(buffer, &rb);
21819 i = 0;
21820 data = rb.map_desc.pData;
21821 for (y = 0; y < dimensions.y; ++y)
21823 for (group_y = 0; group_y < 2; ++group_y)
21825 for (x = 0; x < dimensions.x; ++x)
21827 for (group_x = 0; group_x < 3; ++group_x)
21829 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
21830 const unsigned int group_index = group_y * 3 + group_x;
21831 const struct data *d = &data[i];
21833 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
21834 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
21835 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
21836 i, x, y, group_x, group_y);
21837 ok(d->group_index == group_index,
21838 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
21839 d->group_index, group_index, i, x, y, group_x, group_y);
21840 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
21841 && !d->dispatch_id[2],
21842 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
21843 "at %u (%u, %u, %u, %u).\n",
21844 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
21845 dispatch_id[0], dispatch_id[1], 0,
21846 i, x, y, group_x, group_y);
21847 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
21848 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
21849 "at %u (%u, %u, %u, %u).\n",
21850 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
21851 i, x, y, group_x, group_y);
21852 ++i;
21857 release_resource_readback(&rb);
21859 ID3D11Buffer_Release(cb);
21860 ID3D11Buffer_Release(buffer);
21861 ID3D11ComputeShader_Release(cs);
21862 ID3D11UnorderedAccessView_Release(uav);
21863 release_test_context(&test_context);
21866 static void test_tgsm(void)
21868 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21869 struct d3d11_test_context test_context;
21870 ID3D11UnorderedAccessView *uav, *uav2;
21871 struct resource_readback rb, rb2;
21872 unsigned int i, data, expected;
21873 ID3D11Buffer *buffer, *buffer2;
21874 D3D11_BUFFER_DESC buffer_desc;
21875 ID3D11DeviceContext *context;
21876 ID3D11ComputeShader *cs;
21877 ID3D11Device *device;
21878 float float_data;
21879 HRESULT hr;
21881 static const DWORD raw_tgsm_code[] =
21883 #if 0
21884 RWByteAddressBuffer u;
21885 groupshared uint m;
21887 [numthreads(32, 1, 1)]
21888 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
21890 if (!local_idx)
21891 m = group_id.x;
21892 GroupMemoryBarrierWithGroupSync();
21893 InterlockedAdd(m, group_id.x);
21894 GroupMemoryBarrierWithGroupSync();
21895 if (!local_idx)
21896 u.Store(4 * group_id.x, m);
21898 #endif
21899 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
21900 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21901 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
21902 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
21903 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
21904 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
21905 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
21906 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
21907 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
21908 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
21909 0x01000015, 0x0100003e,
21911 static const DWORD structured_tgsm_code[] =
21913 #if 0
21914 #define GROUP_SIZE 32
21916 RWByteAddressBuffer u;
21917 RWByteAddressBuffer u2;
21918 groupshared uint m[GROUP_SIZE];
21920 [numthreads(GROUP_SIZE, 1, 1)]
21921 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
21923 uint sum, original, i;
21925 if (!local_idx)
21927 for (i = 0; i < GROUP_SIZE; ++i)
21928 m[i] = 2 * group_id.x;
21930 GroupMemoryBarrierWithGroupSync();
21931 InterlockedAdd(m[local_idx], 1);
21932 GroupMemoryBarrierWithGroupSync();
21933 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
21934 u.InterlockedExchange(4 * group_id.x, sum, original);
21935 u2.Store(4 * group_id.x, original);
21937 #endif
21938 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
21939 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21940 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
21941 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
21942 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
21943 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
21944 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
21945 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
21946 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
21947 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
21948 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
21949 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
21950 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
21951 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
21952 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
21953 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
21954 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
21955 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
21956 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
21957 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
21958 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
21959 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
21961 static const DWORD structured_tgsm_float_code[] =
21963 #if 0
21964 #define GROUP_SIZE 32
21966 struct data
21968 float f;
21969 uint u;
21972 RWBuffer<float> u;
21973 RWBuffer<uint> u2;
21974 groupshared data m[GROUP_SIZE];
21976 [numthreads(GROUP_SIZE, 1, 1)]
21977 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
21978 uint thread_id : SV_DispatchThreadID)
21980 uint i;
21981 if (!local_idx)
21983 for (i = 0; i < GROUP_SIZE; ++i)
21985 m[i].f = group_id.x;
21986 m[i].u = group_id.x;
21989 GroupMemoryBarrierWithGroupSync();
21990 for (i = 0; i < local_idx; ++i)
21992 m[local_idx].f += group_id.x;
21993 m[local_idx].u += group_id.x;
21995 u[thread_id.x] = m[local_idx].f;
21996 u2[thread_id.x] = m[local_idx].u;
21998 #endif
21999 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
22000 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22001 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
22002 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
22003 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
22004 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
22005 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
22006 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
22007 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
22008 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
22009 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
22010 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
22011 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
22012 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
22013 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
22014 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
22015 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
22016 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
22017 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
22018 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
22019 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
22020 0x00100556, 0x00000000, 0x0100003e,
22022 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22023 static const unsigned int zero[4] = {0};
22025 if (!init_test_context(&test_context, &feature_level))
22026 return;
22028 device = test_context.device;
22029 context = test_context.immediate_context;
22031 buffer_desc.ByteWidth = 1024;
22032 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
22033 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22034 buffer_desc.CPUAccessFlags = 0;
22035 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
22036 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
22037 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22039 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
22040 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
22041 U(uav_desc).Buffer.FirstElement = 0;
22042 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
22043 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
22044 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
22045 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22047 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
22048 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22050 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22051 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22053 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
22054 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
22055 get_buffer_readback(buffer, &rb);
22056 for (i = 0; i < 64; ++i)
22058 data = get_readback_color(&rb, i, 0, 0);
22059 expected = 33 * i;
22060 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
22062 release_resource_readback(&rb);
22064 ID3D11Buffer_Release(buffer);
22065 ID3D11ComputeShader_Release(cs);
22066 ID3D11UnorderedAccessView_Release(uav);
22068 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
22069 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22070 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
22071 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22072 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
22073 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22074 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
22075 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22076 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
22077 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22079 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22080 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22081 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
22083 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
22084 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
22085 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
22086 get_buffer_readback(buffer, &rb);
22087 get_buffer_readback(buffer2, &rb2);
22088 for (i = 0; i < 32; ++i)
22090 expected = 64 * i + 32;
22091 data = get_readback_color(&rb, i, 0, 0);
22092 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
22093 data = get_readback_color(&rb2, i, 0, 0);
22094 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
22096 release_resource_readback(&rb);
22097 release_resource_readback(&rb2);
22099 ID3D11Buffer_Release(buffer);
22100 ID3D11Buffer_Release(buffer2);
22101 ID3D11ComputeShader_Release(cs);
22102 ID3D11UnorderedAccessView_Release(uav);
22103 ID3D11UnorderedAccessView_Release(uav2);
22105 buffer_desc.MiscFlags = 0;
22106 U(uav_desc).Buffer.Flags = 0;
22107 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
22108 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22109 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
22110 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
22111 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22112 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
22113 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22114 uav_desc.Format = DXGI_FORMAT_R32_UINT;
22115 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
22116 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22117 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
22118 sizeof(structured_tgsm_float_code), NULL, &cs);
22119 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22121 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22122 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22123 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
22125 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
22126 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
22127 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
22128 get_buffer_readback(buffer, &rb);
22129 get_buffer_readback(buffer2, &rb2);
22130 for (i = 0; i < 96; ++i)
22132 expected = (i % 32 + 1) * (i / 32);
22133 float_data = get_readback_float(&rb, i, 0);
22134 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
22135 data = get_readback_color(&rb2, i, 0, 0);
22136 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
22138 release_resource_readback(&rb);
22139 release_resource_readback(&rb2);
22141 ID3D11Buffer_Release(buffer);
22142 ID3D11Buffer_Release(buffer2);
22143 ID3D11ComputeShader_Release(cs);
22144 ID3D11UnorderedAccessView_Release(uav);
22145 ID3D11UnorderedAccessView_Release(uav2);
22146 release_test_context(&test_context);
22149 static void test_geometry_shader(void)
22151 static const struct
22153 struct vec4 position;
22154 unsigned int color;
22156 vertex[] =
22158 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
22160 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
22162 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
22163 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
22165 #if 0
22166 struct vs_data
22168 float4 pos : SV_POSITION;
22169 float4 color : COLOR;
22172 void main(in struct vs_data vs_input, out struct vs_data vs_output)
22174 vs_output.pos = vs_input.pos;
22175 vs_output.color = vs_input.color;
22177 #endif
22178 static const DWORD vs_code[] =
22180 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
22181 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
22182 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
22183 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
22184 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
22185 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
22186 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
22187 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
22188 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
22189 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
22190 0x0100003e,
22192 #if 0
22193 struct gs_data
22195 float4 pos : SV_POSITION;
22196 float4 color : COLOR;
22199 [maxvertexcount(4)]
22200 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
22202 float offset = 0.2 * vin[0].pos.w;
22203 gs_data v;
22205 v.color = vin[0].color;
22207 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
22208 vout.Append(v);
22209 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
22210 vout.Append(v);
22211 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
22212 vout.Append(v);
22213 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
22214 vout.Append(v);
22216 #endif
22217 static const DWORD gs_code[] =
22219 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
22220 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
22221 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
22222 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
22223 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
22224 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
22225 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
22226 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
22227 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
22228 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
22229 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
22230 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
22231 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
22232 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
22233 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
22234 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
22235 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
22236 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
22237 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
22238 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
22239 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
22240 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
22241 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
22242 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
22243 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
22244 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
22245 0x00000001, 0x01000013, 0x0100003e,
22247 static const DWORD gs_5_0_code[] =
22249 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
22250 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
22251 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
22252 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
22253 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
22254 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
22255 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
22256 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
22257 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
22258 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
22259 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
22260 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
22261 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
22262 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
22263 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
22264 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
22265 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
22266 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
22267 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
22268 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
22269 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
22270 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
22271 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
22272 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
22273 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
22274 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
22275 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
22276 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
22277 0x0100003e,
22279 #if 0
22280 struct ps_data
22282 float4 pos : SV_POSITION;
22283 float4 color : COLOR;
22286 float4 main(struct ps_data ps_input) : SV_Target
22288 return ps_input.color;
22290 #endif
22291 static const DWORD ps_code[] =
22293 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
22294 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
22295 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
22296 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
22297 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
22298 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
22299 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
22300 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
22302 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
22303 struct d3d11_test_context test_context;
22304 ID3D11InputLayout *input_layout;
22305 ID3D11DeviceContext *context;
22306 unsigned int stride, offset;
22307 struct resource_readback rb;
22308 ID3D11GeometryShader *gs;
22309 ID3D11VertexShader *vs;
22310 ID3D11PixelShader *ps;
22311 ID3D11Device *device;
22312 ID3D11Buffer *vb;
22313 DWORD color;
22314 HRESULT hr;
22316 if (!init_test_context(&test_context, NULL))
22317 return;
22319 device = test_context.device;
22320 context = test_context.immediate_context;
22322 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
22323 vs_code, sizeof(vs_code), &input_layout);
22324 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
22326 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
22328 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
22329 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
22330 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
22331 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
22332 else
22333 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
22334 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
22335 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22336 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22338 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
22339 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
22340 stride = sizeof(*vertex);
22341 offset = 0;
22342 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
22343 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
22344 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
22345 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22347 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
22348 ID3D11DeviceContext_Draw(context, 1, 0);
22350 get_texture_readback(test_context.backbuffer, 0, &rb);
22351 color = get_readback_color(&rb, 320, 190, 0);
22352 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
22353 color = get_readback_color(&rb, 255, 240, 0);
22354 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
22355 color = get_readback_color(&rb, 320, 240, 0);
22356 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
22357 color = get_readback_color(&rb, 385, 240, 0);
22358 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
22359 color = get_readback_color(&rb, 320, 290, 0);
22360 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
22361 release_resource_readback(&rb);
22363 ID3D11PixelShader_Release(ps);
22364 ID3D11GeometryShader_Release(gs);
22365 ID3D11VertexShader_Release(vs);
22366 ID3D11Buffer_Release(vb);
22367 ID3D11InputLayout_Release(input_layout);
22368 release_test_context(&test_context);
22371 struct triangle
22373 struct vec4 v[3];
22376 #define check_triangles(buffer, triangles, count) check_triangles_(__LINE__, buffer, triangles, count)
22377 static void check_triangles_(unsigned int line, ID3D11Buffer *buffer,
22378 const struct triangle *triangles, unsigned int triangle_count)
22380 const struct triangle *current, *expected;
22381 struct resource_readback rb;
22382 unsigned int i, j, offset;
22383 BOOL all_match = TRUE;
22385 get_buffer_readback(buffer, &rb);
22387 for (i = 0; i < triangle_count; ++i)
22389 current = get_readback_data(&rb, i, 0, 0, sizeof(*current));
22390 expected = &triangles[i];
22392 offset = ~0u;
22393 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
22395 if (compare_vec4(&current->v[0], &expected->v[j], 0))
22397 offset = j;
22398 break;
22402 if (offset == ~0u)
22404 all_match = FALSE;
22405 break;
22408 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
22410 if (!compare_vec4(&current->v[j], &expected->v[(j + offset) % 3], 0))
22412 all_match = FALSE;
22413 break;
22416 if (!all_match)
22417 break;
22420 ok_(__FILE__, line)(all_match, "Triangle %u vertices {%.8e, %.8e, %.8e, %.8e}, "
22421 "{%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e} "
22422 "do not match {%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e}, "
22423 "{%.8e, %.8e, %.8e, %.8e}.\n", i,
22424 current->v[0].x, current->v[0].y, current->v[0].z, current->v[0].w,
22425 current->v[1].x, current->v[1].y, current->v[1].z, current->v[1].w,
22426 current->v[2].x, current->v[2].y, current->v[2].z, current->v[2].w,
22427 expected->v[0].x, expected->v[0].y, expected->v[0].z, expected->v[0].w,
22428 expected->v[1].x, expected->v[1].y, expected->v[1].z, expected->v[1].w,
22429 expected->v[2].x, expected->v[2].y, expected->v[2].z, expected->v[2].w);
22431 release_resource_readback(&rb);
22434 static void test_quad_tessellation(void)
22436 #if 0
22437 struct point_data
22439 float4 position : SV_POSITION;
22442 struct patch_constant_data
22444 float edges[4] : SV_TessFactor;
22445 float inside[2] : SV_InsideTessFactor;
22448 float4 tess_factors;
22449 float2 inside_tess_factors;
22451 patch_constant_data patch_constant(InputPatch<point_data, 4> input)
22453 patch_constant_data output;
22455 output.edges[0] = tess_factors.x;
22456 output.edges[1] = tess_factors.y;
22457 output.edges[2] = tess_factors.z;
22458 output.edges[3] = tess_factors.w;
22459 output.inside[0] = inside_tess_factors.x;
22460 output.inside[1] = inside_tess_factors.y;
22462 return output;
22465 [domain("quad")]
22466 [outputcontrolpoints(4)]
22467 [outputtopology("triangle_ccw")]
22468 [partitioning("integer")]
22469 [patchconstantfunc("patch_constant")]
22470 point_data hs_main(InputPatch<point_data, 4> input,
22471 uint i : SV_OutputControlPointID)
22473 return input[i];
22476 [domain("quad")]
22477 point_data ds_main(patch_constant_data input,
22478 float2 tess_coord : SV_DomainLocation,
22479 const OutputPatch<point_data, 4> patch)
22481 point_data output;
22483 float4 a = lerp(patch[0].position, patch[1].position, tess_coord.x);
22484 float4 b = lerp(patch[2].position, patch[3].position, tess_coord.x);
22485 output.position = lerp(a, b, tess_coord.y);
22487 return output;
22489 #endif
22490 static const DWORD hs_quad_ccw_code[] =
22492 0x43425844, 0xdf8df700, 0x58b08fb1, 0xbd23d2c3, 0xcf884094, 0x00000001, 0x000002b8, 0x00000004,
22493 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
22494 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
22495 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
22496 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
22497 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
22498 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
22499 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
22500 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
22501 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
22502 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
22503 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
22504 0x01002097, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
22505 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
22506 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
22507 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
22508 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
22509 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
22510 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
22511 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
22512 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
22513 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
22515 static const DWORD ds_quad_code[] =
22517 0x43425844, 0xeb6b7631, 0x07f5469e, 0xed0cbf4a, 0x7158b3a6, 0x00000001, 0x00000284, 0x00000004,
22518 0x00000030, 0x00000064, 0x00000128, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
22519 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
22520 0x004e4f49, 0x47534350, 0x000000bc, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b,
22521 0x00000003, 0x00000000, 0x00000001, 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001,
22522 0x00000001, 0x00000098, 0x00000002, 0x0000000b, 0x00000003, 0x00000002, 0x00000001, 0x00000098,
22523 0x00000003, 0x0000000b, 0x00000003, 0x00000003, 0x00000001, 0x000000a6, 0x00000000, 0x0000000c,
22524 0x00000003, 0x00000004, 0x00000001, 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005,
22525 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365,
22526 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
22527 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853,
22528 0x00000120, 0x00040050, 0x00000048, 0x01002093, 0x01001895, 0x0100086a, 0x0200005f, 0x0001c032,
22529 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
22530 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, 0x80219e46, 0x00000041, 0x00000002,
22531 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, 0x001000f2, 0x00000000, 0x0001c006,
22532 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, 0x0a000000, 0x001000f2, 0x00000001,
22533 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, 0x00000001, 0x00000000, 0x09000032,
22534 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, 0x00219e46, 0x00000000, 0x00000000,
22535 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x80100e46, 0x00000041, 0x00000001,
22536 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
22537 0x0100003e,
22539 #if 0
22541 [outputtopology("triangle_cw")]
22543 #endif
22544 static const DWORD hs_quad_cw_code[] =
22546 0x43425844, 0x1ab30cc8, 0x94174771, 0x61f4cdd0, 0xa287f62c, 0x00000001, 0x000002b8, 0x00000004,
22547 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
22548 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
22549 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
22550 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
22551 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
22552 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
22553 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
22554 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
22555 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
22556 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
22557 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
22558 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
22559 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
22560 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
22561 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
22562 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
22563 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
22564 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
22565 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
22566 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
22567 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
22569 #if 0
22570 struct point_data
22572 float4 pos : SV_POSITION;
22575 [maxvertexcount(3)]
22576 void main(triangle point_data vin[3], inout TriangleStream<point_data> vout)
22578 for (uint i = 0; i < 3; ++i)
22579 vout.Append(vin[i]);
22581 #endif
22582 static const DWORD gs_code[] =
22584 0x43425844, 0x8e49d18d, 0x6d08d6e5, 0xb7015628, 0xf9351fdd, 0x00000001, 0x00000164, 0x00000003,
22585 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
22586 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
22587 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
22588 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000000c8, 0x00020040,
22589 0x00000032, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068, 0x00000001,
22590 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000003,
22591 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
22592 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010001a, 0x00000000,
22593 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x01000013,
22594 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016,
22595 0x0100003e,
22597 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
22599 {0, "SV_POSITION", 0, 0, 4, 0},
22601 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22602 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
22603 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
22604 static const BYTE zero_data[1024];
22605 static const struct triangle expected_quad_ccw[] =
22607 {{{-1.0f, -1.0f, 0.0f, 1.0f},
22608 { 1.0f, -1.0f, 0.0f, 1.0f},
22609 {-1.0f, 1.0f, 0.0f, 1.0f}}},
22610 {{{-1.0f, 1.0f, 0.0f, 1.0f},
22611 { 1.0f, -1.0f, 0.0f, 1.0f},
22612 { 1.0f, 1.0f, 0.0f, 1.0f}}},
22613 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
22614 { 0.0f, 0.0f, 0.0f, 0.0f},
22615 { 0.0f, 0.0f, 0.0f, 0.0f}}},
22617 static const struct triangle expected_quad_cw[] =
22619 {{{-1.0f, -1.0f, 0.0f, 1.0f},
22620 {-1.0f, 1.0f, 0.0f, 1.0f},
22621 { 1.0f, -1.0f, 0.0f, 1.0f}}},
22622 {{{-1.0f, 1.0f, 0.0f, 1.0f},
22623 { 1.0f, 1.0f, 0.0f, 1.0f},
22624 { 1.0f, -1.0f, 0.0f, 1.0f}}},
22625 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
22626 { 0.0f, 0.0f, 0.0f, 0.0f},
22627 { 0.0f, 0.0f, 0.0f, 0.0f}}},
22629 struct
22631 float tess_factors[4];
22632 float inside_tess_factors[2];
22633 DWORD padding[2];
22634 } constant;
22636 D3D11_QUERY_DATA_SO_STATISTICS so_statistics;
22637 struct d3d11_test_context test_context;
22638 ID3D11DeviceContext *context;
22639 ID3D11Buffer *cb, *so_buffer;
22640 D3D11_QUERY_DESC query_desc;
22641 ID3D11Asynchronous *query;
22642 ID3D11GeometryShader *gs;
22643 ID3D11DomainShader *ds;
22644 const UINT offset = 0;
22645 ID3D11HullShader *hs;
22646 ID3D11Device *device;
22647 unsigned int i;
22648 HRESULT hr;
22650 if (!init_test_context(&test_context, &feature_level))
22651 return;
22653 device = test_context.device;
22654 context = test_context.immediate_context;
22656 draw_color_quad(&test_context, &white);
22657 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22659 set_quad_color(&test_context, &green);
22660 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
22662 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
22663 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
22664 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0, NULL, &gs);
22665 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
22666 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
22668 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
22669 constant.tess_factors[i] = 1.0f;
22670 for (i = 0; i < ARRAY_SIZE(constant.inside_tess_factors); ++i)
22671 constant.inside_tess_factors[i] = 1.0f;
22672 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
22673 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb);
22674 hr = ID3D11Device_CreateHullShader(device, hs_quad_ccw_code, sizeof(hs_quad_ccw_code), NULL, &hs);
22675 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
22676 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
22677 hr = ID3D11Device_CreateDomainShader(device, ds_quad_code, sizeof(ds_quad_code), NULL, &ds);
22678 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
22679 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
22681 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
22682 ID3D11DeviceContext_Draw(context, 4, 0);
22683 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22684 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
22685 check_triangles(so_buffer, expected_quad_ccw, ARRAY_SIZE(expected_quad_ccw));
22687 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
22689 ID3D11HullShader_Release(hs);
22690 hr = ID3D11Device_CreateHullShader(device, hs_quad_cw_code, sizeof(hs_quad_cw_code), NULL, &hs);
22691 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
22692 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
22694 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
22695 ID3D11DeviceContext_Draw(context, 4, 0);
22696 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
22697 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
22698 check_triangles(so_buffer, expected_quad_cw, ARRAY_SIZE(expected_quad_cw));
22700 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
22702 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
22703 query_desc.Query = D3D11_QUERY_SO_STATISTICS_STREAM0;
22704 query_desc.MiscFlags = 0;
22705 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
22706 ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
22707 ID3D11DeviceContext_Begin(context, query);
22709 set_quad_color(&test_context, &white);
22710 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
22711 constant.tess_factors[i] = 2.0f;
22712 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22713 ID3D11DeviceContext_Draw(context, 4, 0);
22714 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22716 set_quad_color(&test_context, &green);
22717 constant.tess_factors[0] = 0.0f; /* A patch is discarded. */
22718 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22719 ID3D11DeviceContext_Draw(context, 4, 0);
22720 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22722 ID3D11DeviceContext_End(context, query);
22723 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
22724 ok(so_statistics.NumPrimitivesWritten == 8, "Got unexpected primitives written %u.\n",
22725 (unsigned int)so_statistics.NumPrimitivesWritten);
22726 ok(so_statistics.PrimitivesStorageNeeded == 8, "Got unexpected primitives storage needed %u.\n",
22727 (unsigned int)so_statistics.PrimitivesStorageNeeded);
22728 ID3D11DeviceContext_Begin(context, query);
22730 constant.tess_factors[0] = 5.0f;
22731 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22732 ID3D11DeviceContext_Draw(context, 4, 0);
22733 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
22735 ID3D11DeviceContext_End(context, query);
22736 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
22737 ok(so_statistics.NumPrimitivesWritten == 11, "Got unexpected primitives written %u.\n",
22738 (unsigned int)so_statistics.NumPrimitivesWritten);
22739 ok(so_statistics.PrimitivesStorageNeeded == 11, "Got unexpected primitives storage needed %u.\n",
22740 (unsigned int)so_statistics.PrimitivesStorageNeeded);
22741 ID3D11Asynchronous_Release(query);
22743 ID3D11Buffer_Release(so_buffer);
22744 ID3D11GeometryShader_Release(gs);
22745 ID3D11DomainShader_Release(ds);
22746 ID3D11HullShader_Release(hs);
22747 ID3D11Buffer_Release(cb);
22748 release_test_context(&test_context);
22751 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
22752 static void check_so_desc_(unsigned int line, ID3D11Device *device,
22753 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
22754 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
22755 unsigned int rasterizer_stream)
22757 ID3D11GeometryShader *gs;
22758 HRESULT hr;
22760 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
22761 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
22762 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
22763 if (SUCCEEDED(hr))
22764 ID3D11GeometryShader_Release(gs);
22767 #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)
22768 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
22769 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
22770 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
22771 unsigned int rasterizer_stream)
22773 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
22774 HRESULT hr;
22776 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
22777 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
22778 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
22779 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
22780 if (SUCCEEDED(hr))
22781 ID3D11GeometryShader_Release(gs);
22784 static void test_stream_output(void)
22786 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
22787 struct d3d11_test_context test_context;
22788 unsigned int i, count;
22789 ID3D11Device *device;
22791 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22792 static const DWORD vs_code[] =
22794 #if 0
22795 struct data
22797 float4 position : SV_Position;
22798 float4 attrib1 : ATTRIB1;
22799 float3 attrib2 : attrib2;
22800 float2 attrib3 : ATTriB3;
22801 float attrib4 : ATTRIB4;
22804 void main(in data i, out data o)
22806 o = i;
22808 #endif
22809 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
22810 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
22811 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
22812 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
22813 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
22814 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
22815 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
22816 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
22817 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
22818 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
22819 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
22820 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
22821 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
22822 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
22823 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
22824 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
22825 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
22826 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
22827 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
22828 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
22830 static const DWORD gs_code[] =
22832 #if 0
22833 struct data
22835 float4 position : SV_Position;
22836 float4 attrib1 : ATTRIB1;
22837 float3 attrib2 : attrib2;
22838 float2 attrib3 : ATTriB3;
22839 float attrib4 : ATTRIB4;
22842 [maxvertexcount(1)]
22843 void main(point data i[1], inout PointStream<data> o)
22845 o.Append(i[0]);
22847 #endif
22848 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
22849 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
22850 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
22851 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
22852 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
22853 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
22854 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
22855 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
22856 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
22857 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
22858 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
22859 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
22860 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
22861 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
22862 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
22863 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
22864 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
22865 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
22866 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
22867 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
22868 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
22870 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
22872 {0, "SV_Position", 0, 0, 4, 0},
22874 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
22876 {0, "SV_Position", 0, 0, 4, 0},
22877 {0, NULL, 0, 0, 0, 0},
22879 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
22881 /* SemanticName and SemanticIndex */
22883 {0, "sv_position", 0, 0, 4, 0},
22884 {0, "attrib", 1, 0, 4, 0},
22887 {0, "sv_position", 0, 0, 4, 0},
22888 {0, "ATTRIB", 1, 0, 4, 0},
22890 /* Gaps */
22892 {0, "SV_POSITION", 0, 0, 4, 0},
22893 {0, NULL, 0, 0, 8, 0},
22894 {0, "ATTRIB", 1, 0, 4, 0},
22897 {0, "SV_POSITION", 0, 0, 4, 0},
22898 {0, NULL, 0, 0, 4, 0},
22899 {0, NULL, 0, 0, 4, 0},
22900 {0, "ATTRIB", 1, 0, 4, 0},
22902 /* ComponentCount */
22904 {0, "ATTRIB", 1, 0, 4, 0},
22907 {0, "ATTRIB", 2, 0, 3, 0},
22910 {0, "ATTRIB", 3, 0, 2, 0},
22913 {0, "ATTRIB", 4, 0, 1, 0},
22915 /* ComponentIndex */
22917 {0, "ATTRIB", 1, 1, 3, 0},
22920 {0, "ATTRIB", 1, 2, 2, 0},
22923 {0, "ATTRIB", 1, 3, 1, 0},
22926 {0, "ATTRIB", 3, 1, 1, 0},
22928 /* OutputSlot */
22930 {0, "attrib", 1, 0, 4, 0},
22933 {0, "attrib", 1, 0, 4, 1},
22936 {0, "attrib", 1, 0, 4, 2},
22939 {0, "attrib", 1, 0, 4, 3},
22942 {0, "attrib", 1, 0, 4, 0},
22943 {0, "attrib", 2, 0, 3, 1},
22944 {0, NULL, 0, 0, 1, 1},
22945 {0, "attrib", 3, 0, 2, 2},
22946 {0, NULL, 0, 0, 2, 2},
22947 {0, "attrib", 4, 0, 1, 3},
22948 {0, NULL, 0, 0, 7, 3},
22951 {0, "attrib", 1, 0, 4, 0},
22952 {0, "attrib", 2, 0, 3, 1},
22953 {0, NULL, 0, 0, 1, 1},
22954 {0, "attrib", 3, 0, 2, 2},
22955 {0, NULL, 0, 0, 1, 2},
22956 {0, NULL, 0, 0, 1, 2},
22957 {0, "attrib", 4, 0, 1, 3},
22958 {0, NULL, 0, 0, 3, 3},
22959 {0, NULL, 0, 0, 1, 3},
22960 {0, NULL, 0, 0, 1, 3},
22961 {0, NULL, 0, 0, 1, 3},
22962 {0, NULL, 0, 0, 1, 3},
22965 {0, "attrib", 1, 0, 4, 0},
22966 {0, "attrib", 2, 0, 3, 0},
22967 {0, "attrib", 3, 0, 2, 0},
22968 {0, NULL, 0, 0, 1, 0},
22969 {0, "attrib", 4, 0, 1, 0},
22972 {0, "attrib", 1, 0, 4, 0},
22973 {0, "attrib", 2, 0, 3, 0},
22974 {0, "attrib", 3, 0, 2, 3},
22975 {0, NULL, 0, 0, 1, 3},
22976 {0, "attrib", 4, 0, 1, 3},
22978 /* Multiple occurrences of the same output */
22980 {0, "ATTRIB", 1, 0, 2, 0},
22981 {0, "ATTRIB", 1, 2, 2, 1},
22984 {0, "ATTRIB", 1, 0, 1, 0},
22985 {0, "ATTRIB", 1, 1, 3, 0},
22988 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
22990 /* SemanticName and SemanticIndex */
22992 {0, "SV_Position", 0, 0, 4, 0},
22993 {0, "ATTRIB", 0, 0, 4, 0},
22996 {0, "sv_position", 0, 0, 4, 0},
22997 {0, "ATTRIB_", 1, 0, 4, 0},
22999 /* Gaps */
23001 {0, "SV_POSITION", 0, 0, 4, 0},
23002 {0, NULL, 0, 1, 8, 0},
23003 {0, "ATTRIB", 1, 0, 4, 0},
23006 {0, "SV_POSITION", 0, 0, 4, 0},
23007 {0, NULL, 1, 0, 8, 0},
23008 {0, "ATTRIB", 1, 0, 4, 0},
23010 /* Buffer stride */
23012 {0, "SV_POSITION", 0, 0, 4, 0},
23013 {0, NULL, 0, 0, 8, 0},
23014 {0, NULL, 0, 0, 8, 0},
23015 {0, "ATTRIB", 1, 0, 4, 0},
23017 /* ComponentCount */
23019 {0, "ATTRIB", 2, 0, 5, 0},
23022 {0, "ATTRIB", 2, 0, 4, 0},
23025 {0, "ATTRIB", 3, 0, 3, 0},
23028 {0, "ATTRIB", 4, 0, 2, 0},
23030 /* ComponentIndex */
23032 {0, "ATTRIB", 1, 1, 4, 0},
23035 {0, "ATTRIB", 1, 2, 3, 0},
23038 {0, "ATTRIB", 1, 3, 2, 0},
23041 {0, "ATTRIB", 1, 4, 0, 0},
23044 {0, "ATTRIB", 1, 4, 1, 0},
23047 {0, "ATTRIB", 3, 2, 1, 0},
23050 {0, "ATTRIB", 3, 2, 0, 0},
23052 /* OutputSlot */
23054 {0, "attrib", 1, 0, 4, 4},
23057 {0, "attrib", 1, 0, 4, 4},
23060 {0, "attrib", 1, 0, 4, 4},
23063 {0, "attrib", 1, 0, 4, 4},
23066 {0, "attrib", 1, 0, 4, 0},
23067 {0, "attrib", 2, 0, 3, 1},
23068 {0, NULL, 0, 0, 1, 1},
23069 {0, "attrib", 3, 0, 2, 2},
23070 {0, NULL, 0, 0, 2, 2},
23071 {0, "attrib", 4, 0, 1, 3},
23072 {0, NULL, 0, 0, 3, 4},
23075 {0, "attrib", 1, 0, 4, 0},
23076 {0, "attrib", 2, 0, 3, 0},
23077 {0, "attrib", 3, 0, 2, 0},
23078 {0, NULL, 0, 0, 1, 0},
23079 {0, "attrib", 4, 0, 1, 0},
23080 {0, NULL, 0, 0, 3, 3},
23081 {0, NULL, 0, 0, 1, 3},
23082 {0, NULL, 0, 0, 1, 3},
23083 {0, NULL, 0, 0, 1, 3},
23084 {0, NULL, 0, 0, 1, 3},
23087 {0, "attrib", 1, 0, 4, 0},
23088 {0, NULL, 0, 0, 3, 1},
23089 {0, NULL, 0, 0, 1, 1},
23090 {0, NULL, 0, 0, 1, 2},
23091 {0, "attrib", 2, 0, 3, 3},
23092 {0, NULL, 0, 0, 1, 3},
23095 {0, "attrib", 2, 0, 3, 3},
23096 {0, NULL, 0, 0, 3, 1},
23097 {0, NULL, 0, 0, 1, 3},
23098 {0, "attrib", 1, 0, 4, 0},
23099 {0, NULL, 0, 0, 1, 2},
23100 {0, NULL, 0, 0, 1, 1},
23102 /* Stream */
23104 {1, "attrib", 1, 0, 4, 0},
23107 {4, "attrib", 1, 0, 4, 0},
23109 /* Multiple occurrences of the same output */
23111 {0, "ATTRIB", 1, 0, 4, 0},
23112 {0, "ATTRIB", 1, 0, 4, 1},
23115 {0, "ATTRIB", 1, 0, 4, 0},
23116 {0, "ATTRIB", 1, 0, 3, 0},
23120 if (!init_test_context(&test_context, &feature_level))
23121 return;
23123 device = test_context.device;
23125 for (i = 0; i < ARRAY_SIZE(stride); ++i)
23126 stride[i] = 64;
23128 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
23129 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
23130 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
23131 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
23132 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
23133 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
23135 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
23136 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
23137 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
23138 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
23140 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
23141 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
23142 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
23143 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
23144 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
23146 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
23147 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
23148 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
23149 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
23151 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
23153 unsigned int max_output_slot = 0;
23154 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
23156 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
23157 max_output_slot = max(max_output_slot, e->OutputSlot);
23158 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
23159 break;
23162 /* Buffer strides are required for all buffers. */
23163 if (!max_output_slot)
23165 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
23166 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
23167 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
23168 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
23169 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
23170 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
23171 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
23172 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
23173 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
23174 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
23176 else
23178 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
23179 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
23180 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
23181 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
23185 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
23187 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
23189 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
23190 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
23191 break;
23194 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
23195 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
23196 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
23197 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
23198 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
23199 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
23200 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
23201 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
23204 /* Buffer strides */
23205 stride[1] = 63;
23206 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
23207 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
23208 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
23209 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
23210 stride[1] = 1;
23211 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
23212 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
23213 stride[0] = 0;
23214 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
23215 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
23217 /* Rasterizer stream */
23218 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
23219 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
23220 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
23221 NULL, 0, D3D11_SO_STREAM_COUNT);
23223 release_test_context(&test_context);
23226 static void test_fl10_stream_output_desc(void)
23228 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
23229 struct d3d11_test_context test_context;
23230 unsigned int i, count;
23231 ID3D11Device *device;
23233 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
23234 static const DWORD vs_code[] =
23236 #if 0
23237 struct data
23239 float4 position : SV_Position;
23240 float4 attrib1 : ATTRIB1;
23241 float3 attrib2 : attrib2;
23242 float2 attrib3 : ATTriB3;
23243 float attrib4 : ATTRIB4;
23246 void main(in data i, out data o)
23248 o = i;
23250 #endif
23251 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
23252 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
23253 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
23254 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
23255 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
23256 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
23257 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
23258 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
23259 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
23260 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
23261 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
23262 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
23263 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
23264 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
23265 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
23266 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
23267 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
23268 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
23269 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
23270 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
23272 static const DWORD gs_code[] =
23274 #if 0
23275 struct data
23277 float4 position : SV_Position;
23278 float4 attrib1 : ATTRIB1;
23279 float3 attrib2 : attrib2;
23280 float2 attrib3 : ATTriB3;
23281 float attrib4 : ATTRIB4;
23284 [maxvertexcount(1)]
23285 void main(point data i[1], inout PointStream<data> o)
23287 o.Append(i[0]);
23289 #endif
23290 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
23291 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
23292 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
23293 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
23294 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
23295 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
23296 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
23297 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
23298 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
23299 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
23300 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
23301 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
23302 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
23303 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
23304 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
23305 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
23306 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
23307 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
23308 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
23309 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
23310 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
23312 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
23314 {0, "SV_Position", 0, 0, 4, 0},
23316 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
23318 {0, "SV_Position", 0, 0, 4, 0},
23319 {0, NULL, 0, 0, 0, 0},
23321 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
23323 /* Gaps */
23325 {0, "SV_POSITION", 0, 0, 4, 0},
23326 {0, NULL, 0, 0, 8, 0},
23327 {0, "ATTRIB", 1, 0, 4, 0},
23330 {0, "SV_POSITION", 0, 0, 4, 0},
23331 {0, NULL, 0, 0, 4, 0},
23332 {0, NULL, 0, 0, 4, 0},
23333 {0, "ATTRIB", 1, 0, 4, 0},
23335 /* OutputSlot */
23337 {0, "attrib", 1, 0, 4, 0},
23338 {0, "attrib", 2, 0, 3, 0},
23339 {0, "attrib", 3, 0, 2, 0},
23340 {0, "attrib", 4, 0, 1, 0},
23343 {0, "attrib", 1, 0, 4, 0},
23344 {0, "attrib", 2, 0, 3, 1},
23345 {0, "attrib", 3, 0, 2, 2},
23346 {0, "attrib", 4, 0, 1, 3},
23349 {0, "attrib", 1, 0, 4, 0},
23350 {0, "attrib", 2, 0, 3, 3},
23353 {0, "attrib", 1, 0, 4, 0},
23354 {0, "attrib", 2, 0, 3, 0},
23355 {0, "attrib", 3, 0, 2, 0},
23356 {0, NULL, 0, 0, 1, 0},
23357 {0, "attrib", 4, 0, 1, 0},
23359 /* Multiple occurrences of the same output */
23361 {0, "ATTRIB", 1, 0, 2, 0},
23362 {0, "ATTRIB", 1, 2, 2, 1},
23365 {0, "ATTRIB", 1, 0, 1, 0},
23366 {0, "ATTRIB", 1, 1, 3, 0},
23369 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
23371 /* OutputSlot */
23373 {0, "attrib", 1, 0, 4, 0},
23374 {0, NULL, 0, 0, 4, 0},
23375 {0, "attrib", 4, 0, 1, 3},
23378 {0, "attrib", 1, 0, 4, 0},
23379 {0, NULL, 0, 0, 4, 0},
23380 {0, NULL, 0, 0, 4, 0},
23381 {0, "attrib", 4, 0, 1, 3},
23384 {0, "attrib", 1, 0, 4, 0},
23385 {0, "attrib", 2, 0, 3, 0},
23386 {0, "attrib", 3, 0, 2, 0},
23387 {0, "attrib", 4, 0, 1, 1},
23390 {0, "attrib", 1, 0, 4, 0},
23391 {0, "attrib", 2, 0, 3, 0},
23392 {0, "attrib", 3, 0, 2, 3},
23393 {0, NULL, 0, 0, 1, 3},
23394 {0, "attrib", 4, 0, 1, 3},
23397 {0, "attrib", 1, 0, 4, 0},
23398 {0, "attrib", 1, 0, 3, 1},
23399 {0, "attrib", 1, 0, 2, 2},
23400 {0, "attrib", 1, 0, 1, 3},
23401 {0, NULL, 0, 0, 3, 3},
23405 if (!init_test_context(&test_context, &feature_level))
23406 return;
23408 device = test_context.device;
23410 for (i = 0; i < ARRAY_SIZE(stride); ++i)
23411 stride[i] = 64;
23413 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
23414 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
23415 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
23416 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
23418 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
23419 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
23421 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
23422 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
23423 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
23424 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
23425 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
23427 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
23428 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
23430 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
23432 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
23434 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
23435 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
23436 break;
23439 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
23442 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
23444 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
23446 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
23447 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
23448 break;
23451 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
23452 stride, 1, 0);
23453 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
23454 stride, 2, 0);
23455 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
23456 stride, 3, 0);
23457 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
23458 stride, 4, 0);
23461 /* Buffer strides */
23462 stride[1] = 63;
23463 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
23464 &stride[1], 1, 0);
23465 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
23466 stride, 2, 0);
23467 stride[0] = 0;
23468 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
23469 stride, 1, 0);
23471 /* Rasterizer stream */
23472 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
23473 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
23474 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
23475 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
23476 NULL, 0, i);
23477 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
23479 release_test_context(&test_context);
23482 static void test_stream_output_resume(void)
23484 struct d3d11_test_context test_context;
23485 ID3D11Buffer *cb, *so_buffer, *buffer;
23486 unsigned int i, j, idx, offset;
23487 ID3D11DeviceContext *context;
23488 struct resource_readback rb;
23489 ID3D11GeometryShader *gs;
23490 const struct vec4 *data;
23491 ID3D11Device *device;
23492 HRESULT hr;
23494 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
23495 static const DWORD gs_code[] =
23497 #if 0
23498 float4 constant;
23500 struct vertex
23502 float4 position : SV_POSITION;
23505 struct element
23507 float4 position : SV_POSITION;
23508 float4 so_output : so_output;
23511 [maxvertexcount(3)]
23512 void main(triangle vertex input[3], inout PointStream<element> output)
23514 element o;
23515 o.so_output = constant;
23516 o.position = input[0].position;
23517 output.Append(o);
23518 o.position = input[1].position;
23519 output.Append(o);
23520 o.position = input[2].position;
23521 output.Append(o);
23523 #endif
23524 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
23525 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
23526 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
23527 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
23528 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
23529 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
23530 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
23531 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
23532 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
23533 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
23534 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
23535 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
23536 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
23537 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
23539 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
23541 {0, "so_output", 0, 0, 4, 0},
23543 static const struct vec4 constants[] =
23545 {0.5f, 0.250f, 0.0f, 0.0f},
23546 {0.0f, 0.125f, 0.0f, 1.0f},
23547 {1.0f, 1.000f, 1.0f, 0.0f}
23549 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
23550 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
23551 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
23553 if (!init_test_context(&test_context, &feature_level))
23554 return;
23556 device = test_context.device;
23557 context = test_context.immediate_context;
23559 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
23560 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
23561 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
23563 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
23564 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
23566 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
23567 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
23569 offset = 0;
23570 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
23572 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
23573 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
23575 draw_color_quad(&test_context, &red);
23576 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
23578 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
23579 draw_color_quad(&test_context, &green);
23580 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
23582 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
23583 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
23584 draw_color_quad(&test_context, &red);
23585 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
23587 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
23588 draw_color_quad(&test_context, &red);
23589 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
23591 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
23592 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
23593 draw_color_quad(&test_context, &white);
23594 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
23596 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
23597 draw_color_quad(&test_context, &green);
23598 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
23600 buffer = NULL;
23601 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
23602 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
23603 draw_color_quad(&test_context, &white);
23604 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
23606 idx = 0;
23607 get_buffer_readback(so_buffer, &rb);
23608 for (i = 0; i < ARRAY_SIZE(constants); ++i)
23610 for (j = 0; j < 6; ++j) /* 2 triangles */
23612 data = get_readback_vec4(&rb, idx++, 0);
23613 ok(compare_vec4(data, &constants[i], 0),
23614 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
23615 data->x, data->y, data->z, data->w, idx, i, j);
23618 release_resource_readback(&rb);
23620 ID3D11Buffer_Release(cb);
23621 ID3D11Buffer_Release(so_buffer);
23622 ID3D11GeometryShader_Release(gs);
23623 release_test_context(&test_context);
23626 static void test_stream_output_components(void)
23628 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
23629 struct d3d11_test_context test_context;
23630 ID3D11InputLayout *input_layout[2];
23631 ID3D11Buffer *vb[2], *so_buffer;
23632 ID3D11DeviceContext *context;
23633 struct resource_readback rb;
23634 unsigned int stride, offset;
23635 ID3D11GeometryShader *gs;
23636 ID3D11VertexShader *vs;
23637 ID3D11PixelShader *ps;
23638 ID3D11Device *device;
23639 const float *result;
23640 unsigned int i, j;
23641 HRESULT hr;
23643 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
23644 static const DWORD vs_code[] =
23646 #if 0
23647 struct vertex
23649 float4 position : POSITION;
23650 float4 color : COLOR;
23651 float4 color2 : COLOR2;
23654 void main(in vertex i, out vertex o)
23656 o = i;
23658 #endif
23659 0x43425844, 0x95991b76, 0x4898640b, 0xe36ad9d6, 0xfbfe78b4, 0x00000001, 0x00000194, 0x00000003,
23660 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
23661 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
23662 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
23663 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
23664 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
23665 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
23666 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
23667 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
23668 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
23669 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
23670 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
23671 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
23673 static const DWORD gs_code[] =
23675 #if 0
23676 struct vertex
23678 float4 position : POSITION;
23679 float4 color : COLOR;
23680 float4 color2 : COLOR2;
23683 [maxvertexcount(1)]
23684 void main(point vertex input[1], inout PointStream<vertex> output)
23686 output.Append(input[0]);
23688 #endif
23689 0x43425844, 0x218f7d27, 0x555fa7f1, 0x282c545f, 0x3989c843, 0x00000001, 0x000001c0, 0x00000003,
23690 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
23691 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
23692 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
23693 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
23694 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
23695 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
23696 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
23697 0x000000bc, 0x00020040, 0x0000002f, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x0400005f,
23698 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000002, 0x0100085d,
23699 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x03000065,
23700 0x001020f2, 0x00000002, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
23701 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001,
23702 0x06000036, 0x001020f2, 0x00000002, 0x00201e46, 0x00000000, 0x00000002, 0x01000013, 0x0100003e,
23704 static const DWORD ps_code[] =
23706 #if 0
23707 float4 main(float4 position : SV_Position,
23708 float2 texcoord : TEXCOORD) : SV_Target
23710 return float4(position.xy, texcoord);
23712 #endif
23713 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
23714 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
23715 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
23716 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
23717 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
23718 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
23719 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
23720 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
23721 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
23723 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
23725 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
23726 {"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
23727 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
23729 static const D3D11_INPUT_ELEMENT_DESC layout_desc2[] =
23731 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
23732 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
23733 {"COLOR", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
23735 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
23737 {0, "POSITION", 0, 0, 4, 0},
23738 {0, "COLOR", 0, 0, 3, 0},
23739 {0, "COLOR", 2, 0, 2, 0},
23741 static const D3D11_SO_DECLARATION_ENTRY so_declaration2[] =
23743 {0, "POSITION", 0, 0, 1, 0},
23744 {0, "POSITION", 0, 1, 1, 0},
23745 {0, "POSITION", 0, 2, 1, 0},
23746 {0, "POSITION", 0, 3, 1, 0},
23747 {0, "COLOR", 0, 0, 1, 0},
23748 {0, "COLOR", 0, 1, 1, 0},
23749 {0, "COLOR", 0, 2, 1, 0},
23750 {0, "COLOR", 2, 0, 1, 0},
23751 {0, "COLOR", 2, 1, 1, 0},
23753 static const D3D11_SO_DECLARATION_ENTRY so_declaration3[] =
23755 {0, "COLOR", 0, 2, 2, 0},
23756 {0, "COLOR", 2, 3, 1, 0},
23758 static const struct
23760 struct vec4 position;
23761 struct vec3 color;
23762 struct vec2 color2;
23764 vb_data[] =
23766 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.5f, 1.0f}},
23767 {{-1.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
23768 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f}, {0.5f, 0.4f}},
23769 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.1f, 0.6f}},
23771 static const struct
23773 struct vec4 position;
23774 struct vec4 color;
23775 struct vec4 color2;
23777 vb_data2[] =
23779 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
23780 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
23781 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
23782 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
23784 static const unsigned int vb_stride[] = {sizeof(*vb_data), sizeof(*vb_data2)};
23785 static const float expected_data[] =
23787 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f,
23788 -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
23789 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, 0.4f,
23790 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.1f, 0.6f,
23792 static const float expected_data2[] =
23794 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
23795 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
23796 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
23797 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
23799 static const float expected_data3[] =
23801 3.0f, 4.0f, 8.0f, 1.2f, 1.3f, 1.7f, 2.0f, 2.1f, 2.5f, 2.7f, 2.8f, 3.2f,
23803 static const struct
23805 BOOL with_ps;
23806 unsigned int vb_idx;
23807 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
23808 unsigned int so_entry_count;
23809 const float *expected_data;
23810 unsigned int expected_data_size;
23812 tests[] =
23814 {TRUE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
23815 {TRUE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
23816 {TRUE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
23817 {TRUE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
23818 {TRUE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
23820 {FALSE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
23821 {FALSE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
23822 {FALSE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
23823 {FALSE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
23824 {FALSE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
23827 if (!init_test_context(&test_context, &feature_level))
23828 return;
23830 device = test_context.device;
23831 context = test_context.immediate_context;
23833 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
23834 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data2), vb_data2);
23836 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
23837 vs_code, sizeof(vs_code), &input_layout[0]);
23838 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
23839 hr = ID3D11Device_CreateInputLayout(device, layout_desc2, ARRAY_SIZE(layout_desc2),
23840 vs_code, sizeof(vs_code), &input_layout[1]);
23841 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
23843 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
23844 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
23845 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
23846 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
23848 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
23849 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
23851 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
23853 gs = NULL;
23854 current_so_declaration = NULL;
23855 for (i = 0; i < ARRAY_SIZE(tests); ++i)
23857 ID3D11DeviceContext_PSSetShader(context, tests[i].with_ps ? ps : NULL, NULL, 0);
23859 if (current_so_declaration != tests[i].so_declaration)
23861 if (gs)
23862 ID3D11GeometryShader_Release(gs);
23864 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
23865 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
23866 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
23867 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
23868 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
23869 current_so_declaration = tests[i].so_declaration;
23872 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].vb_idx]);
23873 stride = vb_stride[tests[i].vb_idx];
23874 offset = 0;
23875 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[tests[i].vb_idx], &stride, &offset);
23877 offset = 0;
23878 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
23880 ID3D11DeviceContext_Draw(context, 4, 0);
23882 get_buffer_readback(so_buffer, &rb);
23883 result = rb.map_desc.pData;
23884 for (j = 0; j < tests[i].expected_data_size; ++j)
23886 float expected_value = tests[i].expected_data[j];
23887 ok(compare_float(result[j], expected_value, 2),
23888 "Test %u: Got %.8e, expected %.8e at %u.\n",
23889 i, result[j], expected_value, j);
23891 release_resource_readback(&rb);
23894 for (i = 0; i < ARRAY_SIZE(vb); ++i)
23895 ID3D11Buffer_Release(vb[i]);
23896 ID3D11Buffer_Release(so_buffer);
23897 ID3D11VertexShader_Release(vs);
23898 ID3D11GeometryShader_Release(gs);
23899 ID3D11PixelShader_Release(ps);
23900 for (i = 0; i < ARRAY_SIZE(input_layout); ++i)
23901 ID3D11InputLayout_Release(input_layout[i]);
23902 release_test_context(&test_context);
23905 static void test_stream_output_vs(void)
23907 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
23908 struct d3d11_test_context test_context;
23909 ID3D11InputLayout *input_layout;
23910 ID3D11Buffer *vb, *so_buffer;
23911 ID3D11DeviceContext *context;
23912 struct resource_readback rb;
23913 ID3D11GeometryShader *gs;
23914 ID3D11VertexShader *vs;
23915 ID3D11Device *device;
23916 const float *result;
23917 unsigned int offset;
23918 unsigned int i, j;
23919 HRESULT hr;
23921 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
23922 static const DWORD vs_code[] =
23924 #if 0
23925 struct vertex
23927 float4 position : POSITION;
23928 float4 color0 : COLOR0;
23929 float4 color1 : COLOR1;
23932 vertex main(in vertex i)
23934 return i;
23936 #endif
23937 0x43425844, 0xa67e993e, 0x1632c139, 0x02a7725f, 0xfb0221cd, 0x00000001, 0x00000194, 0x00000003,
23938 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
23939 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
23940 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
23941 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
23942 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
23943 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000001, 0x00000000,
23944 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
23945 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
23946 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
23947 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
23948 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
23949 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
23951 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
23953 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
23954 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
23955 {"COLOR", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
23957 static const D3D11_SO_DECLARATION_ENTRY all_so_decl[] =
23959 {0, "POSITION", 0, 0, 4, 0},
23960 {0, "COLOR", 0, 0, 3, 0},
23961 {0, "COLOR", 1, 0, 2, 0},
23963 static const D3D11_SO_DECLARATION_ENTRY position_so_decl[] =
23965 {0, "POSITION", 0, 0, 4, 0},
23967 static const D3D11_SO_DECLARATION_ENTRY position2_so_decl[] =
23969 {0, "POSITION", 0, 0, 2, 0},
23971 static const struct
23973 struct vec4 position;
23974 struct vec4 color0;
23975 struct vec4 color1;
23977 vb_data[] =
23979 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
23980 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
23981 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
23982 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
23984 static const unsigned int vb_stride[] = {sizeof(*vb_data)};
23985 static const float expected_data[] =
23987 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
23988 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
23989 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
23990 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
23992 static const float expected_data2[] =
23994 -1.0f, -1.0f, 0.0f, 1.0f,
23995 -1.0f, 1.0f, 0.0f, 1.0f,
23996 1.0f, -1.0f, 0.0f, 1.0f,
23997 1.0f, 1.0f, 0.0f, 1.0f,
23999 static const float expected_data3[] =
24001 -1.0f, -1.0f,
24002 -1.0f, 1.0f,
24003 1.0f, -1.0f,
24004 1.0f, 1.0f,
24006 static const struct
24008 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
24009 unsigned int so_entry_count;
24010 const float *expected_data;
24011 unsigned int expected_data_size;
24013 tests[] =
24015 {all_so_decl, ARRAY_SIZE(all_so_decl), expected_data, ARRAY_SIZE(expected_data)},
24016 {position_so_decl, ARRAY_SIZE(position_so_decl), expected_data2, ARRAY_SIZE(expected_data2)},
24017 {position2_so_decl, ARRAY_SIZE(position2_so_decl), expected_data3, ARRAY_SIZE(expected_data3)},
24020 if (!init_test_context(&test_context, &feature_level))
24021 return;
24023 device = test_context.device;
24024 context = test_context.immediate_context;
24026 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
24028 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
24029 vs_code, sizeof(vs_code), &input_layout);
24030 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
24032 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
24033 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
24035 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
24037 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
24038 offset = 0;
24039 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, vb_stride, &offset);
24040 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
24042 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
24044 gs = NULL;
24045 current_so_declaration = NULL;
24046 for (i = 0; i < ARRAY_SIZE(tests); ++i)
24048 if (current_so_declaration != tests[i].so_declaration)
24050 if (gs)
24051 ID3D11GeometryShader_Release(gs);
24053 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
24054 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
24055 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
24056 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
24057 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
24058 current_so_declaration = tests[i].so_declaration;
24061 offset = 0;
24062 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
24064 ID3D11DeviceContext_Draw(context, 4, 0);
24066 get_buffer_readback(so_buffer, &rb);
24067 result = rb.map_desc.pData;
24068 for (j = 0; j < tests[i].expected_data_size; ++j)
24070 float expected_value = tests[i].expected_data[j];
24071 ok(compare_float(result[j], expected_value, 2),
24072 "Test %u: Got %.8e, expected %.8e at %u.\n",
24073 i, result[j], expected_value, j);
24075 release_resource_readback(&rb);
24078 ID3D11Buffer_Release(vb);
24079 ID3D11Buffer_Release(so_buffer);
24080 ID3D11VertexShader_Release(vs);
24081 ID3D11GeometryShader_Release(gs);
24082 ID3D11InputLayout_Release(input_layout);
24083 release_test_context(&test_context);
24086 static void test_gather(void)
24088 struct
24090 int width, height;
24091 int offset_x, offset_y;
24092 } constant;
24093 struct d3d11_test_context test_context;
24094 D3D11_TEXTURE2D_DESC texture_desc;
24095 ID3D11ShaderResourceView *srv;
24096 ID3D11Texture2D *texture, *rt;
24097 ID3D11DeviceContext *context;
24098 ID3D11RenderTargetView *rtv;
24099 struct resource_readback rb;
24100 ID3D11PixelShader *ps;
24101 ID3D11Device *device;
24102 unsigned int x, y;
24103 ID3D11Buffer *cb;
24104 HRESULT hr;
24106 static const DWORD gather4_code[] =
24108 #if 0
24109 SamplerState s;
24110 Texture2D<float4> t;
24112 int2 size;
24114 float4 main(float4 position : SV_Position) : SV_Target
24116 return t.Gather(s, position.xy / size);
24118 #endif
24119 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
24120 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
24121 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
24122 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
24123 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
24124 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
24125 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
24126 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
24127 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
24128 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
24129 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
24131 static const DWORD gather4_offset_code[] =
24133 #if 0
24134 SamplerState s;
24135 Texture2D<float4> t;
24137 int2 size;
24139 float4 main(float4 position : SV_Position) : SV_Target
24141 return t.Gather(s, position.xy / size, int2(1, 1));
24143 #endif
24144 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
24145 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
24146 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
24147 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
24148 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
24149 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
24150 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
24151 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
24152 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
24153 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
24154 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
24156 static const DWORD gather4_green_code[] =
24158 #if 0
24159 SamplerState s;
24160 Texture2D<float4> t;
24162 int2 size;
24164 float4 main(float4 position : SV_Position) : SV_Target
24166 return t.GatherGreen(s, position.xy / size);
24168 #endif
24169 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
24170 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
24171 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
24172 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
24173 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
24174 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
24175 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
24176 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
24177 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
24178 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
24179 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
24181 static const DWORD gather4_po_code[] =
24183 #if 0
24184 SamplerState s;
24185 Texture2D<float4> t;
24187 int2 size;
24188 int2 offset;
24190 float4 main(float4 position : SV_Position) : SV_Target
24192 return t.Gather(s, position.xy / size, offset);
24194 #endif
24195 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
24196 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
24197 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
24198 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
24199 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
24200 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
24201 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
24202 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
24203 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
24204 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
24205 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
24206 0x00000000, 0x0100003e,
24208 static const struct vec4 texture_data[] =
24210 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
24211 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
24212 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
24213 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
24215 static const struct vec4 expected_gather4[] =
24217 {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},
24218 {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},
24219 {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},
24220 {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},
24222 static const struct vec4 expected_gather4_offset[] =
24224 {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},
24225 {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},
24226 {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},
24227 {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},
24229 static const struct vec4 expected_gather4_green[] =
24231 {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},
24232 {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},
24233 {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},
24234 {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},
24236 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
24237 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
24239 if (!init_test_context(&test_context, NULL))
24240 return;
24242 device = test_context.device;
24243 context = test_context.immediate_context;
24245 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
24247 skip("Shader model 4.1 required for gather4 instruction.\n");
24248 release_test_context(&test_context);
24249 return;
24252 texture_desc.Width = 4;
24253 texture_desc.Height = 4;
24254 texture_desc.MipLevels = 1;
24255 texture_desc.ArraySize = 1;
24256 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
24257 texture_desc.SampleDesc.Count = 1;
24258 texture_desc.SampleDesc.Quality = 0;
24259 texture_desc.Usage = D3D11_USAGE_DEFAULT;
24260 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
24261 texture_desc.CPUAccessFlags = 0;
24262 texture_desc.MiscFlags = 0;
24263 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
24264 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
24265 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
24266 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
24267 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
24269 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
24270 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
24271 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
24272 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
24273 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
24274 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
24276 constant.width = texture_desc.Width;
24277 constant.height = texture_desc.Height;
24278 constant.offset_x = 1;
24279 constant.offset_y = 1;
24280 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
24281 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
24283 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
24284 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
24285 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
24287 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
24288 draw_quad(&test_context);
24289 get_texture_readback(rt, 0, &rb);
24290 for (y = 0; y < texture_desc.Height; ++y)
24292 for (x = 0; x < texture_desc.Width; ++x)
24294 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
24295 const struct vec4 *got = get_readback_vec4(&rb, x, y);
24296 ok(compare_vec4(got, expected, 0),
24297 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
24298 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
24301 release_resource_readback(&rb);
24303 ID3D11PixelShader_Release(ps);
24304 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
24305 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
24306 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
24308 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
24309 draw_quad(&test_context);
24310 get_texture_readback(rt, 0, &rb);
24311 for (y = 0; y < texture_desc.Height; ++y)
24313 for (x = 0; x < texture_desc.Width; ++x)
24315 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
24316 const struct vec4 *got = get_readback_vec4(&rb, x, y);
24317 ok(compare_vec4(got, expected, 0),
24318 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
24319 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
24322 release_resource_readback(&rb);
24324 ID3D11PixelShader_Release(ps);
24326 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
24328 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
24329 goto done;
24332 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
24333 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
24334 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
24336 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
24337 draw_quad(&test_context);
24338 get_texture_readback(rt, 0, &rb);
24339 for (y = 0; y < texture_desc.Height; ++y)
24341 for (x = 0; x < texture_desc.Width; ++x)
24343 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
24344 const struct vec4 *got = get_readback_vec4(&rb, x, y);
24345 ok(compare_vec4(got, expected, 0),
24346 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
24347 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
24350 release_resource_readback(&rb);
24352 ID3D11PixelShader_Release(ps);
24353 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
24354 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
24355 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
24357 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
24358 draw_quad(&test_context);
24359 get_texture_readback(rt, 0, &rb);
24360 for (y = 0; y < texture_desc.Height; ++y)
24362 for (x = 0; x < texture_desc.Width; ++x)
24364 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
24365 const struct vec4 *got = get_readback_vec4(&rb, x, y);
24366 ok(compare_vec4(got, expected, 0),
24367 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
24368 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
24371 release_resource_readback(&rb);
24373 constant.offset_x = 0;
24374 constant.offset_y = 0;
24375 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
24376 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
24377 draw_quad(&test_context);
24378 get_texture_readback(rt, 0, &rb);
24379 for (y = 0; y < texture_desc.Height; ++y)
24381 for (x = 0; x < texture_desc.Width; ++x)
24383 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
24384 const struct vec4 *got = get_readback_vec4(&rb, x, y);
24385 ok(compare_vec4(got, expected, 0),
24386 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
24387 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
24390 release_resource_readback(&rb);
24392 ID3D11PixelShader_Release(ps);
24394 done:
24395 ID3D11Buffer_Release(cb);
24396 ID3D11Texture2D_Release(rt);
24397 ID3D11Texture2D_Release(texture);
24398 ID3D11RenderTargetView_Release(rtv);
24399 ID3D11ShaderResourceView_Release(srv);
24400 release_test_context(&test_context);
24403 static void test_gather_c(void)
24405 struct
24407 int width, height;
24408 int offset_x, offset_y;
24409 float compare_value;
24410 int padding[3];
24411 } constant;
24412 struct d3d11_test_context test_context;
24413 D3D11_TEXTURE2D_DESC texture_desc;
24414 D3D11_SAMPLER_DESC sampler_desc;
24415 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
24416 ID3D11ShaderResourceView *srv;
24417 ID3D11Texture2D *texture, *rt;
24418 ID3D11DeviceContext *context;
24419 ID3D11SamplerState *sampler;
24420 ID3D11RenderTargetView *rtv;
24421 struct resource_readback rb;
24422 ID3D11PixelShader *ps;
24423 ID3D11Device *device;
24424 unsigned int x, y;
24425 ID3D11Buffer *cb;
24426 HRESULT hr;
24428 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24429 static const DWORD gather4_c_code[] =
24431 #if 0
24432 SamplerComparisonState s;
24433 Texture2D<float4> t;
24435 int2 size;
24436 int2 offset;
24437 float compare;
24439 float4 main(float4 position : SV_Position) : SV_Target
24441 return t.GatherCmp(s, position.xy / size, compare);
24443 #endif
24444 0x43425844, 0xd3d04479, 0x901e9208, 0x7074fd0c, 0xbcadb2da, 0x00000001, 0x00000168, 0x00000003,
24445 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
24446 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
24447 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
24448 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
24449 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
24450 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
24451 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
24452 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
24453 0x00000000, 0x00100046, 0x00000000, 0x8e00007e, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
24454 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0020800a, 0x00000000,
24455 0x00000001, 0x0100003e,
24457 static const DWORD gather4_po_c_code[] =
24459 #if 0
24460 SamplerComparisonState s;
24461 Texture2D<float4> t;
24463 int2 size;
24464 int2 offset;
24465 float compare;
24467 float4 main(float4 position : SV_Position) : SV_Target
24469 return t.GatherCmp(s, position.xy / size, compare, offset);
24471 #endif
24472 0x43425844, 0x501de13e, 0x472d2d20, 0x6df0fee4, 0xef27d9e6, 0x00000001, 0x00000174, 0x00000003,
24473 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
24474 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
24475 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
24476 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d8, 0x00000050,
24477 0x00000036, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
24478 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
24479 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
24480 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
24481 0x00000000, 0x00100046, 0x00000000, 0x91000080, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
24482 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
24483 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
24485 static const float texture_data[] =
24487 0.00f, 0.10f, 0.20f, 0.30f,
24488 0.40f, 0.50f, 0.60f, 0.70f,
24489 0.80f, 0.90f, 0.05f, 0.15f,
24490 0.25f, 0.35f, 0.45f, 0.55f,
24492 static const struct vec4 expected_gather4_c[] =
24494 {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},
24495 {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},
24496 {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},
24497 {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},
24499 static const struct vec4 expected_gather4_po_c[] =
24501 {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},
24502 {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},
24503 {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},
24504 {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},
24506 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
24507 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
24509 if (!init_test_context(&test_context, &feature_level))
24510 return;
24512 device = test_context.device;
24513 context = test_context.immediate_context;
24515 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
24516 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
24517 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
24518 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
24519 sampler_desc.MipLODBias = 0.0f;
24520 sampler_desc.MaxAnisotropy = 0;
24521 sampler_desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
24522 sampler_desc.BorderColor[0] = 0.0f;
24523 sampler_desc.BorderColor[1] = 0.0f;
24524 sampler_desc.BorderColor[2] = 0.0f;
24525 sampler_desc.BorderColor[3] = 0.0f;
24526 sampler_desc.MinLOD = 0.0f;
24527 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
24529 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
24530 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
24531 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
24533 texture_desc.Width = 4;
24534 texture_desc.Height = 4;
24535 texture_desc.MipLevels = 1;
24536 texture_desc.ArraySize = 1;
24537 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
24538 texture_desc.SampleDesc.Count = 1;
24539 texture_desc.SampleDesc.Quality = 0;
24540 texture_desc.Usage = D3D11_USAGE_DEFAULT;
24541 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
24542 texture_desc.CPUAccessFlags = 0;
24543 texture_desc.MiscFlags = 0;
24544 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
24545 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
24546 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
24547 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
24548 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
24550 constant.width = texture_desc.Width;
24551 constant.height = texture_desc.Height;
24552 constant.offset_x = 1;
24553 constant.offset_y = 1;
24554 constant.compare_value = 0.5f;
24555 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
24556 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
24558 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
24559 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
24560 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
24561 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
24563 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
24564 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
24565 U(srv_desc).Texture2D.MostDetailedMip = 0;
24566 U(srv_desc).Texture2D.MipLevels = 1;
24567 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
24568 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
24569 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
24571 hr = ID3D11Device_CreatePixelShader(device, gather4_c_code, sizeof(gather4_c_code), NULL, &ps);
24572 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
24573 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
24575 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
24576 draw_quad(&test_context);
24577 get_texture_readback(rt, 0, &rb);
24578 for (y = 0; y < texture_desc.Height; ++y)
24580 for (x = 0; x < texture_desc.Width; ++x)
24582 const struct vec4 *expected = &expected_gather4_c[y * texture_desc.Width + x];
24583 const struct vec4 *got = get_readback_vec4(&rb, x, y);
24584 ok(compare_vec4(got, expected, 0),
24585 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
24586 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
24589 release_resource_readback(&rb);
24590 ID3D11PixelShader_Release(ps);
24592 hr = ID3D11Device_CreatePixelShader(device, gather4_po_c_code, sizeof(gather4_po_c_code), NULL, &ps);
24593 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
24594 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
24596 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
24597 draw_quad(&test_context);
24598 get_texture_readback(rt, 0, &rb);
24599 for (y = 0; y < texture_desc.Height; ++y)
24601 for (x = 0; x < texture_desc.Width; ++x)
24603 const struct vec4 *expected = &expected_gather4_po_c[y * texture_desc.Width + x];
24604 const struct vec4 *got = get_readback_vec4(&rb, x, y);
24605 ok(compare_vec4(got, expected, 0),
24606 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
24607 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
24610 release_resource_readback(&rb);
24611 ID3D11PixelShader_Release(ps);
24613 ID3D11ShaderResourceView_Release(srv);
24614 ID3D11Texture2D_Release(texture);
24616 ID3D11Buffer_Release(cb);
24617 ID3D11Texture2D_Release(rt);
24618 ID3D11RenderTargetView_Release(rtv);
24619 ID3D11SamplerState_Release(sampler);
24620 release_test_context(&test_context);
24623 static void test_depth_bias(void)
24625 struct vec3 vertices[] =
24627 {-1.0f, -1.0f, 0.5f},
24628 {-1.0f, 1.0f, 0.5f},
24629 { 1.0f, -1.0f, 0.5f},
24630 { 1.0f, 1.0f, 0.5f},
24632 struct d3d11_test_context test_context;
24633 D3D11_RASTERIZER_DESC rasterizer_desc;
24634 struct swapchain_desc swapchain_desc;
24635 D3D11_TEXTURE2D_DESC texture_desc;
24636 double m, r, bias, depth, data;
24637 ID3D11DeviceContext *context;
24638 struct resource_readback rb;
24639 ID3D11DepthStencilView *dsv;
24640 unsigned int expected_value;
24641 ID3D11RasterizerState *rs;
24642 ID3D11Texture2D *texture;
24643 unsigned int format_idx;
24644 unsigned int x, y, i, j;
24645 unsigned int shift = 0;
24646 ID3D11Device *device;
24647 float *depth_values;
24648 DXGI_FORMAT format;
24649 const UINT32 *u32;
24650 const UINT16 *u16;
24651 UINT32 u32_value;
24652 HRESULT hr;
24654 static const struct
24656 float z;
24657 float exponent;
24659 quads[] =
24661 {0.125f, -3.0f},
24662 {0.250f, -2.0f},
24663 {0.500f, -1.0f},
24664 {1.000f, 0.0f},
24666 static const int bias_tests[] =
24668 -10000, -1000, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
24669 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100, 200, 500, 1000, 10000,
24671 static const float quad_slopes[] =
24673 0.0f, 0.5f, 1.0f
24675 static const float slope_scaled_bias_tests[] =
24677 0.0f, 0.5f, 1.0f, 2.0f, 128.0f, 1000.0f, 10000.0f,
24679 static const DXGI_FORMAT formats[] =
24681 DXGI_FORMAT_D32_FLOAT,
24682 DXGI_FORMAT_D24_UNORM_S8_UINT,
24683 DXGI_FORMAT_D16_UNORM,
24686 swapchain_desc.windowed = TRUE;
24687 swapchain_desc.buffer_count = 1;
24688 swapchain_desc.width = 200;
24689 swapchain_desc.height = 200;
24690 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
24691 swapchain_desc.flags = 0;
24692 if (!init_test_context_ext(&test_context, NULL, &swapchain_desc))
24693 return;
24695 device = test_context.device;
24696 context = test_context.immediate_context;
24698 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
24699 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
24700 rasterizer_desc.CullMode = D3D11_CULL_NONE;
24701 rasterizer_desc.FrontCounterClockwise = FALSE;
24702 rasterizer_desc.DepthBias = 0;
24703 rasterizer_desc.DepthBiasClamp = 0.0f;
24704 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
24705 rasterizer_desc.DepthClipEnable = TRUE;
24707 depth_values = heap_calloc(swapchain_desc.height, sizeof(*depth_values));
24708 ok(!!depth_values, "Failed to allocate memory.\n");
24710 for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx)
24712 format = formats[format_idx];
24714 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
24715 texture_desc.Format = format;
24716 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
24717 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
24718 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
24719 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
24720 ok(SUCCEEDED(hr), "Failed to create render depth stencil view, hr %#x.\n", hr);
24721 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
24722 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
24723 draw_quad(&test_context);
24724 switch (format)
24726 case DXGI_FORMAT_D32_FLOAT:
24727 check_texture_float(texture, 0.0f, 0);
24728 break;
24729 case DXGI_FORMAT_D24_UNORM_S8_UINT:
24730 /* FIXME: Depth/stencil byte order is reversed in wined3d. */
24731 shift = get_texture_color(texture, 0, 0) == 0xffffff ? 0 : 8;
24732 todo_wine
24733 check_texture_color(texture, 0xffffff, 1);
24734 break;
24735 case DXGI_FORMAT_D16_UNORM:
24736 get_texture_readback(texture, 0, &rb);
24737 for (y = 0; y < texture_desc.Height; ++y)
24739 for (x = 0; x < texture_desc.Width; ++x)
24741 u16 = get_readback_data(&rb, x, y, 0, sizeof(*u16));
24742 ok(*u16 == 0xffff, "Got unexpected value %#x.\n", *u16);
24745 release_resource_readback(&rb);
24746 break;
24747 default:
24748 trace("Unhandled format %#x.\n", format);
24749 break;
24752 /* DepthBias */
24753 for (i = 0; i < ARRAY_SIZE(quads); ++i)
24755 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
24756 vertices[j].z = quads[i].z;
24757 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
24758 0, NULL, vertices, 0, 0);
24760 for (j = 0; j < ARRAY_SIZE(bias_tests); ++j)
24762 rasterizer_desc.DepthBias = bias_tests[j];
24763 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
24764 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
24765 ID3D11DeviceContext_RSSetState(context, rs);
24766 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
24767 draw_quad(&test_context);
24768 switch (format)
24770 case DXGI_FORMAT_D32_FLOAT:
24771 bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f);
24772 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
24774 check_texture_float(texture, depth, 2);
24775 break;
24776 case DXGI_FORMAT_D24_UNORM_S8_UINT:
24777 r = 1.0f / 16777215.0f;
24778 bias = rasterizer_desc.DepthBias * r;
24779 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
24781 get_texture_readback(texture, 0, &rb);
24782 for (y = 0; y < texture_desc.Height; ++y)
24784 expected_value = depth * 16777215.0f + 0.5f;
24785 for (x = 0; x < texture_desc.Width; ++x)
24787 u32 = get_readback_data(&rb, x, y, 0, sizeof(*u32));
24788 u32_value = *u32 >> shift;
24789 ok(abs(u32_value - expected_value) <= 1,
24790 "Got value %#x (%.8e), expected %#x (%.8e).\n",
24791 u32_value, u32_value / 16777215.0f,
24792 expected_value, expected_value / 16777215.0f);
24795 release_resource_readback(&rb);
24796 break;
24797 case DXGI_FORMAT_D16_UNORM:
24798 r = 1.0f / 65535.0f;
24799 bias = rasterizer_desc.DepthBias * r;
24800 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
24802 get_texture_readback(texture, 0, &rb);
24803 for (y = 0; y < texture_desc.Height; ++y)
24805 expected_value = depth * 65535.0f + 0.5f;
24806 for (x = 0; x < texture_desc.Width; ++x)
24808 u16 = get_readback_data(&rb, x, y, 0, sizeof(*u16));
24809 ok(abs(*u16 - expected_value) <= 1,
24810 "Got value %#x (%.8e), expected %#x (%.8e).\n",
24811 *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f);
24814 release_resource_readback(&rb);
24815 break;
24816 default:
24817 break;
24819 ID3D11RasterizerState_Release(rs);
24823 /* SlopeScaledDepthBias */
24824 rasterizer_desc.DepthBias = 0;
24825 for (i = 0; i < ARRAY_SIZE(quad_slopes); ++i)
24827 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
24828 vertices[j].z = j == 1 || j == 3 ? 0.0f : quad_slopes[i];
24829 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
24830 0, NULL, vertices, 0, 0);
24832 ID3D11DeviceContext_RSSetState(context, NULL);
24833 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
24834 draw_quad(&test_context);
24835 get_texture_readback(texture, 0, &rb);
24836 for (y = 0; y < texture_desc.Height; ++y)
24838 switch (format)
24840 case DXGI_FORMAT_D32_FLOAT:
24841 depth_values[y] = get_readback_float(&rb, 0, y);
24842 break;
24843 case DXGI_FORMAT_D24_UNORM_S8_UINT:
24844 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
24845 u32_value = *u32 >> shift;
24846 depth_values[y] = u32_value / 16777215.0f;
24847 break;
24848 case DXGI_FORMAT_D16_UNORM:
24849 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
24850 depth_values[y] = *u16 / 65535.0f;
24851 break;
24852 default:
24853 break;
24856 release_resource_readback(&rb);
24858 for (j = 0; j < ARRAY_SIZE(slope_scaled_bias_tests); ++j)
24860 rasterizer_desc.SlopeScaledDepthBias = slope_scaled_bias_tests[j];
24861 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
24862 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
24863 ID3D11DeviceContext_RSSetState(context, rs);
24864 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
24865 draw_quad(&test_context);
24867 m = quad_slopes[i] / texture_desc.Height;
24868 bias = rasterizer_desc.SlopeScaledDepthBias * m;
24869 get_texture_readback(texture, 0, &rb);
24870 for (y = 0; y < texture_desc.Height; ++y)
24872 depth = min(max(0.0f, depth_values[y] + bias), 1.0f);
24873 switch (format)
24875 case DXGI_FORMAT_D32_FLOAT:
24876 data = get_readback_float(&rb, 0, y);
24877 ok(compare_float(data, depth, 64),
24878 "Got depth %.8e, expected %.8e.\n", data, depth);
24879 break;
24880 case DXGI_FORMAT_D24_UNORM_S8_UINT:
24881 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
24882 u32_value = *u32 >> shift;
24883 expected_value = depth * 16777215.0f + 0.5f;
24884 ok(abs(u32_value - expected_value) <= 3,
24885 "Got value %#x (%.8e), expected %#x (%.8e).\n",
24886 u32_value, u32_value / 16777215.0f,
24887 expected_value, expected_value / 16777215.0f);
24888 break;
24889 case DXGI_FORMAT_D16_UNORM:
24890 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
24891 expected_value = depth * 65535.0f + 0.5f;
24892 ok(abs(*u16 - expected_value) <= 1,
24893 "Got value %#x (%.8e), expected %#x (%.8e).\n",
24894 *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f);
24895 break;
24896 default:
24897 break;
24900 release_resource_readback(&rb);
24901 ID3D11RasterizerState_Release(rs);
24905 ID3D11Texture2D_Release(texture);
24906 ID3D11DepthStencilView_Release(dsv);
24909 heap_free(depth_values);
24910 release_test_context(&test_context);
24913 static void test_fractional_viewports(void)
24915 struct d3d11_test_context test_context;
24916 D3D11_TEXTURE2D_DESC texture_desc;
24917 ID3D11InputLayout *input_layout;
24918 ID3D11DeviceContext *context;
24919 struct resource_readback rb;
24920 ID3D11RenderTargetView *rtv;
24921 ID3D11VertexShader *vs;
24922 ID3D11PixelShader *ps;
24923 unsigned int i, x, y;
24924 ID3D11Device *device;
24925 ID3D11Texture2D *rt;
24926 UINT offset, stride;
24927 ID3D11Buffer *vb;
24928 HRESULT hr;
24930 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24931 static const DWORD vs_code[] =
24933 #if 0
24934 void main(in float4 in_position : POSITION,
24935 in float2 in_texcoord : TEXCOORD,
24936 out float4 position : SV_Position,
24937 out float2 texcoord : TEXCOORD)
24939 position = in_position;
24940 texcoord = in_texcoord;
24942 #endif
24943 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
24944 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
24945 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
24946 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
24947 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
24948 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
24949 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
24950 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
24951 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
24952 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
24953 0x00000001, 0x0100003e,
24955 static const DWORD ps_code[] =
24957 #if 0
24958 float4 main(float4 position : SV_Position,
24959 float2 texcoord : TEXCOORD) : SV_Target
24961 return float4(position.xy, texcoord);
24963 #endif
24964 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
24965 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
24966 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
24967 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
24968 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
24969 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
24970 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
24971 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
24972 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
24974 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
24976 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
24977 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
24979 static const struct
24981 struct vec2 position;
24982 struct vec2 texcoord;
24984 quad[] =
24986 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
24987 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
24988 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
24989 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
24991 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
24992 static const float viewport_offsets[] =
24994 0.0f, 1.0f / 2.0f, 1.0f / 4.0f, 1.0f / 8.0f, 1.0f / 16.0f, 1.0f / 32.0f,
24995 1.0f / 64.0f, 1.0f / 128.0f, 1.0f / 256.0f, 63.0f / 128.0f,
24998 if (!init_test_context(&test_context, &feature_level))
24999 return;
25000 device = test_context.device;
25001 context = test_context.immediate_context;
25003 texture_desc.Width = 4;
25004 texture_desc.Height = 4;
25005 texture_desc.MipLevels = 1;
25006 texture_desc.ArraySize = 1;
25007 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
25008 texture_desc.SampleDesc.Count = 1;
25009 texture_desc.SampleDesc.Quality = 0;
25010 texture_desc.Usage = D3D11_USAGE_DEFAULT;
25011 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
25012 texture_desc.CPUAccessFlags = 0;
25013 texture_desc.MiscFlags = 0;
25014 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
25015 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
25016 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
25017 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
25018 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
25020 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
25021 vs_code, sizeof(vs_code), &input_layout);
25022 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
25023 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
25025 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
25026 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
25027 stride = sizeof(*quad);
25028 offset = 0;
25029 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
25031 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
25032 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
25033 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
25035 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
25036 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25037 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25039 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
25041 set_viewport(context, viewport_offsets[i], viewport_offsets[i],
25042 texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
25043 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
25044 ID3D11DeviceContext_Draw(context, 4, 0);
25045 get_texture_readback(rt, 0, &rb);
25046 for (y = 0; y < texture_desc.Height; ++y)
25048 for (x = 0; x < texture_desc.Width; ++x)
25050 const struct vec4 *v = get_readback_vec4(&rb, x, y);
25051 struct vec4 expected = {x + 0.5f, y + 0.5f,
25052 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
25053 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
25054 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
25055 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
25056 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
25057 todo_wine
25058 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
25059 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
25060 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
25063 release_resource_readback(&rb);
25066 ID3D11InputLayout_Release(input_layout);
25067 ID3D11Buffer_Release(vb);
25068 ID3D11VertexShader_Release(vs);
25069 ID3D11PixelShader_Release(ps);
25070 ID3D11RenderTargetView_Release(rtv);
25071 ID3D11Texture2D_Release(rt);
25072 release_test_context(&test_context);
25075 static void test_negative_viewports(const D3D_FEATURE_LEVEL feature_level)
25077 struct d3d11_test_context test_context;
25078 ID3D11DeviceContext *context;
25079 BOOL quirk;
25080 RECT rect;
25082 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
25083 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
25085 if (!init_test_context(&test_context, &feature_level))
25086 return;
25087 context = test_context.immediate_context;
25089 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
25090 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
25091 draw_color_quad(&test_context, &green);
25092 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
25094 set_viewport(context, -0.0f, -0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
25095 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
25096 draw_color_quad(&test_context, &green);
25097 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
25099 /* For feature levels greater than or equal to 11_0, a negative top left
25100 * corner shifts the bottom right corner by a whole integer. It seems that
25101 * floor() is used to round viewport corners to integers.
25103 quirk = feature_level >= D3D_FEATURE_LEVEL_11_0;
25105 set_viewport(context, -0.4f, -0.4f, 640.0f, 480.0f, 0.0f, 1.0f);
25106 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
25107 draw_color_quad(&test_context, &green);
25108 SetRect(&rect, 0, 0, 639, 479);
25109 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
25110 SetRect(&rect, 639, 479, 640, 480);
25111 todo_wine_if(quirk)
25112 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
25114 set_viewport(context, -1.0f / 128.0f, -1.0 / 128.0f, 640.0f, 480.0f, 0.0f, 1.0f);
25115 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
25116 draw_color_quad(&test_context, &green);
25117 SetRect(&rect, 0, 0, 639, 479);
25118 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
25119 SetRect(&rect, 639, 479, 640, 480);
25120 todo_wine_if(quirk)
25121 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
25123 release_test_context(&test_context);
25126 static void test_early_depth_stencil(void)
25128 ID3D11DepthStencilState *depth_stencil_state;
25129 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
25130 ID3D11Texture2D *texture, *depth_texture;
25131 struct d3d11_test_context test_context;
25132 D3D11_TEXTURE2D_DESC texture_desc;
25133 ID3D11UnorderedAccessView *uav;
25134 ID3D11DeviceContext *context;
25135 ID3D11DepthStencilView *dsv;
25136 ID3D11PixelShader *ps;
25137 ID3D11Device *device;
25138 HRESULT hr;
25140 static const DWORD ps_code[] =
25142 #if 0
25143 RWTexture2D<int> u;
25145 [earlydepthstencil]
25146 float4 main() : SV_Target
25148 InterlockedAdd(u[uint2(0, 0)], 1);
25149 return float4(1.0f, 1.0f, 1.0f, 1.0f);
25151 #endif
25152 0x43425844, 0xda4325ad, 0xc01d3815, 0xfd610cc9, 0x8ed1e351, 0x00000001, 0x000000ec, 0x00000003,
25153 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
25154 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
25155 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000074, 0x00000050, 0x0000001d,
25156 0x0100286a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x03000065, 0x001020f2, 0x00000000,
25157 0x0a0000ad, 0x0011e000, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
25158 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
25159 0x3f800000, 0x3f800000, 0x0100003e,
25161 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25162 static const UINT values[4] = {0};
25164 if (!init_test_context(&test_context, &feature_level))
25165 return;
25167 device = test_context.device;
25168 context = test_context.immediate_context;
25170 depth_stencil_desc.DepthEnable = TRUE;
25171 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
25172 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
25173 depth_stencil_desc.StencilEnable = FALSE;
25174 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
25175 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
25177 texture_desc.Width = 1;
25178 texture_desc.Height = 1;
25179 texture_desc.MipLevels = 1;
25180 texture_desc.ArraySize = 1;
25181 texture_desc.Format = DXGI_FORMAT_R32_SINT;
25182 texture_desc.SampleDesc.Count = 1;
25183 texture_desc.SampleDesc.Quality = 0;
25184 texture_desc.Usage = D3D11_USAGE_DEFAULT;
25185 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
25186 texture_desc.CPUAccessFlags = 0;
25187 texture_desc.MiscFlags = 0;
25188 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
25189 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
25190 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
25191 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
25193 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
25194 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
25195 texture_desc.Usage = D3D11_USAGE_DEFAULT;
25196 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
25197 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
25198 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
25199 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
25200 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
25202 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
25203 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25204 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25206 set_viewport(context, 0.0f, 0.0f, 1.0f, 100.0f, 0.5f, 0.5f);
25207 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
25208 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
25209 1, &test_context.backbuffer_rtv, dsv, 1, 1, &uav, NULL);
25211 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
25213 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
25214 draw_quad(&test_context);
25215 check_texture_color(texture, 100, 1);
25216 draw_quad(&test_context);
25217 check_texture_color(texture, 200, 1);
25218 check_texture_float(depth_texture, 0.6f, 1);
25220 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.3f, 0);
25221 draw_quad(&test_context);
25222 draw_quad(&test_context);
25223 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.55f, 0);
25224 draw_quad(&test_context);
25225 check_texture_color(texture, 300, 1);
25227 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
25228 draw_quad(&test_context);
25229 check_texture_color(texture, 400, 1);
25230 check_texture_float(depth_texture, 0.5f, 1);
25232 ID3D11Texture2D_Release(depth_texture);
25233 ID3D11DepthStencilView_Release(dsv);
25234 ID3D11DepthStencilState_Release(depth_stencil_state);
25235 ID3D11PixelShader_Release(ps);
25236 ID3D11Texture2D_Release(texture);
25237 ID3D11UnorderedAccessView_Release(uav);
25238 release_test_context(&test_context);
25241 static void test_conservative_depth_output(void)
25243 struct shader
25245 const DWORD *code;
25246 size_t size;
25249 ID3D11DepthStencilState *depth_stencil_state;
25250 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
25251 struct d3d11_test_context test_context;
25252 const struct shader *current_shader;
25253 D3D11_TEXTURE2D_DESC texture_desc;
25254 ID3D11DeviceContext *context;
25255 ID3D11DepthStencilView *dsv;
25256 ID3D11Texture2D *texture;
25257 ID3D11PixelShader *ps;
25258 DWORD expected_color;
25259 float expected_depth;
25260 ID3D11Device *device;
25261 struct vec4 ps_depth;
25262 ID3D11Buffer *cb;
25263 unsigned int i;
25264 HRESULT hr;
25266 static const DWORD ps_depth_le_code[] =
25268 #if 0
25269 float depth;
25271 float4 main(out float out_depth : SV_DepthLessEqual) : SV_Target0
25273 out_depth = depth;
25274 return float4(0.0f, 1.0f, 0.f, 1.0f);
25276 #endif
25277 0x43425844, 0x045c8d00, 0xc49e2ebe, 0x76f6022a, 0xf6996ecc, 0x00000001, 0x00000108, 0x00000003,
25278 0x0000002c, 0x0000003c, 0x00000098, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
25279 0x00000054, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
25280 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
25281 0x65677261, 0x56530074, 0x7065445f, 0x654c6874, 0x71457373, 0x006c6175, 0x58454853, 0x00000068,
25282 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065,
25283 0x001020f2, 0x00000000, 0x02000065, 0x00027001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
25284 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00027001, 0x0020800a, 0x00000000,
25285 0x00000000, 0x0100003e,
25287 static const struct shader ps_depth_le = {ps_depth_le_code, sizeof(ps_depth_le_code)};
25288 static const DWORD ps_depth_ge_code[] =
25290 #if 0
25291 float depth;
25293 float4 main(out float out_depth : SV_DepthGreaterEqual) : SV_Target0
25295 out_depth = depth;
25296 return float4(0.0f, 1.0f, 0.f, 1.0f);
25298 #endif
25299 0x43425844, 0xd17af83e, 0xa32c01cc, 0x0d8e9665, 0xe6dc17c2, 0x00000001, 0x0000010c, 0x00000003,
25300 0x0000002c, 0x0000003c, 0x0000009c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
25301 0x00000058, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
25302 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
25303 0x65677261, 0x56530074, 0x7065445f, 0x72476874, 0x65746165, 0x75714572, 0xab006c61, 0x58454853,
25304 0x00000068, 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
25305 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x00026001, 0x08000036, 0x001020f2, 0x00000000,
25306 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00026001, 0x0020800a,
25307 0x00000000, 0x00000000, 0x0100003e,
25309 static const struct shader ps_depth_ge = {ps_depth_ge_code, sizeof(ps_depth_ge_code)};
25310 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25311 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
25312 static const struct
25314 const struct shader *ps;
25315 float vs_depth;
25316 float ps_depth;
25317 BOOL passes_depth_test;
25319 tests[] =
25321 {&ps_depth_le, 0.7f, 0.7f, TRUE},
25322 {&ps_depth_le, 0.7f, 0.4f, FALSE},
25323 {&ps_depth_le, 0.4f, 0.4f, FALSE},
25324 /* {&ps_depth_le, 0.4f, 0.6f, FALSE}, undefined result */
25325 {&ps_depth_ge, 0.7f, 0.7f, TRUE},
25326 /* {&ps_depth_ge, 0.7f, 0.4f, TRUE}, undefined result */
25327 {&ps_depth_ge, 0.4f, 0.4f, FALSE},
25328 {&ps_depth_ge, 0.4f, 0.6f, TRUE},
25331 if (!init_test_context(&test_context, &feature_level))
25332 return;
25334 device = test_context.device;
25335 context = test_context.immediate_context;
25337 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_depth), NULL);
25339 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
25340 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
25341 texture_desc.Usage = D3D11_USAGE_DEFAULT;
25342 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
25343 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
25344 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
25345 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
25346 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
25348 depth_stencil_desc.DepthEnable = TRUE;
25349 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
25350 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_GREATER_EQUAL;
25351 depth_stencil_desc.StencilEnable = FALSE;
25352 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
25353 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
25355 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
25356 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
25357 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
25359 ps = NULL;
25360 current_shader = NULL;
25361 for (i = 0; i < ARRAY_SIZE(tests); ++i)
25363 if (current_shader != tests[i].ps)
25365 if (ps)
25366 ID3D11PixelShader_Release(ps);
25368 current_shader = tests[i].ps;
25369 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
25370 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25371 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25374 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
25375 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
25376 ps_depth.x = tests[i].ps_depth;
25377 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_depth, 0, 0);
25378 draw_quad_z(&test_context, tests[i].vs_depth);
25380 expected_color = tests[i].passes_depth_test ? 0xff00ff00 : 0xffffffff;
25381 expected_depth = tests[i].passes_depth_test ? max(tests[i].vs_depth, tests[i].ps_depth) : 0.5f;
25382 check_texture_color(test_context.backbuffer, expected_color, 0);
25383 check_texture_float(texture, expected_depth, 1);
25386 ID3D11Buffer_Release(cb);
25387 ID3D11PixelShader_Release(ps);
25388 ID3D11DepthStencilView_Release(dsv);
25389 ID3D11DepthStencilState_Release(depth_stencil_state);
25390 ID3D11Texture2D_Release(texture);
25391 release_test_context(&test_context);
25394 static void test_format_compatibility(void)
25396 ID3D11Texture2D *dst_texture, *src_texture;
25397 D3D11_SUBRESOURCE_DATA resource_data;
25398 D3D11_TEXTURE2D_DESC texture_desc;
25399 ID3D11DeviceContext *context;
25400 struct resource_readback rb;
25401 DWORD colour, expected;
25402 ID3D11Device *device;
25403 unsigned int i, j;
25404 ULONG refcount;
25405 HRESULT hr;
25407 static const struct
25409 DXGI_FORMAT src_format;
25410 DXGI_FORMAT dst_format;
25411 size_t texel_size;
25412 BOOL success;
25414 test_data[] =
25416 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
25417 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
25418 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
25419 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
25420 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
25421 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
25422 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
25423 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
25424 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
25425 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
25426 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
25427 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
25428 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
25429 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
25430 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
25431 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
25432 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
25433 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
25434 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
25436 static const DWORD initial_data[16] = {0};
25437 static const DWORD bitmap_data[] =
25439 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
25440 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
25441 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
25442 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
25445 if (!(device = create_device(NULL)))
25447 skip("Failed to create device.\n");
25448 return;
25450 ID3D11Device_GetImmediateContext(device, &context);
25452 texture_desc.Height = 4;
25453 texture_desc.MipLevels = 1;
25454 texture_desc.ArraySize = 1;
25455 texture_desc.SampleDesc.Count = 1;
25456 texture_desc.SampleDesc.Quality = 0;
25457 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
25458 texture_desc.CPUAccessFlags = 0;
25459 texture_desc.MiscFlags = 0;
25461 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
25463 unsigned int x, y, texel_dwords;
25464 D3D11_BOX box;
25466 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
25467 texture_desc.Format = test_data[i].src_format;
25468 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
25470 resource_data.pSysMem = bitmap_data;
25471 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
25472 resource_data.SysMemSlicePitch = 0;
25474 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
25475 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
25477 texture_desc.Format = test_data[i].dst_format;
25478 texture_desc.Usage = D3D11_USAGE_DEFAULT;
25480 resource_data.pSysMem = initial_data;
25482 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
25483 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
25485 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
25486 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0, 1, 1, 0,
25487 (ID3D11Resource *)src_texture, 0, &box);
25489 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
25490 get_texture_readback(dst_texture, 0, &rb);
25491 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
25493 x = j % 4;
25494 y = j / 4;
25495 colour = get_readback_color(&rb, x, y, 0);
25496 expected = test_data[i].success && x >= texel_dwords && y
25497 ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
25498 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
25499 i, colour, x, y, expected);
25501 release_resource_readback(&rb);
25503 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
25505 get_texture_readback(dst_texture, 0, &rb);
25506 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
25508 x = j % 4;
25509 y = j / 4;
25510 colour = get_readback_color(&rb, x, y, 0);
25511 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
25512 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
25513 i, colour, x, y, expected);
25515 release_resource_readback(&rb);
25517 ID3D11Texture2D_Release(dst_texture);
25518 ID3D11Texture2D_Release(src_texture);
25521 ID3D11DeviceContext_Release(context);
25522 refcount = ID3D11Device_Release(device);
25523 ok(!refcount, "Device has %u references left.\n", refcount);
25526 static void check_clip_distance(struct d3d11_test_context *test_context, ID3D11Buffer *vb)
25528 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
25529 struct vertex
25531 float clip_distance0;
25532 float clip_distance1;
25535 ID3D11DeviceContext *context = test_context->immediate_context;
25536 struct resource_readback rb;
25537 struct vertex vertices[4];
25538 unsigned int i;
25539 RECT rect;
25541 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
25542 vertices[i].clip_distance0 = 1.0f;
25543 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
25544 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
25545 ID3D11DeviceContext_Draw(context, 4, 0);
25546 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
25548 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
25549 vertices[i].clip_distance0 = 0.0f;
25550 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
25551 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
25552 ID3D11DeviceContext_Draw(context, 4, 0);
25553 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
25555 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
25556 vertices[i].clip_distance0 = -1.0f;
25557 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
25558 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
25559 ID3D11DeviceContext_Draw(context, 4, 0);
25560 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
25562 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
25563 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
25564 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
25565 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
25566 ID3D11DeviceContext_Draw(context, 4, 0);
25567 get_texture_readback(test_context->backbuffer, 0, &rb);
25568 SetRect(&rect, 0, 0, 320, 480);
25569 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
25570 SetRect(&rect, 320, 0, 320, 480);
25571 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
25572 release_resource_readback(&rb);
25574 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
25575 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
25576 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
25577 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
25578 ID3D11DeviceContext_Draw(context, 4, 0);
25579 get_texture_readback(test_context->backbuffer, 0, &rb);
25580 SetRect(&rect, 0, 0, 640, 240);
25581 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
25582 SetRect(&rect, 0, 240, 640, 240);
25583 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
25584 release_resource_readback(&rb);
25587 static void test_clip_distance(void)
25589 struct d3d11_test_context test_context;
25590 ID3D11Buffer *vs_cb, *tess_cb, *gs_cb;
25591 D3D_FEATURE_LEVEL feature_level;
25592 ID3D11DomainShader *ds = NULL;
25593 ID3D11DeviceContext *context;
25594 struct resource_readback rb;
25595 unsigned int offset, stride;
25596 ID3D11HullShader *hs = NULL;
25597 ID3D11GeometryShader *gs;
25598 ID3D11Device *device;
25599 ID3D11Buffer *vb;
25600 unsigned int i;
25601 HRESULT hr;
25602 RECT rect;
25604 static const DWORD vs_code[] =
25606 #if 0
25607 bool use_constant;
25608 float clip_distance;
25610 struct input
25612 float4 position : POSITION;
25613 float distance0 : CLIP_DISTANCE0;
25614 float distance1 : CLIP_DISTANCE1;
25617 struct vertex
25619 float4 position : SV_POSITION;
25620 float user_clip : CLIP_DISTANCE;
25621 float clip : SV_ClipDistance;
25624 void main(input vin, out vertex vertex)
25626 vertex.position = vin.position;
25627 vertex.user_clip = vin.distance0;
25628 vertex.clip = vin.distance0;
25629 if (use_constant)
25630 vertex.clip = clip_distance;
25632 #endif
25633 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
25634 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
25635 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
25636 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
25637 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
25638 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
25639 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
25640 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
25641 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
25642 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
25643 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
25644 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
25645 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
25646 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
25647 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
25649 static const DWORD vs_multiple_code[] =
25651 #if 0
25652 bool use_constant;
25653 float clip_distance0;
25654 float clip_distance1;
25656 struct input
25658 float4 position : POSITION;
25659 float distance0 : CLIP_DISTANCE0;
25660 float distance1 : CLIP_DISTANCE1;
25663 struct vertex
25665 float4 position : SV_POSITION;
25666 float user_clip : CLIP_DISTANCE;
25667 float2 clip : SV_ClipDistance;
25670 void main(input vin, out vertex vertex)
25672 vertex.position = vin.position;
25673 vertex.user_clip = vin.distance0;
25674 vertex.clip.x = vin.distance0;
25675 if (use_constant)
25676 vertex.clip.x = clip_distance0;
25677 vertex.clip.y = vin.distance1;
25678 if (use_constant)
25679 vertex.clip.y = clip_distance1;
25681 #endif
25682 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
25683 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
25684 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
25685 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
25686 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
25687 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
25688 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
25689 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
25690 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
25691 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
25692 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
25693 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
25694 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
25695 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
25696 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
25697 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
25698 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
25700 #if 0
25701 bool use_constant;
25702 float clip_distance0;
25703 float clip_distance1;
25704 float tessellation_factor;
25706 struct vertex
25708 float4 position : SV_POSITION;
25709 float user_clip : CLIP_DISTANCE;
25710 float clip : SV_ClipDistance;
25713 struct patch_constant_data
25715 float edges[4] : SV_TessFactor;
25716 float inside[2] : SV_InsideTessFactor;
25719 patch_constant_data patch_constant()
25721 patch_constant_data output;
25723 output.edges[0] = tessellation_factor;
25724 output.edges[1] = tessellation_factor;
25725 output.edges[2] = tessellation_factor;
25726 output.edges[3] = tessellation_factor;
25727 output.inside[0] = tessellation_factor;
25728 output.inside[1] = tessellation_factor;
25730 return output;
25733 [domain("quad")]
25734 [outputcontrolpoints(4)]
25735 [outputtopology("triangle_cw")]
25736 [partitioning("pow2")]
25737 [patchconstantfunc("patch_constant")]
25738 vertex hs_main(InputPatch<vertex, 4> input,
25739 uint i : SV_OutputControlPointID)
25741 vertex o;
25742 o.position = input[i].position;
25743 o.user_clip = input[i].user_clip;
25744 o.clip = input[i].user_clip;
25745 return o;
25748 float4 interpolate_vec(float4 a, float4 b, float4 c, float4 d, float2 tess_coord)
25750 float4 e = lerp(a, b, tess_coord.x);
25751 float4 f = lerp(c, d, tess_coord.x);
25752 return lerp(e, f, tess_coord.y);
25755 float interpolate(float a, float b, float c, float d, float2 tess_coord)
25757 float e = lerp(a, b, tess_coord.x);
25758 float f = lerp(c, d, tess_coord.x);
25759 return lerp(e, f, tess_coord.y);
25762 [domain("quad")]
25763 vertex ds_main(patch_constant_data input,
25764 float2 tess_coord : SV_DomainLocation,
25765 const OutputPatch<vertex, 4> patch)
25767 vertex output;
25769 output.position = interpolate_vec(patch[0].position, patch[1].position,
25770 patch[2].position, patch[3].position, tess_coord);
25771 output.user_clip = interpolate(patch[0].user_clip, patch[1].user_clip,
25772 patch[2].user_clip, patch[3].user_clip, tess_coord);
25773 output.clip = interpolate(patch[0].clip, patch[1].clip,
25774 patch[2].clip, patch[3].clip, tess_coord);
25775 if (use_constant)
25776 output.clip = clip_distance0;
25778 return output;
25780 #endif
25781 static const DWORD hs_code[] =
25783 0x43425844, 0x5a6d7564, 0x5f30a6c9, 0x2cf3b848, 0x5b4c6dca, 0x00000001, 0x00000414, 0x00000004,
25784 0x00000030, 0x000000b4, 0x00000138, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
25785 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
25786 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
25787 0x00000002, 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
25788 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003,
25789 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c,
25790 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002,
25791 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f,
25792 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc,
25793 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
25794 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
25795 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
25796 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
25797 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
25798 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
25799 0x00000210, 0x00030050, 0x00000084, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01001096,
25800 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x01000072, 0x0200005f,
25801 0x00016000, 0x0400005f, 0x002010f2, 0x00000004, 0x00000000, 0x0400005f, 0x00201012, 0x00000004,
25802 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
25803 0x00102012, 0x00000002, 0x02000068, 0x00000001, 0x04000036, 0x00100012, 0x00000000, 0x00016001,
25804 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x07000036,
25805 0x00102012, 0x00000001, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x07000036, 0x00102012,
25806 0x00000002, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x0100003e, 0x01000073, 0x02000099,
25807 0x00000004, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x0000000b, 0x04000067,
25808 0x00102012, 0x00000001, 0x0000000c, 0x04000067, 0x00102012, 0x00000002, 0x0000000d, 0x04000067,
25809 0x00102012, 0x00000003, 0x0000000e, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000000,
25810 0x00000004, 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x07000036, 0x00902012, 0x0010000a,
25811 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002,
25812 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000004, 0x0000000f, 0x04000067, 0x00102012,
25813 0x00000005, 0x00000010, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000004, 0x00000002,
25814 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x08000036, 0x00d02012, 0x00000004, 0x0010000a,
25815 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e,
25817 static const DWORD ds_code[] =
25819 0x43425844, 0xc54dc020, 0x063a9622, 0x6f649eb9, 0xceb1dd36, 0x00000001, 0x0000054c, 0x00000004,
25820 0x00000030, 0x000000b4, 0x00000178, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
25821 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
25822 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
25823 0x00000002, 0x00000101, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
25824 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc, 0x00000006,
25825 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000001, 0x00000098,
25826 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000001, 0x00000098, 0x00000002, 0x0000000b,
25827 0x00000003, 0x00000002, 0x00000001, 0x00000098, 0x00000003, 0x0000000b, 0x00000003, 0x00000003,
25828 0x00000001, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000001, 0x000000a6,
25829 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
25830 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000007c,
25831 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
25832 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000,
25833 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43,
25834 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x58454853,
25835 0x00000348, 0x00040050, 0x000000d2, 0x01002093, 0x01001895, 0x0100086a, 0x04000059, 0x00208e46,
25836 0x00000000, 0x00000001, 0x0200005f, 0x0001c032, 0x0400005f, 0x002190f2, 0x00000004, 0x00000000,
25837 0x0400005f, 0x00219012, 0x00000004, 0x00000001, 0x0400005f, 0x00219012, 0x00000004, 0x00000002,
25838 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067,
25839 0x00102012, 0x00000002, 0x00000002, 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000,
25840 0x80219e46, 0x00000041, 0x00000002, 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032,
25841 0x001000f2, 0x00000000, 0x0001c006, 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000,
25842 0x0a000000, 0x001000f2, 0x00000001, 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46,
25843 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001,
25844 0x00219e46, 0x00000000, 0x00000000, 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
25845 0x80100e46, 0x00000041, 0x00000001, 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46,
25846 0x00000000, 0x00100e46, 0x00000001, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041,
25847 0x00000002, 0x00000001, 0x0021900a, 0x00000003, 0x00000001, 0x09000032, 0x00100012, 0x00000000,
25848 0x0001c00a, 0x0010000a, 0x00000000, 0x0021900a, 0x00000002, 0x00000001, 0x0a000000, 0x00100022,
25849 0x00000000, 0x8021900a, 0x00000041, 0x00000000, 0x00000001, 0x0021900a, 0x00000001, 0x00000001,
25850 0x09000032, 0x00100022, 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000,
25851 0x00000001, 0x08000000, 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a,
25852 0x00000000, 0x08000032, 0x00102012, 0x00000001, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a,
25853 0x00000000, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041, 0x00000002, 0x00000002,
25854 0x0021900a, 0x00000003, 0x00000002, 0x09000032, 0x00100012, 0x00000000, 0x0001c00a, 0x0010000a,
25855 0x00000000, 0x0021900a, 0x00000002, 0x00000002, 0x0a000000, 0x00100022, 0x00000000, 0x8021900a,
25856 0x00000041, 0x00000000, 0x00000002, 0x0021900a, 0x00000001, 0x00000002, 0x09000032, 0x00100022,
25857 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000, 0x00000002, 0x08000000,
25858 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a, 0x00000000, 0x08000032,
25859 0x00100012, 0x00000000, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000, 0x0b000037,
25860 0x00102012, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
25861 0x0010000a, 0x00000000, 0x0100003e,
25863 static const DWORD gs_code[] =
25865 #if 0
25866 bool use_constant;
25867 float clip_distance;
25869 struct vertex
25871 float4 position : SV_POSITION;
25872 float user_clip : CLIP_DISTANCE;
25873 float clip : SV_ClipDistance;
25876 [maxvertexcount(3)]
25877 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
25879 vertex o;
25880 o = input[0];
25881 o.clip = input[0].user_clip;
25882 if (use_constant)
25883 o.clip = clip_distance;
25884 output.Append(o);
25885 o = input[1];
25886 o.clip = input[1].user_clip;
25887 if (use_constant)
25888 o.clip = clip_distance;
25889 output.Append(o);
25890 o = input[2];
25891 o.clip = input[2].user_clip;
25892 if (use_constant)
25893 o.clip = clip_distance;
25894 output.Append(o);
25896 #endif
25897 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
25898 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
25899 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
25900 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
25901 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
25902 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
25903 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
25904 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
25905 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
25906 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
25907 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
25908 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
25909 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
25910 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
25911 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
25912 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
25913 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
25914 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
25915 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
25916 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
25917 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
25918 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
25919 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
25920 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
25921 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
25922 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
25924 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
25926 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
25927 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
25928 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
25930 struct
25932 float clip_distance0;
25933 float clip_distance1;
25935 vertices[] =
25937 {1.0f, 1.0f},
25938 {1.0f, 1.0f},
25939 {1.0f, 1.0f},
25940 {1.0f, 1.0f},
25942 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
25943 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
25944 struct
25946 BOOL use_constant;
25947 float clip_distance0;
25948 float clip_distance1;
25949 float tessellation_factor;
25950 } cb_data;
25952 if (!init_test_context(&test_context, NULL))
25953 return;
25954 device = test_context.device;
25955 context = test_context.immediate_context;
25956 feature_level = ID3D11Device_GetFeatureLevel(device);
25958 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
25959 vs_code, sizeof(vs_code), &test_context.input_layout);
25960 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
25962 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
25963 stride = sizeof(*vertices);
25964 offset = 0;
25965 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
25967 memset(&cb_data, 0, sizeof(cb_data));
25968 cb_data.tessellation_factor = 1.0f;
25969 vs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
25970 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &vs_cb);
25971 tess_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
25972 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &tess_cb);
25973 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, 1, &tess_cb);
25974 gs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
25975 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &gs_cb);
25977 /* vertex shader */
25978 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
25979 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
25980 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
25982 check_clip_distance(&test_context, vb);
25984 cb_data.use_constant = TRUE;
25985 cb_data.clip_distance0 = -1.0f;
25986 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
25988 /* tessellation shaders */
25989 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
25991 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
25993 hr = ID3D11Device_CreateHullShader(device, hs_code, sizeof(hs_code), NULL, &hs);
25994 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
25995 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
25996 hr = ID3D11Device_CreateDomainShader(device, ds_code, sizeof(ds_code), NULL, &ds);
25997 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
25998 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
26000 check_clip_distance(&test_context, vb);
26002 cb_data.use_constant = FALSE;
26003 cb_data.tessellation_factor = 2.0f;
26004 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
26006 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
26007 vertices[i].clip_distance0 = 1.0f;
26008 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
26009 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26010 ID3D11DeviceContext_Draw(context, 4, 0);
26011 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
26013 cb_data.use_constant = TRUE;
26014 cb_data.clip_distance0 = -1.0f;
26015 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
26017 else
26019 skip("Tessellation shaders are not supported.\n");
26022 /* geometry shader */
26023 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
26024 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
26025 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26027 check_clip_distance(&test_context, vb);
26029 cb_data.use_constant = TRUE;
26030 cb_data.clip_distance0 = 1.0f;
26031 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
26032 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26033 ID3D11DeviceContext_Draw(context, 4, 0);
26034 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
26036 /* multiple clip distances */
26037 ID3D11DeviceContext_HSSetShader(context, NULL, NULL, 0);
26038 ID3D11DeviceContext_DSSetShader(context, NULL, NULL, 0);
26039 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26041 cb_data.use_constant = FALSE;
26042 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
26044 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
26045 vertices[i].clip_distance0 = 1.0f;
26046 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
26047 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26048 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
26049 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
26051 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
26053 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
26054 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
26056 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
26057 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26058 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
26059 get_texture_readback(test_context.backbuffer, 0, &rb);
26060 SetRect(&rect, 0, 0, 320, 240);
26061 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
26062 SetRect(&rect, 0, 240, 320, 480);
26063 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
26064 SetRect(&rect, 320, 0, 640, 480);
26065 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
26066 release_resource_readback(&rb);
26068 cb_data.use_constant = TRUE;
26069 cb_data.clip_distance0 = 0.0f;
26070 cb_data.clip_distance1 = 0.0f;
26071 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
26072 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26073 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
26074 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
26076 if (hs)
26077 ID3D11HullShader_Release(hs);
26078 if (ds)
26079 ID3D11DomainShader_Release(ds);
26080 ID3D11GeometryShader_Release(gs);
26081 ID3D11Buffer_Release(vb);
26082 ID3D11Buffer_Release(vs_cb);
26083 ID3D11Buffer_Release(tess_cb);
26084 ID3D11Buffer_Release(gs_cb);
26085 release_test_context(&test_context);
26088 static void test_combined_clip_and_cull_distances(void)
26090 struct d3d11_test_context test_context;
26091 ID3D11DeviceContext *context;
26092 struct resource_readback rb;
26093 unsigned int offset, stride;
26094 ID3D11Device *device;
26095 unsigned int i, j, k;
26096 ID3D11Buffer *vb;
26097 HRESULT hr;
26099 static const DWORD vs_code[] =
26101 #if 0
26102 struct input
26104 float4 position : POSITION;
26105 float clip0 : CLIP_DISTANCE0;
26106 float clip1 : CLIP_DISTANCE1;
26107 float clip2 : CLIP_DISTANCE2;
26108 float clip3 : CLIP_DISTANCE3;
26109 float cull0 : CULL_DISTANCE0;
26110 float cull1 : CULL_DISTANCE1;
26111 float cull2 : CULL_DISTANCE2;
26112 float cull3 : CULL_DISTANCE3;
26115 struct vertex
26117 float4 position : SV_Position;
26118 float3 clip0 : SV_ClipDistance1;
26119 float3 cull0 : SV_CullDistance1;
26120 float clip1 : SV_ClipDistance2;
26121 float cull1 : SV_CullDistance2;
26124 void main(input vin, out vertex vertex)
26126 vertex.position = vin.position;
26127 vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2);
26128 vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2);
26129 vertex.clip1 = vin.clip3;
26130 vertex.cull1 = vin.cull3;
26132 #endif
26133 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003,
26134 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0,
26135 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000,
26136 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
26137 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9,
26138 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000,
26139 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006,
26140 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7,
26141 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300,
26142 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f,
26143 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
26144 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c,
26145 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003,
26146 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002,
26147 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e,
26148 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f,
26149 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
26150 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f,
26151 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007,
26152 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
26153 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067,
26154 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036,
26155 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a,
26156 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042,
26157 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004,
26158 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002,
26159 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036,
26160 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e,
26162 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
26164 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26165 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26166 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
26167 {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
26168 {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
26169 {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26170 {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
26171 {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
26172 {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
26174 struct
26176 float clip_distance[4];
26177 float cull_distance[4];
26179 vertices[4] =
26181 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
26182 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
26183 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
26184 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
26186 static const struct test
26188 float vertices[4];
26189 BOOL triangle_visible[2];
26191 cull_distance_tests[] =
26193 {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
26194 {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
26195 {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
26196 {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
26197 {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
26198 {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
26199 {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
26200 {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
26201 {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
26203 {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}},
26204 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
26205 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
26206 {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
26207 {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}},
26209 {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}},
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, NULL))
26215 return;
26216 device = test_context.device;
26217 context = test_context.immediate_context;
26219 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
26220 vs_code, sizeof(vs_code), &test_context.input_layout);
26221 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
26223 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
26224 stride = sizeof(*vertices);
26225 offset = 0;
26226 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
26228 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26229 draw_color_quad(&test_context, &green);
26230 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
26232 for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i)
26234 for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j)
26236 const struct test *test = &cull_distance_tests[j];
26237 unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)];
26238 unsigned int color;
26240 for (k = 0; k < ARRAY_SIZE(vertices); ++k)
26241 vertices[k].cull_distance[i] = test->vertices[k];
26242 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
26244 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26245 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
26247 for (k = 0; k < ARRAY_SIZE(expected_color); ++k)
26248 expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff;
26250 if (expected_color[0] == expected_color[1])
26252 check_texture_color(test_context.backbuffer, *expected_color, 1);
26254 else
26256 get_texture_readback(test_context.backbuffer, 0, &rb);
26257 color = get_readback_color(&rb, 160, 240, 0);
26258 ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color);
26259 color = get_readback_color(&rb, 480, 240, 0);
26260 ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color);
26261 release_resource_readback(&rb);
26265 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
26266 vertices[j].cull_distance[i] = 1.0f;
26269 for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i)
26271 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
26272 vertices[j].clip_distance[i] = -1.0f;
26273 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
26275 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26276 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
26277 check_texture_color(test_context.backbuffer, 0xffffffff, 1);
26279 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
26280 vertices[j].clip_distance[i] = 1.0f;
26283 memset(vertices, 0, sizeof(vertices));
26284 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
26285 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
26286 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
26287 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
26289 ID3D11Buffer_Release(vb);
26290 release_test_context(&test_context);
26293 static void test_generate_mips(void)
26295 static const DWORD ps_code[] =
26297 #if 0
26298 Texture2D t;
26299 SamplerState s;
26301 float4 main(float4 position : SV_POSITION) : SV_Target
26303 float2 p;
26305 p.x = position.x / 640.0f;
26306 p.y = position.y / 480.0f;
26307 return t.Sample(s, p);
26309 #endif
26310 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
26311 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26312 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
26313 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26314 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
26315 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
26316 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
26317 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
26318 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
26319 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
26321 static const DWORD ps_code_3d[] =
26323 #if 0
26324 Texture3D t;
26325 SamplerState s;
26327 float4 main(float4 position : SV_POSITION) : SV_Target
26329 float3 p;
26331 p.x = position.x / 640.0f;
26332 p.y = position.y / 480.0f;
26333 p.z = 0.5f;
26334 return t.Sample(s, p);
26336 #endif
26337 0x43425844, 0xa1e26083, 0xeb45763e, 0x1e5a5089, 0xdfbbe0df, 0x00000001, 0x00000148, 0x00000003,
26338 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26339 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
26340 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26341 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ac, 0x00000040,
26342 0x0000002b, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
26343 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
26344 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
26345 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f000000,
26346 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
26347 0x00000000, 0x0100003e,
26349 static const struct
26351 D3D11_RESOURCE_DIMENSION dim;
26352 D3D11_SRV_DIMENSION srv_dim;
26353 unsigned int array_size;
26355 resource_types[] =
26357 {D3D11_RESOURCE_DIMENSION_BUFFER, D3D11_SRV_DIMENSION_BUFFER, 1},
26358 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2D, 1},
26359 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2DARRAY, 4},
26360 {D3D11_RESOURCE_DIMENSION_TEXTURE3D, D3D11_SRV_DIMENSION_TEXTURE3D, 1},
26362 static const struct
26364 DXGI_FORMAT texture_format;
26365 UINT bind_flags;
26366 UINT misc_flags;
26367 BOOL null_srv;
26368 UINT base_level;
26369 BOOL expected_creation;
26370 BOOL expected_mips;
26372 tests[] =
26374 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
26375 0, TRUE, FALSE},
26376 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
26377 0, TRUE, FALSE},
26378 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
26379 0, TRUE, FALSE},
26380 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
26381 0, TRUE, FALSE},
26382 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
26383 0, FALSE, FALSE},
26384 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
26385 0, FALSE, FALSE},
26386 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
26387 0, TRUE, TRUE},
26388 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
26389 1, TRUE, TRUE},
26390 {DXGI_FORMAT_R8G8B8A8_TYPELESS, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
26391 1, TRUE, TRUE},
26392 {DXGI_FORMAT_R8G8B8A8_UINT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, TRUE,
26393 1, TRUE, FALSE},
26395 static const struct
26397 POINT pos;
26398 DWORD color;
26400 expected[] =
26402 {{200, 200}, 0xffff0000},
26403 {{280, 200}, 0xffff0000},
26404 {{360, 200}, 0xff00ff00},
26405 {{440, 200}, 0xff00ff00},
26406 {{200, 270}, 0xff0000ff},
26407 {{280, 270}, 0xff0000ff},
26408 {{360, 270}, 0xff000000},
26409 {{440, 270}, 0xff000000},
26411 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
26412 static const RECT r1 = {8, 8, 16, 16};
26413 static const RECT r2 = {16, 8, 24, 16};
26414 static const RECT r3 = {8, 16, 16, 24};
26415 static const RECT r4 = {16, 16, 24, 24};
26416 DWORD *data, *zero_data, color, expected_color;
26417 ID3D11ShaderResourceView *srv, *srv_sampling;
26418 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
26419 struct d3d11_test_context test_context;
26420 D3D11_TEXTURE2D_DESC texture2d_desc;
26421 D3D11_TEXTURE3D_DESC texture3d_desc;
26422 ID3D11SamplerState *sampler_state;
26423 D3D11_SAMPLER_DESC sampler_desc;
26424 D3D11_BUFFER_DESC buffer_desc;
26425 unsigned int i, j, k, x, y, z;
26426 ID3D11PixelShader *ps, *ps_3d;
26427 ID3D11DeviceContext *context;
26428 struct resource_readback rb;
26429 ID3D11Resource *resource;
26430 ID3D11Device *device;
26431 HRESULT hr;
26433 if (!init_test_context(&test_context, NULL))
26434 return;
26436 device = test_context.device;
26437 context = test_context.immediate_context;
26439 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
26440 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
26442 hr = ID3D11Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), NULL, &ps_3d);
26443 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
26445 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
26446 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
26447 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
26448 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
26449 sampler_desc.MipLODBias = 0.0f;
26450 sampler_desc.MaxAnisotropy = 0;
26451 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
26452 sampler_desc.BorderColor[0] = 0.0f;
26453 sampler_desc.BorderColor[1] = 0.0f;
26454 sampler_desc.BorderColor[2] = 0.0f;
26455 sampler_desc.BorderColor[3] = 0.0f;
26456 sampler_desc.MinLOD = 0.0f;
26457 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
26459 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
26460 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
26461 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
26463 data = heap_alloc(sizeof(*data) * 32 * 32 * 32);
26465 for (z = 0; z < 32; ++z)
26467 for (y = 0; y < 32; ++y)
26469 for (x = 0; x < 32; ++x)
26471 DWORD *dst = &data[z * 32 * 32 + y * 32 + x];
26472 POINT pt;
26474 pt.x = x;
26475 pt.y = y;
26476 if (PtInRect(&r1, pt))
26477 *dst = 0xffff0000;
26478 else if (PtInRect(&r2, pt))
26479 *dst = 0xff00ff00;
26480 else if (PtInRect(&r3, pt))
26481 *dst = 0xff0000ff;
26482 else if (PtInRect(&r4, pt))
26483 *dst = 0xff000000;
26484 else
26485 *dst = 0xffffffff;
26490 zero_data = heap_alloc_zero(sizeof(*zero_data) * 16 * 16 * 16);
26492 for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
26494 for (j = 0; j < ARRAY_SIZE(tests); ++j)
26496 unsigned int base_multiplier = 1u << tests[j].base_level;
26498 if (is_warp_device(device) && tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT)
26500 /* Testing this format seems to break the WARP device. */
26501 skip("Skipping test with DXGI_FORMAT_R8G8B8A8_UINT on WARP.\n");
26502 continue;
26505 switch (resource_types[i].dim)
26507 case D3D11_RESOURCE_DIMENSION_BUFFER:
26508 buffer_desc.ByteWidth = 32 * base_multiplier;
26509 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
26510 buffer_desc.BindFlags = tests[j].bind_flags;
26511 buffer_desc.CPUAccessFlags = 0;
26512 buffer_desc.MiscFlags = tests[j].misc_flags;
26513 buffer_desc.StructureByteStride = 0;
26515 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL,
26516 (ID3D11Buffer **)&resource);
26517 break;
26518 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
26519 texture2d_desc.Width = 32 * base_multiplier;
26520 texture2d_desc.Height = 32 * base_multiplier;
26521 texture2d_desc.MipLevels = 0;
26522 texture2d_desc.ArraySize = resource_types[i].array_size;
26523 texture2d_desc.Format = tests[j].texture_format;
26524 texture2d_desc.SampleDesc.Count = 1;
26525 texture2d_desc.SampleDesc.Quality = 0;
26526 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
26527 texture2d_desc.BindFlags = tests[j].bind_flags;
26528 texture2d_desc.CPUAccessFlags = 0;
26529 texture2d_desc.MiscFlags = tests[j].misc_flags;
26531 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL,
26532 (ID3D11Texture2D **)&resource);
26533 break;
26534 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
26535 texture3d_desc.Width = 32 * base_multiplier;
26536 texture3d_desc.Height = 32 * base_multiplier;
26537 texture3d_desc.Depth = 32 * base_multiplier;
26538 texture3d_desc.MipLevels = 0;
26539 texture3d_desc.Format = tests[j].texture_format;
26540 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
26541 texture3d_desc.BindFlags = tests[j].bind_flags;
26542 texture3d_desc.CPUAccessFlags = 0;
26543 texture3d_desc.MiscFlags = tests[j].misc_flags;
26545 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL,
26546 (ID3D11Texture3D **)&resource);
26547 break;
26548 default:
26549 break;
26551 if (tests[j].expected_creation && (resource_types[i].dim != D3D11_RESOURCE_DIMENSION_BUFFER
26552 || !(tests[j].misc_flags & D3D11_RESOURCE_MISC_GENERATE_MIPS)))
26554 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create resource, hr %#x.\n", i, j, hr);
26556 else
26558 ok(hr == E_INVALIDARG, "Resource type %u, test %u: unexpectedly succeeded "
26559 "to create resource, hr %#x.\n", i, j, hr);
26560 continue;
26563 if (tests[j].null_srv)
26565 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
26567 else
26569 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
26570 srv_desc.ViewDimension = resource_types[i].srv_dim;
26571 switch (resource_types[i].srv_dim)
26573 case D3D11_SRV_DIMENSION_BUFFER:
26574 srv_desc.Buffer.ElementOffset = 0;
26575 srv_desc.Buffer.ElementWidth = 0;
26576 break;
26577 case D3D11_SRV_DIMENSION_TEXTURE2D:
26578 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level;
26579 srv_desc.Texture2D.MipLevels = ~0u;
26580 break;
26581 case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
26582 srv_desc.Texture2DArray.MostDetailedMip = tests[j].base_level;
26583 srv_desc.Texture2DArray.MipLevels = ~0u;
26584 srv_desc.Texture2DArray.FirstArraySlice = 0;
26585 srv_desc.Texture2DArray.ArraySize = resource_types[i].array_size;
26586 break;
26587 case D3D11_SRV_DIMENSION_TEXTURE3D:
26588 srv_desc.Texture3D.MostDetailedMip = tests[j].base_level;
26589 srv_desc.Texture3D.MipLevels = ~0u;
26590 break;
26591 default:
26592 break;
26594 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
26596 if (resource_types[i].dim == D3D11_RESOURCE_DIMENSION_BUFFER)
26598 ok(FAILED(hr), "Test %u: unexpectedly succeeded to create shader resource view, "
26599 "hr %#x.\n", j, hr);
26600 ID3D11Resource_Release(resource);
26601 continue;
26603 else
26605 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create "
26606 "shader resource view, hr %#x.\n", i, j, hr);
26609 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level,
26610 NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
26611 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level + 1,
26612 NULL, zero_data, sizeof(*zero_data) * 16, sizeof(*zero_data) * 16 * 16);
26614 ID3D11DeviceContext_GenerateMips(context, srv);
26616 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
26618 srv_desc.Format = tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT
26619 ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
26620 srv_desc.ViewDimension = resource_types[i].dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D
26621 ? D3D11_SRV_DIMENSION_TEXTURE3D : D3D11_SRV_DIMENSION_TEXTURE2D;
26622 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level + 1;
26623 srv_desc.Texture2D.MipLevels = ~0u;
26624 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
26625 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create shader resource view, "
26626 "hr %#x.\n", i, j, hr);
26627 ID3D11DeviceContext_PSSetShader(context, resource_types[i].dim
26628 == D3D11_RESOURCE_DIMENSION_TEXTURE3D ? ps_3d : ps, NULL, 0);
26629 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
26631 draw_quad(&test_context);
26633 get_texture_readback(test_context.backbuffer, 0, &rb);
26634 for (k = 0; k < ARRAY_SIZE(expected); ++k)
26636 color = get_readback_color(&rb, expected[k].pos.x, expected[k].pos.y, 0);
26637 expected_color = tests[j].expected_mips ? expected[k].color : 0;
26638 ok(color == expected_color, "Resource type %u, test %u: pixel (%u, %u) "
26639 "has color %08x, expected %08x.\n",
26640 i, j, expected[k].pos.x, expected[k].pos.y, color, expected_color);
26642 release_resource_readback(&rb);
26644 ID3D11ShaderResourceView_Release(srv_sampling);
26645 ID3D11ShaderResourceView_Release(srv);
26646 ID3D11Resource_Release(resource);
26650 /* Test the effect of sRGB views. */
26651 for (y = 0; y < 32; ++y)
26653 for (x = 0; x < 32; ++x)
26655 DWORD *dst = &data[y * 32 + x];
26657 *dst = (x + y) % 2 * 0xffffffff;
26660 texture2d_desc.Width = 32;
26661 texture2d_desc.Height = 32;
26662 texture2d_desc.MipLevels = 0;
26663 texture2d_desc.ArraySize = 1;
26664 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
26665 texture2d_desc.SampleDesc.Count = 1;
26666 texture2d_desc.SampleDesc.Quality = 0;
26667 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
26668 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
26669 texture2d_desc.CPUAccessFlags = 0;
26670 texture2d_desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
26672 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D11Texture2D **)&resource);
26673 ok(SUCCEEDED(hr), "Failed to create resource, hr %#x.\n", hr);
26674 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
26675 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
26676 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
26677 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
26678 srv_desc.Texture2D.MostDetailedMip = 0;
26679 srv_desc.Texture2D.MipLevels = ~0u;
26680 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
26681 ID3D11DeviceContext_UpdateSubresource(context, resource,
26682 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
26684 ID3D11DeviceContext_GenerateMips(context, srv);
26686 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
26688 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
26689 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
26690 srv_desc.Texture2D.MostDetailedMip = 1;
26691 srv_desc.Texture2D.MipLevels = ~0u;
26692 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
26693 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
26694 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
26695 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
26697 draw_quad(&test_context);
26699 get_texture_readback(test_context.backbuffer, 0, &rb);
26700 color = get_readback_color(&rb, 320, 240, 0);
26701 ok(compare_color(color, 0x7fbcbcbc, 1) || broken(compare_color(color, 0x7f7f7f7f, 1)), /* AMD */
26702 "Unexpected color %08x.\n", color);
26703 release_resource_readback(&rb);
26705 ID3D11ShaderResourceView_Release(srv_sampling);
26706 ID3D11ShaderResourceView_Release(srv);
26708 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
26709 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
26710 srv_desc.Texture2D.MostDetailedMip = 0;
26711 srv_desc.Texture2D.MipLevels = ~0u;
26712 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
26713 ID3D11DeviceContext_UpdateSubresource(context, resource,
26714 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
26716 ID3D11DeviceContext_GenerateMips(context, srv);
26718 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
26720 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
26721 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
26722 srv_desc.Texture2D.MostDetailedMip = 1;
26723 srv_desc.Texture2D.MipLevels = ~0u;
26724 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
26725 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
26726 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
26727 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
26729 draw_quad(&test_context);
26731 get_texture_readback(test_context.backbuffer, 0, &rb);
26732 check_readback_data_color(&rb, NULL, 0x7f7f7f7f, 1);
26733 release_resource_readback(&rb);
26735 ID3D11ShaderResourceView_Release(srv_sampling);
26736 ID3D11ShaderResourceView_Release(srv);
26738 ID3D11Resource_Release(resource);
26740 heap_free(zero_data);
26741 heap_free(data);
26743 ID3D11SamplerState_Release(sampler_state);
26744 ID3D11PixelShader_Release(ps_3d);
26745 ID3D11PixelShader_Release(ps);
26746 release_test_context(&test_context);
26749 static void test_alpha_to_coverage(void)
26751 struct ps_cb
26753 struct vec2 top;
26754 struct vec2 bottom;
26755 float alpha[2];
26756 float padding[2];
26759 struct d3d11_test_context test_context;
26760 ID3D11Texture2D *render_targets[3];
26761 D3D11_TEXTURE2D_DESC texture_desc;
26762 ID3D11Texture2D *readback_texture;
26763 ID3D11RenderTargetView *rtvs[3];
26764 ID3D11BlendState *blend_state;
26765 ID3D11DeviceContext *context;
26766 D3D11_BLEND_DESC blend_desc;
26767 struct resource_readback rb;
26768 UINT quality_level_count;
26769 ID3D11PixelShader *ps;
26770 struct ps_cb cb_data;
26771 ID3D11Device *device;
26772 ID3D11Buffer *cb;
26773 unsigned int i;
26774 HRESULT hr;
26775 RECT rect;
26777 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
26778 static const DWORD ps_code[] =
26780 #if 0
26781 float2 top;
26782 float2 bottom;
26783 float alpha1;
26784 float alpha2;
26786 void main(float4 position : SV_Position,
26787 out float4 target0 : SV_Target0,
26788 out float4 target1 : SV_Target1,
26789 out float4 target2 : SV_Target2)
26791 float alpha = all(top <= position.xy) && all(position.xy <= bottom) ? 1.0f : 0.0f;
26792 target0 = float4(0.0f, 1.0f, 0.0f, alpha);
26793 target1 = float4(0.0f, 0.0f, 1.0f, alpha1);
26794 target2 = float4(0.0f, 1.0f, 0.0f, alpha2);
26796 #endif
26797 0x43425844, 0x771ff802, 0xca927279, 0x5bdd75ae, 0xf53cb31b, 0x00000001, 0x00000264, 0x00000003,
26798 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26799 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
26800 0x4e47534f, 0x0000005c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003,
26801 0x00000000, 0x0000000f, 0x00000050, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
26802 0x00000050, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x545f5653, 0x65677261,
26803 0xabab0074, 0x52444853, 0x00000198, 0x00000040, 0x00000066, 0x04000059, 0x00208e46, 0x00000000,
26804 0x00000002, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
26805 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001,
26806 0x0800001d, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00208046, 0x00000000, 0x00000000,
26807 0x07000001, 0x00100012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0800001d,
26808 0x00100062, 0x00000000, 0x00208ba6, 0x00000000, 0x00000000, 0x00101106, 0x00000000, 0x07000001,
26809 0x00100022, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x07000001, 0x00100012,
26810 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00102082, 0x00000000,
26811 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x08000036, 0x00102072, 0x00000000, 0x00004002,
26812 0x00000000, 0x3f800000, 0x00000000, 0x00000000, 0x08000036, 0x00102072, 0x00000001, 0x00004002,
26813 0x00000000, 0x00000000, 0x3f800000, 0x00000000, 0x06000036, 0x00102082, 0x00000001, 0x0020800a,
26814 0x00000000, 0x00000001, 0x08000036, 0x00102072, 0x00000002, 0x00004002, 0x00000000, 0x3f800000,
26815 0x00000000, 0x00000000, 0x06000036, 0x00102082, 0x00000002, 0x0020801a, 0x00000000, 0x00000001,
26816 0x0100003e,
26818 static const DWORD colors[] = {0xff00ff00, 0xbfff0000, 0x8000ff00};
26820 if (!init_test_context(&test_context, NULL))
26821 return;
26822 device = test_context.device;
26823 context = test_context.immediate_context;
26825 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
26826 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
26827 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
26829 memset(&blend_desc, 0, sizeof(blend_desc));
26830 blend_desc.AlphaToCoverageEnable = TRUE;
26831 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
26832 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
26833 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
26834 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
26836 render_targets[0] = test_context.backbuffer;
26837 rtvs[0] = test_context.backbuffer_rtv;
26838 for (i = 1; i < ARRAY_SIZE(render_targets); ++i)
26840 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
26841 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
26842 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
26843 hr = ID3D11Device_CreateRenderTargetView(device,
26844 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
26845 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
26847 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
26849 cb_data.top.x = cb_data.top.y = 0.0f;
26850 cb_data.bottom.x = cb_data.bottom.y = 200.0f;
26851 cb_data.alpha[0] = 0.75;
26852 cb_data.alpha[1] = 0.5f;
26853 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
26854 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
26856 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
26857 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
26858 draw_quad(&test_context);
26859 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
26861 DWORD expected_color;
26863 assert(i < ARRAY_SIZE(colors));
26864 expected_color = colors[i];
26865 get_texture_readback(render_targets[i], 0, &rb);
26866 SetRect(&rect, 0, 0, 200, 200);
26867 check_readback_data_color(&rb, &rect, expected_color, 1);
26868 SetRect(&rect, 200, 0, 640, 200);
26869 todo_wine
26870 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
26871 SetRect(&rect, 0, 200, 640, 480);
26872 todo_wine
26873 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
26874 release_resource_readback(&rb);
26876 if (i > 0)
26877 ID3D11Texture2D_Release(render_targets[i]);
26878 render_targets[i] = NULL;
26881 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
26882 texture_desc.Format = DXGI_FORMAT_R16G16_UNORM;
26883 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[0]);
26884 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
26885 hr = ID3D11Device_CreateRenderTargetView(device,
26886 (ID3D11Resource *)render_targets[0], NULL, &rtvs[0]);
26887 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
26888 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
26890 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
26891 draw_quad(&test_context);
26892 get_texture_readback(render_targets[0], 0, &rb);
26893 SetRect(&rect, 0, 0, 200, 200);
26894 check_readback_data_color(&rb, &rect, 0xffff0000, 1);
26895 SetRect(&rect, 200, 0, 640, 200);
26896 todo_wine
26897 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
26898 SetRect(&rect, 0, 200, 640, 480);
26899 todo_wine
26900 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
26901 release_resource_readback(&rb);
26903 ID3D11Texture2D_Release(render_targets[0]);
26904 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
26905 ID3D11RenderTargetView_Release(rtvs[i]);
26907 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
26908 hr = ID3D11Device_CheckMultisampleQualityLevels(device,
26909 texture_desc.Format, 4, &quality_level_count);
26910 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
26911 if (!quality_level_count)
26913 skip("4xMSAA not supported.\n");
26914 goto done;
26916 texture_desc.SampleDesc.Count = 4;
26917 texture_desc.SampleDesc.Quality = 0;
26919 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
26921 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
26922 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
26923 hr = ID3D11Device_CreateRenderTargetView(device,
26924 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
26925 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
26927 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
26929 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
26930 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
26931 draw_quad(&test_context);
26932 texture_desc.SampleDesc.Count = 1;
26933 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
26934 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
26935 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
26937 DWORD expected_color;
26939 assert(i < ARRAY_SIZE(colors));
26940 expected_color = colors[i];
26942 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
26943 (ID3D11Resource *)render_targets[i], 0, texture_desc.Format);
26945 get_texture_readback(readback_texture, 0, &rb);
26946 SetRect(&rect, 0, 0, 200, 200);
26947 check_readback_data_color(&rb, &rect, expected_color, 1);
26948 SetRect(&rect, 200, 0, 640, 200);
26949 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
26950 SetRect(&rect, 0, 200, 640, 480);
26951 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
26952 release_resource_readback(&rb);
26954 ID3D11Texture2D_Release(readback_texture);
26956 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
26958 ID3D11Texture2D_Release(render_targets[i]);
26959 ID3D11RenderTargetView_Release(rtvs[i]);
26962 done:
26963 ID3D11Buffer_Release(cb);
26964 ID3D11PixelShader_Release(ps);
26965 ID3D11BlendState_Release(blend_state);
26966 release_test_context(&test_context);
26969 static void test_unbound_multisample_texture(void)
26971 struct d3d11_test_context test_context;
26972 ID3D11DeviceContext *context;
26973 ID3D11PixelShader *ps;
26974 struct uvec4 cb_data;
26975 ID3D11Device *device;
26976 ID3D11Buffer *cb;
26977 unsigned int i;
26978 HRESULT hr;
26980 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
26981 static const DWORD ps_code[] =
26983 #if 0
26984 Texture2DMS<float4, 4> t;
26986 uint sample_index;
26988 float4 main(float4 position : SV_Position) : SV_Target
26990 float3 p;
26991 t.GetDimensions(p.x, p.y, p.z);
26992 p *= float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
26993 /* sample index must be a literal */
26994 switch (sample_index)
26996 case 1: return t.Load(int2(p.xy), 1);
26997 case 2: return t.Load(int2(p.xy), 2);
26998 case 3: return t.Load(int2(p.xy), 3);
26999 default: return t.Load(int2(p.xy), 0);
27002 #endif
27003 0x43425844, 0x03d62416, 0x1914ee8b, 0xccd08d68, 0x27f42136, 0x00000001, 0x000002f8, 0x00000003,
27004 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27005 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27006 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27007 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000025c, 0x00000040,
27008 0x00000097, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04042058, 0x00107000, 0x00000000,
27009 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
27010 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46,
27011 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000,
27012 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
27013 0x00000000, 0x00000000, 0x0400004c, 0x0020800a, 0x00000000, 0x00000000, 0x03000006, 0x00004001,
27014 0x00000001, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000, 0x08000036, 0x001000c2,
27015 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0900002e, 0x001020f2,
27016 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
27017 0x03000006, 0x00004001, 0x00000002, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000,
27018 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
27019 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001,
27020 0x00000002, 0x0100003e, 0x03000006, 0x00004001, 0x00000003, 0x0500001b, 0x00100032, 0x00000001,
27021 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000,
27022 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46,
27023 0x00000000, 0x00004001, 0x00000003, 0x0100003e, 0x0100000a, 0x0500001b, 0x00100032, 0x00000000,
27024 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
27025 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46,
27026 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000017, 0x0100003e,
27029 if (!init_test_context(&test_context, NULL))
27030 return;
27031 device = test_context.device;
27032 context = test_context.immediate_context;
27034 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
27035 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
27036 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27038 memset(&cb_data, 0, sizeof(cb_data));
27039 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
27040 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
27042 for (i = 0; i < 4; ++i)
27044 cb_data.x = i;
27045 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_data, 0, 0);
27046 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27047 draw_quad(&test_context);
27048 check_texture_color(test_context.backbuffer, 0x00000000, 1);
27051 ID3D11Buffer_Release(cb);
27052 ID3D11PixelShader_Release(ps);
27053 release_test_context(&test_context);
27056 static void test_multiple_viewports(void)
27058 struct
27060 unsigned int draw_id;
27061 unsigned int padding[3];
27062 } constant;
27063 D3D11_VIEWPORT vp[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE + 1];
27064 struct d3d11_test_context test_context;
27065 D3D11_TEXTURE2D_DESC texture_desc;
27066 ID3D11DeviceContext *context;
27067 ID3D11RenderTargetView *rtv;
27068 ID3D11Texture2D *texture;
27069 ID3D11GeometryShader *gs;
27070 ID3D11PixelShader *ps;
27071 ID3D11Device *device;
27072 ID3D11Buffer *cb;
27073 HRESULT hr;
27075 static const DWORD gs_code[] =
27077 #if 0
27078 struct gs_in
27080 float4 pos : SV_Position;
27083 struct gs_out
27085 float4 pos : SV_Position;
27086 uint viewport : SV_ViewportArrayIndex;
27089 [maxvertexcount(6)]
27090 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
27092 gs_out o;
27093 for (uint instance_id = 0; instance_id < 2; ++instance_id)
27095 o.viewport = instance_id;
27096 for (uint i = 0; i < 3; ++i)
27098 o.pos = vin[i].pos;
27099 vout.Append(o);
27101 vout.RestartStrip();
27104 #endif
27105 0x43425844, 0xabbb660f, 0x0729bf23, 0x14a9a104, 0x1b454917, 0x00000001, 0x0000021c, 0x00000003,
27106 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27107 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
27108 0x4e47534f, 0x0000005c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
27109 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005, 0x00000001, 0x00000001, 0x00000e01,
27110 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569, 0x4174726f, 0x79617272, 0x65646e49,
27111 0xabab0078, 0x52444853, 0x00000150, 0x00020040, 0x00000054, 0x05000061, 0x002010f2, 0x00000003,
27112 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
27113 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000005, 0x0200005e, 0x00000006,
27114 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
27115 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x03040003, 0x0010001a, 0x00000000,
27116 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
27117 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000,
27118 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036,
27119 0x00102012, 0x00000001, 0x0010000a, 0x00000000, 0x01000013, 0x0700001e, 0x00100022, 0x00000000,
27120 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012,
27121 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
27123 static const DWORD ps_code[] =
27125 #if 0
27126 uint draw_id;
27128 float4 main(in float4 pos : SV_Position,
27129 in uint viewport : SV_ViewportArrayIndex) : SV_Target
27131 return float4(viewport, draw_id, 0, 0);
27133 #endif
27134 0x43425844, 0x77334c0f, 0x5df3ca7a, 0xc53c00db, 0x3e6e5750, 0x00000001, 0x00000150, 0x00000003,
27135 0x0000002c, 0x00000090, 0x000000c4, 0x4e475349, 0x0000005c, 0x00000002, 0x00000008, 0x00000038,
27136 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005,
27137 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569,
27138 0x4174726f, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
27139 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261,
27140 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46, 0x00000000,
27141 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000005, 0x03000065, 0x001020f2, 0x00000000,
27142 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022, 0x00000000,
27143 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000,
27144 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
27146 static const struct vec4 expected_values[] =
27148 {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},
27149 {0.0f, 5.0f}, {0.5f, 0.5f}, {1.0f, 5.0f}, {0.5f, 0.5f},
27151 static const float clear_color[] = {0.5f, 0.5f, 0.0f, 0.0f};
27152 ID3D11RasterizerState *rasterizer_state;
27153 D3D11_RASTERIZER_DESC rasterizer_desc;
27154 unsigned int count, i;
27155 D3D11_RECT rects[2];
27156 RECT rect;
27157 int width;
27159 if (!init_test_context(&test_context, NULL))
27160 return;
27162 device = test_context.device;
27163 context = test_context.immediate_context;
27165 memset(&constant, 0, sizeof(constant));
27166 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
27167 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
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 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
27174 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27175 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27177 texture_desc.Width = 32;
27178 texture_desc.Height = 32;
27179 texture_desc.MipLevels = 1;
27180 texture_desc.ArraySize = 1;
27181 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27182 texture_desc.SampleDesc.Count = 1;
27183 texture_desc.SampleDesc.Quality = 0;
27184 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27185 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27186 texture_desc.CPUAccessFlags = 0;
27187 texture_desc.MiscFlags = 0;
27188 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
27189 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27191 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
27192 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27193 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27195 width = texture_desc.Width / 2;
27197 vp[0].TopLeftX = 0.0f;
27198 vp[0].TopLeftY = 0.0f;
27199 vp[0].Width = width;
27200 vp[0].Height = texture_desc.Height;
27201 vp[0].MinDepth = 0.0f;
27202 vp[0].MaxDepth = 1.0f;
27204 vp[1] = vp[0];
27205 vp[1].TopLeftX = width;
27206 vp[1].Width = width;
27207 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
27209 count = ARRAY_SIZE(vp);
27210 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
27211 ok(count == 2, "Unexpected viewport count %d.\n", count);
27213 constant.draw_id = 0;
27214 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
27215 draw_quad(&test_context);
27216 constant.draw_id = 1;
27217 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
27218 draw_quad(&test_context);
27220 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
27221 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[0], 1);
27222 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
27223 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[1], 1);
27225 /* One viewport. */
27226 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
27227 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
27228 constant.draw_id = 2;
27229 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
27230 draw_quad(&test_context);
27231 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
27232 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[2], 1);
27233 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
27234 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[3], 1);
27236 /* Reset viewports. */
27237 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
27238 ID3D11DeviceContext_RSSetViewports(context, 0, NULL);
27239 constant.draw_id = 3;
27240 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
27241 draw_quad(&test_context);
27242 check_texture_sub_resource_vec4(texture, 0, NULL, &expected_values[4], 1);
27244 /* Two viewports, only first scissor rectangle set. */
27245 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
27246 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
27247 rasterizer_desc.CullMode = D3D11_CULL_BACK;
27248 rasterizer_desc.DepthClipEnable = TRUE;
27249 rasterizer_desc.ScissorEnable = TRUE;
27250 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
27251 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
27253 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
27254 ID3D11RasterizerState_Release(rasterizer_state);
27256 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
27257 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
27259 rects[0].left = 0;
27260 rects[0].top = 0;
27261 rects[0].right = width;
27262 rects[0].bottom = texture_desc.Height / 2;
27263 memset(&rects[1], 0, sizeof(*rects));
27264 ID3D11DeviceContext_RSSetScissorRects(context, 1, rects);
27265 constant.draw_id = 4;
27266 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
27267 draw_quad(&test_context);
27269 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
27270 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[5], 1);
27271 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
27272 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[6], 1);
27273 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
27274 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[7], 1);
27276 /* Set both rectangles. */
27277 rects[0].left = 0;
27278 rects[0].top = 0;
27279 rects[0].right = width;
27280 rects[0].bottom = texture_desc.Height / 2;
27281 rects[1].left = width;
27282 rects[1].top = 0;
27283 rects[1].right = width * 2;
27284 rects[1].bottom = texture_desc.Height / 2;
27285 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
27286 ID3D11DeviceContext_RSSetScissorRects(context, 2, rects);
27287 constant.draw_id = 5;
27288 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
27289 draw_quad(&test_context);
27291 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
27292 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[8], 1);
27293 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
27294 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[9], 1);
27296 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height / 2 - 1);
27297 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[10], 1);
27298 SetRect(&rect, width, texture_desc.Height / 2, 2 * width - 1, texture_desc.Height - 1);
27299 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[11], 1);
27301 /* Viewport count exceeding maximum value. */
27302 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
27304 vp[0].TopLeftX = 1.0f;
27305 vp[0].TopLeftY = 0.0f;
27306 vp[0].Width = width;
27307 vp[0].Height = texture_desc.Height;
27308 vp[0].MinDepth = 0.0f;
27309 vp[0].MaxDepth = 1.0f;
27310 for (i = 1; i < ARRAY_SIZE(vp); ++i)
27312 vp[i] = vp[0];
27314 ID3D11DeviceContext_RSSetViewports(context, ARRAY_SIZE(vp), vp);
27316 count = ARRAY_SIZE(vp);
27317 memset(vp, 0, sizeof(vp));
27318 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
27319 ok(count == 1, "Unexpected viewport count %d.\n", count);
27320 ok(vp[0].TopLeftX == 0.0f && vp[0].Width == width, "Unexpected viewport.\n");
27322 ID3D11RenderTargetView_Release(rtv);
27323 ID3D11Texture2D_Release(texture);
27325 ID3D11Buffer_Release(cb);
27326 ID3D11GeometryShader_Release(gs);
27327 ID3D11PixelShader_Release(ps);
27328 release_test_context(&test_context);
27331 static void test_multisample_resolve(void)
27333 struct d3d11_test_context test_context;
27334 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
27335 ID3D11Texture2D *texture, *ms_texture;
27336 D3D11_TEXTURE2D_DESC texture_desc;
27337 ID3D11DeviceContext *context;
27338 ID3D11RenderTargetView *rtv;
27339 ID3D11Device *device;
27340 unsigned int i;
27341 HRESULT hr;
27343 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
27344 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
27345 static const struct vec4 color = {0.25f, 0.5f, 0.75f, 1.0f};
27346 static const struct
27348 DXGI_FORMAT src_format;
27349 DXGI_FORMAT dst_format;
27350 DXGI_FORMAT format;
27352 DXGI_FORMAT rtv_format;
27354 const struct vec4 *color;
27355 DWORD expected_color;
27357 BOOL todo;
27359 tests[] =
27361 {DXGI_FORMAT_R8G8B8A8_UNORM,
27362 DXGI_FORMAT_R8G8B8A8_UNORM,
27363 DXGI_FORMAT_R8G8B8A8_UNORM,
27364 DXGI_FORMAT_R8G8B8A8_UNORM,
27365 &green, 0xff00ff00},
27366 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27367 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27368 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27369 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27370 &green, 0xff00ff00},
27371 {DXGI_FORMAT_R8G8B8A8_UNORM,
27372 DXGI_FORMAT_R8G8B8A8_UNORM,
27373 DXGI_FORMAT_R8G8B8A8_UNORM,
27374 DXGI_FORMAT_R8G8B8A8_UNORM,
27375 &color, 0xffbf7f40},
27376 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27377 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27378 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27379 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27380 &color, 0xffe1bc89},
27382 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27383 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27384 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27385 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27386 &green, 0xff00ff00},
27387 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
27388 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27389 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27390 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27391 &green, 0xff00ff00},
27392 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27393 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27394 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27395 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27396 &color, 0xffe1bc89, TRUE},
27397 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
27398 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27399 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27400 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27401 &color, 0xffe1bc89},
27403 {DXGI_FORMAT_R8G8B8A8_UNORM,
27404 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27405 DXGI_FORMAT_R8G8B8A8_UNORM,
27406 DXGI_FORMAT_R8G8B8A8_UNORM,
27407 &green, 0xff00ff00},
27408 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
27409 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27410 DXGI_FORMAT_R8G8B8A8_UNORM,
27411 DXGI_FORMAT_R8G8B8A8_UNORM,
27412 &green, 0xff00ff00},
27413 {DXGI_FORMAT_R8G8B8A8_UNORM,
27414 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27415 DXGI_FORMAT_R8G8B8A8_UNORM,
27416 DXGI_FORMAT_R8G8B8A8_UNORM,
27417 &color, 0xffbf7f40},
27418 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
27419 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27420 DXGI_FORMAT_R8G8B8A8_UNORM,
27421 DXGI_FORMAT_R8G8B8A8_UNORM,
27422 &color, 0xffbf7f40},
27424 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
27425 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27426 DXGI_FORMAT_R8G8B8A8_UNORM,
27427 DXGI_FORMAT_R8G8B8A8_UNORM,
27428 &green, 0xff00ff00},
27429 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
27430 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27431 DXGI_FORMAT_R8G8B8A8_UNORM,
27432 DXGI_FORMAT_R8G8B8A8_UNORM,
27433 &color, 0xffbf7f40},
27434 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
27435 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27436 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27437 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27438 &green, 0xff00ff00},
27439 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
27440 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27441 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27442 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27443 &color, 0xffe1bc89},
27444 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
27445 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27446 DXGI_FORMAT_R8G8B8A8_UNORM,
27447 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27448 &green, 0xff00ff00},
27449 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
27450 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27451 DXGI_FORMAT_R8G8B8A8_UNORM,
27452 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27453 &color, 0xffe1bc89},
27454 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
27455 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27456 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27457 DXGI_FORMAT_R8G8B8A8_UNORM,
27458 &green, 0xff00ff00},
27459 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
27460 DXGI_FORMAT_R8G8B8A8_TYPELESS,
27461 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
27462 DXGI_FORMAT_R8G8B8A8_UNORM,
27463 &color, 0xffbf7f40},
27466 if (!init_test_context(&test_context, NULL))
27467 return;
27468 device = test_context.device;
27469 context = test_context.immediate_context;
27471 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &i);
27472 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
27473 if (!i)
27475 skip("4xMSAA not supported.\n");
27476 release_test_context(&test_context);
27477 return;
27480 for (i = 0; i < ARRAY_SIZE(tests); ++i)
27482 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
27483 texture_desc.Format = tests[i].dst_format;
27484 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
27485 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
27487 texture_desc.Format = tests[i].src_format;
27488 texture_desc.SampleDesc.Count = 4;
27489 texture_desc.SampleDesc.Quality = 0;
27490 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ms_texture);
27491 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
27492 rtv_desc.Format = tests[i].rtv_format;
27493 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
27494 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)ms_texture, &rtv_desc, &rtv);
27495 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
27497 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27498 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
27499 draw_color_quad(&test_context, tests[i].color);
27500 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)texture, 0,
27501 (ID3D11Resource *)ms_texture, 0, tests[i].format);
27502 todo_wine_if(tests[i].todo)
27503 check_texture_color(texture, tests[i].expected_color, 2);
27505 ID3D11RenderTargetView_Release(rtv);
27506 ID3D11Texture2D_Release(ms_texture);
27507 ID3D11Texture2D_Release(texture);
27510 release_test_context(&test_context);
27513 static void test_sample_shading(void)
27515 struct shader
27517 const DWORD *code;
27518 size_t size;
27521 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
27522 struct d3d11_test_context test_context;
27523 struct swapchain_desc swapchain_desc;
27524 D3D11_TEXTURE2D_DESC texture_desc;
27525 ID3D11UnorderedAccessView *uav;
27526 D3D11_BUFFER_DESC buffer_desc;
27527 ID3D11ShaderResourceView *srv;
27528 ID3D11DeviceContext *context;
27529 ID3D11RenderTargetView *rtv;
27530 struct resource_readback rb;
27531 ID3D11Buffer *buffer, *cb;
27532 ID3D11Texture2D *texture;
27533 struct uvec4 ps_constant;
27534 ID3D11PixelShader *ps;
27535 ID3D11Device *device;
27536 unsigned int data;
27537 unsigned int i;
27538 HRESULT hr;
27540 static const DWORD ps_unused_sample_index_code[] =
27542 #if 0
27543 RWByteAddressBuffer u;
27545 float4 main(uint id : SV_SampleIndex) : SV_Target
27547 u.InterlockedAdd(0, 1);
27548 return float4(0.0f, 1.0f, 0.0f, 1.0f);
27550 #endif
27551 0x43425844, 0x41e4574b, 0x1e6441d6, 0x5e756375, 0xacd5dc27, 0x00000001, 0x00000104, 0x00000003,
27552 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
27553 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000001, 0x535f5653, 0x6c706d61, 0x646e4965,
27554 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
27555 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064,
27556 0x00000050, 0x00000019, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2,
27557 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
27558 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
27559 0x0100003e,
27561 static const struct shader ps_unused_sample_index
27562 = {ps_unused_sample_index_code, sizeof(ps_unused_sample_index_code)};
27563 static const DWORD ps_sample_index_code[] =
27565 #if 0
27566 RWByteAddressBuffer u;
27568 float4 main(uint id : SV_SampleIndex) : SV_Target
27570 u.InterlockedAdd(0, 1);
27571 u.InterlockedAdd(4, id);
27572 return float4(0.0f, 1.0f, 0.0f, 1.0f);
27574 #endif
27575 0x43425844, 0x943ab9ed, 0x91520b4a, 0xb75df9d0, 0x692cd3e6, 0x00000001, 0x00000130, 0x00000003,
27576 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
27577 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
27578 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
27579 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000090,
27580 0x00000050, 0x00000024, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
27581 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001,
27582 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
27583 0x00000004, 0x0010100a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
27584 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
27586 static const struct shader ps_sample_index = {ps_sample_index_code, sizeof(ps_sample_index_code)};
27587 static const DWORD ps_samplepos_code[] =
27589 #if 0
27590 Texture2DMS<float> t;
27591 RWByteAddressBuffer u;
27593 float4 main() : SV_Target
27595 float2 sample_position = t.GetSamplePosition(0);
27596 u.InterlockedAdd(0, 1);
27597 u.InterlockedAdd(4, sample_position.x + sample_position.y);
27598 return float4(0.0f, 1.0f, 0.0f, 1.0f);
27600 #endif
27601 0x43425844, 0x9ec7f344, 0x588f5863, 0x436c0531, 0x69dc54bb, 0x00000001, 0x00000160, 0x00000003,
27602 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
27603 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
27604 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e8, 0x00000050, 0x0000003a,
27605 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
27606 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
27607 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0800006e, 0x00100032, 0x00000000, 0x00107046,
27608 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
27609 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
27610 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
27611 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
27613 static const struct shader ps_samplepos = {ps_samplepos_code, sizeof(ps_samplepos_code)};
27614 static const DWORD ps_samplepos_rasterizer_code[] =
27616 #if 0
27617 RWByteAddressBuffer u;
27619 float4 main() : SV_Target
27621 float2 sample_position = GetRenderTargetSamplePosition(0);
27622 u.InterlockedAdd(0, 1);
27623 u.InterlockedAdd(4, sample_position.x + sample_position.y);
27624 return float4(0.0f, 1.0f, 0.0f, 1.0f);
27626 #endif
27627 0x43425844, 0xe31795d9, 0x4e9951da, 0xc1713913, 0xfb12da31, 0x00000001, 0x00000148, 0x00000003,
27628 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
27629 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
27630 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d0, 0x00000050, 0x00000034,
27631 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
27632 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
27633 0x0600006e, 0x00100032, 0x00000000, 0x0000e046, 0x00004001, 0x00000000, 0x07000000, 0x00100012,
27634 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
27635 0x0010000a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
27636 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
27637 0x3f800000, 0x0100003e,
27639 static const struct shader ps_samplepos_rasterizer
27640 = {ps_samplepos_rasterizer_code, sizeof(ps_samplepos_rasterizer_code)};
27641 static const DWORD ps_samplepos_indexed_code[] =
27643 #if 0
27644 RWByteAddressBuffer u;
27646 float4 main(uint id : SV_SampleIndex) : SV_Target
27648 float2 sample_position = GetRenderTargetSamplePosition(id);
27649 u.InterlockedAdd(0, 1);
27650 u.InterlockedAdd(4, sample_position.x + sample_position.y);
27651 return float4(0.0f, 1.0f, 0.0f, 1.0f);
27653 #endif
27654 0x43425844, 0x4b501464, 0x0cd4f636, 0x36428677, 0x6db6b4fb, 0x00000001, 0x00000180, 0x00000003,
27655 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
27656 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
27657 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
27658 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e0,
27659 0x00000050, 0x00000038, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
27660 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad,
27661 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0600006e, 0x00100032,
27662 0x00000000, 0x0000e046, 0x0010100a, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
27663 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
27664 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
27665 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
27667 static const struct shader ps_samplepos_indexed
27668 = {ps_samplepos_indexed_code, sizeof(ps_samplepos_indexed_code)};
27669 static const DWORD ps_sampleinfo_code[] =
27671 #if 0
27672 Texture2DMS<float> t;
27673 RWByteAddressBuffer u;
27675 float4 main() : SV_Target
27677 uint width, height, sample_count;
27678 t.GetDimensions(width, height, sample_count);
27679 u.InterlockedAdd(0, 1);
27680 u.InterlockedAdd(4, sample_count);
27681 return float4(0.0f, 1.0f, 0.0f, 1.0f);
27683 #endif
27684 0x43425844, 0x4e4f4065, 0x20d88902, 0xd4750e8c, 0x652b8c04, 0x00000001, 0x00000124, 0x00000003,
27685 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
27686 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
27687 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050, 0x0000002b,
27688 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
27689 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
27690 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a,
27691 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000,
27692 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
27693 0x0100003e,
27695 static const struct shader ps_sampleinfo = {ps_sampleinfo_code, sizeof(ps_sampleinfo_code)};
27696 static const DWORD ps_sampleinfo_rasterizer_code[] =
27698 #if 0
27699 RWByteAddressBuffer u;
27701 float4 main() : SV_Target
27703 uint sample_count = GetRenderTargetSampleCount();
27704 u.InterlockedAdd(0, 1);
27705 u.InterlockedAdd(4, sample_count);
27706 return float4(0.0f, 1.0f, 0.0f, 1.0f);
27708 #endif
27709 0x43425844, 0xfbbd8619, 0x9c2654c8, 0xb385363a, 0x4aacd10f, 0x00000001, 0x00000110, 0x00000003,
27710 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
27711 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
27712 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000098, 0x00000050, 0x00000026,
27713 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
27714 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
27715 0x0400086f, 0x00100012, 0x00000000, 0x0000e00a, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
27716 0x00000004, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
27717 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
27719 static const struct shader ps_sampleinfo_rasterizer
27720 = {ps_sampleinfo_rasterizer_code, sizeof(ps_sampleinfo_rasterizer_code)};
27721 static const DWORD ps_sample_code[] =
27723 #if 0
27724 RWByteAddressBuffer u;
27726 float4 main(sample float4 position : SV_Position) : SV_Target
27728 u.InterlockedAdd(0, 1);
27729 u.InterlockedAdd(4, position.x);
27730 return float4(0.0f, 1.0f, 0.0f, 1.0f);
27732 #endif
27733 0x43425844, 0x46ecbadb, 0xedccbea6, 0x236d7923, 0x0c356c8c, 0x00000001, 0x00000148, 0x00000003,
27734 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27735 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x7469736f, 0x006e6f69,
27736 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27737 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050,
27738 0x0000002b, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04003864, 0x00101012, 0x00000000,
27739 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000,
27740 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500001c, 0x00100012, 0x00000000,
27741 0x0010100a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
27742 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
27743 0x3f800000, 0x0100003e,
27745 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
27746 static const DWORD ps_color_code[] =
27748 #if 0
27749 float4 main(uint id : SV_SampleIndex) : SV_Target
27751 switch (id)
27753 case 0: return float4(1.0f, 0.0f, 0.0f, 1.0f);
27754 case 1: return float4(0.0f, 1.0f, 0.0f, 1.0f);
27755 case 2: return float4(0.0f, 0.0f, 1.0f, 1.0f);
27756 default: return float4(0.0f, 0.0f, 0.0f, 1.0f);
27759 #endif
27760 0x43425844, 0x94c35f48, 0x04c6b0f7, 0x407d8214, 0xc24f01e5, 0x00000001, 0x00000194, 0x00000003,
27761 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
27762 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
27763 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
27764 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f4,
27765 0x00000050, 0x0000003d, 0x0100086a, 0x04000863, 0x00101012, 0x00000000, 0x0000000a, 0x03000065,
27766 0x001020f2, 0x00000000, 0x0300004c, 0x0010100a, 0x00000000, 0x03000006, 0x00004001, 0x00000000,
27767 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
27768 0x0100003e, 0x03000006, 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
27769 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x03000006, 0x00004001, 0x00000002,
27770 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000,
27771 0x0100003e, 0x0100000a, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
27772 0x00000000, 0x3f800000, 0x0100003e, 0x01000017, 0x0100003e,
27774 static const DWORD ps_resolve_code[] =
27776 #if 0
27777 Texture2DMS<float4> t;
27779 uint sample;
27780 uint rt_size;
27782 float4 main(float4 position : SV_Position) : SV_Target
27784 float3 p;
27785 t.GetDimensions(p.x, p.y, p.z);
27786 p *= float3(position.x / rt_size, position.y / rt_size, 0);
27787 return t.Load((int2)p.xy, sample);
27789 #endif
27790 0x43425844, 0x68a4590b, 0xc1ec3070, 0x1b957c43, 0x0c080741, 0x00000001, 0x000001c8, 0x00000003,
27791 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27792 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27793 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27794 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000012c, 0x00000050,
27795 0x0000004b, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002058, 0x00107000,
27796 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
27797 0x00000000, 0x02000068, 0x00000001, 0x06000056, 0x00100012, 0x00000000, 0x0020801a, 0x00000000,
27798 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00100006, 0x00000000,
27799 0x8900003d, 0x80000102, 0x00155543, 0x001000c2, 0x00000000, 0x00004001, 0x00000000, 0x001074e6,
27800 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000,
27801 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000,
27802 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8c00002e, 0x80000102, 0x00155543,
27803 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0020800a, 0x00000000,
27804 0x00000000, 0x0100003e,
27806 static const struct
27808 const struct shader *ps;
27809 BOOL sample_shading;
27810 BOOL todo;
27811 BOOL broken;
27813 tests[] =
27815 {&ps_unused_sample_index, FALSE, FALSE, TRUE /* broken on Nvidia */},
27816 {&ps_sample_index, TRUE},
27817 {&ps_samplepos, FALSE},
27818 {&ps_samplepos_rasterizer, FALSE},
27819 {&ps_samplepos_indexed, TRUE, TRUE},
27820 {&ps_sampleinfo, FALSE},
27821 {&ps_sampleinfo_rasterizer, FALSE},
27822 {&ps_sample, TRUE, TRUE, TRUE /* broken on Intel */},
27824 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27825 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
27826 static const unsigned int zero[4] = {0};
27828 swapchain_desc.windowed = TRUE;
27829 swapchain_desc.buffer_count = 1;
27830 swapchain_desc.width = 32;
27831 swapchain_desc.height = 32;
27832 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
27833 swapchain_desc.flags = 0;
27834 if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc))
27835 return;
27836 device = test_context.device;
27837 context = test_context.immediate_context;
27839 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
27840 texture_desc.SampleDesc.Count = 4;
27841 texture_desc.SampleDesc.Quality = 0;
27842 texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
27843 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
27844 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
27845 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
27846 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
27847 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
27848 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
27850 buffer_desc.ByteWidth = 1024;
27851 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
27852 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
27853 buffer_desc.CPUAccessFlags = 0;
27854 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
27855 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
27856 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
27857 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
27858 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
27859 U(uav_desc).Buffer.FirstElement = 0;
27860 U(uav_desc).Buffer.NumElements = 256;
27861 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
27862 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
27863 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
27865 for (i = 0; i < ARRAY_SIZE(tests); ++i)
27867 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
27868 ok(hr == S_OK, "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
27869 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27871 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
27872 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27873 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
27874 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL);
27875 draw_quad(&test_context);
27876 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
27877 get_buffer_readback(buffer, &rb);
27878 data = get_readback_color(&rb, 0, 0, 0);
27879 ok(1024 <= data && data <= 1056, "Test %u: Got unexpected value %u.\n", i, data);
27880 release_resource_readback(&rb);
27882 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
27883 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
27884 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
27885 1, &rtv, NULL, 1, 1, &uav, NULL);
27886 draw_quad(&test_context);
27887 get_buffer_readback(buffer, &rb);
27888 data = get_readback_color(&rb, 0, 0, 0);
27889 todo_wine_if(tests[i].todo)
27891 if (tests[i].sample_shading)
27893 ok(4096 <= data || broken(tests[i].broken && data >= 1024),
27894 "Test %u: Got unexpected value %u.\n", i, data);
27896 else
27898 ok((1024 <= data && data <= 1056) || broken(tests[i].broken && data >= 4096),
27899 "Test %u: Got unexpected value %u.\n", i, data);
27902 release_resource_readback(&rb);
27904 ID3D11PixelShader_Release(ps);
27907 if (is_warp_device(device))
27909 skip("Sample shading tests fail on WARP.\n");
27910 goto done;
27913 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps);
27914 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
27915 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27916 ID3D11PixelShader_Release(ps);
27918 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
27919 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27920 draw_quad(&test_context);
27921 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
27922 (ID3D11Resource *)texture, 0, texture_desc.Format);
27923 check_texture_color(test_context.backbuffer, 0xff404040, 2);
27925 hr = ID3D11Device_CreatePixelShader(device, ps_resolve_code, sizeof(ps_resolve_code), NULL, &ps);
27926 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
27927 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27928 ID3D11PixelShader_Release(ps);
27929 ps_constant.x = 0;
27930 ps_constant.y = texture_desc.Width;
27931 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
27932 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
27934 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27935 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
27936 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
27937 draw_quad(&test_context);
27938 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
27939 ps_constant.x = 1;
27940 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
27941 draw_quad(&test_context);
27942 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
27943 ps_constant.x = 2;
27944 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
27945 draw_quad(&test_context);
27946 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
27947 ps_constant.x = 3;
27948 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
27949 draw_quad(&test_context);
27950 check_texture_color(test_context.backbuffer, 0xff000000, 0);
27952 ID3D11Buffer_Release(cb);
27953 done:
27954 ID3D11Buffer_Release(buffer);
27955 ID3D11UnorderedAccessView_Release(uav);
27956 ID3D11RenderTargetView_Release(rtv);
27957 ID3D11ShaderResourceView_Release(srv);
27958 ID3D11Texture2D_Release(texture);
27959 release_test_context(&test_context);
27962 static void test_sample_mask(void)
27964 static const DWORD ps_code[] =
27966 #if 0
27967 float4 main(in float4 pos : SV_Position, out uint sample_mask : SV_Coverage) : SV_Target
27969 sample_mask = 0x5;
27970 return float4(1.0, 1.0, 1.0, 1.0);
27972 #endif
27973 0x43425844, 0x196779a9, 0xda85988a, 0xb7f0a0b6, 0xb30dd6ba, 0x00000001, 0x00000114, 0x00000003,
27974 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27975 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
27976 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
27977 0x00000000, 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000001, 0xffffffff, 0x00000e01,
27978 0x545f5653, 0x65677261, 0x56530074, 0x766f435f, 0x67617265, 0xabab0065, 0x58454853, 0x00000054,
27979 0x00000050, 0x00000015, 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x0000f000,
27980 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
27981 0x04000036, 0x0000f001, 0x00004001, 0x00000005, 0x0100003e,
27983 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27984 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
27985 struct d3d11_test_context test_context;
27986 D3D11_TEXTURE2D_DESC texture_desc;
27987 ID3D11DeviceContext *context;
27988 ID3D11RenderTargetView *rtv;
27989 ID3D11Texture2D *texture;
27990 ID3D11PixelShader *ps;
27991 ID3D11Device *device;
27992 UINT quality_levels;
27993 HRESULT hr;
27995 if (!init_test_context(&test_context, &feature_level))
27996 return;
27997 device = test_context.device;
27998 context = test_context.immediate_context;
28000 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &quality_levels);
28001 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
28002 if (!quality_levels)
28004 skip("4xMSAA not supported.\n");
28005 release_test_context(&test_context);
28006 return;
28009 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
28010 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
28011 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
28013 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
28014 texture_desc.SampleDesc.Count = 4;
28015 texture_desc.SampleDesc.Quality = 0;
28016 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
28017 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
28018 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
28019 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
28021 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
28022 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
28023 draw_quad(&test_context);
28024 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
28025 (ID3D11Resource *)texture, 0, texture_desc.Format);
28026 check_texture_color(test_context.backbuffer, 0x7f7f7f7f, 1);
28028 ID3D11RenderTargetView_Release(rtv);
28029 ID3D11Texture2D_Release(texture);
28030 ID3D11PixelShader_Release(ps);
28031 release_test_context(&test_context);
28034 static void test_depth_clip(void)
28036 struct d3d11_test_context test_context;
28037 D3D11_TEXTURE2D_DESC texture_desc;
28038 D3D11_RASTERIZER_DESC rs_desc;
28039 ID3D11DeviceContext *context;
28040 ID3D11DepthStencilView *dsv;
28041 ID3D11RasterizerState *rs;
28042 ID3D11Texture2D *texture;
28043 ID3D11Device *device;
28044 unsigned int count;
28045 D3D11_VIEWPORT vp;
28046 HRESULT hr;
28048 if (!init_test_context(&test_context, NULL))
28049 return;
28050 device = test_context.device;
28051 context = test_context.immediate_context;
28053 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
28054 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
28055 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
28057 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
28058 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28059 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
28060 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
28061 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
28063 count = 1;
28064 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
28066 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
28067 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
28068 draw_quad_z(&test_context, 2.0f);
28069 check_texture_float(texture, 1.0f, 1);
28070 draw_quad_z(&test_context, 0.5f);
28071 check_texture_float(texture, 0.5f, 1);
28072 draw_quad_z(&test_context, -1.0f);
28073 check_texture_float(texture, 0.5f, 1);
28075 rs_desc.FillMode = D3D11_FILL_SOLID;
28076 rs_desc.CullMode = D3D11_CULL_BACK;
28077 rs_desc.FrontCounterClockwise = FALSE;
28078 rs_desc.DepthBias = 0;
28079 rs_desc.DepthBiasClamp = 0.0f;
28080 rs_desc.SlopeScaledDepthBias = 0.0f;
28081 rs_desc.DepthClipEnable = FALSE;
28082 rs_desc.ScissorEnable = FALSE;
28083 rs_desc.MultisampleEnable = FALSE;
28084 rs_desc.AntialiasedLineEnable = FALSE;
28085 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
28086 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
28088 ID3D11DeviceContext_RSSetState(context, rs);
28090 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
28091 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
28092 draw_quad_z(&test_context, 2.0f);
28093 check_texture_float(texture, 0.6f, 1);
28094 draw_quad_z(&test_context, 0.5f);
28095 check_texture_float(texture, 0.5f, 1);
28096 draw_quad_z(&test_context, -1.0f);
28097 check_texture_float(texture, 0.4f, 1);
28099 ID3D11DepthStencilView_Release(dsv);
28100 ID3D11Texture2D_Release(texture);
28101 ID3D11RasterizerState_Release(rs);
28102 release_test_context(&test_context);
28105 static void test_staging_buffers(void)
28107 struct d3d11_test_context test_context;
28108 ID3D11Buffer *dst_buffer, *src_buffer;
28109 D3D11_SUBRESOURCE_DATA resource_data;
28110 D3D11_BUFFER_DESC buffer_desc;
28111 ID3D11DeviceContext *context;
28112 struct resource_readback rb;
28113 float data[16], value;
28114 ID3D11Device *device;
28115 unsigned int i;
28116 HRESULT hr;
28118 if (!init_test_context(&test_context, NULL))
28119 return;
28120 device = test_context.device;
28121 context = test_context.immediate_context;
28123 buffer_desc.ByteWidth = sizeof(data);
28124 buffer_desc.Usage = D3D11_USAGE_STAGING;
28125 buffer_desc.BindFlags = 0;
28126 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
28127 buffer_desc.MiscFlags = 0;
28128 buffer_desc.StructureByteStride = 0;
28130 for (i = 0; i < ARRAY_SIZE(data); ++i)
28131 data[i] = i;
28132 resource_data.pSysMem = data;
28133 resource_data.SysMemPitch = 0;
28134 resource_data.SysMemSlicePitch = 0;
28136 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &src_buffer);
28137 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
28139 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
28140 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
28141 buffer_desc.CPUAccessFlags = 0;
28142 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &dst_buffer);
28143 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
28145 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
28146 get_buffer_readback(dst_buffer, &rb);
28147 for (i = 0; i < ARRAY_SIZE(data); ++i)
28149 value = get_readback_float(&rb, i, 0);
28150 ok(value == data[i], "Got unexpected value %.8e at %u.\n", value, i);
28152 release_resource_readback(&rb);
28154 for (i = 0; i < ARRAY_SIZE(data); ++i)
28155 data[i] = 2 * i;
28156 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, NULL, data, 0, 0);
28157 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
28158 get_buffer_readback(dst_buffer, &rb);
28159 for (i = 0; i < ARRAY_SIZE(data); ++i)
28161 value = get_readback_float(&rb, i, 0);
28162 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
28164 release_resource_readback(&rb);
28166 ID3D11Buffer_Release(dst_buffer);
28167 ID3D11Buffer_Release(src_buffer);
28168 release_test_context(&test_context);
28171 START_TEST(d3d11)
28173 unsigned int argc, i;
28174 char **argv;
28176 argc = winetest_get_mainargs(&argv);
28177 for (i = 2; i < argc; ++i)
28179 if (!strcmp(argv[i], "--warp"))
28180 use_warp_adapter = TRUE;
28181 else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
28182 use_adapter_idx = atoi(argv[++i]);
28183 else if (!strcmp(argv[i], "--single"))
28184 use_mt = FALSE;
28187 print_adapter_info();
28189 queue_test(test_create_device);
28190 queue_for_each_feature_level(test_device_interfaces);
28191 queue_test(test_get_immediate_context);
28192 queue_test(test_create_texture1d);
28193 queue_test(test_texture1d_interfaces);
28194 queue_test(test_create_texture2d);
28195 queue_test(test_texture2d_interfaces);
28196 queue_test(test_create_texture3d);
28197 queue_test(test_texture3d_interfaces);
28198 queue_test(test_create_buffer);
28199 queue_test(test_create_depthstencil_view);
28200 queue_test(test_depthstencil_view_interfaces);
28201 queue_test(test_create_rendertarget_view);
28202 queue_test(test_create_shader_resource_view);
28203 queue_for_each_feature_level(test_create_shader);
28204 queue_test(test_create_sampler_state);
28205 queue_test(test_create_blend_state);
28206 queue_test(test_create_depthstencil_state);
28207 queue_test(test_create_rasterizer_state);
28208 queue_test(test_create_query);
28209 queue_test(test_occlusion_query);
28210 queue_test(test_pipeline_statistics_query);
28211 queue_test(test_timestamp_query);
28212 queue_test(test_device_removed_reason);
28213 queue_test(test_private_data);
28214 queue_for_each_feature_level(test_state_refcounting);
28215 queue_test(test_device_context_state);
28216 queue_test(test_blend);
28217 queue_test(test_texture1d);
28218 queue_test(test_texture);
28219 queue_test(test_cube_maps);
28220 queue_test(test_depth_stencil_sampling);
28221 queue_test(test_sample_c_lz);
28222 queue_test(test_multiple_render_targets);
28223 queue_test(test_render_target_views);
28224 queue_test(test_layered_rendering);
28225 queue_test(test_scissor);
28226 queue_test(test_clear_state);
28227 queue_test(test_il_append_aligned);
28228 queue_test(test_instance_id);
28229 queue_test(test_fragment_coords);
28230 queue_test(test_update_subresource);
28231 queue_test(test_copy_subresource_region);
28232 queue_test(test_copy_subresource_region_1d);
28233 queue_test(test_copy_subresource_region_3d);
28234 queue_test(test_resource_map);
28235 queue_for_each_feature_level(test_resource_access);
28236 queue_test(test_check_multisample_quality_levels);
28237 queue_for_each_feature_level(test_swapchain_formats);
28238 queue_test(test_swapchain_views);
28239 queue_test(test_swapchain_flip);
28240 queue_test(test_clear_render_target_view_1d);
28241 queue_test(test_clear_render_target_view_2d);
28242 queue_test(test_clear_render_target_view_3d);
28243 queue_test(test_clear_depth_stencil_view);
28244 queue_test(test_clear_buffer_unordered_access_view);
28245 queue_test(test_initial_depth_stencil_state);
28246 queue_test(test_draw_depth_only);
28247 queue_test(test_draw_uav_only);
28248 queue_test(test_cb_relative_addressing);
28249 queue_test(test_vs_input_relative_addressing);
28250 queue_test(test_getdc);
28251 queue_test(test_shader_stage_input_output_matching);
28252 queue_test(test_shader_interstage_interface);
28253 queue_test(test_sm4_if_instruction);
28254 queue_test(test_sm4_breakc_instruction);
28255 queue_test(test_sm4_continuec_instruction);
28256 queue_test(test_sm4_discard_instruction);
28257 queue_test(test_sm5_swapc_instruction);
28258 queue_test(test_create_input_layout);
28259 queue_test(test_input_assembler);
28260 queue_test(test_null_sampler);
28261 queue_test(test_check_feature_support);
28262 queue_test(test_create_unordered_access_view);
28263 queue_test(test_immediate_constant_buffer);
28264 queue_test(test_fp_specials);
28265 queue_test(test_uint_shader_instructions);
28266 queue_test(test_index_buffer_offset);
28267 queue_test(test_face_culling);
28268 queue_test(test_line_antialiasing_blending);
28269 queue_for_each_feature_level(test_required_format_support);
28270 queue_for_each_9_x_feature_level(test_fl9_draw);
28271 queue_test(test_ddy);
28272 queue_test(test_shader_input_registers_limits);
28273 queue_test(test_unbind_shader_resource_view);
28274 queue_test(test_stencil_separate);
28275 queue_test(test_uav_load);
28276 queue_test(test_cs_uav_store);
28277 queue_test(test_uav_store_immediate_constant);
28278 queue_test(test_ps_cs_uav_binding);
28279 queue_test(test_atomic_instructions);
28280 queue_test(test_sm4_ret_instruction);
28281 queue_test(test_primitive_restart);
28282 queue_test(test_resinfo_instruction);
28283 queue_test(test_sm5_bufinfo_instruction);
28284 queue_test(test_sampleinfo_instruction);
28285 queue_test(test_render_target_device_mismatch);
28286 queue_test(test_buffer_srv);
28287 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
28288 test_unaligned_raw_buffer_access);
28289 queue_test(test_uav_counters);
28290 queue_test(test_dispatch_indirect);
28291 queue_test(test_compute_shader_registers);
28292 queue_test(test_tgsm);
28293 queue_test(test_geometry_shader);
28294 queue_test(test_quad_tessellation);
28295 queue_test(test_stream_output);
28296 queue_test(test_fl10_stream_output_desc);
28297 queue_test(test_stream_output_resume);
28298 queue_test(test_stream_output_components);
28299 queue_test(test_stream_output_vs);
28300 queue_test(test_gather);
28301 queue_test(test_gather_c);
28302 queue_test(test_depth_bias);
28303 queue_test(test_fractional_viewports);
28304 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0, test_negative_viewports);
28305 queue_test(test_early_depth_stencil);
28306 queue_test(test_conservative_depth_output);
28307 queue_test(test_format_compatibility);
28308 queue_test(test_clip_distance);
28309 queue_test(test_combined_clip_and_cull_distances);
28310 queue_test(test_generate_mips);
28311 queue_test(test_alpha_to_coverage);
28312 queue_test(test_unbound_multisample_texture);
28313 queue_test(test_multiple_viewports);
28314 queue_test(test_multisample_resolve);
28315 queue_test(test_sample_shading);
28316 queue_test(test_sample_mask);
28317 queue_test(test_depth_clip);
28318 queue_test(test_staging_buffers);
28320 run_queued_tests();