d3d11/tests: Add test for clearing buffer unordered access views.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob80088937fad03253dd18094a91ffccbef2a52abd
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 <stdlib.h>
23 #define COBJMACROS
24 #include "initguid.h"
25 #include "d3d11_1.h"
26 #include "wine/test.h"
27 #include <limits.h>
29 #ifndef ARRAY_SIZE
30 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
31 #endif
33 #define BITS_NNAN 0xffc00000
34 #define BITS_NAN 0x7fc00000
35 #define BITS_NINF 0xff800000
36 #define BITS_INF 0x7f800000
37 #define BITS_N1_0 0xbf800000
38 #define BITS_1_0 0x3f800000
40 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
42 struct format_support
44 DXGI_FORMAT format;
45 D3D_FEATURE_LEVEL fl_required;
46 D3D_FEATURE_LEVEL fl_optional;
49 static const struct format_support display_format_support[] =
51 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
52 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
53 {DXGI_FORMAT_B8G8R8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
54 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
55 {DXGI_FORMAT_R16G16B16A16_FLOAT, D3D_FEATURE_LEVEL_10_0},
56 {DXGI_FORMAT_R10G10B10A2_UNORM, D3D_FEATURE_LEVEL_10_0},
57 {DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0},
60 struct vec2
62 float x, y;
65 struct vec3
67 float x, y, z;
70 struct vec4
72 float x, y, z, w;
75 struct ivec4
77 int x, y, z, w;
80 struct uvec4
82 unsigned int x, y, z, w;
85 struct device_desc
87 const D3D_FEATURE_LEVEL *feature_level;
88 UINT flags;
91 struct swapchain_desc
93 BOOL windowed;
94 UINT buffer_count;
95 DXGI_SWAP_EFFECT swap_effect;
96 DWORD flags;
99 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
101 box->left = left;
102 box->top = top;
103 box->front = front;
104 box->right = right;
105 box->bottom = bottom;
106 box->back = back;
109 static ULONG get_refcount(void *iface)
111 IUnknown *unknown = iface;
112 IUnknown_AddRef(unknown);
113 return IUnknown_Release(unknown);
116 #define check_interface(a, b, c, d) check_interface_(__LINE__, a, b, c, d)
117 static HRESULT check_interface_(unsigned int line, void *iface, REFIID riid, BOOL supported, BOOL is_broken)
119 HRESULT hr, expected_hr, broken_hr;
120 IUnknown *unknown = iface, *out;
122 if (supported)
124 expected_hr = S_OK;
125 broken_hr = E_NOINTERFACE;
127 else
129 expected_hr = E_NOINTERFACE;
130 broken_hr = S_OK;
133 hr = IUnknown_QueryInterface(unknown, riid, (void **)&out);
134 ok_(__FILE__, line)(hr == expected_hr || broken(is_broken && hr == broken_hr),
135 "Got hr %#x, expected %#x.\n", hr, expected_hr);
136 if (SUCCEEDED(hr))
137 IUnknown_Release(out);
138 return hr;
141 static BOOL compare_float(float f, float g, unsigned int ulps)
143 int x = *(int *)&f;
144 int y = *(int *)&g;
146 if (x < 0)
147 x = INT_MIN - x;
148 if (y < 0)
149 y = INT_MIN - y;
151 if (abs(x - y) > ulps)
152 return FALSE;
154 return TRUE;
157 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
159 return compare_float(v1->x, v2->x, ulps)
160 && compare_float(v1->y, v2->y, ulps)
161 && compare_float(v1->z, v2->z, ulps)
162 && compare_float(v1->w, v2->w, ulps);
165 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
167 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
170 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
172 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
173 return FALSE;
174 c1 >>= 8; c2 >>= 8;
175 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
176 return FALSE;
177 c1 >>= 8; c2 >>= 8;
178 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
179 return FALSE;
180 c1 >>= 8; c2 >>= 8;
181 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
182 return FALSE;
183 return TRUE;
186 struct srv_desc
188 DXGI_FORMAT format;
189 D3D11_SRV_DIMENSION dimension;
190 unsigned int miplevel_idx;
191 unsigned int miplevel_count;
192 unsigned int layer_idx;
193 unsigned int layer_count;
196 static void get_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *d3d11_desc, const struct srv_desc *desc)
198 d3d11_desc->Format = desc->format;
199 d3d11_desc->ViewDimension = desc->dimension;
200 if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1D)
202 U(*d3d11_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
203 U(*d3d11_desc).Texture1D.MipLevels = desc->miplevel_count;
205 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1DARRAY)
207 U(*d3d11_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
208 U(*d3d11_desc).Texture1DArray.MipLevels = desc->miplevel_count;
209 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
210 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
212 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
214 U(*d3d11_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
215 U(*d3d11_desc).Texture2D.MipLevels = desc->miplevel_count;
217 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
219 U(*d3d11_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
220 U(*d3d11_desc).Texture2DArray.MipLevels = desc->miplevel_count;
221 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
222 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
224 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
226 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
227 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
229 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE3D)
231 U(*d3d11_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
232 U(*d3d11_desc).Texture3D.MipLevels = desc->miplevel_count;
234 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
236 U(*d3d11_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
237 U(*d3d11_desc).TextureCube.MipLevels = desc->miplevel_count;
239 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
241 U(*d3d11_desc).TextureCubeArray.MostDetailedMip = desc->miplevel_idx;
242 U(*d3d11_desc).TextureCubeArray.MipLevels = desc->miplevel_count;
243 U(*d3d11_desc).TextureCubeArray.First2DArrayFace = desc->layer_idx;
244 U(*d3d11_desc).TextureCubeArray.NumCubes = desc->layer_count;
246 else if (desc->dimension != D3D11_SRV_DIMENSION_UNKNOWN
247 && desc->dimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
249 trace("Unhandled view dimension %#x.\n", desc->dimension);
253 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
254 static void check_srv_desc_(unsigned int line, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc,
255 const struct srv_desc *expected_desc)
257 ok_(__FILE__, line)(desc->Format == expected_desc->format,
258 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
259 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
260 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
262 if (desc->ViewDimension != expected_desc->dimension)
263 return;
265 if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D)
267 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
268 "Got MostDetailedMip %u, expected %u.\n",
269 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
270 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
271 "Got MipLevels %u, expected %u.\n",
272 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
274 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
276 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
277 "Got MostDetailedMip %u, expected %u.\n",
278 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
279 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
280 "Got MipLevels %u, expected %u.\n",
281 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
282 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
283 "Got FirstArraySlice %u, expected %u.\n",
284 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
285 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
286 "Got ArraySize %u, expected %u.\n",
287 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
289 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
291 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
292 "Got FirstArraySlice %u, expected %u.\n",
293 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
294 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
295 "Got ArraySize %u, expected %u.\n",
296 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
298 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D)
300 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
301 "Got MostDetailedMip %u, expected %u.\n",
302 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
303 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
304 "Got MipLevels %u, expected %u.\n",
305 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
307 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
309 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
310 "Got MostDetailedMip %u, expected %u.\n",
311 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
312 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
313 "Got MipLevels %u, expected %u.\n",
314 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
316 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
318 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MostDetailedMip == expected_desc->miplevel_idx,
319 "Got MostDetailedMip %u, expected %u.\n",
320 U(*desc).TextureCubeArray.MostDetailedMip, expected_desc->miplevel_idx);
321 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MipLevels == expected_desc->miplevel_count,
322 "Got MipLevels %u, expected %u.\n",
323 U(*desc).TextureCubeArray.MipLevels, expected_desc->miplevel_count);
324 ok_(__FILE__, line)(U(*desc).TextureCubeArray.First2DArrayFace == expected_desc->layer_idx,
325 "Got First2DArrayFace %u, expected %u.\n",
326 U(*desc).TextureCubeArray.First2DArrayFace, expected_desc->layer_idx);
327 ok_(__FILE__, line)(U(*desc).TextureCubeArray.NumCubes == expected_desc->layer_count,
328 "Got NumCubes %u, expected %u.\n",
329 U(*desc).TextureCubeArray.NumCubes, expected_desc->layer_count);
331 else if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
333 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
337 struct rtv_desc
339 DXGI_FORMAT format;
340 D3D11_RTV_DIMENSION dimension;
341 unsigned int miplevel_idx;
342 unsigned int layer_idx;
343 unsigned int layer_count;
346 static void get_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *d3d11_desc, const struct rtv_desc *desc)
348 d3d11_desc->Format = desc->format;
349 d3d11_desc->ViewDimension = desc->dimension;
350 if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1D)
352 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
354 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1DARRAY)
356 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
357 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
358 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
360 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
362 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
364 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
366 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
367 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
368 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
370 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
372 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
373 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
375 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE3D)
377 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
378 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
379 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
381 else if (desc->dimension != D3D11_RTV_DIMENSION_UNKNOWN
382 && desc->dimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
384 trace("Unhandled view dimension %#x.\n", desc->dimension);
388 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
389 static void check_rtv_desc_(unsigned int line, const D3D11_RENDER_TARGET_VIEW_DESC *desc,
390 const struct rtv_desc *expected_desc)
392 ok_(__FILE__, line)(desc->Format == expected_desc->format,
393 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
394 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
395 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
397 if (desc->ViewDimension != expected_desc->dimension)
398 return;
400 if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D)
402 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
403 "Got MipSlice %u, expected %u.\n",
404 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
406 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
408 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
409 "Got MipSlice %u, expected %u.\n",
410 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
411 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
412 "Got FirstArraySlice %u, expected %u.\n",
413 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
414 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
415 "Got ArraySize %u, expected %u.\n",
416 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
418 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
420 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
421 "Got FirstArraySlice %u, expected %u.\n",
422 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
423 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
424 "Got ArraySize %u, expected %u.\n",
425 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
427 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE3D)
429 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
430 "Got MipSlice %u, expected %u.\n",
431 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
432 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
433 "Got FirstWSlice %u, expected %u.\n",
434 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
435 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
436 "Got WSize %u, expected %u.\n",
437 U(*desc).Texture3D.WSize, expected_desc->layer_count);
439 else if (desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
441 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
445 struct dsv_desc
447 DXGI_FORMAT format;
448 D3D11_DSV_DIMENSION dimension;
449 unsigned int miplevel_idx;
450 unsigned int layer_idx;
451 unsigned int layer_count;
454 static void get_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *d3d11_desc, const struct dsv_desc *desc)
456 d3d11_desc->Format = desc->format;
457 d3d11_desc->ViewDimension = desc->dimension;
458 d3d11_desc->Flags = 0;
459 if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1D)
461 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
463 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1DARRAY)
465 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
466 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
467 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
469 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2D)
471 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
473 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
475 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
476 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
477 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
479 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
481 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
482 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
484 else if (desc->dimension != D3D11_DSV_DIMENSION_UNKNOWN
485 && desc->dimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
487 trace("Unhandled view dimension %#x.\n", desc->dimension);
491 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
492 static void check_dsv_desc_(unsigned int line, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc,
493 const struct dsv_desc *expected_desc)
495 ok_(__FILE__, line)(desc->Format == expected_desc->format,
496 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
497 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
498 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
500 if (desc->ViewDimension != expected_desc->dimension)
501 return;
503 if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D)
505 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
506 "Got MipSlice %u, expected %u.\n",
507 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
509 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
511 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
512 "Got MipSlice %u, expected %u.\n",
513 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
514 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
515 "Got FirstArraySlice %u, expected %u.\n",
516 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
517 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
518 "Got ArraySize %u, expected %u.\n",
519 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
521 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
523 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
524 "Got FirstArraySlice %u, expected %u.\n",
525 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
526 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
527 "Got ArraySize %u, expected %u.\n",
528 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
530 else if (desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
532 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
536 struct uav_desc
538 DXGI_FORMAT format;
539 D3D11_UAV_DIMENSION dimension;
540 unsigned int miplevel_idx;
541 unsigned int layer_idx;
542 unsigned int layer_count;
545 static void get_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC *d3d11_desc, const struct uav_desc *desc)
547 d3d11_desc->Format = desc->format;
548 d3d11_desc->ViewDimension = desc->dimension;
549 if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1D)
551 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
553 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
555 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
556 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
557 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
559 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2D)
561 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
563 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
565 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
566 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
567 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
569 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE3D)
571 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
572 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
573 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
575 else if (desc->dimension != D3D11_UAV_DIMENSION_UNKNOWN)
577 trace("Unhandled view dimension %#x.\n", desc->dimension);
581 #define check_uav_desc(a, b) check_uav_desc_(__LINE__, a, b)
582 static void check_uav_desc_(unsigned int line, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc,
583 const struct uav_desc *expected_desc)
585 ok_(__FILE__, line)(desc->Format == expected_desc->format,
586 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
587 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
588 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
590 if (desc->ViewDimension != expected_desc->dimension)
591 return;
593 if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2D)
595 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
596 "Got MipSlice %u, expected %u.\n",
597 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
599 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
601 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
602 "Got MipSlice %u, expected %u.\n",
603 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
604 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
605 "Got FirstArraySlice %u, expected %u.\n",
606 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
607 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
608 "Got ArraySize %u, expected %u.\n",
609 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
611 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE3D)
613 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
614 "Got MipSlice %u, expected %u.\n",
615 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
616 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
617 "Got FirstWSlice %u, expected %u.\n",
618 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
619 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
620 "Got WSize %u, expected %u.\n",
621 U(*desc).Texture3D.WSize, expected_desc->layer_count);
623 else
625 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
629 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, c, d)
630 static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
631 unsigned int bind_flags, unsigned int size, const void *data)
633 D3D11_SUBRESOURCE_DATA resource_data;
634 D3D11_BUFFER_DESC buffer_desc;
635 ID3D11Buffer *buffer;
636 HRESULT hr;
638 buffer_desc.ByteWidth = size;
639 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
640 buffer_desc.BindFlags = bind_flags;
641 buffer_desc.CPUAccessFlags = 0;
642 buffer_desc.MiscFlags = 0;
643 buffer_desc.StructureByteStride = 0;
645 resource_data.pSysMem = data;
646 resource_data.SysMemPitch = 0;
647 resource_data.SysMemSlicePitch = 0;
649 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
650 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
651 return buffer;
654 struct resource_readback
656 ID3D11Resource *resource;
657 D3D11_MAPPED_SUBRESOURCE map_desc;
658 ID3D11DeviceContext *immediate_context;
659 unsigned int width, height, sub_resource_idx;
662 static void get_buffer_readback(ID3D11Buffer *buffer, struct resource_readback *rb)
664 D3D11_BUFFER_DESC buffer_desc;
665 ID3D11Device *device;
666 HRESULT hr;
668 memset(rb, 0, sizeof(*rb));
670 ID3D11Buffer_GetDevice(buffer, &device);
672 ID3D11Buffer_GetDesc(buffer, &buffer_desc);
673 buffer_desc.Usage = D3D11_USAGE_STAGING;
674 buffer_desc.BindFlags = 0;
675 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
676 buffer_desc.MiscFlags = 0;
677 buffer_desc.StructureByteStride = 0;
678 if (FAILED(hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D11Buffer **)&rb->resource)))
680 trace("Failed to create staging buffer, hr %#x.\n", hr);
681 ID3D11Device_Release(device);
682 return;
685 rb->width = buffer_desc.ByteWidth;
686 rb->height = 1;
687 rb->sub_resource_idx = 0;
689 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
691 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)buffer);
692 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, 0,
693 D3D11_MAP_READ, 0, &rb->map_desc)))
695 trace("Failed to map buffer, hr %#x.\n", hr);
696 ID3D11Resource_Release(rb->resource);
697 rb->resource = NULL;
698 ID3D11DeviceContext_Release(rb->immediate_context);
699 rb->immediate_context = NULL;
702 ID3D11Device_Release(device);
705 static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
706 struct resource_readback *rb)
708 D3D11_TEXTURE2D_DESC texture_desc;
709 unsigned int miplevel;
710 ID3D11Device *device;
711 HRESULT hr;
713 memset(rb, 0, sizeof(*rb));
715 ID3D11Texture2D_GetDevice(texture, &device);
717 ID3D11Texture2D_GetDesc(texture, &texture_desc);
718 texture_desc.Usage = D3D11_USAGE_STAGING;
719 texture_desc.BindFlags = 0;
720 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
721 texture_desc.MiscFlags = 0;
722 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->resource)))
724 trace("Failed to create texture, hr %#x.\n", hr);
725 ID3D11Device_Release(device);
726 return;
729 miplevel = sub_resource_idx % texture_desc.MipLevels;
730 rb->width = max(1, texture_desc.Width >> miplevel);
731 rb->height = max(1, texture_desc.Height >> miplevel);
732 rb->sub_resource_idx = sub_resource_idx;
734 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
736 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)texture);
737 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, sub_resource_idx,
738 D3D11_MAP_READ, 0, &rb->map_desc)))
740 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
741 ID3D11Resource_Release(rb->resource);
742 rb->resource = NULL;
743 ID3D11DeviceContext_Release(rb->immediate_context);
744 rb->immediate_context = NULL;
747 ID3D11Device_Release(device);
750 static void *get_readback_data(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned byte_width)
752 return (BYTE *)rb->map_desc.pData + y * rb->map_desc.RowPitch + x * byte_width;
755 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y)
757 return *(DWORD *)get_readback_data(rb, x, y, sizeof(DWORD));
760 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
762 return *(float *)get_readback_data(rb, x, y, sizeof(float));
765 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
767 return get_readback_data(rb, x, y, sizeof(struct vec4));
770 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
772 return get_readback_data(rb, x, y, sizeof(struct uvec4));
775 static void release_resource_readback(struct resource_readback *rb)
777 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
778 ID3D11Resource_Release(rb->resource);
779 ID3D11DeviceContext_Release(rb->immediate_context);
782 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
784 struct resource_readback rb;
785 DWORD color;
787 get_texture_readback(texture, 0, &rb);
788 color = get_readback_color(&rb, x, y);
789 release_resource_readback(&rb);
791 return color;
794 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
795 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
796 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
798 struct resource_readback rb;
799 unsigned int x = 0, y = 0;
800 BOOL all_match = TRUE;
801 RECT default_rect;
802 DWORD color = 0;
804 get_texture_readback(texture, sub_resource_idx, &rb);
805 if (!rect)
807 SetRect(&default_rect, 0, 0, rb.width, rb.height);
808 rect = &default_rect;
810 for (y = rect->top; y < rect->bottom; ++y)
812 for (x = rect->left; x < rect->right; ++x)
814 color = get_readback_color(&rb, x, y);
815 if (!compare_color(color, expected_color, max_diff))
817 all_match = FALSE;
818 break;
821 if (!all_match)
822 break;
824 release_resource_readback(&rb);
825 ok_(__FILE__, line)(all_match,
826 "Got 0x%08x, expected 0x%08x at (%u, %u), sub-resource %u.\n",
827 color, expected_color, x, y, sub_resource_idx);
830 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
831 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
832 DWORD expected_color, BYTE max_diff)
834 unsigned int sub_resource_idx, sub_resource_count;
835 D3D11_TEXTURE2D_DESC texture_desc;
837 ID3D11Texture2D_GetDesc(texture, &texture_desc);
838 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
839 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
840 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
843 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
844 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
845 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
847 struct resource_readback rb;
848 unsigned int x = 0, y = 0;
849 BOOL all_match = TRUE;
850 float value = 0.0f;
851 RECT default_rect;
853 get_texture_readback(texture, sub_resource_idx, &rb);
854 if (!rect)
856 SetRect(&default_rect, 0, 0, rb.width, rb.height);
857 rect = &default_rect;
859 for (y = rect->top; y < rect->bottom; ++y)
861 for (x = rect->left; x < rect->right; ++x)
863 value = get_readback_float(&rb, x, y);
864 if (!compare_float(value, expected_value, max_diff))
866 all_match = FALSE;
867 break;
870 if (!all_match)
871 break;
873 release_resource_readback(&rb);
874 ok_(__FILE__, line)(all_match,
875 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
876 value, expected_value, x, y, sub_resource_idx);
879 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
880 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
881 float expected_value, BYTE max_diff)
883 unsigned int sub_resource_idx, sub_resource_count;
884 D3D11_TEXTURE2D_DESC texture_desc;
886 ID3D11Texture2D_GetDesc(texture, &texture_desc);
887 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
888 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
889 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
892 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
893 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
894 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
896 struct resource_readback rb;
897 unsigned int x = 0, y = 0;
898 struct vec4 value = {0};
899 BOOL all_match = TRUE;
900 RECT default_rect;
902 get_texture_readback(texture, sub_resource_idx, &rb);
903 if (!rect)
905 SetRect(&default_rect, 0, 0, rb.width, rb.height);
906 rect = &default_rect;
908 for (y = rect->top; y < rect->bottom; ++y)
910 for (x = rect->left; x < rect->right; ++x)
912 value = *get_readback_vec4(&rb, x, y);
913 if (!compare_vec4(&value, expected_value, max_diff))
915 all_match = FALSE;
916 break;
919 if (!all_match)
920 break;
922 release_resource_readback(&rb);
923 ok_(__FILE__, line)(all_match,
924 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
925 value.x, value.y, value.z, value.w,
926 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
927 x, y, sub_resource_idx);
930 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
931 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
932 const struct vec4 *expected_value, BYTE max_diff)
934 unsigned int sub_resource_idx, sub_resource_count;
935 D3D11_TEXTURE2D_DESC texture_desc;
937 ID3D11Texture2D_GetDesc(texture, &texture_desc);
938 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
939 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
940 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
943 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
944 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
945 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
947 struct resource_readback rb;
948 unsigned int x = 0, y = 0;
949 struct uvec4 value = {0};
950 BOOL all_match = TRUE;
951 RECT default_rect;
953 get_texture_readback(texture, sub_resource_idx, &rb);
954 if (!rect)
956 SetRect(&default_rect, 0, 0, rb.width, rb.height);
957 rect = &default_rect;
959 for (y = rect->top; y < rect->bottom; ++y)
961 for (x = rect->left; x < rect->right; ++x)
963 value = *get_readback_uvec4(&rb, x, y);
964 if (!compare_uvec4(&value, expected_value))
966 all_match = FALSE;
967 break;
970 if (!all_match)
971 break;
973 release_resource_readback(&rb);
974 ok_(__FILE__, line)(all_match,
975 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
976 "at (%u, %u), sub-resource %u.\n",
977 value.x, value.y, value.z, value.w,
978 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
979 x, y, sub_resource_idx);
982 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
983 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
984 const struct uvec4 *expected_value)
986 unsigned int sub_resource_idx, sub_resource_count;
987 D3D11_TEXTURE2D_DESC texture_desc;
989 ID3D11Texture2D_GetDesc(texture, &texture_desc);
990 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
991 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
992 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
995 static ID3D11Device *create_device(const struct device_desc *desc)
997 static const D3D_FEATURE_LEVEL default_feature_level[] =
999 D3D_FEATURE_LEVEL_11_0,
1000 D3D_FEATURE_LEVEL_10_0,
1002 const D3D_FEATURE_LEVEL *feature_level;
1003 UINT flags = desc ? desc->flags : 0;
1004 unsigned int feature_level_count;
1005 ID3D11Device *device;
1007 if (desc && desc->feature_level)
1009 feature_level = desc->feature_level;
1010 feature_level_count = 1;
1012 else
1014 feature_level = default_feature_level;
1015 feature_level_count = ARRAY_SIZE(default_feature_level);
1018 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, feature_level, feature_level_count,
1019 D3D11_SDK_VERSION, &device, NULL, NULL)))
1020 return device;
1021 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags, feature_level, feature_level_count,
1022 D3D11_SDK_VERSION, &device, NULL, NULL)))
1023 return device;
1024 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags, feature_level, feature_level_count,
1025 D3D11_SDK_VERSION, &device, NULL, NULL)))
1026 return device;
1028 return NULL;
1031 static void get_device_adapter_desc(ID3D11Device *device, DXGI_ADAPTER_DESC *adapter_desc)
1033 IDXGIDevice *dxgi_device;
1034 IDXGIAdapter *adapter;
1035 HRESULT hr;
1037 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1038 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1039 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1040 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1041 IDXGIDevice_Release(dxgi_device);
1042 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1043 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1044 IDXGIAdapter_Release(adapter);
1047 static BOOL is_warp_device(ID3D11Device *device)
1049 DXGI_ADAPTER_DESC adapter_desc;
1050 get_device_adapter_desc(device, &adapter_desc);
1051 return !adapter_desc.SubSysId && !adapter_desc.Revision
1052 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1053 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1056 static BOOL is_vendor_device(ID3D11Device *device, unsigned int vendor_id)
1058 DXGI_ADAPTER_DESC adapter_desc;
1060 if (!strcmp(winetest_platform, "wine"))
1061 return FALSE;
1063 get_device_adapter_desc(device, &adapter_desc);
1064 return adapter_desc.VendorId == vendor_id;
1067 static BOOL is_amd_device(ID3D11Device *device)
1069 return is_vendor_device(device, 0x1002);
1072 static BOOL is_intel_device(ID3D11Device *device)
1074 return is_vendor_device(device, 0x8086);
1077 static BOOL is_nvidia_device(ID3D11Device *device)
1079 return is_vendor_device(device, 0x10de);
1082 static BOOL check_compute_shaders_via_sm4_support(ID3D11Device *device)
1084 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
1086 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1087 D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(options))))
1088 return FALSE;
1089 return options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x;
1092 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, const struct swapchain_desc *swapchain_desc)
1094 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1095 IDXGISwapChain *swapchain;
1096 IDXGIDevice *dxgi_device;
1097 IDXGIAdapter *adapter;
1098 IDXGIFactory *factory;
1099 HRESULT hr;
1101 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1102 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1103 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1104 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1105 IDXGIDevice_Release(dxgi_device);
1106 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1107 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1108 IDXGIAdapter_Release(adapter);
1110 dxgi_desc.BufferDesc.Width = 640;
1111 dxgi_desc.BufferDesc.Height = 480;
1112 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1113 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1114 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1115 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1116 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1117 dxgi_desc.SampleDesc.Count = 1;
1118 dxgi_desc.SampleDesc.Quality = 0;
1119 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1120 dxgi_desc.BufferCount = 1;
1121 dxgi_desc.OutputWindow = window;
1122 dxgi_desc.Windowed = TRUE;
1123 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1124 dxgi_desc.Flags = 0;
1126 if (swapchain_desc)
1128 dxgi_desc.Windowed = swapchain_desc->windowed;
1129 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1130 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1132 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1133 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1136 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1137 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1138 IDXGIFactory_Release(factory);
1140 return swapchain;
1143 struct d3d11_test_context
1145 ID3D11Device *device;
1146 HWND window;
1147 IDXGISwapChain *swapchain;
1148 ID3D11Texture2D *backbuffer;
1149 ID3D11RenderTargetView *backbuffer_rtv;
1150 ID3D11DeviceContext *immediate_context;
1152 ID3D11InputLayout *input_layout;
1153 ID3D11VertexShader *vs;
1154 ID3D11Buffer *vb;
1156 ID3D11PixelShader *ps;
1157 ID3D11Buffer *ps_cb;
1160 #define init_test_context(c, l) init_test_context_(__LINE__, c, l)
1161 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1162 const D3D_FEATURE_LEVEL *feature_level)
1164 struct device_desc device_desc;
1165 D3D11_VIEWPORT vp;
1166 HRESULT hr;
1167 RECT rect;
1169 memset(context, 0, sizeof(*context));
1171 device_desc.feature_level = feature_level;
1172 device_desc.flags = 0;
1173 if (!(context->device = create_device(&device_desc)))
1175 skip_(__FILE__, line)("Failed to create device.\n");
1176 return FALSE;
1178 SetRect(&rect, 0, 0, 640, 480);
1179 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1180 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1181 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1182 context->swapchain = create_swapchain(context->device, context->window, NULL);
1183 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1184 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1186 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1187 NULL, &context->backbuffer_rtv);
1188 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1190 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1192 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1194 vp.TopLeftX = 0.0f;
1195 vp.TopLeftY = 0.0f;
1196 vp.Width = 640.0f;
1197 vp.Height = 480.0f;
1198 vp.MinDepth = 0.0f;
1199 vp.MaxDepth = 1.0f;
1200 ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp);
1202 return TRUE;
1205 #define release_test_context(c) release_test_context_(__LINE__, c)
1206 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1208 ULONG ref;
1210 if (context->input_layout)
1211 ID3D11InputLayout_Release(context->input_layout);
1212 if (context->vs)
1213 ID3D11VertexShader_Release(context->vs);
1214 if (context->vb)
1215 ID3D11Buffer_Release(context->vb);
1216 if (context->ps)
1217 ID3D11PixelShader_Release(context->ps);
1218 if (context->ps_cb)
1219 ID3D11Buffer_Release(context->ps_cb);
1221 ID3D11DeviceContext_Release(context->immediate_context);
1222 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1223 ID3D11Texture2D_Release(context->backbuffer);
1224 IDXGISwapChain_Release(context->swapchain);
1225 DestroyWindow(context->window);
1227 ref = ID3D11Device_Release(context->device);
1228 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1231 #define draw_quad(c) draw_quad_(__LINE__, c)
1232 static void draw_quad_(unsigned int line, struct d3d11_test_context *context)
1234 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1236 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1238 static const DWORD default_vs_code[] =
1240 #if 0
1241 float4 main(float4 position : POSITION) : SV_POSITION
1243 return position;
1245 #endif
1246 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1247 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1248 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1249 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1250 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1251 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1252 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1253 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1254 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1255 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1256 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1257 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1258 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1259 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1260 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1262 static const struct vec2 quad[] =
1264 {-1.0f, -1.0f},
1265 {-1.0f, 1.0f},
1266 { 1.0f, -1.0f},
1267 { 1.0f, 1.0f},
1270 ID3D11Device *device = context->device;
1271 unsigned int stride, offset;
1272 HRESULT hr;
1274 if (!context->input_layout)
1276 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1277 default_vs_code, sizeof(default_vs_code), &context->input_layout);
1278 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1280 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1282 hr = ID3D11Device_CreateVertexShader(device, default_vs_code, sizeof(default_vs_code), NULL, &context->vs);
1283 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1286 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1287 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1288 stride = sizeof(*quad);
1289 offset = 0;
1290 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1291 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1293 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1296 #define draw_color_quad(c, color) draw_color_quad_(__LINE__, c, color)
1297 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context, const struct vec4 *color)
1299 static const DWORD ps_color_code[] =
1301 #if 0
1302 float4 color;
1304 float4 main() : SV_TARGET
1306 return color;
1308 #endif
1309 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1310 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1311 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1312 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1313 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1314 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1315 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1316 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1317 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1318 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1319 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1322 ID3D11Device *device = context->device;
1323 HRESULT hr;
1325 if (!context->ps)
1327 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1328 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1331 if (!context->ps_cb)
1332 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1334 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1335 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1337 ID3D11DeviceContext_UpdateSubresource(context->immediate_context, (ID3D11Resource *)context->ps_cb, 0,
1338 NULL, color, 0, 0);
1340 draw_quad_(line, context);
1343 static void test_create_device(void)
1345 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1347 D3D_FEATURE_LEVEL_11_0,
1348 D3D_FEATURE_LEVEL_10_1,
1349 D3D_FEATURE_LEVEL_10_0,
1350 D3D_FEATURE_LEVEL_9_3,
1351 D3D_FEATURE_LEVEL_9_2,
1352 D3D_FEATURE_LEVEL_9_1,
1354 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1355 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1356 ID3D11DeviceContext *immediate_context;
1357 IDXGISwapChain *swapchain;
1358 ID3D11Device *device;
1359 ULONG refcount;
1360 HWND window;
1361 HRESULT hr;
1363 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1364 &device, NULL, NULL)))
1366 skip("Failed to create HAL device.\n");
1367 if ((device = create_device(NULL)))
1369 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
1370 ID3D11Device_Release(device);
1372 return;
1375 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
1376 trace("Feature level %#x.\n", supported_feature_level);
1377 ID3D11Device_Release(device);
1379 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
1380 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1382 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
1383 &feature_level, NULL);
1384 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1385 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1386 feature_level, supported_feature_level);
1388 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
1389 ARRAY_SIZE(default_feature_levels), D3D11_SDK_VERSION, NULL, &feature_level, NULL);
1390 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1391 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1392 feature_level, supported_feature_level);
1394 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
1395 &immediate_context);
1396 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1398 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
1399 refcount = get_refcount(immediate_context);
1400 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1402 ID3D11DeviceContext_GetDevice(immediate_context, &device);
1403 refcount = ID3D11Device_Release(device);
1404 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1406 refcount = ID3D11DeviceContext_Release(immediate_context);
1407 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
1409 device = (ID3D11Device *)0xdeadbeef;
1410 feature_level = 0xdeadbeef;
1411 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1412 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1413 &device, &feature_level, &immediate_context);
1414 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
1415 ok(!device, "Got unexpected device pointer %p.\n", device);
1416 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1417 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1419 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
1421 swapchain_desc.BufferDesc.Width = 800;
1422 swapchain_desc.BufferDesc.Height = 600;
1423 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
1424 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
1425 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1426 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1427 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1428 swapchain_desc.SampleDesc.Count = 1;
1429 swapchain_desc.SampleDesc.Quality = 0;
1430 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1431 swapchain_desc.BufferCount = 1;
1432 swapchain_desc.OutputWindow = window;
1433 swapchain_desc.Windowed = TRUE;
1434 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1435 swapchain_desc.Flags = 0;
1437 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1438 &swapchain_desc, NULL, NULL, NULL, NULL);
1439 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1441 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1442 &swapchain_desc, NULL, NULL, &feature_level, NULL);
1443 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1444 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1445 feature_level, supported_feature_level);
1447 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1448 &swapchain_desc, &swapchain, &device, NULL, NULL);
1449 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1451 memset(&obtained_desc, 0, sizeof(obtained_desc));
1452 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
1453 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
1454 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
1455 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
1456 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
1457 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
1458 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
1459 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
1460 obtained_desc.BufferDesc.RefreshRate.Numerator);
1461 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
1462 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
1463 obtained_desc.BufferDesc.RefreshRate.Denominator);
1464 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
1465 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
1466 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
1467 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
1468 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
1469 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
1470 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
1471 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
1472 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
1473 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
1474 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
1475 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
1476 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
1477 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
1478 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
1479 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
1480 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
1481 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
1482 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
1483 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
1484 ok(obtained_desc.Flags == swapchain_desc.Flags,
1485 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
1487 refcount = IDXGISwapChain_Release(swapchain);
1488 ok(!refcount, "Swapchain has %u references left.\n", refcount);
1490 feature_level = ID3D11Device_GetFeatureLevel(device);
1491 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1492 feature_level, supported_feature_level);
1494 refcount = ID3D11Device_Release(device);
1495 ok(!refcount, "Device has %u references left.\n", refcount);
1497 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1498 NULL, NULL, &device, NULL, NULL);
1499 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1500 ID3D11Device_Release(device);
1502 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1503 NULL, NULL, NULL, NULL, NULL);
1504 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1506 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1507 NULL, NULL, NULL, &feature_level, NULL);
1508 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1509 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1510 feature_level, supported_feature_level);
1512 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1513 NULL, NULL, NULL, NULL, &immediate_context);
1514 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1515 ID3D11DeviceContext_Release(immediate_context);
1517 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1518 &swapchain_desc, NULL, NULL, NULL, NULL);
1519 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1521 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1522 &swapchain_desc, &swapchain, NULL, NULL, NULL);
1523 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1524 IDXGISwapChain_Release(swapchain);
1526 swapchain_desc.OutputWindow = NULL;
1527 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1528 &swapchain_desc, NULL, NULL, NULL, NULL);
1529 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1530 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1531 &swapchain_desc, NULL, &device, NULL, NULL);
1532 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1533 ID3D11Device_Release(device);
1535 swapchain = (IDXGISwapChain *)0xdeadbeef;
1536 device = (ID3D11Device *)0xdeadbeef;
1537 feature_level = 0xdeadbeef;
1538 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1539 swapchain_desc.OutputWindow = NULL;
1540 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1541 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1542 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1543 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1544 ok(!device, "Got unexpected device pointer %p.\n", device);
1545 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1546 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1548 swapchain = (IDXGISwapChain *)0xdeadbeef;
1549 device = (ID3D11Device *)0xdeadbeef;
1550 feature_level = 0xdeadbeef;
1551 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1552 swapchain_desc.OutputWindow = window;
1553 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
1554 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1555 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1556 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1557 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1558 ok(!device, "Got unexpected device pointer %p.\n", device);
1559 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1560 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1562 DestroyWindow(window);
1565 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
1567 struct device_desc device_desc;
1568 IDXGIAdapter *dxgi_adapter;
1569 IDXGIDevice *dxgi_device;
1570 ID3D11Device *device;
1571 IUnknown *iface;
1572 ULONG refcount;
1573 HRESULT hr;
1575 device_desc.feature_level = &feature_level;
1576 device_desc.flags = 0;
1577 if (!(device = create_device(&device_desc)))
1579 skip("Failed to create device for feature level %#x.\n", feature_level);
1580 return;
1583 check_interface(device, &IID_IUnknown, TRUE, FALSE);
1584 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
1585 check_interface(device, &IID_IDXGIDevice, TRUE, FALSE);
1586 check_interface(device, &IID_IDXGIDevice1, TRUE, FALSE);
1587 check_interface(device, &IID_ID3D10Multithread, TRUE, TRUE); /* Not available on all Windows versions. */
1588 todo_wine check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
1589 todo_wine check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
1590 check_interface(device, &IID_ID3D11InfoQueue, FALSE, FALSE); /* Non-debug mode. */
1592 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1593 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1594 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1595 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1596 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1597 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1598 IUnknown_Release(iface);
1599 IDXGIAdapter_Release(dxgi_adapter);
1600 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1601 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1602 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1603 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
1604 IUnknown_Release(iface);
1605 IDXGIAdapter_Release(dxgi_adapter);
1606 IDXGIDevice_Release(dxgi_device);
1608 refcount = ID3D11Device_Release(device);
1609 ok(!refcount, "Device has %u references left.\n", refcount);
1611 device_desc.feature_level = &feature_level;
1612 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
1613 if (!(device = create_device(&device_desc)))
1615 skip("Failed to create debug device for feature level %#x.\n", feature_level);
1616 return;
1619 todo_wine check_interface(device, &IID_ID3D11InfoQueue, TRUE, FALSE);
1621 refcount = ID3D11Device_Release(device);
1622 ok(!refcount, "Device has %u references left.\n", refcount);
1625 static void test_get_immediate_context(void)
1627 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
1628 ULONG expected_refcount, refcount;
1629 ID3D11Device *device;
1631 if (!(device = create_device(NULL)))
1633 skip("Failed to create device.\n");
1634 return;
1637 expected_refcount = get_refcount(device) + 1;
1638 ID3D11Device_GetImmediateContext(device, &immediate_context);
1639 refcount = get_refcount(device);
1640 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1641 previous_immediate_context = immediate_context;
1643 ID3D11Device_GetImmediateContext(device, &immediate_context);
1644 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1645 refcount = get_refcount(device);
1646 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1648 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
1649 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1650 refcount = ID3D11DeviceContext_Release(immediate_context);
1651 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1653 ID3D11Device_GetImmediateContext(device, &immediate_context);
1654 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1655 refcount = ID3D11DeviceContext_Release(immediate_context);
1656 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1658 refcount = ID3D11Device_Release(device);
1659 ok(!refcount, "Device has %u references left.\n", refcount);
1662 static void test_create_texture2d(void)
1664 ULONG refcount, expected_refcount;
1665 D3D11_SUBRESOURCE_DATA data = {0};
1666 D3D_FEATURE_LEVEL feature_level;
1667 ID3D11Device *device, *tmp;
1668 D3D11_TEXTURE2D_DESC desc;
1669 ID3D11Texture2D *texture;
1670 UINT quality_level_count;
1671 unsigned int i;
1672 HRESULT hr;
1674 static const struct
1676 DXGI_FORMAT format;
1677 UINT array_size;
1678 D3D11_BIND_FLAG bind_flags;
1679 UINT misc_flags;
1680 BOOL succeeds;
1681 BOOL todo;
1683 tests[] =
1685 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1686 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1687 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1688 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1689 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1690 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1691 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1692 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1693 FALSE, FALSE},
1694 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1695 FALSE, FALSE},
1696 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1697 FALSE, FALSE},
1698 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1699 TRUE, FALSE},
1700 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1701 TRUE, FALSE},
1702 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1703 TRUE, FALSE},
1704 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1705 TRUE, FALSE},
1706 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1707 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1708 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1709 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1710 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1711 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1712 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1713 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1714 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1715 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1716 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1717 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1718 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1719 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1720 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1721 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1722 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1723 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1724 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1725 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1726 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1727 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1728 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1729 TRUE, FALSE},
1730 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1731 TRUE, FALSE},
1732 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1733 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
1734 FALSE, TRUE},
1735 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1736 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
1737 FALSE, TRUE},
1738 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1739 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1740 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1741 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1742 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1743 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1744 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1745 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1746 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1747 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1748 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1749 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1750 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1751 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1752 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1753 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1754 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1755 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1756 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1757 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1758 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1759 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1760 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1761 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1762 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1763 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1764 FALSE, TRUE},
1765 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1766 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1769 if (!(device = create_device(NULL)))
1771 skip("Failed to create device.\n");
1772 return;
1775 feature_level = ID3D11Device_GetFeatureLevel(device);
1777 desc.Width = 512;
1778 desc.Height = 512;
1779 desc.MipLevels = 1;
1780 desc.ArraySize = 1;
1781 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1782 desc.SampleDesc.Count = 1;
1783 desc.SampleDesc.Quality = 0;
1784 desc.Usage = D3D11_USAGE_DEFAULT;
1785 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1786 desc.CPUAccessFlags = 0;
1787 desc.MiscFlags = 0;
1789 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
1790 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1792 expected_refcount = get_refcount(device) + 1;
1793 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1794 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1795 refcount = get_refcount(device);
1796 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1797 tmp = NULL;
1798 expected_refcount = refcount + 1;
1799 ID3D11Texture2D_GetDevice(texture, &tmp);
1800 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1801 refcount = get_refcount(device);
1802 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1803 ID3D11Device_Release(tmp);
1805 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1806 ID3D11Texture2D_Release(texture);
1808 desc.MipLevels = 0;
1809 expected_refcount = get_refcount(device) + 1;
1810 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1811 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1812 refcount = get_refcount(device);
1813 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1814 tmp = NULL;
1815 expected_refcount = refcount + 1;
1816 ID3D11Texture2D_GetDevice(texture, &tmp);
1817 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1818 refcount = get_refcount(device);
1819 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1820 ID3D11Device_Release(tmp);
1822 ID3D11Texture2D_GetDesc(texture, &desc);
1823 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1824 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1825 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1826 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1827 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1828 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1829 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1830 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1831 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1832 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1833 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1835 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1836 ID3D11Texture2D_Release(texture);
1838 desc.MipLevels = 1;
1839 desc.ArraySize = 2;
1840 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1841 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1843 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1844 ID3D11Texture2D_Release(texture);
1846 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1847 desc.ArraySize = 1;
1848 desc.SampleDesc.Count = 2;
1849 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1850 if (quality_level_count)
1852 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1853 ID3D11Texture2D_Release(texture);
1854 desc.SampleDesc.Quality = quality_level_count;
1855 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1857 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1859 /* We assume 15 samples multisampling is never supported in practice. */
1860 desc.SampleDesc.Count = 15;
1861 desc.SampleDesc.Quality = 0;
1862 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1863 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1865 desc.SampleDesc.Count = 1;
1866 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1868 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
1869 BOOL todo = tests[i].todo;
1871 if (feature_level < D3D_FEATURE_LEVEL_10_1
1872 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
1873 && tests[i].array_size > 6)
1875 expected_hr = E_INVALIDARG;
1876 todo = TRUE;
1879 desc.ArraySize = tests[i].array_size;
1880 desc.Format = tests[i].format;
1881 desc.BindFlags = tests[i].bind_flags;
1882 desc.MiscFlags = tests[i].misc_flags;
1883 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, (ID3D11Texture2D **)&texture);
1885 todo_wine_if(todo)
1886 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
1887 i, hr, desc.Format);
1889 if (SUCCEEDED(hr))
1890 ID3D11Texture2D_Release(texture);
1893 refcount = ID3D11Device_Release(device);
1894 ok(!refcount, "Device has %u references left.\n", refcount);
1897 static void test_texture2d_interfaces(void)
1899 ID3D10Texture2D *d3d10_texture;
1900 D3D11_TEXTURE2D_DESC desc;
1901 ID3D11Texture2D *texture;
1902 ID3D11Device *device;
1903 unsigned int i;
1904 ULONG refcount;
1905 HRESULT hr;
1907 static const struct test
1909 BOOL implements_d3d10_interfaces;
1910 UINT bind_flags;
1911 UINT misc_flags;
1912 UINT expected_bind_flags;
1913 UINT expected_misc_flags;
1915 desc_conversion_tests[] =
1918 TRUE,
1919 D3D11_BIND_SHADER_RESOURCE, 0,
1920 D3D10_BIND_SHADER_RESOURCE, 0
1923 TRUE,
1924 D3D11_BIND_UNORDERED_ACCESS, 0,
1925 D3D11_BIND_UNORDERED_ACCESS, 0
1928 FALSE,
1929 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1930 0, 0
1933 TRUE,
1934 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
1935 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1938 TRUE,
1939 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
1940 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1944 if (!(device = create_device(NULL)))
1946 skip("Failed to create ID3D11Device, skipping tests.\n");
1947 return;
1950 desc.Width = 512;
1951 desc.Height = 512;
1952 desc.MipLevels = 0;
1953 desc.ArraySize = 1;
1954 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1955 desc.SampleDesc.Count = 1;
1956 desc.SampleDesc.Quality = 0;
1957 desc.Usage = D3D11_USAGE_DEFAULT;
1958 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1959 desc.CPUAccessFlags = 0;
1960 desc.MiscFlags = 0;
1962 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1963 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1964 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1965 hr = check_interface(texture, &IID_ID3D10Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
1966 ID3D11Texture2D_Release(texture);
1967 if (FAILED(hr))
1969 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
1970 ID3D11Device_Release(device);
1971 return;
1974 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
1976 const struct test *current = &desc_conversion_tests[i];
1977 D3D10_TEXTURE2D_DESC d3d10_desc;
1978 ID3D10Device *d3d10_device;
1980 desc.Width = 512;
1981 desc.Height = 512;
1982 desc.MipLevels = 1;
1983 desc.ArraySize = 1;
1984 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1985 desc.SampleDesc.Count = 1;
1986 desc.SampleDesc.Quality = 0;
1987 desc.Usage = D3D11_USAGE_DEFAULT;
1988 desc.BindFlags = current->bind_flags;
1989 desc.CPUAccessFlags = 0;
1990 desc.MiscFlags = current->misc_flags;
1992 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1993 /* Shared resources are not supported by REF and WARP devices. */
1994 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1995 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
1996 if (FAILED(hr))
1998 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
1999 continue;
2002 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2004 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2005 ID3D11Texture2D_Release(texture);
2007 if (current->implements_d3d10_interfaces)
2009 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2011 else
2013 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2014 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
2015 continue;
2018 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
2020 ok(d3d10_desc.Width == desc.Width,
2021 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2022 ok(d3d10_desc.Height == desc.Height,
2023 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2024 ok(d3d10_desc.MipLevels == desc.MipLevels,
2025 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2026 ok(d3d10_desc.ArraySize == desc.ArraySize,
2027 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2028 ok(d3d10_desc.Format == desc.Format,
2029 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2030 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
2031 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
2032 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2033 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
2034 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2035 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2036 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2037 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2038 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2039 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2040 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2041 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2043 d3d10_device = (ID3D10Device *)0xdeadbeef;
2044 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
2045 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2046 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2048 ID3D10Texture2D_Release(d3d10_texture);
2051 refcount = ID3D11Device_Release(device);
2052 ok(!refcount, "Device has %u references left.\n", refcount);
2055 static void test_create_texture3d(void)
2057 ULONG refcount, expected_refcount;
2058 D3D11_SUBRESOURCE_DATA data = {0};
2059 ID3D11Device *device, *tmp;
2060 D3D11_TEXTURE3D_DESC desc;
2061 ID3D11Texture3D *texture;
2062 unsigned int i;
2063 HRESULT hr;
2065 static const struct
2067 DXGI_FORMAT format;
2068 D3D11_BIND_FLAG bind_flags;
2069 BOOL succeeds;
2070 BOOL todo;
2072 tests[] =
2074 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
2075 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
2076 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2077 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2078 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2079 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2080 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2081 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2082 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2085 if (!(device = create_device(NULL)))
2087 skip("Failed to create ID3D11Device, skipping tests.\n");
2088 return;
2091 desc.Width = 64;
2092 desc.Height = 64;
2093 desc.Depth = 64;
2094 desc.MipLevels = 1;
2095 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2096 desc.Usage = D3D11_USAGE_DEFAULT;
2097 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2098 desc.CPUAccessFlags = 0;
2099 desc.MiscFlags = 0;
2101 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2102 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2104 expected_refcount = get_refcount(device) + 1;
2105 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2106 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2107 refcount = get_refcount(device);
2108 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2109 tmp = NULL;
2110 expected_refcount = refcount + 1;
2111 ID3D11Texture3D_GetDevice(texture, &tmp);
2112 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2113 refcount = get_refcount(device);
2114 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2115 ID3D11Device_Release(tmp);
2117 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2118 ID3D11Texture3D_Release(texture);
2120 desc.MipLevels = 0;
2121 expected_refcount = get_refcount(device) + 1;
2122 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2123 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2124 refcount = get_refcount(device);
2125 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2126 tmp = NULL;
2127 expected_refcount = refcount + 1;
2128 ID3D11Texture3D_GetDevice(texture, &tmp);
2129 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2130 refcount = get_refcount(device);
2131 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2132 ID3D11Device_Release(tmp);
2134 ID3D11Texture3D_GetDesc(texture, &desc);
2135 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2136 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2137 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2138 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2139 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2140 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2141 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2142 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2143 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2145 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2146 ID3D11Texture3D_Release(texture);
2148 desc.MipLevels = 1;
2149 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2151 desc.Format = tests[i].format;
2152 desc.BindFlags = tests[i].bind_flags;
2153 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, (ID3D11Texture3D **)&texture);
2155 todo_wine_if(tests[i].todo)
2156 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2158 if (SUCCEEDED(hr))
2159 ID3D11Texture3D_Release(texture);
2162 refcount = ID3D11Device_Release(device);
2163 ok(!refcount, "Device has %u references left.\n", refcount);
2166 static void test_texture3d_interfaces(void)
2168 ID3D10Texture3D *d3d10_texture;
2169 D3D11_TEXTURE3D_DESC desc;
2170 ID3D11Texture3D *texture;
2171 ID3D11Device *device;
2172 unsigned int i;
2173 ULONG refcount;
2174 HRESULT hr;
2176 static const struct test
2178 BOOL implements_d3d10_interfaces;
2179 UINT bind_flags;
2180 UINT misc_flags;
2181 UINT expected_bind_flags;
2182 UINT expected_misc_flags;
2184 desc_conversion_tests[] =
2187 TRUE,
2188 D3D11_BIND_SHADER_RESOURCE, 0,
2189 D3D10_BIND_SHADER_RESOURCE, 0
2192 TRUE,
2193 D3D11_BIND_UNORDERED_ACCESS, 0,
2194 D3D11_BIND_UNORDERED_ACCESS, 0
2197 FALSE,
2198 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2199 0, 0
2202 TRUE,
2203 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2204 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2208 if (!(device = create_device(NULL)))
2210 skip("Failed to create ID3D11Device.\n");
2211 return;
2214 desc.Width = 64;
2215 desc.Height = 64;
2216 desc.Depth = 64;
2217 desc.MipLevels = 0;
2218 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2219 desc.Usage = D3D11_USAGE_DEFAULT;
2220 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2221 desc.CPUAccessFlags = 0;
2222 desc.MiscFlags = 0;
2224 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2225 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2226 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2227 hr = check_interface(texture, &IID_ID3D10Texture3D, TRUE, TRUE); /* Not available on all Windows versions. */
2228 ID3D11Texture3D_Release(texture);
2229 if (FAILED(hr))
2231 win_skip("3D textures do not implement ID3D10Texture3D.\n");
2232 ID3D11Device_Release(device);
2233 return;
2236 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2238 const struct test *current = &desc_conversion_tests[i];
2239 D3D10_TEXTURE3D_DESC d3d10_desc;
2240 ID3D10Device *d3d10_device;
2242 desc.Width = 64;
2243 desc.Height = 64;
2244 desc.Depth = 64;
2245 desc.MipLevels = 1;
2246 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2247 desc.Usage = D3D11_USAGE_DEFAULT;
2248 desc.BindFlags = current->bind_flags;
2249 desc.CPUAccessFlags = 0;
2250 desc.MiscFlags = current->misc_flags;
2252 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2253 /* Shared resources are not supported by REF and WARP devices. */
2254 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2255 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
2256 if (FAILED(hr))
2258 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
2259 continue;
2262 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2264 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2265 ID3D11Texture3D_Release(texture);
2267 if (current->implements_d3d10_interfaces)
2269 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
2271 else
2273 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
2274 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2275 continue;
2278 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
2280 ok(d3d10_desc.Width == desc.Width,
2281 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2282 ok(d3d10_desc.Height == desc.Height,
2283 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2284 ok(d3d10_desc.Depth == desc.Depth,
2285 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
2286 ok(d3d10_desc.MipLevels == desc.MipLevels,
2287 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2288 ok(d3d10_desc.Format == desc.Format,
2289 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2290 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2291 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2292 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2293 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2294 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2295 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2296 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2297 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2299 d3d10_device = (ID3D10Device *)0xdeadbeef;
2300 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
2301 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2302 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2304 ID3D10Texture3D_Release(d3d10_texture);
2307 refcount = ID3D11Device_Release(device);
2308 ok(!refcount, "Device has %u references left.\n", refcount);
2311 static void test_create_buffer(void)
2313 ID3D10Buffer *d3d10_buffer;
2314 D3D11_BUFFER_DESC desc;
2315 ID3D11Buffer *buffer;
2316 ID3D11Device *device;
2317 unsigned int i;
2318 ULONG refcount;
2319 HRESULT hr;
2321 static const struct test
2323 BOOL succeeds;
2324 BOOL implements_d3d10_interfaces;
2325 UINT bind_flags;
2326 UINT misc_flags;
2327 UINT structure_stride;
2328 UINT expected_bind_flags;
2329 UINT expected_misc_flags;
2331 tests[] =
2334 TRUE, TRUE,
2335 D3D11_BIND_VERTEX_BUFFER, 0, 0,
2336 D3D10_BIND_VERTEX_BUFFER, 0
2339 TRUE, TRUE,
2340 D3D11_BIND_INDEX_BUFFER, 0, 0,
2341 D3D10_BIND_INDEX_BUFFER, 0
2344 TRUE, TRUE,
2345 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
2346 D3D10_BIND_CONSTANT_BUFFER, 0
2349 TRUE, TRUE,
2350 D3D11_BIND_SHADER_RESOURCE, 0, 0,
2351 D3D10_BIND_SHADER_RESOURCE, 0
2354 TRUE, TRUE,
2355 D3D11_BIND_STREAM_OUTPUT, 0, 0,
2356 D3D10_BIND_STREAM_OUTPUT, 0
2359 TRUE, TRUE,
2360 D3D11_BIND_RENDER_TARGET, 0, 0,
2361 D3D10_BIND_RENDER_TARGET, 0
2364 TRUE, TRUE,
2365 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
2366 D3D11_BIND_UNORDERED_ACCESS, 0
2369 TRUE, TRUE,
2370 0, D3D11_RESOURCE_MISC_SHARED, 0,
2371 0, D3D10_RESOURCE_MISC_SHARED
2374 TRUE, TRUE,
2375 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
2376 0, 0
2379 FALSE, FALSE,
2380 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2383 FALSE, FALSE,
2384 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2387 FALSE, FALSE,
2388 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2391 TRUE, TRUE,
2392 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2393 D3D10_BIND_SHADER_RESOURCE, 0
2396 FALSE, FALSE,
2397 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2400 FALSE, FALSE,
2401 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2404 TRUE, TRUE,
2405 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2406 D3D11_BIND_UNORDERED_ACCESS, 0
2409 FALSE, FALSE,
2410 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2412 /* Structured buffers do not implement ID3D10Buffer. */
2414 TRUE, FALSE,
2415 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2418 TRUE, FALSE,
2419 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2422 FALSE, FALSE,
2423 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
2426 FALSE, FALSE,
2427 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
2430 FALSE, FALSE,
2431 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
2434 FALSE, FALSE,
2435 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
2438 FALSE, FALSE,
2439 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
2442 TRUE, FALSE,
2443 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
2446 FALSE, FALSE,
2447 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
2450 TRUE, FALSE,
2451 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
2454 TRUE, FALSE,
2455 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
2458 FALSE, FALSE,
2459 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
2462 TRUE, FALSE,
2463 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
2466 TRUE, TRUE,
2467 0, 0, 513,
2468 0, 0
2471 TRUE, TRUE,
2472 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
2473 D3D10_BIND_CONSTANT_BUFFER, 0
2476 TRUE, TRUE,
2477 D3D11_BIND_SHADER_RESOURCE, 0, 513,
2478 D3D10_BIND_SHADER_RESOURCE, 0
2481 TRUE, TRUE,
2482 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
2483 D3D11_BIND_UNORDERED_ACCESS, 0
2486 FALSE, FALSE,
2487 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2490 FALSE, FALSE,
2491 D3D11_BIND_SHADER_RESOURCE,
2492 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2495 TRUE, TRUE,
2496 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
2497 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2501 if (!(device = create_device(NULL)))
2503 skip("Failed to create ID3D11Device.\n");
2504 return;
2507 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
2508 hr = check_interface(buffer, &IID_ID3D10Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
2509 ID3D11Buffer_Release(buffer);
2511 if (FAILED(hr))
2513 win_skip("Buffers do not implement ID3D10Buffer.\n");
2514 ID3D11Device_Release(device);
2515 return;
2518 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2520 const struct test *current = &tests[i];
2521 D3D11_BUFFER_DESC obtained_desc;
2522 D3D10_BUFFER_DESC d3d10_desc;
2523 ID3D10Device *d3d10_device;
2524 HRESULT expected_hr;
2526 desc.ByteWidth = 1024;
2527 desc.Usage = D3D11_USAGE_DEFAULT;
2528 desc.BindFlags = current->bind_flags;
2529 desc.CPUAccessFlags = 0;
2530 desc.MiscFlags = current->misc_flags;
2531 desc.StructureByteStride = current->structure_stride;
2533 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2534 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
2535 /* Shared resources are not supported by REF and WARP devices. */
2536 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
2537 i, hr, expected_hr);
2538 if (FAILED(hr))
2540 if (hr == E_OUTOFMEMORY)
2541 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2542 continue;
2545 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
2546 desc.StructureByteStride = 0;
2548 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
2550 ok(obtained_desc.ByteWidth == desc.ByteWidth,
2551 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
2552 ok(obtained_desc.Usage == desc.Usage,
2553 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
2554 ok(obtained_desc.BindFlags == desc.BindFlags,
2555 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
2556 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
2557 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
2558 ok(obtained_desc.MiscFlags == desc.MiscFlags,
2559 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
2560 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
2561 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
2563 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2564 ID3D11Buffer_Release(buffer);
2566 if (current->implements_d3d10_interfaces)
2568 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
2570 else
2572 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
2573 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2574 continue;
2577 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
2579 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
2580 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
2581 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2582 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2583 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2584 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2585 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2586 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2587 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2588 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2590 d3d10_device = (ID3D10Device *)0xdeadbeef;
2591 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
2592 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2593 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2595 ID3D10Buffer_Release(d3d10_buffer);
2598 refcount = ID3D11Device_Release(device);
2599 ok(!refcount, "Device has %u references left.\n", refcount);
2602 static void test_create_depthstencil_view(void)
2604 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2605 D3D11_TEXTURE2D_DESC texture_desc;
2606 ULONG refcount, expected_refcount;
2607 ID3D11DepthStencilView *dsview;
2608 ID3D11Device *device, *tmp;
2609 ID3D11Texture2D *texture;
2610 unsigned int i;
2611 HRESULT hr;
2613 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2614 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2615 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2616 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
2617 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
2618 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
2619 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
2620 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
2621 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
2622 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
2623 static const struct
2625 struct
2627 unsigned int miplevel_count;
2628 unsigned int array_size;
2629 DXGI_FORMAT format;
2630 } texture;
2631 struct dsv_desc dsv_desc;
2632 struct dsv_desc expected_dsv_desc;
2634 tests[] =
2636 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2637 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2638 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2639 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2640 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2641 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2642 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2643 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2644 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2645 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2646 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2647 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2648 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2649 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2650 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2651 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2652 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2653 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2654 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2655 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2656 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2657 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2658 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2659 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2660 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2661 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2662 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2664 static const struct
2666 struct
2668 unsigned int miplevel_count;
2669 unsigned int array_size;
2670 DXGI_FORMAT format;
2671 } texture;
2672 struct dsv_desc dsv_desc;
2674 invalid_desc_tests[] =
2676 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2677 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2678 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2679 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2680 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2681 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2682 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2683 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2684 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2685 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2686 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2687 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2688 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2690 #undef FMT_UNKNOWN
2691 #undef D24S8
2692 #undef R24S8_TL
2693 #undef DIM_UNKNOWN
2694 #undef TEX_1D
2695 #undef TEX_1D_ARRAY
2696 #undef TEX_2D
2697 #undef TEX_2D_ARRAY
2698 #undef TEX_2DMS
2699 #undef TEX_2DMS_ARR
2701 if (!(device = create_device(NULL)))
2703 skip("Failed to create device.\n");
2704 return;
2707 texture_desc.Width = 512;
2708 texture_desc.Height = 512;
2709 texture_desc.MipLevels = 1;
2710 texture_desc.ArraySize = 1;
2711 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2712 texture_desc.SampleDesc.Count = 1;
2713 texture_desc.SampleDesc.Quality = 0;
2714 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2715 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2716 texture_desc.CPUAccessFlags = 0;
2717 texture_desc.MiscFlags = 0;
2719 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2720 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2722 expected_refcount = get_refcount(device) + 1;
2723 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
2724 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2725 refcount = get_refcount(device);
2726 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2727 tmp = NULL;
2728 expected_refcount = refcount + 1;
2729 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
2730 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2731 refcount = get_refcount(device);
2732 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2733 ID3D11Device_Release(tmp);
2735 memset(&dsv_desc, 0, sizeof(dsv_desc));
2736 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2737 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2738 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
2739 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2740 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
2741 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2743 ID3D11DepthStencilView_Release(dsview);
2744 ID3D11Texture2D_Release(texture);
2746 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2748 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
2750 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2751 texture_desc.ArraySize = tests[i].texture.array_size;
2752 texture_desc.Format = tests[i].texture.format;
2754 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2755 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2757 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
2759 current_desc = NULL;
2761 else
2763 current_desc = &dsv_desc;
2764 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2767 expected_refcount = get_refcount(texture);
2768 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
2769 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2770 refcount = get_refcount(texture);
2771 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2773 /* Not available on all Windows versions. */
2774 check_interface(dsview, &IID_ID3D10DepthStencilView, TRUE, TRUE);
2776 memset(&dsv_desc, 0, sizeof(dsv_desc));
2777 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2778 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2780 ID3D11DepthStencilView_Release(dsview);
2781 ID3D11Texture2D_Release(texture);
2784 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2786 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2787 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2788 texture_desc.Format = invalid_desc_tests[i].texture.format;
2790 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2791 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2793 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2794 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2795 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2797 ID3D11Texture2D_Release(texture);
2800 refcount = ID3D11Device_Release(device);
2801 ok(!refcount, "Device has %u references left.\n", refcount);
2804 static void test_depthstencil_view_interfaces(void)
2806 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
2807 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2808 ID3D10DepthStencilView *d3d10_dsview;
2809 D3D11_TEXTURE2D_DESC texture_desc;
2810 ID3D11DepthStencilView *dsview;
2811 ID3D11Texture2D *texture;
2812 ID3D11Device *device;
2813 ULONG refcount;
2814 HRESULT hr;
2816 if (!(device = create_device(NULL)))
2818 skip("Failed to create device.\n");
2819 return;
2822 texture_desc.Width = 512;
2823 texture_desc.Height = 512;
2824 texture_desc.MipLevels = 1;
2825 texture_desc.ArraySize = 1;
2826 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2827 texture_desc.SampleDesc.Count = 1;
2828 texture_desc.SampleDesc.Quality = 0;
2829 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2830 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2831 texture_desc.CPUAccessFlags = 0;
2832 texture_desc.MiscFlags = 0;
2834 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2835 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2837 dsv_desc.Format = texture_desc.Format;
2838 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
2839 dsv_desc.Flags = 0;
2840 U(dsv_desc).Texture2D.MipSlice = 0;
2842 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2843 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2845 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
2846 ID3D11DepthStencilView_Release(dsview);
2847 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2848 "Depth stencil view should implement ID3D10DepthStencilView.\n");
2850 if (FAILED(hr))
2852 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
2853 goto done;
2856 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
2857 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
2858 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
2859 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
2860 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2861 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
2863 ID3D10DepthStencilView_Release(d3d10_dsview);
2865 done:
2866 ID3D11Texture2D_Release(texture);
2868 refcount = ID3D11Device_Release(device);
2869 ok(!refcount, "Device has %u references left.\n", refcount);
2872 static void test_create_rendertarget_view(void)
2874 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
2875 D3D11_TEXTURE3D_DESC texture3d_desc;
2876 D3D11_TEXTURE2D_DESC texture2d_desc;
2877 D3D11_SUBRESOURCE_DATA data = {0};
2878 ULONG refcount, expected_refcount;
2879 D3D11_BUFFER_DESC buffer_desc;
2880 ID3D11RenderTargetView *rtview;
2881 ID3D11Device *device, *tmp;
2882 ID3D11Texture3D *texture3d;
2883 ID3D11Texture2D *texture2d;
2884 ID3D11Resource *texture;
2885 ID3D11Buffer *buffer;
2886 unsigned int i;
2887 HRESULT hr;
2889 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2890 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2891 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2892 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
2893 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
2894 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
2895 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
2896 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
2897 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
2898 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
2899 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
2900 static const struct
2902 struct
2904 unsigned int miplevel_count;
2905 unsigned int depth_or_array_size;
2906 DXGI_FORMAT format;
2907 } texture;
2908 struct rtv_desc rtv_desc;
2909 struct rtv_desc expected_rtv_desc;
2911 tests[] =
2913 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2914 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2915 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2916 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2917 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2918 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2919 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2920 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2921 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2922 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2923 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2924 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2925 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2926 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2927 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2928 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2929 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2930 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2931 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2932 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2933 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2934 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2935 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2936 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2937 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2938 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2939 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2940 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2941 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2942 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2943 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2944 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2945 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2946 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2947 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2948 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2949 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2950 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2951 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2952 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2953 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2954 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2955 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2956 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2958 static const struct
2960 struct
2962 D3D11_RTV_DIMENSION dimension;
2963 unsigned int miplevel_count;
2964 unsigned int depth_or_array_size;
2965 DXGI_FORMAT format;
2966 } texture;
2967 struct rtv_desc rtv_desc;
2969 invalid_desc_tests[] =
2971 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2972 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2973 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2974 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2975 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
2976 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
2977 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
2978 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2979 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
2980 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
2981 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
2982 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
2983 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
2984 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
2985 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
2986 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2987 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2988 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2989 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2990 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2991 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2992 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2993 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2994 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
2995 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
2996 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2997 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2998 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
2999 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3000 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3001 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
3002 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
3003 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
3004 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
3005 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
3007 #undef FMT_UNKNOWN
3008 #undef RGBA8_UNORM
3009 #undef RGBA8_TL
3010 #undef DIM_UNKNOWN
3011 #undef TEX_1D
3012 #undef TEX_1D_ARRAY
3013 #undef TEX_2D
3014 #undef TEX_2D_ARRAY
3015 #undef TEX_2DMS
3016 #undef TEX_2DMS_ARR
3017 #undef TEX_3D
3019 if (!(device = create_device(NULL)))
3021 skip("Failed to create device.\n");
3022 return;
3025 buffer_desc.ByteWidth = 1024;
3026 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3027 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3028 buffer_desc.CPUAccessFlags = 0;
3029 buffer_desc.MiscFlags = 0;
3030 buffer_desc.StructureByteStride = 0;
3032 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
3033 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3035 expected_refcount = get_refcount(device) + 1;
3036 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3037 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3038 refcount = get_refcount(device);
3039 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3040 tmp = NULL;
3041 expected_refcount = refcount + 1;
3042 ID3D11Buffer_GetDevice(buffer, &tmp);
3043 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3044 refcount = get_refcount(device);
3045 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3046 ID3D11Device_Release(tmp);
3048 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3049 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
3050 U1(U(rtv_desc).Buffer).ElementOffset = 0;
3051 U2(U(rtv_desc).Buffer).ElementWidth = 64;
3053 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
3054 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3056 expected_refcount = get_refcount(device) + 1;
3057 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
3058 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
3059 refcount = get_refcount(device);
3060 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3061 tmp = NULL;
3062 expected_refcount = refcount + 1;
3063 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
3064 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3065 refcount = get_refcount(device);
3066 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3067 ID3D11Device_Release(tmp);
3069 /* Not available on all Windows versions. */
3070 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3072 ID3D11RenderTargetView_Release(rtview);
3073 ID3D11Buffer_Release(buffer);
3075 texture2d_desc.Width = 512;
3076 texture2d_desc.Height = 512;
3077 texture2d_desc.SampleDesc.Count = 1;
3078 texture2d_desc.SampleDesc.Quality = 0;
3079 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3080 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3081 texture2d_desc.CPUAccessFlags = 0;
3082 texture2d_desc.MiscFlags = 0;
3084 texture3d_desc.Width = 64;
3085 texture3d_desc.Height = 64;
3086 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3087 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3088 texture3d_desc.CPUAccessFlags = 0;
3089 texture3d_desc.MiscFlags = 0;
3091 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3093 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3095 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3097 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3098 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3099 texture2d_desc.Format = tests[i].texture.format;
3101 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3102 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3103 texture = (ID3D11Resource *)texture2d;
3105 else
3107 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3108 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3109 texture3d_desc.Format = tests[i].texture.format;
3111 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3112 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3113 texture = (ID3D11Resource *)texture3d;
3116 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
3118 current_desc = NULL;
3120 else
3122 current_desc = &rtv_desc;
3123 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3126 expected_refcount = get_refcount(texture);
3127 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3128 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3129 refcount = get_refcount(texture);
3130 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3132 /* Not available on all Windows versions. */
3133 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3135 memset(&rtv_desc, 0, sizeof(rtv_desc));
3136 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
3137 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3139 ID3D11RenderTargetView_Release(rtview);
3140 ID3D11Resource_Release(texture);
3143 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3145 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
3146 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
3148 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3150 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3151 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3152 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3154 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3155 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3156 texture = (ID3D11Resource *)texture2d;
3158 else
3160 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3161 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3162 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3164 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3165 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3166 texture = (ID3D11Resource *)texture3d;
3169 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3170 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3171 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3173 ID3D11Resource_Release(texture);
3176 refcount = ID3D11Device_Release(device);
3177 ok(!refcount, "Device has %u references left.\n", refcount);
3180 static void test_create_shader_resource_view(void)
3182 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
3183 D3D11_TEXTURE3D_DESC texture3d_desc;
3184 D3D11_TEXTURE2D_DESC texture2d_desc;
3185 ULONG refcount, expected_refcount;
3186 ID3D11ShaderResourceView *srview;
3187 D3D_FEATURE_LEVEL feature_level;
3188 D3D11_BUFFER_DESC buffer_desc;
3189 ID3D11Device *device, *tmp;
3190 ID3D11Texture3D *texture3d;
3191 ID3D11Texture2D *texture2d;
3192 ID3D11Resource *texture;
3193 ID3D11Buffer *buffer;
3194 unsigned int i;
3195 HRESULT hr;
3197 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3198 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3199 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3200 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
3201 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
3202 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
3203 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
3204 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
3205 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
3206 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
3207 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
3208 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
3209 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3210 static const struct
3212 struct
3214 unsigned int miplevel_count;
3215 unsigned int depth_or_array_size;
3216 DXGI_FORMAT format;
3217 } texture;
3218 struct srv_desc srv_desc;
3219 struct srv_desc expected_srv_desc;
3221 tests[] =
3223 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3224 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3225 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3226 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3227 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3228 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3229 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3230 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3231 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3232 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3233 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3234 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3235 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3236 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3237 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3238 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3239 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3240 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3241 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3242 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3243 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3244 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3245 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3246 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3247 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3248 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3249 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3250 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3251 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3252 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3253 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3254 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3255 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3256 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3257 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3258 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3259 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3260 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3261 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3262 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3263 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3264 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3265 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3266 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3267 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3268 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
3270 static const struct
3272 struct
3274 D3D11_SRV_DIMENSION dimension;
3275 unsigned int miplevel_count;
3276 unsigned int depth_or_array_size;
3277 DXGI_FORMAT format;
3278 } texture;
3279 struct srv_desc srv_desc;
3281 invalid_desc_tests[] =
3283 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3284 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3285 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3286 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3287 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3288 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3289 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3290 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3291 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3292 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3293 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3294 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3295 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3296 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3297 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3298 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3299 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3300 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3301 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3302 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3303 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3304 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3305 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3306 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3307 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
3308 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
3309 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3310 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3311 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3312 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
3313 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
3314 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
3315 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
3316 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
3317 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3318 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3319 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3320 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3321 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3322 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3323 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3324 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3325 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3326 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3327 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3328 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3329 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3330 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3331 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3332 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3333 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3334 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3336 #undef FMT_UNKNOWN
3337 #undef RGBA8_UNORM
3338 #undef DIM_UNKNOWN
3339 #undef TEX_1D
3340 #undef TEX_1D_ARRAY
3341 #undef TEX_2D
3342 #undef TEX_2D_ARRAY
3343 #undef TEX_2DMS
3344 #undef TEX_2DMS_ARR
3345 #undef TEX_3D
3346 #undef TEX_CUBE
3347 #undef CUBE_ARRAY
3349 if (!(device = create_device(NULL)))
3351 skip("Failed to create device.\n");
3352 return;
3354 feature_level = ID3D11Device_GetFeatureLevel(device);
3356 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
3358 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3359 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3361 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3362 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
3363 U1(U(srv_desc).Buffer).ElementOffset = 0;
3364 U2(U(srv_desc).Buffer).ElementWidth = 64;
3366 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
3367 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3369 expected_refcount = get_refcount(device) + 1;
3370 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
3371 ok(SUCCEEDED(hr), "Failed to create a shader resource 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 ID3D11ShaderResourceView_GetDevice(srview, &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 /* Not available on all Windows versions. */
3383 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
3384 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3386 ID3D11ShaderResourceView_Release(srview);
3387 ID3D11Buffer_Release(buffer);
3389 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
3391 buffer_desc.ByteWidth = 1024;
3392 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3393 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3394 buffer_desc.CPUAccessFlags = 0;
3395 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
3396 buffer_desc.StructureByteStride = 4;
3398 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3399 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3401 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3402 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
3404 memset(&srv_desc, 0, sizeof(srv_desc));
3405 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3407 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
3408 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
3409 srv_desc.ViewDimension);
3410 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
3411 U1(U(srv_desc).Buffer).FirstElement);
3412 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
3413 U2(U(srv_desc).Buffer).NumElements);
3415 ID3D11ShaderResourceView_Release(srview);
3416 ID3D11Buffer_Release(buffer);
3418 else
3420 skip("Structured buffers require feature level 11_0.\n");
3423 texture2d_desc.Width = 512;
3424 texture2d_desc.Height = 512;
3425 texture2d_desc.SampleDesc.Count = 1;
3426 texture2d_desc.SampleDesc.Quality = 0;
3427 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3428 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3429 texture2d_desc.CPUAccessFlags = 0;
3431 texture3d_desc.Width = 64;
3432 texture3d_desc.Height = 64;
3433 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3434 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3435 texture3d_desc.CPUAccessFlags = 0;
3436 texture3d_desc.MiscFlags = 0;
3438 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3440 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
3442 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
3444 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3445 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3446 texture2d_desc.Format = tests[i].texture.format;
3447 texture2d_desc.MiscFlags = 0;
3449 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3450 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3451 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3453 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
3454 && (texture2d_desc.ArraySize != 6
3455 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3456 && feature_level < D3D_FEATURE_LEVEL_10_1)
3458 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3459 continue;
3462 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3463 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3464 texture = (ID3D11Resource *)texture2d;
3466 else
3468 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3469 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3470 texture3d_desc.Format = tests[i].texture.format;
3472 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3473 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3474 texture = (ID3D11Resource *)texture3d;
3477 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
3479 current_desc = NULL;
3481 else
3483 current_desc = &srv_desc;
3484 get_srv_desc(current_desc, &tests[i].srv_desc);
3487 expected_refcount = get_refcount(texture);
3488 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3489 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3490 refcount = get_refcount(texture);
3491 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3493 /* Not available on all Windows versions. */
3494 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
3495 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3497 memset(&srv_desc, 0, sizeof(srv_desc));
3498 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3499 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3501 ID3D11ShaderResourceView_Release(srview);
3502 ID3D11Resource_Release(texture);
3505 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3507 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
3508 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
3510 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
3512 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3513 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3514 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3515 texture2d_desc.MiscFlags = 0;
3517 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3518 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3519 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3521 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3522 && feature_level < D3D_FEATURE_LEVEL_10_1)
3524 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3525 continue;
3528 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3529 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3530 texture = (ID3D11Resource *)texture2d;
3532 else
3534 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3535 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3536 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3538 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3539 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3540 texture = (ID3D11Resource *)texture3d;
3543 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3544 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3545 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3547 ID3D11Resource_Release(texture);
3550 refcount = ID3D11Device_Release(device);
3551 ok(!refcount, "Device has %u references left.\n", refcount);
3554 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
3556 #if 0
3557 float4 light;
3558 float4x4 mat;
3560 struct input
3562 float4 position : POSITION;
3563 float3 normal : NORMAL;
3566 struct output
3568 float4 position : POSITION;
3569 float4 diffuse : COLOR;
3572 output main(const input v)
3574 output o;
3576 o.position = mul(v.position, mat);
3577 o.diffuse = dot((float3)light, v.normal);
3579 return o;
3581 #endif
3582 static const DWORD vs_4_1[] =
3584 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
3585 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
3586 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
3587 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
3588 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3589 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
3590 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
3591 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3592 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
3593 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
3594 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
3595 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
3596 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
3597 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
3598 0x0100003e,
3600 static const DWORD vs_4_0[] =
3602 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3603 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3604 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3605 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3606 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3607 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3608 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3609 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3610 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3611 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3612 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3613 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3614 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3615 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3616 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3617 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3619 static const DWORD vs_3_0[] =
3621 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3622 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3623 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3624 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3625 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3626 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3627 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3628 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3629 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3630 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3631 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3632 0x0000ffff,
3634 static const DWORD vs_2_0[] =
3636 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3637 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3638 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3639 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3640 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3641 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3642 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3643 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3644 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3645 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3646 0x90e40001, 0x0000ffff,
3649 #if 0
3650 float4 main(const float4 color : COLOR) : SV_TARGET
3652 float4 o;
3654 o = color;
3656 return o;
3658 #endif
3659 static const DWORD ps_4_1[] =
3661 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
3662 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3663 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3664 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3665 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
3666 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3667 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3669 static const DWORD ps_4_0[] =
3671 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
3672 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
3673 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
3674 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
3675 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
3676 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
3677 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
3678 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3679 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
3680 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
3681 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
3682 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
3683 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3684 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
3685 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3686 0x00000000, 0x00000000,
3688 static const DWORD ps_4_0_level_9_0[] =
3690 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
3691 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
3692 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
3693 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
3694 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
3695 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
3696 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
3697 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
3698 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3699 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
3700 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3701 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3702 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
3703 0xabab0054,
3705 static const DWORD ps_4_0_level_9_1[] =
3707 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
3708 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3709 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3710 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3711 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3712 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3713 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3714 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3715 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3716 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3717 0x45475241, 0xabab0054,
3719 static const DWORD ps_4_0_level_9_3[] =
3721 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
3722 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3723 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3724 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3725 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3726 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3727 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3728 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3729 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3730 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3731 0x45475241, 0xabab0054,
3734 #if 0
3735 struct gs_out
3737 float4 pos : SV_POSITION;
3740 [maxvertexcount(4)]
3741 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3743 float offset = 0.1 * vin[0].w;
3744 gs_out v;
3746 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3747 vout.Append(v);
3748 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3749 vout.Append(v);
3750 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3751 vout.Append(v);
3752 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3753 vout.Append(v);
3755 #endif
3756 static const DWORD gs_4_1[] =
3758 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
3759 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3760 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3761 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3762 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
3763 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
3764 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
3765 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
3766 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
3767 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3768 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
3769 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3770 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
3771 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3772 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
3773 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3774 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
3775 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3777 static const DWORD gs_4_0[] =
3779 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3780 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3781 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3782 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3783 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3784 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3785 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3786 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3787 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3788 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3789 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3790 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3791 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3792 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3793 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3794 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3795 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3796 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3799 ULONG refcount, expected_refcount;
3800 struct device_desc device_desc;
3801 ID3D11Device *device, *tmp;
3802 ID3D11GeometryShader *gs;
3803 ID3D11VertexShader *vs;
3804 ID3D11PixelShader *ps;
3805 HRESULT hr;
3807 device_desc.feature_level = &feature_level;
3808 device_desc.flags = 0;
3809 if (!(device = create_device(&device_desc)))
3811 skip("Failed to create device for feature level %#x.\n", feature_level);
3812 return;
3815 /* level_9 shaders */
3816 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
3817 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3818 ID3D11PixelShader_Release(ps);
3820 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
3821 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3822 ID3D11PixelShader_Release(ps);
3824 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
3825 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3826 ID3D11PixelShader_Release(ps);
3828 /* vertex shader */
3829 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
3830 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3832 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
3833 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3835 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
3836 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
3837 hr, feature_level);
3839 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3840 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
3841 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3842 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3843 else
3844 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3846 refcount = get_refcount(device);
3847 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3848 refcount, expected_refcount);
3849 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3851 tmp = NULL;
3852 expected_refcount = refcount + 1;
3853 ID3D11VertexShader_GetDevice(vs, &tmp);
3854 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3855 refcount = get_refcount(device);
3856 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3857 refcount, expected_refcount);
3858 ID3D11Device_Release(tmp);
3860 /* Not available on all Windows versions. */
3861 check_interface(vs, &IID_ID3D10VertexShader, TRUE, TRUE);
3863 refcount = ID3D11VertexShader_Release(vs);
3864 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3867 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
3868 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3870 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3871 hr, feature_level);
3872 refcount = ID3D11VertexShader_Release(vs);
3873 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3875 else
3877 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3878 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3879 hr, feature_level);
3880 if (SUCCEEDED(hr))
3881 ID3D11VertexShader_Release(vs);
3884 /* pixel shader */
3885 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3886 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
3887 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3888 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3889 else
3890 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3892 refcount = get_refcount(device);
3893 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3894 refcount, expected_refcount);
3895 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3897 tmp = NULL;
3898 expected_refcount = refcount + 1;
3899 ID3D11PixelShader_GetDevice(ps, &tmp);
3900 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3901 refcount = get_refcount(device);
3902 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3903 refcount, expected_refcount);
3904 ID3D11Device_Release(tmp);
3906 /* Not available on all Windows versions. */
3907 check_interface(ps, &IID_ID3D10PixelShader, TRUE, TRUE);
3909 refcount = ID3D11PixelShader_Release(ps);
3910 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3913 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
3914 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3916 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
3917 hr, feature_level);
3918 refcount = ID3D11PixelShader_Release(ps);
3919 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3921 else
3923 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3924 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3925 if (SUCCEEDED(hr))
3926 ID3D11PixelShader_Release(ps);
3929 /* geometry shader */
3930 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3931 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
3932 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3933 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3934 else
3935 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3937 refcount = get_refcount(device);
3938 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3939 refcount, expected_refcount);
3940 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3942 tmp = NULL;
3943 expected_refcount = refcount + 1;
3944 ID3D11GeometryShader_GetDevice(gs, &tmp);
3945 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3946 refcount = get_refcount(device);
3947 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3948 refcount, expected_refcount);
3949 ID3D11Device_Release(tmp);
3951 /* Not available on all Windows versions. */
3952 check_interface(gs, &IID_ID3D10GeometryShader, TRUE, TRUE);
3954 refcount = ID3D11GeometryShader_Release(gs);
3955 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3958 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
3959 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3961 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
3962 hr, feature_level);
3963 refcount = ID3D11GeometryShader_Release(gs);
3964 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3966 else
3968 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3969 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
3970 hr, feature_level);
3971 if (SUCCEEDED(hr))
3972 ID3D11GeometryShader_Release(gs);
3975 refcount = ID3D11Device_Release(device);
3976 ok(!refcount, "Device has %u references left.\n", refcount);
3979 static void test_create_sampler_state(void)
3981 static const struct test
3983 D3D11_FILTER filter;
3984 D3D10_FILTER expected_filter;
3986 desc_conversion_tests[] =
3988 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
3989 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
3990 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
3991 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
3992 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
3993 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
3994 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
3995 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
3996 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
3997 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
3998 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
4000 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
4001 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
4003 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
4004 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
4006 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
4007 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
4009 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
4010 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
4011 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
4014 ID3D11SamplerState *sampler_state1, *sampler_state2;
4015 ID3D10SamplerState *d3d10_sampler_state;
4016 ULONG refcount, expected_refcount;
4017 ID3D11Device *device, *tmp;
4018 D3D11_SAMPLER_DESC desc;
4019 unsigned int i;
4020 HRESULT hr;
4022 if (!(device = create_device(NULL)))
4024 skip("Failed to create device.\n");
4025 return;
4028 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
4029 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4031 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
4032 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4033 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4034 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
4035 desc.MipLODBias = 0.0f;
4036 desc.MaxAnisotropy = 16;
4037 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4038 desc.BorderColor[0] = 0.0f;
4039 desc.BorderColor[1] = 1.0f;
4040 desc.BorderColor[2] = 0.0f;
4041 desc.BorderColor[3] = 1.0f;
4042 desc.MinLOD = 0.0f;
4043 desc.MaxLOD = 16.0f;
4045 expected_refcount = get_refcount(device) + 1;
4046 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4047 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4048 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
4049 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4050 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4051 refcount = get_refcount(device);
4052 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4053 tmp = NULL;
4054 expected_refcount = refcount + 1;
4055 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
4056 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4057 refcount = get_refcount(device);
4058 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4059 ID3D11Device_Release(tmp);
4061 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
4062 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4063 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4064 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4065 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4066 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4067 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4068 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4069 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4070 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4071 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4072 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4073 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4075 refcount = ID3D11SamplerState_Release(sampler_state2);
4076 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4077 refcount = ID3D11SamplerState_Release(sampler_state1);
4078 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4080 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4082 const struct test *current = &desc_conversion_tests[i];
4083 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4085 desc.Filter = current->filter;
4086 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4087 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4088 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4089 desc.MipLODBias = 0.0f;
4090 desc.MaxAnisotropy = 16;
4091 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4092 desc.BorderColor[0] = 0.0f;
4093 desc.BorderColor[1] = 1.0f;
4094 desc.BorderColor[2] = 0.0f;
4095 desc.BorderColor[3] = 1.0f;
4096 desc.MinLOD = 0.0f;
4097 desc.MaxLOD = 16.0f;
4099 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4100 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4102 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
4103 (void **)&d3d10_sampler_state);
4104 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4105 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4106 if (FAILED(hr))
4108 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
4109 ID3D11SamplerState_Release(sampler_state1);
4110 break;
4113 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4114 expected_desc.Filter = current->expected_filter;
4115 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4116 expected_desc.MaxAnisotropy = 0;
4117 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4118 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4120 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
4121 ok(d3d10_desc.Filter == expected_desc.Filter,
4122 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
4123 ok(d3d10_desc.AddressU == expected_desc.AddressU,
4124 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
4125 ok(d3d10_desc.AddressV == expected_desc.AddressV,
4126 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
4127 ok(d3d10_desc.AddressW == expected_desc.AddressW,
4128 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
4129 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
4130 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
4131 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4132 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
4133 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4134 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
4135 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
4136 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
4137 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
4138 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
4139 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4140 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
4141 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
4142 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
4143 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
4144 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
4145 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
4147 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
4148 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4149 refcount = ID3D11SamplerState_Release(sampler_state1);
4150 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4153 refcount = ID3D11Device_Release(device);
4154 ok(!refcount, "Device has %u references left.\n", refcount);
4157 static void test_create_blend_state(void)
4159 static const D3D11_BLEND_DESC desc_conversion_tests[] =
4162 FALSE, FALSE,
4165 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4166 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
4171 FALSE, TRUE,
4174 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4175 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4178 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4179 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
4182 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4183 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4186 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4187 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
4190 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4191 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4194 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4195 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4198 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4199 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4202 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4203 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4208 FALSE, TRUE,
4211 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4212 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4215 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
4216 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4219 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
4220 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4223 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4224 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4227 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
4228 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4231 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
4232 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4235 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4236 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4239 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4240 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4246 ID3D11BlendState *blend_state1, *blend_state2;
4247 D3D11_BLEND_DESC desc, obtained_desc;
4248 ID3D10BlendState *d3d10_blend_state;
4249 D3D10_BLEND_DESC d3d10_blend_desc;
4250 ULONG refcount, expected_refcount;
4251 ID3D11Device *device, *tmp;
4252 unsigned int i, j;
4253 HRESULT hr;
4255 if (!(device = create_device(NULL)))
4257 skip("Failed to create device.\n");
4258 return;
4261 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
4262 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4264 memset(&desc, 0, sizeof(desc));
4265 desc.AlphaToCoverageEnable = FALSE;
4266 desc.IndependentBlendEnable = FALSE;
4267 desc.RenderTarget[0].BlendEnable = FALSE;
4268 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
4269 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
4270 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
4271 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
4272 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
4273 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
4274 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
4276 expected_refcount = get_refcount(device) + 1;
4277 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
4278 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4279 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
4280 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4281 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4282 refcount = get_refcount(device);
4283 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4284 tmp = NULL;
4285 expected_refcount = refcount + 1;
4286 ID3D11BlendState_GetDevice(blend_state1, &tmp);
4287 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4288 refcount = get_refcount(device);
4289 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4290 ID3D11Device_Release(tmp);
4292 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
4293 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
4294 obtained_desc.AlphaToCoverageEnable);
4295 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
4296 obtained_desc.IndependentBlendEnable);
4297 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4299 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
4300 "Got unexpected blend enable %#x for render target %u.\n",
4301 obtained_desc.RenderTarget[i].BlendEnable, i);
4302 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
4303 "Got unexpected src blend %u for render target %u.\n",
4304 obtained_desc.RenderTarget[i].SrcBlend, i);
4305 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
4306 "Got unexpected dest blend %u for render target %u.\n",
4307 obtained_desc.RenderTarget[i].DestBlend, i);
4308 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
4309 "Got unexpected blend op %u for render target %u.\n",
4310 obtained_desc.RenderTarget[i].BlendOp, i);
4311 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
4312 "Got unexpected src blend alpha %u for render target %u.\n",
4313 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
4314 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
4315 "Got unexpected dest blend alpha %u for render target %u.\n",
4316 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
4317 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
4318 "Got unexpected blend op alpha %u for render target %u.\n",
4319 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
4320 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
4321 "Got unexpected render target write mask %#x for render target %u.\n",
4322 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
4325 /* Not available on all Windows versions. */
4326 hr = check_interface(blend_state1, &IID_ID3D10BlendState, TRUE, TRUE);
4327 hr = check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
4329 refcount = ID3D11BlendState_Release(blend_state1);
4330 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4331 refcount = ID3D11BlendState_Release(blend_state2);
4332 ok(!refcount, "Blend state has %u references left.\n", refcount);
4334 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4336 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
4338 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
4339 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4341 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
4342 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4343 "Blend state should implement ID3D10BlendState.\n");
4344 if (FAILED(hr))
4346 win_skip("Blend state does not implement ID3D10BlendState.\n");
4347 ID3D11BlendState_Release(blend_state1);
4348 break;
4351 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
4352 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
4353 "Got unexpected alpha to coverage enable %#x for test %u.\n",
4354 d3d10_blend_desc.AlphaToCoverageEnable, i);
4355 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
4356 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
4357 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
4358 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
4359 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
4360 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
4361 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
4362 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
4363 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
4364 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
4365 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
4366 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
4367 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
4369 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
4370 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
4371 "Got unexpected blend enable %#x for test %u, render target %u.\n",
4372 d3d10_blend_desc.BlendEnable[j], i, j);
4373 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
4374 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
4375 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
4378 ID3D10BlendState_Release(d3d10_blend_state);
4380 refcount = ID3D11BlendState_Release(blend_state1);
4381 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4384 refcount = ID3D11Device_Release(device);
4385 ok(!refcount, "Device has %u references left.\n", refcount);
4388 static void test_create_depthstencil_state(void)
4390 ID3D11DepthStencilState *ds_state1, *ds_state2;
4391 ULONG refcount, expected_refcount;
4392 D3D11_DEPTH_STENCIL_DESC ds_desc;
4393 ID3D11Device *device, *tmp;
4394 HRESULT hr;
4396 if (!(device = create_device(NULL)))
4398 skip("Failed to create device.\n");
4399 return;
4402 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
4403 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4405 ds_desc.DepthEnable = TRUE;
4406 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
4407 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
4408 ds_desc.StencilEnable = FALSE;
4409 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
4410 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
4411 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4412 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4413 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4414 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4415 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4416 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4417 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4418 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4420 expected_refcount = get_refcount(device) + 1;
4421 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4422 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4423 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4424 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4425 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4426 refcount = get_refcount(device);
4427 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4428 tmp = NULL;
4429 expected_refcount = refcount + 1;
4430 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
4431 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4432 refcount = get_refcount(device);
4433 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4434 ID3D11Device_Release(tmp);
4436 /* Not available on all Windows versions. */
4437 hr = check_interface(ds_state1, &IID_ID3D10DepthStencilState, TRUE, TRUE);
4439 refcount = ID3D11DepthStencilState_Release(ds_state2);
4440 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4441 refcount = ID3D11DepthStencilState_Release(ds_state1);
4442 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4444 ds_desc.DepthEnable = FALSE;
4445 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
4446 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
4447 ds_desc.StencilEnable = FALSE;
4448 ds_desc.StencilReadMask = 0;
4449 ds_desc.StencilWriteMask = 0;
4450 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
4451 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
4452 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
4453 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
4454 ds_desc.BackFace = ds_desc.FrontFace;
4456 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4457 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4459 memset(&ds_desc, 0, sizeof(ds_desc));
4460 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
4461 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4462 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
4463 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4464 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4465 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4466 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
4467 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4468 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
4469 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4470 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4471 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4472 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4473 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4474 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4475 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4476 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4477 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4478 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4479 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4480 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4481 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4482 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4483 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4484 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4485 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4487 ID3D11DepthStencilState_Release(ds_state1);
4489 refcount = ID3D11Device_Release(device);
4490 ok(!refcount, "Device has %u references left.\n", refcount);
4493 static void test_create_rasterizer_state(void)
4495 ID3D11RasterizerState *rast_state1, *rast_state2;
4496 ID3D10RasterizerState *d3d10_rast_state;
4497 ULONG refcount, expected_refcount;
4498 D3D10_RASTERIZER_DESC d3d10_desc;
4499 D3D11_RASTERIZER_DESC desc;
4500 ID3D11Device *device, *tmp;
4501 HRESULT hr;
4503 if (!(device = create_device(NULL)))
4505 skip("Failed to create device.\n");
4506 return;
4509 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
4510 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4512 desc.FillMode = D3D11_FILL_SOLID;
4513 desc.CullMode = D3D11_CULL_BACK;
4514 desc.FrontCounterClockwise = FALSE;
4515 desc.DepthBias = 0;
4516 desc.DepthBiasClamp = 0.0f;
4517 desc.SlopeScaledDepthBias = 0.0f;
4518 desc.DepthClipEnable = TRUE;
4519 desc.ScissorEnable = FALSE;
4520 desc.MultisampleEnable = FALSE;
4521 desc.AntialiasedLineEnable = FALSE;
4523 expected_refcount = get_refcount(device) + 1;
4524 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
4525 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4526 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
4527 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4528 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4529 refcount = get_refcount(device);
4530 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4531 tmp = NULL;
4532 expected_refcount = refcount + 1;
4533 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
4534 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4535 refcount = get_refcount(device);
4536 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4537 ID3D11Device_Release(tmp);
4539 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
4540 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4541 "Rasterizer state should implement ID3D10RasterizerState.\n");
4542 if (SUCCEEDED(hr))
4544 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
4545 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
4546 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
4547 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
4548 d3d10_desc.FrontCounterClockwise);
4549 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
4550 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
4551 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
4552 d3d10_desc.SlopeScaledDepthBias);
4553 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
4554 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
4555 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
4556 d3d10_desc.MultisampleEnable);
4557 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
4558 d3d10_desc.AntialiasedLineEnable);
4560 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
4561 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4564 refcount = ID3D11RasterizerState_Release(rast_state2);
4565 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4566 refcount = ID3D11RasterizerState_Release(rast_state1);
4567 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4569 refcount = ID3D11Device_Release(device);
4570 ok(!refcount, "Device has %u references left.\n", refcount);
4573 static void test_create_query(void)
4575 static const struct
4577 D3D11_QUERY query;
4578 D3D_FEATURE_LEVEL required_feature_level;
4579 BOOL is_predicate;
4580 BOOL can_use_create_predicate;
4581 BOOL todo;
4583 tests[] =
4585 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4586 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4587 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4588 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4589 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4590 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
4591 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4592 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
4593 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4594 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4595 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4596 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4597 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4598 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4599 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4600 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4603 ULONG refcount, expected_refcount;
4604 D3D_FEATURE_LEVEL feature_level;
4605 D3D11_QUERY_DESC query_desc;
4606 ID3D11Predicate *predicate;
4607 ID3D11Device *device, *tmp;
4608 HRESULT hr, expected_hr;
4609 ID3D11Query *query;
4610 unsigned int i;
4612 if (!(device = create_device(NULL)))
4614 skip("Failed to create device.\n");
4615 return;
4617 feature_level = ID3D11Device_GetFeatureLevel(device);
4619 hr = ID3D11Device_CreateQuery(device, NULL, &query);
4620 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4621 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
4622 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4624 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4626 if (tests[i].required_feature_level > feature_level)
4628 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
4629 continue;
4632 query_desc.Query = tests[i].query;
4633 query_desc.MiscFlags = 0;
4635 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
4636 todo_wine_if(tests[i].todo)
4637 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4639 query_desc.Query = tests[i].query;
4640 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
4641 todo_wine_if(tests[i].todo)
4642 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4643 if (FAILED(hr))
4644 continue;
4646 check_interface(query, &IID_ID3D11Predicate, tests[i].is_predicate, FALSE);
4647 ID3D11Query_Release(query);
4649 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
4650 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
4651 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4653 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
4654 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4655 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4656 if (SUCCEEDED(hr))
4657 ID3D11Predicate_Release(predicate);
4660 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
4661 expected_refcount = get_refcount(device) + 1;
4662 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4663 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4664 refcount = get_refcount(device);
4665 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4666 tmp = NULL;
4667 expected_refcount = refcount + 1;
4668 ID3D11Predicate_GetDevice(predicate, &tmp);
4669 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4670 refcount = get_refcount(device);
4671 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4672 ID3D11Device_Release(tmp);
4673 /* Not available on all Windows versions. */
4674 check_interface(predicate, &IID_ID3D10Predicate, TRUE, TRUE);
4675 ID3D11Predicate_Release(predicate);
4677 refcount = ID3D11Device_Release(device);
4678 ok(!refcount, "Device has %u references left.\n", refcount);
4681 static void test_occlusion_query(void)
4683 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4684 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4686 struct d3d11_test_context test_context;
4687 D3D11_TEXTURE2D_DESC texture_desc;
4688 ID3D11DeviceContext *context;
4689 ID3D11RenderTargetView *rtv;
4690 D3D11_QUERY_DESC query_desc;
4691 ID3D11Asynchronous *query;
4692 unsigned int data_size, i;
4693 ID3D11Texture2D *texture;
4694 ID3D11Device *device;
4695 D3D11_VIEWPORT vp;
4696 union
4698 UINT64 uint;
4699 DWORD dword[2];
4700 } data;
4701 HRESULT hr;
4703 if (!init_test_context(&test_context, NULL))
4704 return;
4706 device = test_context.device;
4707 context = test_context.immediate_context;
4709 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4711 query_desc.Query = D3D11_QUERY_OCCLUSION;
4712 query_desc.MiscFlags = 0;
4713 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4714 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4715 data_size = ID3D11Asynchronous_GetDataSize(query);
4716 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4718 memset(&data, 0xff, sizeof(data));
4719 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4720 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4721 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4722 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4723 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4724 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4726 ID3D11DeviceContext_End(context, query);
4727 ID3D11DeviceContext_Begin(context, query);
4728 ID3D11DeviceContext_Begin(context, query);
4730 memset(&data, 0xff, sizeof(data));
4731 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4732 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4733 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4734 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4735 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4736 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4738 draw_color_quad(&test_context, &red);
4740 ID3D11DeviceContext_End(context, query);
4741 for (i = 0; i < 500; ++i)
4743 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4744 break;
4745 Sleep(10);
4747 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4749 memset(&data, 0xff, sizeof(data));
4750 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4751 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4752 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4754 memset(&data, 0xff, sizeof(data));
4755 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
4756 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4757 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
4758 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4759 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
4760 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4761 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
4762 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4763 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4764 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4766 memset(&data, 0xff, sizeof(data));
4767 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
4768 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4769 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4770 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4772 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
4773 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4774 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
4775 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4777 ID3D11DeviceContext_Begin(context, query);
4778 ID3D11DeviceContext_End(context, query);
4779 ID3D11DeviceContext_End(context, query);
4781 for (i = 0; i < 500; ++i)
4783 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4784 break;
4785 Sleep(10);
4787 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4789 data.dword[0] = 0x12345678;
4790 data.dword[1] = 0x12345678;
4791 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4792 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4793 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4794 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4795 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4797 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4798 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4799 texture_desc.MipLevels = 1;
4800 texture_desc.ArraySize = 1;
4801 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4802 texture_desc.SampleDesc.Count = 1;
4803 texture_desc.SampleDesc.Quality = 0;
4804 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4805 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4806 texture_desc.CPUAccessFlags = 0;
4807 texture_desc.MiscFlags = 0;
4808 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4809 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4810 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
4811 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4813 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
4814 vp.TopLeftX = 0.0f;
4815 vp.TopLeftY = 0.0f;
4816 vp.Width = texture_desc.Width;
4817 vp.Height = texture_desc.Height;
4818 vp.MinDepth = 0.0f;
4819 vp.MaxDepth = 1.0f;
4820 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4822 ID3D11DeviceContext_Begin(context, query);
4823 for (i = 0; i < 100; i++)
4824 draw_color_quad(&test_context, &red);
4825 ID3D11DeviceContext_End(context, query);
4827 for (i = 0; i < 500; ++i)
4829 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4830 break;
4831 Sleep(10);
4833 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4835 memset(&data, 0xff, sizeof(data));
4836 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4837 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4838 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4839 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4840 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4841 || (data.dword[0] == 0xffffffff && !data.dword[1])
4842 || broken(!data.uint),
4843 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4845 ID3D11Asynchronous_Release(query);
4846 ID3D11RenderTargetView_Release(rtv);
4847 ID3D11Texture2D_Release(texture);
4848 release_test_context(&test_context);
4851 static void test_timestamp_query(void)
4853 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4855 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
4856 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
4857 struct d3d11_test_context test_context;
4858 ID3D11DeviceContext *context;
4859 D3D11_QUERY_DESC query_desc;
4860 unsigned int data_size, i;
4861 ID3D11Device *device;
4862 UINT64 timestamp;
4863 HRESULT hr;
4865 if (!init_test_context(&test_context, NULL))
4866 return;
4868 device = test_context.device;
4869 context = test_context.immediate_context;
4871 query_desc.Query = D3D11_QUERY_TIMESTAMP;
4872 query_desc.MiscFlags = 0;
4873 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
4874 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4875 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
4876 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
4878 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
4879 query_desc.MiscFlags = 0;
4880 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
4881 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4882 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
4883 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
4885 disjoint.Frequency = 0xdeadbeef;
4886 disjoint.Disjoint = 0xdeadbeef;
4887 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4888 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4889 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4890 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4891 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4892 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
4894 /* Test a TIMESTAMP_DISJOINT query. */
4895 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
4897 disjoint.Frequency = 0xdeadbeef;
4898 disjoint.Disjoint = 0xdeadbeef;
4899 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4900 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4901 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4902 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4903 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4904 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
4906 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
4907 for (i = 0; i < 500; ++i)
4909 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
4910 break;
4911 Sleep(10);
4913 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4915 disjoint.Frequency = 0xdeadbeef;
4916 disjoint.Disjoint = 0xff;
4917 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4918 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4919 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
4920 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4922 prev_disjoint = disjoint;
4924 disjoint.Frequency = 0xdeadbeef;
4925 disjoint.Disjoint = 0xff;
4926 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
4927 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4928 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
4929 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4930 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
4931 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4932 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
4933 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4934 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4935 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
4937 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4938 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4939 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
4940 D3D11_ASYNC_GETDATA_DONOTFLUSH);
4941 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4942 ok(!memcmp(&disjoint, &prev_disjoint, sizeof(disjoint)), "Disjoint data mismatch.\n");
4944 memset(&timestamp, 0xff, sizeof(timestamp));
4945 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
4946 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4947 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4948 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4949 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
4951 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
4952 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
4954 memset(&timestamp, 0xff, sizeof(timestamp));
4955 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4956 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4957 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
4959 draw_color_quad(&test_context, &red);
4961 ID3D11DeviceContext_End(context, timestamp_query);
4962 for (i = 0; i < 500; ++i)
4964 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
4965 break;
4966 Sleep(10);
4968 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4970 timestamp = 0xdeadbeef;
4971 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4972 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4973 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4975 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4976 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4977 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
4979 timestamp = 0xdeadbeef;
4980 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
4981 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4982 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
4983 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4984 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4985 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4986 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
4987 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4988 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4990 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
4991 for (i = 0; i < 500; ++i)
4993 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
4994 break;
4995 Sleep(10);
4997 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4999 disjoint.Frequency = 0xdeadbeef;
5000 disjoint.Disjoint = 0xff;
5001 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5002 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5003 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
5004 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5006 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
5007 ID3D11Asynchronous_Release(timestamp_query);
5008 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5009 query_desc.MiscFlags = 0;
5010 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5011 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5013 draw_color_quad(&test_context, &red);
5015 ID3D11DeviceContext_End(context, timestamp_query);
5016 for (i = 0; i < 500; ++i)
5018 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
5019 break;
5020 Sleep(10);
5022 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5023 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5024 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5026 ID3D11Asynchronous_Release(timestamp_query);
5027 ID3D11Asynchronous_Release(timestamp_disjoint_query);
5028 release_test_context(&test_context);
5031 static void test_device_removed_reason(void)
5033 ID3D11Device *device;
5034 ULONG refcount;
5035 HRESULT hr;
5037 if (!(device = create_device(NULL)))
5039 skip("Failed to create device.\n");
5040 return;
5043 hr = ID3D11Device_GetDeviceRemovedReason(device);
5044 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5045 hr = ID3D11Device_GetDeviceRemovedReason(device);
5046 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5048 refcount = ID3D11Device_Release(device);
5049 ok(!refcount, "Device has %u references left.\n", refcount);
5052 static void test_private_data(void)
5054 ULONG refcount, expected_refcount;
5055 D3D11_TEXTURE2D_DESC texture_desc;
5056 ID3D10Texture2D *d3d10_texture;
5057 ID3D11Device *test_object;
5058 ID3D11Texture2D *texture;
5059 IDXGIDevice *dxgi_device;
5060 IDXGISurface *surface;
5061 ID3D11Device *device;
5062 IUnknown *ptr;
5063 HRESULT hr;
5064 UINT size;
5066 static const GUID test_guid =
5067 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
5068 static const GUID test_guid2 =
5069 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
5070 static const DWORD data[] = {1, 2, 3, 4};
5072 if (!(device = create_device(NULL)))
5074 skip("Failed to create device.\n");
5075 return;
5078 test_object = create_device(NULL);
5080 texture_desc.Width = 512;
5081 texture_desc.Height = 512;
5082 texture_desc.MipLevels = 1;
5083 texture_desc.ArraySize = 1;
5084 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5085 texture_desc.SampleDesc.Count = 1;
5086 texture_desc.SampleDesc.Quality = 0;
5087 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5088 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5089 texture_desc.CPUAccessFlags = 0;
5090 texture_desc.MiscFlags = 0;
5092 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5093 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5094 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
5095 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
5097 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
5098 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5099 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5100 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5101 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5102 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5103 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5104 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5106 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5107 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5108 size = sizeof(ptr) * 2;
5109 ptr = (IUnknown *)0xdeadbeef;
5110 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5111 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5112 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5113 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5115 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
5116 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
5117 size = sizeof(ptr) * 2;
5118 ptr = (IUnknown *)0xdeadbeef;
5119 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
5120 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5121 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5122 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5123 IDXGIDevice_Release(dxgi_device);
5125 refcount = get_refcount(test_object);
5126 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5127 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5128 expected_refcount = refcount + 1;
5129 refcount = get_refcount(test_object);
5130 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5131 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5132 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5133 refcount = get_refcount(test_object);
5134 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5136 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5137 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5138 --expected_refcount;
5139 refcount = get_refcount(test_object);
5140 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5142 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5143 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5144 size = sizeof(data);
5145 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
5146 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5147 refcount = get_refcount(test_object);
5148 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5149 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5150 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5151 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5152 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5154 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5155 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5156 ++expected_refcount;
5157 size = 2 * sizeof(ptr);
5158 ptr = NULL;
5159 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5160 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5161 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
5162 ++expected_refcount;
5163 refcount = get_refcount(test_object);
5164 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5165 IUnknown_Release(ptr);
5166 --expected_refcount;
5168 ptr = (IUnknown *)0xdeadbeef;
5169 size = 1;
5170 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5171 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5172 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5173 size = 2 * sizeof(ptr);
5174 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5175 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5176 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5177 refcount = get_refcount(test_object);
5178 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5180 size = 1;
5181 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5182 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
5183 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5184 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5185 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
5186 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5187 size = 0xdeadbabe;
5188 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
5189 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
5190 ok(size == 0, "Got unexpected size %u.\n", size);
5191 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5192 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
5193 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5194 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5196 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
5197 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5198 ptr = NULL;
5199 size = sizeof(ptr);
5200 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
5201 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5202 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5203 IUnknown_Release(ptr);
5205 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
5206 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5207 "Texture should implement ID3D10Texture2D.\n");
5208 if (SUCCEEDED(hr))
5210 ptr = NULL;
5211 size = sizeof(ptr);
5212 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
5213 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5214 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5215 IUnknown_Release(ptr);
5216 ID3D10Texture2D_Release(d3d10_texture);
5219 IDXGISurface_Release(surface);
5220 ID3D11Texture2D_Release(texture);
5221 refcount = ID3D11Device_Release(device);
5222 ok(!refcount, "Device has %u references left.\n", refcount);
5223 refcount = ID3D11Device_Release(test_object);
5224 ok(!refcount, "Test object has %u references left.\n", refcount);
5227 static void test_state_refcounting(const D3D_FEATURE_LEVEL feature_level)
5229 ID3D11RasterizerState *rasterizer_state, *tmp_rasterizer_state;
5230 ID3D11Predicate *predicate, *tmp_predicate;
5231 ID3D11SamplerState *sampler, *tmp_sampler;
5232 ID3D11ShaderResourceView *srv, *tmp_srv;
5233 ID3D11RenderTargetView *rtv, *tmp_rtv;
5234 D3D11_RASTERIZER_DESC rasterizer_desc;
5235 D3D11_TEXTURE2D_DESC texture_desc;
5236 D3D11_QUERY_DESC predicate_desc;
5237 D3D11_SAMPLER_DESC sampler_desc;
5238 struct device_desc device_desc;
5239 ID3D11DeviceContext *context;
5240 ID3D11Texture2D *texture;
5241 ID3D11Device *device;
5242 ULONG refcount;
5243 HRESULT hr;
5245 device_desc.feature_level = &feature_level;
5246 device_desc.flags = 0;
5247 if (!(device = create_device(&device_desc)))
5249 skip("Failed to create device for feature level %#x.\n", feature_level);
5250 return;
5253 ID3D11Device_GetImmediateContext(device, &context);
5255 /* ID3D11SamplerState */
5256 memset(&sampler_desc, 0, sizeof(sampler_desc));
5257 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5258 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5259 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5260 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5261 sampler_desc.MaxLOD = FLT_MAX;
5262 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
5263 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5265 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
5266 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5267 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5268 ID3D11SamplerState_Release(tmp_sampler);
5270 tmp_sampler = sampler;
5271 refcount = get_refcount(sampler);
5272 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
5273 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
5274 refcount = ID3D11SamplerState_Release(sampler);
5275 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5276 sampler = NULL;
5277 ID3D11DeviceContext_PSGetSamplers(context, 0, 1, &sampler);
5278 ok(sampler == tmp_sampler, "Got sampler %p, expected %p.\n", sampler, tmp_sampler);
5279 refcount = ID3D11SamplerState_Release(sampler);
5280 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5282 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
5283 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5284 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5285 refcount = ID3D11SamplerState_Release(tmp_sampler);
5286 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5288 /* ID3D11RasterizerState */
5289 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
5290 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
5291 rasterizer_desc.CullMode = D3D11_CULL_BACK;
5292 rasterizer_desc.DepthClipEnable = TRUE;
5293 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
5294 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5296 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
5297 refcount = ID3D11RasterizerState_Release(rasterizer_state);
5298 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5299 ID3D11DeviceContext_RSGetState(context, &tmp_rasterizer_state);
5300 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
5301 tmp_rasterizer_state, rasterizer_state);
5302 refcount = ID3D11RasterizerState_Release(tmp_rasterizer_state);
5303 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5305 /* ID3D11ShaderResourceView */
5306 memset(&texture_desc, 0, sizeof(texture_desc));
5307 texture_desc.Width = 32;
5308 texture_desc.Height = 32;
5309 texture_desc.MipLevels = 1;
5310 texture_desc.ArraySize = 1;
5311 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5312 texture_desc.SampleDesc.Count = 1;
5313 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5314 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
5315 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5316 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5317 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
5318 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
5319 ID3D11Texture2D_Release(texture);
5321 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
5322 refcount = ID3D11ShaderResourceView_Release(srv);
5323 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5324 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &tmp_srv);
5325 ok(tmp_srv == srv, "Got SRV %p, expected %p.\n", tmp_srv, srv);
5326 refcount = ID3D11ShaderResourceView_Release(tmp_srv);
5327 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5329 /* ID3D11RenderTargetView */
5330 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5331 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5332 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5333 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
5334 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5335 ID3D11Texture2D_Release(texture);
5337 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
5338 refcount = ID3D11RenderTargetView_Release(rtv);
5339 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5340 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &tmp_rtv, NULL);
5341 ok(tmp_rtv == rtv, "Got RTV %p, expected %p.\n", tmp_rtv, rtv);
5342 refcount = ID3D11RenderTargetView_Release(tmp_rtv);
5343 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5345 /* ID3D11Predicate */
5346 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
5348 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
5349 predicate_desc.MiscFlags = 0;
5350 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
5351 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5353 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
5354 refcount = ID3D11Predicate_Release(predicate);
5355 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5356 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, NULL);
5357 ok(tmp_predicate == predicate, "Got predicate %p, expected %p.\n", tmp_predicate, predicate);
5358 refcount = ID3D11Predicate_Release(tmp_predicate);
5359 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5362 ID3D11DeviceContext_Release(context);
5363 refcount = ID3D11Device_Release(device);
5364 ok(!refcount, "Device has %u references left.\n", refcount);
5367 static void test_device_context_state(void)
5369 ID3DDeviceContextState *context_state, *previous_context_state;
5370 ID3D11SamplerState *sampler, *tmp_sampler;
5371 D3D11_SAMPLER_DESC sampler_desc;
5372 D3D_FEATURE_LEVEL feature_level;
5373 ID3D11DeviceContext1 *context;
5374 ID3D11Device *d3d11_device;
5375 ID3D11Device1 *device;
5376 ULONG refcount;
5377 HRESULT hr;
5379 if (!(d3d11_device = create_device(NULL)))
5381 skip("Failed to create device.\n");
5382 return;
5385 hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11Device1, (void **)&device);
5386 ID3D11Device_Release(d3d11_device);
5387 if (FAILED(hr))
5389 skip("ID3D11Device1 is not available.\n");
5390 return;
5393 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
5394 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
5396 feature_level = ID3D11Device1_GetFeatureLevel(device);
5397 ID3D11Device1_GetImmediateContext1(device, &context);
5399 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5400 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5401 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5402 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5403 sampler_desc.MipLODBias = 0.0f;
5404 sampler_desc.MaxAnisotropy = 0;
5405 sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
5406 sampler_desc.BorderColor[0] = 0.0f;
5407 sampler_desc.BorderColor[1] = 1.0f;
5408 sampler_desc.BorderColor[2] = 0.0f;
5409 sampler_desc.BorderColor[3] = 1.0f;
5410 sampler_desc.MinLOD = 0.0f;
5411 sampler_desc.MaxLOD = 16.0f;
5412 hr = ID3D11Device1_CreateSamplerState(device, &sampler_desc, &sampler);
5413 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5415 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5416 tmp_sampler = NULL;
5417 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5418 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5419 ID3D11SamplerState_Release(tmp_sampler);
5421 feature_level = min(feature_level, D3D_FEATURE_LEVEL_10_1);
5422 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
5423 &IID_ID3D10Device, NULL, &context_state);
5424 ok(SUCCEEDED(hr), "Failed to create device context state, hr %#x.\n", hr);
5425 refcount = get_refcount(context_state);
5426 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
5428 /* Enable ID3D10Device behavior. */
5429 previous_context_state = NULL;
5430 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
5431 refcount = ID3DDeviceContextState_Release(context_state);
5432 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5434 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5435 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
5436 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5437 ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler);
5438 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
5440 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
5441 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
5443 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
5444 refcount = ID3DDeviceContextState_Release(context_state);
5445 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5446 refcount = ID3DDeviceContextState_Release(previous_context_state);
5447 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5449 /* ID3DDeviceContextState retains the previous state. */
5450 tmp_sampler = NULL;
5451 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5452 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5453 ID3D11SamplerState_Release(tmp_sampler);
5455 tmp_sampler = NULL;
5456 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
5457 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
5458 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5459 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
5460 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5461 tmp_sampler = NULL;
5462 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5463 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5464 ID3D11SamplerState_Release(tmp_sampler);
5466 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
5467 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
5469 ID3D11SamplerState_Release(sampler);
5470 ID3D11DeviceContext1_Release(context);
5471 refcount = ID3D11Device1_Release(device);
5472 ok(!refcount, "Device has %u references left.\n", refcount);
5475 static void test_blend(void)
5477 ID3D11BlendState *src_blend, *dst_blend;
5478 struct d3d11_test_context test_context;
5479 ID3D11RenderTargetView *offscreen_rtv;
5480 D3D11_TEXTURE2D_DESC texture_desc;
5481 ID3D11InputLayout *input_layout;
5482 ID3D11DeviceContext *context;
5483 D3D11_BLEND_DESC blend_desc;
5484 unsigned int stride, offset;
5485 ID3D11Texture2D *offscreen;
5486 ID3D11VertexShader *vs;
5487 ID3D11PixelShader *ps;
5488 ID3D11Device *device;
5489 D3D11_VIEWPORT vp;
5490 ID3D11Buffer *vb;
5491 DWORD color;
5492 HRESULT hr;
5494 static const DWORD vs_code[] =
5496 #if 0
5497 struct vs_out
5499 float4 position : SV_POSITION;
5500 float4 color : COLOR;
5503 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5505 struct vs_out o;
5507 o.position = position;
5508 o.color = color;
5510 return o;
5512 #endif
5513 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5514 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5515 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5516 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5517 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5518 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5519 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5520 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5521 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5522 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5524 static const DWORD ps_code[] =
5526 #if 0
5527 struct vs_out
5529 float4 position : SV_POSITION;
5530 float4 color : COLOR;
5533 float4 main(struct vs_out i) : SV_TARGET
5535 return i.color;
5537 #endif
5538 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5539 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5540 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5541 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5542 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5543 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5544 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5545 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5547 static const struct
5549 struct vec3 position;
5550 DWORD diffuse;
5552 quads[] =
5554 /* quad1 */
5555 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5556 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5557 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5558 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5559 /* quad2 */
5560 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5561 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5562 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5563 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5565 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
5567 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
5568 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
5570 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5571 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5573 if (!init_test_context(&test_context, NULL))
5574 return;
5576 device = test_context.device;
5577 context = test_context.immediate_context;
5579 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
5580 vs_code, sizeof(vs_code), &input_layout);
5581 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5583 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5585 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
5586 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5587 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5588 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5590 memset(&blend_desc, 0, sizeof(blend_desc));
5591 blend_desc.RenderTarget[0].BlendEnable = TRUE;
5592 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
5593 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
5594 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
5595 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
5596 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
5597 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
5598 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5600 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
5601 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5603 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
5604 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
5605 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
5606 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
5608 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
5609 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5611 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
5612 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5613 stride = sizeof(*quads);
5614 offset = 0;
5615 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
5616 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
5617 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5619 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
5621 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5622 ID3D11DeviceContext_Draw(context, 4, 0);
5623 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5624 ID3D11DeviceContext_Draw(context, 4, 4);
5626 color = get_texture_color(test_context.backbuffer, 320, 360);
5627 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5628 color = get_texture_color(test_context.backbuffer, 320, 120);
5629 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5631 texture_desc.Width = 128;
5632 texture_desc.Height = 128;
5633 texture_desc.MipLevels = 1;
5634 texture_desc.ArraySize = 1;
5635 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5636 texture_desc.SampleDesc.Count = 1;
5637 texture_desc.SampleDesc.Quality = 0;
5638 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5639 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
5640 texture_desc.CPUAccessFlags = 0;
5641 texture_desc.MiscFlags = 0;
5643 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5644 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5646 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
5647 goto done;
5650 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
5651 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5653 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
5655 vp.TopLeftX = 0.0f;
5656 vp.TopLeftY = 0.0f;
5657 vp.Width = 128.0f;
5658 vp.Height = 128.0f;
5659 vp.MinDepth = 0.0f;
5660 vp.MaxDepth = 1.0f;
5661 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
5663 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
5665 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5666 ID3D11DeviceContext_Draw(context, 4, 0);
5667 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5668 ID3D11DeviceContext_Draw(context, 4, 4);
5670 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5671 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5672 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5673 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5675 ID3D11RenderTargetView_Release(offscreen_rtv);
5676 ID3D11Texture2D_Release(offscreen);
5677 done:
5678 ID3D11BlendState_Release(dst_blend);
5679 ID3D11BlendState_Release(src_blend);
5680 ID3D11PixelShader_Release(ps);
5681 ID3D11VertexShader_Release(vs);
5682 ID3D11Buffer_Release(vb);
5683 ID3D11InputLayout_Release(input_layout);
5684 release_test_context(&test_context);
5687 static void test_texture(void)
5689 struct shader
5691 const DWORD *code;
5692 size_t size;
5694 struct texture
5696 UINT width;
5697 UINT height;
5698 UINT miplevel_count;
5699 UINT array_size;
5700 DXGI_FORMAT format;
5701 D3D11_SUBRESOURCE_DATA data[3];
5704 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
5705 struct d3d11_test_context test_context;
5706 const struct texture *current_texture;
5707 D3D11_TEXTURE2D_DESC texture_desc;
5708 D3D11_SAMPLER_DESC sampler_desc;
5709 const struct shader *current_ps;
5710 D3D_FEATURE_LEVEL feature_level;
5711 ID3D11ShaderResourceView *srv;
5712 ID3D11DeviceContext *context;
5713 ID3D11SamplerState *sampler;
5714 struct resource_readback rb;
5715 ID3D11Texture2D *texture;
5716 struct vec4 ps_constant;
5717 ID3D11PixelShader *ps;
5718 ID3D11Device *device;
5719 unsigned int i, x, y;
5720 ID3D11Buffer *cb;
5721 DWORD color;
5722 HRESULT hr;
5724 static const DWORD ps_ld_code[] =
5726 #if 0
5727 Texture2D t;
5729 float miplevel;
5731 float4 main(float4 position : SV_POSITION) : SV_TARGET
5733 float3 p;
5734 t.GetDimensions(miplevel, p.x, p.y, p.z);
5735 p.z = miplevel;
5736 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5737 return t.Load(int3(p));
5739 #endif
5740 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5741 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5742 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5743 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5744 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5745 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5746 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5747 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5748 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5749 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5750 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5751 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5752 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5753 0x00107e46, 0x00000000, 0x0100003e,
5755 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5756 static const DWORD ps_ld_sint8_code[] =
5758 #if 0
5759 Texture2D<int4> t;
5761 float4 main(float4 position : SV_POSITION) : SV_TARGET
5763 float3 p, s;
5764 int4 c;
5766 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5767 t.GetDimensions(0, s.x, s.y, s.z);
5768 p *= s;
5770 c = t.Load(int3(p));
5771 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5773 #endif
5774 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
5775 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5776 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5777 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5778 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5779 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5780 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5781 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5782 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5783 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5784 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5785 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5786 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5787 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5788 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5789 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5790 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5791 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5793 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5794 static const DWORD ps_ld_uint8_code[] =
5796 #if 0
5797 Texture2D<uint4> t;
5799 float4 main(float4 position : SV_POSITION) : SV_TARGET
5801 float3 p, s;
5803 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5804 t.GetDimensions(0, s.x, s.y, s.z);
5805 p *= s;
5807 return t.Load(int3(p)) / (float4)255;
5809 #endif
5810 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5811 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5812 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5813 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5814 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5815 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5816 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5817 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5818 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5819 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5820 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5821 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5822 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5823 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5824 0x3b808081, 0x0100003e,
5826 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5827 static const DWORD ps_sample_code[] =
5829 #if 0
5830 Texture2D t;
5831 SamplerState s;
5833 float4 main(float4 position : SV_POSITION) : SV_Target
5835 float2 p;
5837 p.x = position.x / 640.0f;
5838 p.y = position.y / 480.0f;
5839 return t.Sample(s, p);
5841 #endif
5842 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5843 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5844 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5845 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5846 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5847 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5848 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5849 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5850 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5851 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5853 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
5854 static const DWORD ps_sample_b_code[] =
5856 #if 0
5857 Texture2D t;
5858 SamplerState s;
5860 float bias;
5862 float4 main(float4 position : SV_POSITION) : SV_Target
5864 float2 p;
5866 p.x = position.x / 640.0f;
5867 p.y = position.y / 480.0f;
5868 return t.SampleBias(s, p, bias);
5870 #endif
5871 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
5872 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5873 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5874 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5875 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5876 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5877 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5878 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5879 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
5880 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5881 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5883 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
5884 static const DWORD ps_sample_l_code[] =
5886 #if 0
5887 Texture2D t;
5888 SamplerState s;
5890 float level;
5892 float4 main(float4 position : SV_POSITION) : SV_Target
5894 float2 p;
5896 p.x = position.x / 640.0f;
5897 p.y = position.y / 480.0f;
5898 return t.SampleLevel(s, p, level);
5900 #endif
5901 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
5902 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5903 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5904 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5905 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5906 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5907 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5908 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5909 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
5910 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5911 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5913 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
5914 static const DWORD ps_sample_2d_array_code[] =
5916 #if 0
5917 Texture2DArray t;
5918 SamplerState s;
5920 float layer;
5922 float4 main(float4 position : SV_POSITION) : SV_TARGET
5924 float3 d;
5925 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5926 t.GetDimensions(d.x, d.y, d.z);
5927 d.z = layer;
5928 return t.Sample(s, p * d);
5930 #endif
5931 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
5932 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5933 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5934 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5935 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
5936 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5937 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5938 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
5939 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
5940 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
5941 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
5942 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
5943 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5945 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
5946 static const DWORD red_data[] =
5948 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5949 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5950 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5951 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5953 static const DWORD green_data[] =
5955 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5956 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5957 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5958 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5960 static const DWORD blue_data[] =
5962 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5963 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5964 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5965 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5967 static const DWORD rgba_level_0[] =
5969 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
5970 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
5971 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
5972 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
5974 static const DWORD rgba_level_1[] =
5976 0xffffffff, 0xff0000ff,
5977 0xff000000, 0xff00ff00,
5979 static const DWORD rgba_level_2[] =
5981 0xffff0000,
5983 static const DWORD srgb_data[] =
5985 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
5986 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
5987 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
5988 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
5990 static const BYTE a8_data[] =
5992 0x00, 0x10, 0x20, 0x30,
5993 0x40, 0x50, 0x60, 0x70,
5994 0x80, 0x90, 0xa0, 0xb0,
5995 0xc0, 0xd0, 0xe0, 0xf0,
5997 static const BYTE bc1_data[] =
5999 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6000 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6001 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6002 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6004 static const BYTE bc2_data[] =
6006 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6007 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6008 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6009 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6011 static const BYTE bc3_data[] =
6013 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6014 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6015 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6016 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6018 static const BYTE bc4_data[] =
6020 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6021 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6022 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6023 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6025 static const BYTE bc5_data[] =
6027 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6028 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6029 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6030 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6032 static const BYTE bc6h_u_data[] =
6034 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6035 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6036 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6037 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6039 static const BYTE bc6h_s_data[] =
6041 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6042 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6043 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6044 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6046 static const BYTE bc7_data[] =
6048 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6049 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6050 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6051 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
6053 static const float r32_float[] =
6055 0.0f, 1.0f, 0.5f, 0.50f,
6056 1.0f, 0.0f, 0.0f, 0.75f,
6057 0.0f, 1.0f, 0.5f, 0.25f,
6058 1.0f, 0.0f, 0.0f, 0.75f,
6060 static const DWORD r32_uint[] =
6062 0, 1, 2, 3,
6063 100, 200, 255, 128,
6064 40, 30, 20, 10,
6065 250, 210, 155, 190,
6067 static const struct texture rgba_texture =
6069 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
6071 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
6072 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
6073 {rgba_level_2, sizeof(*rgba_level_2), 0},
6076 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6077 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6078 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
6079 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6080 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
6081 {{a8_data, 4 * sizeof(*a8_data)}}};
6082 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
6083 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
6084 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
6085 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
6086 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
6087 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
6088 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
6089 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
6090 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
6091 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
6092 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
6093 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
6094 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
6095 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
6096 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
6097 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
6098 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6099 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
6100 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6101 static const struct texture array_2d_texture =
6103 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
6105 {red_data, 6 * sizeof(*red_data)},
6106 {green_data, 4 * sizeof(*green_data)},
6107 {blue_data, 5 * sizeof(*blue_data)},
6110 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6111 {{r32_float, 4 * sizeof(*r32_float)}}};
6112 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6113 {{r32_uint, 4 * sizeof(*r32_uint)}}};
6114 static const DWORD red_colors[] =
6116 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6117 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6118 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6119 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6121 static const DWORD blue_colors[] =
6123 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6124 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6125 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6126 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6128 static const DWORD level_1_colors[] =
6130 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6131 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6132 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6133 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6135 static const DWORD lerp_1_2_colors[] =
6137 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6138 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6139 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6140 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6142 static const DWORD level_2_colors[] =
6144 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6145 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6146 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6147 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6149 static const DWORD srgb_colors[] =
6151 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
6152 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
6153 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
6154 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
6156 static const DWORD a8_colors[] =
6158 0x00000000, 0x10000000, 0x20000000, 0x30000000,
6159 0x40000000, 0x50000000, 0x60000000, 0x70000000,
6160 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
6161 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
6163 static const DWORD bc_colors[] =
6165 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6166 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6167 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6168 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6170 static const DWORD bc4_colors[] =
6172 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
6173 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
6174 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6175 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6177 static const DWORD bc5_colors[] =
6179 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
6180 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
6181 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6182 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6184 static const DWORD bc7_colors[] =
6186 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6187 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6188 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6189 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6191 static const DWORD sint8_colors[] =
6193 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
6194 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
6195 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
6196 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
6198 static const DWORD r32f_colors[] =
6200 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
6201 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6202 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
6203 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6205 static const DWORD r32u_colors[16] =
6207 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6208 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
6209 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
6210 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
6212 static const DWORD zero_colors[4 * 4] = {0};
6213 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6215 static const struct texture_test
6217 const struct shader *ps;
6218 const struct texture *texture;
6219 D3D11_FILTER filter;
6220 float lod_bias;
6221 float min_lod;
6222 float max_lod;
6223 float ps_constant;
6224 const DWORD *expected_colors;
6226 texture_tests[] =
6228 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
6229 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
6230 #define MIP_MAX D3D11_FLOAT32_MAX
6231 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6232 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6233 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6234 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6235 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6236 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6237 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6238 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6239 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6240 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6241 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6242 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6243 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6244 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6245 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6246 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6247 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6248 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6249 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6250 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6251 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6252 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6253 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6254 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6255 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6256 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6257 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6258 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6259 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6260 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6261 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6262 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6263 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6264 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6265 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6266 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6267 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6268 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6269 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
6270 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6271 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6272 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6273 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6274 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
6275 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
6276 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
6277 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
6278 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
6279 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
6280 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
6281 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
6282 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6283 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6284 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6285 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6286 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
6287 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6288 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
6289 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
6290 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
6291 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
6292 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6293 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
6294 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
6295 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
6296 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
6297 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
6298 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
6299 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
6300 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
6301 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6302 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6303 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6304 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6305 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6306 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6307 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6308 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6309 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6310 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6311 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6312 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
6313 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
6314 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
6315 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
6316 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
6317 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
6318 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
6319 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
6320 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
6321 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
6322 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
6323 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
6324 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
6325 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
6326 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
6327 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
6328 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6329 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6330 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
6331 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6332 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6333 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
6334 #undef POINT
6335 #undef POINT_LINEAR
6336 #undef MIP_MAX
6338 static const struct srv_test
6340 const struct shader *ps;
6341 const struct texture *texture;
6342 struct srv_desc srv_desc;
6343 float ps_constant;
6344 const DWORD *expected_colors;
6346 srv_tests[] =
6348 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
6349 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
6350 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
6351 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
6352 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
6353 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
6354 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
6355 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
6356 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
6357 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
6358 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
6359 #define R32_UINT DXGI_FORMAT_R32_UINT
6360 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
6361 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6362 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6363 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6364 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6365 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6366 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6367 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
6368 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
6369 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
6370 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
6371 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
6372 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
6373 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
6374 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
6375 #undef TEX_2D
6376 #undef TEX_2D_ARRAY
6377 #undef BC1_UNORM
6378 #undef BC1_UNORM_SRGB
6379 #undef BC2_UNORM
6380 #undef BC2_UNORM_SRGB
6381 #undef BC3_UNORM
6382 #undef BC3_UNORM_SRGB
6383 #undef R8G8B8A8_UNORM_SRGB
6384 #undef R8G8B8A8_UNORM
6385 #undef R32_FLOAT
6386 #undef R32_UINT
6387 #undef FMT_UNKNOWN
6390 if (!init_test_context(&test_context, NULL))
6391 return;
6393 device = test_context.device;
6394 context = test_context.immediate_context;
6395 feature_level = ID3D11Device_GetFeatureLevel(device);
6397 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6399 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6401 texture_desc.SampleDesc.Count = 1;
6402 texture_desc.SampleDesc.Quality = 0;
6403 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6404 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6405 texture_desc.CPUAccessFlags = 0;
6406 texture_desc.MiscFlags = 0;
6408 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6409 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
6410 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
6411 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
6412 sampler_desc.MipLODBias = 0.0f;
6413 sampler_desc.MaxAnisotropy = 0;
6414 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
6415 sampler_desc.BorderColor[0] = 0.0f;
6416 sampler_desc.BorderColor[1] = 0.0f;
6417 sampler_desc.BorderColor[2] = 0.0f;
6418 sampler_desc.BorderColor[3] = 0.0f;
6419 sampler_desc.MinLOD = 0.0f;
6420 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6422 ps = NULL;
6423 srv = NULL;
6424 sampler = NULL;
6425 texture = NULL;
6426 current_ps = NULL;
6427 current_texture = NULL;
6428 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6430 const struct texture_test *test = &texture_tests[i];
6432 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
6433 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
6434 && feature_level < D3D_FEATURE_LEVEL_11_0)
6436 skip("Feature level >= 11.0 is required for BC7 tests.\n");
6437 continue;
6440 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
6441 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
6442 && feature_level < D3D_FEATURE_LEVEL_11_0)
6444 skip("Feature level >= 11.0 is required for BC6H tests.\n");
6445 continue;
6448 if (current_ps != test->ps)
6450 if (ps)
6451 ID3D11PixelShader_Release(ps);
6453 current_ps = test->ps;
6455 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6456 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6458 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6461 if (current_texture != test->texture)
6463 if (texture)
6464 ID3D11Texture2D_Release(texture);
6465 if (srv)
6466 ID3D11ShaderResourceView_Release(srv);
6468 current_texture = test->texture;
6470 if (current_texture)
6472 texture_desc.Width = current_texture->width;
6473 texture_desc.Height = current_texture->height;
6474 texture_desc.MipLevels = current_texture->miplevel_count;
6475 texture_desc.ArraySize = current_texture->array_size;
6476 texture_desc.Format = current_texture->format;
6478 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6479 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6481 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6482 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6484 else
6486 texture = NULL;
6487 srv = NULL;
6490 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6493 if (!sampler || (sampler_desc.Filter != test->filter
6494 || sampler_desc.MipLODBias != test->lod_bias
6495 || sampler_desc.MinLOD != test->min_lod
6496 || sampler_desc.MaxLOD != test->max_lod))
6498 if (sampler)
6499 ID3D11SamplerState_Release(sampler);
6501 sampler_desc.Filter = test->filter;
6502 sampler_desc.MipLODBias = test->lod_bias;
6503 sampler_desc.MinLOD = test->min_lod;
6504 sampler_desc.MaxLOD = test->max_lod;
6506 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6507 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6509 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6512 ps_constant.x = test->ps_constant;
6513 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6515 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6517 draw_quad(&test_context);
6519 get_texture_readback(test_context.backbuffer, 0, &rb);
6520 for (y = 0; y < 4; ++y)
6522 for (x = 0; x < 4; ++x)
6524 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6525 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
6526 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6529 release_resource_readback(&rb);
6531 if (srv)
6532 ID3D11ShaderResourceView_Release(srv);
6533 ID3D11SamplerState_Release(sampler);
6534 if (texture)
6535 ID3D11Texture2D_Release(texture);
6536 ID3D11PixelShader_Release(ps);
6538 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_10_1)
6540 win_skip("SRV tests are broken on WARP.\n");
6541 ID3D11Buffer_Release(cb);
6542 release_test_context(&test_context);
6543 return;
6546 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6547 sampler_desc.MipLODBias = 0.0f;
6548 sampler_desc.MinLOD = 0.0f;
6549 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6551 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6552 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6554 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6556 ps = NULL;
6557 srv = NULL;
6558 texture = NULL;
6559 current_ps = NULL;
6560 current_texture = NULL;
6561 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
6563 const struct srv_test *test = &srv_tests[i];
6565 if (current_ps != test->ps)
6567 if (ps)
6568 ID3D11PixelShader_Release(ps);
6570 current_ps = test->ps;
6572 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6573 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6575 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6578 if (current_texture != test->texture)
6580 if (texture)
6581 ID3D11Texture2D_Release(texture);
6583 current_texture = test->texture;
6585 texture_desc.Width = current_texture->width;
6586 texture_desc.Height = current_texture->height;
6587 texture_desc.MipLevels = current_texture->miplevel_count;
6588 texture_desc.ArraySize = current_texture->array_size;
6589 texture_desc.Format = current_texture->format;
6591 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6592 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6595 if (srv)
6596 ID3D11ShaderResourceView_Release(srv);
6598 get_srv_desc(&srv_desc, &test->srv_desc);
6599 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
6600 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6602 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6604 ps_constant.x = test->ps_constant;
6605 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6607 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6609 draw_quad(&test_context);
6611 get_texture_readback(test_context.backbuffer, 0, &rb);
6612 for (y = 0; y < 4; ++y)
6614 for (x = 0; x < 4; ++x)
6616 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6617 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
6618 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6621 release_resource_readback(&rb);
6623 ID3D11PixelShader_Release(ps);
6624 ID3D11Texture2D_Release(texture);
6625 ID3D11ShaderResourceView_Release(srv);
6626 ID3D11SamplerState_Release(sampler);
6628 ID3D11Buffer_Release(cb);
6629 release_test_context(&test_context);
6632 static void test_cube_maps(void)
6634 struct shader
6636 const DWORD *code;
6637 size_t size;
6640 unsigned int i, j, sub_resource_idx, sub_resource_count;
6641 struct d3d11_test_context test_context;
6642 D3D11_TEXTURE2D_DESC texture_desc;
6643 const struct shader *current_ps;
6644 D3D_FEATURE_LEVEL feature_level;
6645 ID3D11ShaderResourceView *srv;
6646 ID3D11DeviceContext *context;
6647 ID3D11Texture2D *rtv_texture;
6648 ID3D11RenderTargetView *rtv;
6649 struct vec4 expected_result;
6650 ID3D11Resource *texture;
6651 ID3D11PixelShader *ps;
6652 ID3D11Device *device;
6653 float data[64 * 64];
6654 ID3D11Buffer *cb;
6655 HRESULT hr;
6656 RECT rect;
6657 struct
6659 unsigned int face;
6660 unsigned int level;
6661 unsigned int cube;
6662 unsigned int padding;
6663 } constant;
6665 static const DWORD ps_cube_code[] =
6667 #if 0
6668 TextureCube t;
6669 SamplerState s;
6671 uint face;
6672 uint level;
6674 float4 main(float4 position : SV_POSITION) : SV_Target
6676 float2 p;
6677 p.x = position.x / 640.0f;
6678 p.y = position.y / 480.0f;
6680 float3 coord;
6681 switch (face)
6683 case 0:
6684 coord = float3(1.0f, p.x, p.y);
6685 break;
6686 case 1:
6687 coord = float3(-1.0f, p.x, p.y);
6688 break;
6689 case 2:
6690 coord = float3(p.x, 1.0f, p.y);
6691 break;
6692 case 3:
6693 coord = float3(p.x, -1.0f, p.y);
6694 break;
6695 case 4:
6696 coord = float3(p.x, p.y, 1.0f);
6697 break;
6698 case 5:
6699 default:
6700 coord = float3(p.x, p.y, -1.0f);
6701 break;
6703 return t.SampleLevel(s, coord, level);
6705 #endif
6706 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
6707 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6708 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6709 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6710 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
6711 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6712 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6713 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
6714 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
6715 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
6716 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
6717 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
6718 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
6719 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6720 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
6721 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
6722 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
6723 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
6724 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
6725 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
6726 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6727 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
6728 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
6729 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
6730 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
6732 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
6733 static const DWORD ps_cube_array_code[] =
6735 #if 0
6736 TextureCubeArray t;
6737 SamplerState s;
6739 uint face;
6740 uint level;
6741 uint cube;
6743 float4 main(float4 position : SV_POSITION) : SV_Target
6745 float2 p;
6746 p.x = position.x / 640.0f;
6747 p.y = position.y / 480.0f;
6749 float3 coord;
6750 switch (face)
6752 case 0:
6753 coord = float3(1.0f, p.x, p.y);
6754 break;
6755 case 1:
6756 coord = float3(-1.0f, p.x, p.y);
6757 break;
6758 case 2:
6759 coord = float3(p.x, 1.0f, p.y);
6760 break;
6761 case 3:
6762 coord = float3(p.x, -1.0f, p.y);
6763 break;
6764 case 4:
6765 coord = float3(p.x, p.y, 1.0f);
6766 break;
6767 case 5:
6768 default:
6769 coord = float3(p.x, p.y, -1.0f);
6770 break;
6772 return t.SampleLevel(s, float4(coord, cube), level);
6774 #endif
6775 0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
6776 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6777 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6778 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6779 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
6780 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
6781 0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
6782 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
6783 0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
6784 0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6785 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
6786 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
6787 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
6788 0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
6789 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
6790 0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
6791 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
6792 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
6793 0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6794 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
6795 0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
6796 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
6797 0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
6798 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
6799 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
6800 0x00000001, 0x0100003e,
6802 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
6803 static const struct ps_test
6805 const struct shader *ps;
6806 unsigned int miplevel_count;
6807 unsigned int array_size;
6809 ps_tests[] =
6811 {&ps_cube, 1, 6},
6812 {&ps_cube, 2, 6},
6813 {&ps_cube, 3, 6},
6814 {&ps_cube, 0, 6},
6816 {&ps_cube_array, 1, 12},
6817 {&ps_cube_array, 2, 12},
6818 {&ps_cube_array, 3, 12},
6819 {&ps_cube_array, 0, 12},
6822 if (!init_test_context(&test_context, NULL))
6823 return;
6825 device = test_context.device;
6826 context = test_context.immediate_context;
6827 feature_level = ID3D11Device_GetFeatureLevel(device);
6829 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
6830 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
6831 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
6832 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6833 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
6834 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
6836 memset(&constant, 0, sizeof(constant));
6837 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
6839 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6840 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6842 ps = NULL;
6843 current_ps = NULL;
6844 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
6846 const struct ps_test *test = &ps_tests[i];
6848 if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
6850 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
6851 continue;
6854 if (current_ps != test->ps)
6856 if (ps)
6857 ID3D11PixelShader_Release(ps);
6859 current_ps = test->ps;
6861 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6862 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6863 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6866 if (!test->miplevel_count)
6868 srv = NULL;
6869 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6871 memset(&expected_result, 0, sizeof(expected_result));
6873 memset(&constant, 0, sizeof(constant));
6874 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
6875 draw_quad(&test_context);
6876 check_texture_vec4(rtv_texture, &expected_result, 0);
6877 constant.level = 1;
6878 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
6879 draw_quad(&test_context);
6880 check_texture_vec4(rtv_texture, &expected_result, 0);
6881 continue;
6884 texture_desc.Width = 64;
6885 texture_desc.Height = 64;
6886 texture_desc.MipLevels = test->miplevel_count;
6887 texture_desc.ArraySize = test->array_size;
6888 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
6889 texture_desc.SampleDesc.Count = 1;
6890 texture_desc.SampleDesc.Quality = 0;
6891 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6892 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6893 texture_desc.CPUAccessFlags = 0;
6894 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
6895 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
6896 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6898 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
6899 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6900 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6902 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
6903 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
6905 for (j = 0; j < ARRAY_SIZE(data); ++j)
6906 data[j] = sub_resource_idx;
6907 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, sub_resource_idx, NULL,
6908 data, texture_desc.Width * sizeof(*data), 0);
6911 expected_result.y = expected_result.z = 0.0f;
6912 expected_result.w = 1.0f;
6913 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
6915 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
6916 constant.level = sub_resource_idx % texture_desc.MipLevels;
6917 constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
6918 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
6920 draw_quad(&test_context);
6921 expected_result.x = sub_resource_idx;
6922 /* Avoid testing values affected by seamless cube map filtering. */
6923 SetRect(&rect, 100, 100, 540, 380);
6924 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
6927 ID3D11Resource_Release(texture);
6928 ID3D11ShaderResourceView_Release(srv);
6930 ID3D11PixelShader_Release(ps);
6932 ID3D11Buffer_Release(cb);
6933 ID3D11RenderTargetView_Release(rtv);
6934 ID3D11Texture2D_Release(rtv_texture);
6935 release_test_context(&test_context);
6938 static void test_depth_stencil_sampling(void)
6940 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
6941 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
6942 ID3D11SamplerState *cmp_sampler, *sampler;
6943 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
6944 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
6945 struct d3d11_test_context test_context;
6946 ID3D11Texture2D *texture, *rt_texture;
6947 D3D11_TEXTURE2D_DESC texture_desc;
6948 D3D11_SAMPLER_DESC sampler_desc;
6949 ID3D11DeviceContext *context;
6950 ID3D11DepthStencilView *dsv;
6951 ID3D11RenderTargetView *rtv;
6952 struct vec4 ps_constant;
6953 ID3D11Device *device;
6954 ID3D11Buffer *cb;
6955 unsigned int i;
6956 HRESULT hr;
6958 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
6959 static const DWORD ps_compare_code[] =
6961 #if 0
6962 Texture2D t;
6963 SamplerComparisonState s;
6965 float ref;
6967 float4 main(float4 position : SV_Position) : SV_Target
6969 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
6971 #endif
6972 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
6973 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6974 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6975 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6976 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
6977 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
6978 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6979 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6980 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
6981 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
6982 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
6983 0x0100003e,
6985 static const DWORD ps_sample_code[] =
6987 #if 0
6988 Texture2D t;
6989 SamplerState s;
6991 float4 main(float4 position : SV_Position) : SV_Target
6993 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
6995 #endif
6996 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
6997 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6998 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6999 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7000 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7001 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7002 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7003 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7004 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7005 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7007 static const DWORD ps_stencil_code[] =
7009 #if 0
7010 Texture2D<uint4> t;
7012 float4 main(float4 position : SV_Position) : SV_Target
7014 float2 s;
7015 t.GetDimensions(s.x, s.y);
7016 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
7018 #endif
7019 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
7020 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7021 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7022 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7023 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
7024 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
7025 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
7026 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
7027 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
7028 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
7029 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
7030 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7031 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
7033 static const DWORD ps_depth_stencil_code[] =
7035 #if 0
7036 SamplerState samp;
7037 Texture2D depth_tex;
7038 Texture2D<uint4> stencil_tex;
7040 float main(float4 position: SV_Position) : SV_Target
7042 float2 s, p;
7043 float depth, stencil;
7044 depth_tex.GetDimensions(s.x, s.y);
7045 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
7046 depth = depth_tex.Sample(samp, p).r;
7047 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
7048 return depth + stencil;
7050 #endif
7051 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
7052 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7053 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7054 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7055 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
7056 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7057 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7058 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
7059 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
7060 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
7061 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
7062 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
7063 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
7064 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
7065 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
7066 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
7068 static const struct test
7070 DXGI_FORMAT typeless_format;
7071 DXGI_FORMAT dsv_format;
7072 DXGI_FORMAT depth_view_format;
7073 DXGI_FORMAT stencil_view_format;
7075 tests[] =
7077 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
7078 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
7079 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
7080 DXGI_FORMAT_R32_FLOAT},
7081 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
7082 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
7083 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
7084 DXGI_FORMAT_R16_UNORM},
7087 if (!init_test_context(&test_context, NULL))
7088 return;
7090 device = test_context.device;
7091 context = test_context.immediate_context;
7093 if (is_amd_device(device))
7095 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
7096 win_skip("Some AMD drivers have a bug affecting the test.\n");
7097 release_test_context(&test_context);
7098 return;
7101 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
7102 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7103 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7104 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7105 sampler_desc.MipLODBias = 0.0f;
7106 sampler_desc.MaxAnisotropy = 0;
7107 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
7108 sampler_desc.BorderColor[0] = 0.0f;
7109 sampler_desc.BorderColor[1] = 0.0f;
7110 sampler_desc.BorderColor[2] = 0.0f;
7111 sampler_desc.BorderColor[3] = 0.0f;
7112 sampler_desc.MinLOD = 0.0f;
7113 sampler_desc.MaxLOD = 0.0f;
7114 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
7115 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7117 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7118 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7119 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
7120 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7122 texture_desc.Width = 640;
7123 texture_desc.Height = 480;
7124 texture_desc.MipLevels = 1;
7125 texture_desc.ArraySize = 1;
7126 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7127 texture_desc.SampleDesc.Count = 1;
7128 texture_desc.SampleDesc.Quality = 0;
7129 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7130 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7131 texture_desc.CPUAccessFlags = 0;
7132 texture_desc.MiscFlags = 0;
7133 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
7134 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7135 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
7136 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
7137 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7139 memset(&ps_constant, 0, sizeof(ps_constant));
7140 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
7141 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7143 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
7144 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7145 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
7146 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7147 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
7148 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7149 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
7150 &ps_depth_stencil);
7151 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7153 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7155 texture_desc.Format = tests[i].typeless_format;
7156 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
7157 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7158 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
7159 texture_desc.Format, hr);
7161 dsv_desc.Format = tests[i].dsv_format;
7162 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
7163 dsv_desc.Flags = 0;
7164 U(dsv_desc).Texture2D.MipSlice = 0;
7165 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7166 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
7167 dsv_desc.Format, hr);
7169 srv_desc.Format = tests[i].depth_view_format;
7170 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
7171 U(srv_desc).Texture2D.MostDetailedMip = 0;
7172 U(srv_desc).Texture2D.MipLevels = 1;
7173 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
7174 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
7175 srv_desc.Format, hr);
7177 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
7178 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
7179 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
7181 ps_constant.x = 0.5f;
7182 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7183 NULL, &ps_constant, 0, 0);
7185 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7186 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7187 draw_quad(&test_context);
7188 check_texture_float(rt_texture, 0.0f, 2);
7190 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
7191 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7192 draw_quad(&test_context);
7193 check_texture_float(rt_texture, 1.0f, 2);
7195 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
7196 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7197 draw_quad(&test_context);
7198 check_texture_float(rt_texture, 0.0f, 2);
7200 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
7201 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7202 draw_quad(&test_context);
7203 check_texture_float(rt_texture, 0.0f, 2);
7205 ps_constant.x = 0.7f;
7206 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7207 NULL, &ps_constant, 0, 0);
7209 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7210 draw_quad(&test_context);
7211 check_texture_float(rt_texture, 1.0f, 2);
7213 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
7214 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7216 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7217 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7218 draw_quad(&test_context);
7219 check_texture_float(rt_texture, 1.0f, 2);
7221 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
7222 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7223 draw_quad(&test_context);
7224 check_texture_float(rt_texture, 0.2f, 2);
7226 if (!tests[i].stencil_view_format)
7228 ID3D11DepthStencilView_Release(dsv);
7229 ID3D11ShaderResourceView_Release(depth_srv);
7230 ID3D11Texture2D_Release(texture);
7231 continue;
7234 srv_desc.Format = tests[i].stencil_view_format;
7235 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
7236 if (hr == E_OUTOFMEMORY)
7238 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
7239 ID3D11DepthStencilView_Release(dsv);
7240 ID3D11ShaderResourceView_Release(depth_srv);
7241 ID3D11Texture2D_Release(texture);
7242 continue;
7244 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
7245 srv_desc.Format, hr);
7247 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
7248 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
7250 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
7251 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7252 draw_quad(&test_context);
7253 check_texture_float(rt_texture, 0.0f, 0);
7255 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
7256 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7257 draw_quad(&test_context);
7258 check_texture_float(rt_texture, 100.0f, 0);
7260 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
7261 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7262 draw_quad(&test_context);
7263 check_texture_float(rt_texture, 255.0f, 0);
7265 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
7266 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
7267 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
7269 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
7270 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7271 draw_quad(&test_context);
7272 check_texture_float(rt_texture, 3.3f, 2);
7274 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
7275 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7276 draw_quad(&test_context);
7277 check_texture_float(rt_texture, 4.0f, 2);
7279 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
7280 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7281 draw_quad(&test_context);
7282 check_texture_float(rt_texture, 0.0f, 2);
7284 ID3D11DepthStencilView_Release(dsv);
7285 ID3D11ShaderResourceView_Release(depth_srv);
7286 ID3D11ShaderResourceView_Release(stencil_srv);
7287 ID3D11Texture2D_Release(texture);
7290 ID3D11Buffer_Release(cb);
7291 ID3D11PixelShader_Release(ps_cmp);
7292 ID3D11PixelShader_Release(ps_depth);
7293 ID3D11PixelShader_Release(ps_depth_stencil);
7294 ID3D11PixelShader_Release(ps_stencil);
7295 ID3D11RenderTargetView_Release(rtv);
7296 ID3D11SamplerState_Release(cmp_sampler);
7297 ID3D11SamplerState_Release(sampler);
7298 ID3D11Texture2D_Release(rt_texture);
7299 release_test_context(&test_context);
7302 static void test_multiple_render_targets(void)
7304 D3D11_TEXTURE2D_DESC texture_desc;
7305 ID3D11InputLayout *input_layout;
7306 unsigned int stride, offset, i;
7307 ID3D11RenderTargetView *rtv[4];
7308 ID3D11DeviceContext *context;
7309 ID3D11Texture2D *rt[4];
7310 ID3D11VertexShader *vs;
7311 ID3D11PixelShader *ps;
7312 ID3D11Device *device;
7313 D3D11_VIEWPORT vp;
7314 ID3D11Buffer *vb;
7315 ULONG refcount;
7316 HRESULT hr;
7318 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
7320 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
7322 static const DWORD vs_code[] =
7324 #if 0
7325 float4 main(float4 position : POSITION) : SV_POSITION
7327 return position;
7329 #endif
7330 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
7331 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7332 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7333 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
7334 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
7335 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7336 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
7338 static const DWORD ps_code[] =
7340 #if 0
7341 struct output
7343 float4 t1 : SV_TARGET0;
7344 float4 t2 : SV_Target1;
7345 float4 t3 : SV_TARGET2;
7346 float4 t4 : SV_Target3;
7349 output main(float4 position : SV_POSITION)
7351 struct output o;
7352 o.t1 = (float4)1.0f;
7353 o.t2 = (float4)0.5f;
7354 o.t3 = (float4)0.2f;
7355 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
7356 return o;
7358 #endif
7359 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
7360 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7361 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7362 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
7363 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
7364 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
7365 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
7366 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
7367 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
7368 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
7369 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
7370 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
7371 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
7372 0x3f800000, 0x0100003e,
7374 static const struct vec2 quad[] =
7376 {-1.0f, -1.0f},
7377 {-1.0f, 1.0f},
7378 { 1.0f, -1.0f},
7379 { 1.0f, 1.0f},
7381 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
7383 if (!(device = create_device(NULL)))
7385 skip("Failed to create device.\n");
7386 return;
7389 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
7390 vs_code, sizeof(vs_code), &input_layout);
7391 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7393 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7395 texture_desc.Width = 640;
7396 texture_desc.Height = 480;
7397 texture_desc.MipLevels = 1;
7398 texture_desc.ArraySize = 1;
7399 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7400 texture_desc.SampleDesc.Count = 1;
7401 texture_desc.SampleDesc.Quality = 0;
7402 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7403 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7404 texture_desc.CPUAccessFlags = 0;
7405 texture_desc.MiscFlags = 0;
7407 for (i = 0; i < ARRAY_SIZE(rt); ++i)
7409 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
7410 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
7412 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
7413 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
7416 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
7417 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7418 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7419 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7421 ID3D11Device_GetImmediateContext(device, &context);
7423 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
7424 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
7425 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7426 stride = sizeof(*quad);
7427 offset = 0;
7428 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
7429 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
7430 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7432 vp.TopLeftX = 0.0f;
7433 vp.TopLeftY = 0.0f;
7434 vp.Width = 640.0f;
7435 vp.Height = 480.0f;
7436 vp.MinDepth = 0.0f;
7437 vp.MaxDepth = 1.0f;
7438 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
7440 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7441 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
7443 ID3D11DeviceContext_Draw(context, 4, 0);
7445 check_texture_color(rt[0], 0xffffffff, 2);
7446 check_texture_color(rt[1], 0x7f7f7f7f, 2);
7447 check_texture_color(rt[2], 0x33333333, 2);
7448 check_texture_color(rt[3], 0xff7f3300, 2);
7450 ID3D11Buffer_Release(vb);
7451 ID3D11PixelShader_Release(ps);
7452 ID3D11VertexShader_Release(vs);
7453 ID3D11InputLayout_Release(input_layout);
7454 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7456 ID3D11RenderTargetView_Release(rtv[i]);
7457 ID3D11Texture2D_Release(rt[i]);
7459 ID3D11DeviceContext_Release(context);
7460 refcount = ID3D11Device_Release(device);
7461 ok(!refcount, "Device has %u references left.\n", refcount);
7464 static void test_render_target_views(void)
7466 struct texture
7468 UINT miplevel_count;
7469 UINT array_size;
7472 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
7473 static struct test
7475 struct texture texture;
7476 struct rtv_desc rtv;
7477 DWORD expected_colors[4];
7479 tests[] =
7481 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7482 {0xff0000ff, 0x00000000}},
7483 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
7484 {0x00000000, 0xff0000ff}},
7485 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7486 {0xff0000ff, 0x00000000}},
7487 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7488 {0x00000000, 0xff0000ff}},
7489 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7490 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7491 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7492 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7493 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7494 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7495 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
7496 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7497 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
7498 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7499 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
7500 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7501 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7502 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7503 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7504 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7505 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7506 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7507 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7508 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7509 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
7510 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7513 struct d3d11_test_context test_context;
7514 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7515 D3D11_TEXTURE2D_DESC texture_desc;
7516 ID3D11DeviceContext *context;
7517 ID3D11RenderTargetView *rtv;
7518 ID3D11Texture2D *texture;
7519 ID3D11Device *device;
7520 unsigned int i, j, k;
7521 void *data;
7522 HRESULT hr;
7524 if (!init_test_context(&test_context, NULL))
7525 return;
7527 device = test_context.device;
7528 context = test_context.immediate_context;
7530 texture_desc.Width = 32;
7531 texture_desc.Height = 32;
7532 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7533 texture_desc.SampleDesc.Count = 1;
7534 texture_desc.SampleDesc.Quality = 0;
7535 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7536 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7537 texture_desc.CPUAccessFlags = 0;
7538 texture_desc.MiscFlags = 0;
7540 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, texture_desc.Width * texture_desc.Height * 4);
7541 ok(!!data, "Failed to allocate memory.\n");
7543 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7545 const struct test *test = &tests[i];
7546 unsigned int sub_resource_count;
7548 texture_desc.MipLevels = test->texture.miplevel_count;
7549 texture_desc.ArraySize = test->texture.array_size;
7551 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7552 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
7554 get_rtv_desc(&rtv_desc, &test->rtv);
7555 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7556 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
7558 for (j = 0; j < texture_desc.ArraySize; ++j)
7560 for (k = 0; k < texture_desc.MipLevels; ++k)
7562 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
7563 ID3D11DeviceContext_UpdateSubresource(context,
7564 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
7567 check_texture_color(texture, 0, 0);
7569 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7570 draw_color_quad(&test_context, &red);
7572 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7573 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
7574 for (j = 0; j < sub_resource_count; ++j)
7575 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
7577 ID3D11RenderTargetView_Release(rtv);
7578 ID3D11Texture2D_Release(texture);
7581 HeapFree(GetProcessHeap(), 0, data);
7582 release_test_context(&test_context);
7585 static void test_layered_rendering(void)
7587 struct
7589 unsigned int layer_offset;
7590 unsigned int draw_id;
7591 unsigned int padding[2];
7592 } constant;
7593 struct d3d11_test_context test_context;
7594 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7595 unsigned int i, sub_resource_count;
7596 D3D11_TEXTURE2D_DESC texture_desc;
7597 ID3D11DeviceContext *context;
7598 ID3D11RenderTargetView *rtv;
7599 ID3D11Texture2D *texture;
7600 ID3D11GeometryShader *gs;
7601 ID3D11PixelShader *ps;
7602 ID3D11Device *device;
7603 ID3D11Buffer *cb;
7604 HRESULT hr;
7605 BOOL warp;
7607 static const DWORD gs_5_code[] =
7609 #if 0
7610 uint layer_offset;
7612 struct gs_in
7614 float4 pos : SV_Position;
7617 struct gs_out
7619 float4 pos : SV_Position;
7620 uint layer : SV_RenderTargetArrayIndex;
7623 [instance(4)]
7624 [maxvertexcount(3)]
7625 void main(triangle gs_in vin[3], in uint instance_id : SV_GSInstanceID,
7626 inout TriangleStream<gs_out> vout)
7628 gs_out o;
7629 o.layer = layer_offset + instance_id;
7630 for (uint i = 0; i < 3; ++i)
7632 o.pos = vin[i].pos;
7633 vout.Append(o);
7636 #endif
7637 0x43425844, 0xb52da162, 0x9a13d8ee, 0xf7c30b50, 0xe80bc2e7, 0x00000001, 0x00000218, 0x00000003,
7638 0x0000002c, 0x00000060, 0x000000d0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7639 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
7640 0x3547534f, 0x00000068, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
7641 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000004, 0x00000001,
7642 0x00000001, 0x00000e01, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472,
7643 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x58454853, 0x00000140, 0x00020050, 0x00000050,
7644 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
7645 0x00000000, 0x00000001, 0x0200005f, 0x00025000, 0x02000068, 0x00000001, 0x020000ce, 0x00000004,
7646 0x0100185d, 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
7647 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x00000003, 0x0700001e,
7648 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0002500a, 0x05000036, 0x00100022,
7649 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a,
7650 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000, 0x07000036, 0x001020f2,
7651 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001,
7652 0x0010000a, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x0700001e, 0x00100022, 0x00000000,
7653 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
7655 static const DWORD gs_4_code[] =
7657 #if 0
7658 uint layer_offset;
7660 struct gs_in
7662 float4 pos : SV_Position;
7665 struct gs_out
7667 float4 pos : SV_Position;
7668 uint layer : SV_RenderTargetArrayIndex;
7671 [maxvertexcount(12)]
7672 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
7674 gs_out o;
7675 for (uint instance_id = 0; instance_id < 4; ++instance_id)
7677 o.layer = layer_offset + instance_id;
7678 for (uint i = 0; i < 3; ++i)
7680 o.pos = vin[i].pos;
7681 vout.Append(o);
7683 vout.RestartStrip();
7686 #endif
7687 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
7688 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7689 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
7690 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
7691 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
7692 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
7693 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
7694 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
7695 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
7696 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
7697 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
7698 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
7699 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
7700 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
7701 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
7702 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
7703 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
7704 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
7705 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
7707 static const DWORD ps_code[] =
7709 #if 0
7710 uint layer_offset;
7711 uint draw_id;
7713 float4 main(in float4 pos : SV_Position,
7714 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
7716 return float4(layer, draw_id, 0, 0);
7718 #endif
7719 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
7720 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
7721 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
7722 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
7723 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
7724 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
7725 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
7726 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
7727 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
7728 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
7729 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
7731 static const struct vec4 expected_values[] =
7733 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
7734 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
7735 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
7736 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
7739 if (!init_test_context(&test_context, NULL))
7740 return;
7742 device = test_context.device;
7743 context = test_context.immediate_context;
7745 warp = is_warp_device(device);
7747 memset(&constant, 0, sizeof(constant));
7748 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
7749 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
7750 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7752 /* Geometry shader instancing seems broken on WARP. */
7753 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0 || warp)
7755 hr = ID3D11Device_CreateGeometryShader(device, gs_4_code, sizeof(gs_4_code), NULL, &gs);
7756 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
7758 else
7760 hr = ID3D11Device_CreateGeometryShader(device, gs_5_code, sizeof(gs_5_code), NULL, &gs);
7761 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
7763 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
7765 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7766 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7767 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7769 texture_desc.Width = 32;
7770 texture_desc.Height = 32;
7771 texture_desc.MipLevels = 3;
7772 texture_desc.ArraySize = 8;
7773 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
7774 texture_desc.SampleDesc.Count = 1;
7775 texture_desc.SampleDesc.Quality = 0;
7776 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7777 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7778 texture_desc.CPUAccessFlags = 0;
7779 texture_desc.MiscFlags = 0;
7780 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7781 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7783 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
7784 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7785 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7786 constant.layer_offset = 0;
7787 constant.draw_id = 0;
7788 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7789 draw_quad(&test_context);
7790 constant.layer_offset = 4;
7791 constant.draw_id = 1;
7792 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7793 draw_quad(&test_context);
7794 ID3D11RenderTargetView_Release(rtv);
7796 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
7797 rtv_desc.Format = texture_desc.Format;
7798 U(rtv_desc).Texture2DArray.MipSlice = 0;
7799 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
7800 U(rtv_desc).Texture2DArray.ArraySize = 1;
7801 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7802 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7803 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7804 constant.layer_offset = 1;
7805 constant.draw_id = 2;
7806 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7807 draw_quad(&test_context);
7808 ID3D11RenderTargetView_Release(rtv);
7810 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
7811 U(rtv_desc).Texture2DArray.MipSlice = 1;
7812 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
7813 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
7814 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7815 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7816 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7817 constant.layer_offset = 0;
7818 constant.draw_id = 3;
7819 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7820 draw_quad(&test_context);
7821 constant.layer_offset = 4;
7822 constant.draw_id = 3;
7823 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7824 draw_quad(&test_context);
7825 ID3D11RenderTargetView_Release(rtv);
7827 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
7828 U(rtv_desc).Texture2DArray.MipSlice = 2;
7829 U(rtv_desc).Texture2DArray.ArraySize = 1;
7830 for (i = 0; i < texture_desc.ArraySize; ++i)
7832 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
7833 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7834 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7835 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7836 constant.layer_offset = 0;
7837 constant.draw_id = 4 + i;
7838 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7839 draw_quad(&test_context);
7840 ID3D11RenderTargetView_Release(rtv);
7843 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7844 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
7845 for (i = 0; i < sub_resource_count; ++i)
7847 if (warp && (i == 3 || i == 4)) /* Broken on WARP. */
7848 continue;
7849 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
7852 ID3D11Texture2D_Release(texture);
7854 ID3D11Buffer_Release(cb);
7855 ID3D11GeometryShader_Release(gs);
7856 ID3D11PixelShader_Release(ps);
7857 release_test_context(&test_context);
7860 static void test_scissor(void)
7862 struct d3d11_test_context test_context;
7863 ID3D11DeviceContext *immediate_context;
7864 D3D11_RASTERIZER_DESC rs_desc;
7865 ID3D11RasterizerState *rs;
7866 D3D11_RECT scissor_rect;
7867 ID3D11PixelShader *ps;
7868 ID3D11Device *device;
7869 DWORD color;
7870 HRESULT hr;
7872 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
7873 static const DWORD ps_code[] =
7875 #if 0
7876 float4 main(float4 position : SV_POSITION) : SV_Target
7878 return float4(0.0, 1.0, 0.0, 1.0);
7880 #endif
7881 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
7882 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7883 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7884 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7885 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
7886 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
7887 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
7890 if (!init_test_context(&test_context, NULL))
7891 return;
7893 device = test_context.device;
7894 immediate_context = test_context.immediate_context;
7896 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7897 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7899 rs_desc.FillMode = D3D11_FILL_SOLID;
7900 rs_desc.CullMode = D3D11_CULL_BACK;
7901 rs_desc.FrontCounterClockwise = FALSE;
7902 rs_desc.DepthBias = 0;
7903 rs_desc.DepthBiasClamp = 0.0f;
7904 rs_desc.SlopeScaledDepthBias = 0.0f;
7905 rs_desc.DepthClipEnable = TRUE;
7906 rs_desc.ScissorEnable = TRUE;
7907 rs_desc.MultisampleEnable = FALSE;
7908 rs_desc.AntialiasedLineEnable = FALSE;
7909 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
7910 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
7912 ID3D11DeviceContext_PSSetShader(immediate_context, ps, NULL, 0);
7914 scissor_rect.left = 160;
7915 scissor_rect.top = 120;
7916 scissor_rect.right = 480;
7917 scissor_rect.bottom = 360;
7918 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
7920 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
7921 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
7923 draw_quad(&test_context);
7924 color = get_texture_color(test_context.backbuffer, 320, 60);
7925 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7926 color = get_texture_color(test_context.backbuffer, 80, 240);
7927 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7928 color = get_texture_color(test_context.backbuffer, 320, 240);
7929 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7930 color = get_texture_color(test_context.backbuffer, 560, 240);
7931 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7932 color = get_texture_color(test_context.backbuffer, 320, 420);
7933 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7935 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
7936 ID3D11DeviceContext_RSSetState(immediate_context, rs);
7937 draw_quad(&test_context);
7938 color = get_texture_color(test_context.backbuffer, 320, 60);
7939 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7940 color = get_texture_color(test_context.backbuffer, 80, 240);
7941 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7942 color = get_texture_color(test_context.backbuffer, 320, 240);
7943 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7944 color = get_texture_color(test_context.backbuffer, 560, 240);
7945 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7946 color = get_texture_color(test_context.backbuffer, 320, 420);
7947 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7949 ID3D11RasterizerState_Release(rs);
7950 ID3D11PixelShader_Release(ps);
7951 release_test_context(&test_context);
7954 static void test_il_append_aligned(void)
7956 struct d3d11_test_context test_context;
7957 ID3D11InputLayout *input_layout;
7958 ID3D11DeviceContext *context;
7959 unsigned int stride, offset;
7960 ID3D11VertexShader *vs;
7961 ID3D11PixelShader *ps;
7962 ID3D11Device *device;
7963 ID3D11Buffer *vb[3];
7964 DWORD color;
7965 HRESULT hr;
7967 /* Semantic names are case-insensitive. */
7968 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
7970 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
7971 D3D11_INPUT_PER_INSTANCE_DATA, 2},
7972 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
7973 D3D11_INPUT_PER_INSTANCE_DATA, 1},
7974 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
7975 D3D11_INPUT_PER_VERTEX_DATA, 0},
7976 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
7977 D3D11_INPUT_PER_INSTANCE_DATA, 1},
7978 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
7979 D3D11_INPUT_PER_INSTANCE_DATA, 2},
7981 static const DWORD vs_code[] =
7983 #if 0
7984 struct vs_in
7986 float4 position : POSITION;
7987 float2 color_xy : COLOR0;
7988 float2 color_zw : COLOR1;
7989 unsigned int instance_id : SV_INSTANCEID;
7992 struct vs_out
7994 float4 position : SV_POSITION;
7995 float2 color_xy : COLOR0;
7996 float2 color_zw : COLOR1;
7999 struct vs_out main(struct vs_in i)
8001 struct vs_out o;
8003 o.position = i.position;
8004 o.position.x += i.instance_id * 0.5;
8005 o.color_xy = i.color_xy;
8006 o.color_zw = i.color_zw;
8008 return o;
8010 #endif
8011 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
8012 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
8013 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
8014 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
8015 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
8016 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
8017 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
8018 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
8019 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
8020 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
8021 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
8022 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
8023 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
8024 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
8025 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
8026 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
8027 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
8029 static const DWORD ps_code[] =
8031 #if 0
8032 struct vs_out
8034 float4 position : SV_POSITION;
8035 float2 color_xy : COLOR0;
8036 float2 color_zw : COLOR1;
8039 float4 main(struct vs_out i) : SV_TARGET
8041 return float4(i.color_xy.xy, i.color_zw.xy);
8043 #endif
8044 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
8045 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
8046 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
8047 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
8048 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
8049 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
8050 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
8051 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8052 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8054 static const struct
8056 struct vec4 position;
8058 stream0[] =
8060 {{-1.0f, -1.0f, 0.0f, 1.0f}},
8061 {{-1.0f, 1.0f, 0.0f, 1.0f}},
8062 {{-0.5f, -1.0f, 0.0f, 1.0f}},
8063 {{-0.5f, 1.0f, 0.0f, 1.0f}},
8065 static const struct
8067 struct vec2 color2;
8068 struct vec2 color1;
8070 stream1[] =
8072 {{0.5f, 0.5f}, {0.0f, 1.0f}},
8073 {{0.5f, 0.5f}, {1.0f, 1.0f}},
8075 static const struct
8077 struct vec2 color3;
8078 struct vec2 color0;
8080 stream2[] =
8082 {{0.5f, 0.5f}, {1.0f, 0.0f}},
8083 {{0.5f, 0.5f}, {0.0f, 1.0f}},
8084 {{0.5f, 0.5f}, {0.0f, 0.0f}},
8085 {{0.5f, 0.5f}, {1.0f, 0.0f}},
8087 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8089 if (!init_test_context(&test_context, NULL))
8090 return;
8092 device = test_context.device;
8093 context = test_context.immediate_context;
8095 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8096 vs_code, sizeof(vs_code), &input_layout);
8097 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8099 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
8100 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
8101 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
8103 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
8104 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8105 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8106 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8108 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
8109 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8110 offset = 0;
8111 stride = sizeof(*stream0);
8112 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
8113 stride = sizeof(*stream1);
8114 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
8115 stride = sizeof(*stream2);
8116 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
8117 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
8118 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8120 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8122 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
8124 color = get_texture_color(test_context.backbuffer, 80, 240);
8125 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8126 color = get_texture_color(test_context.backbuffer, 240, 240);
8127 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8128 color = get_texture_color(test_context.backbuffer, 400, 240);
8129 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
8130 color = get_texture_color(test_context.backbuffer, 560, 240);
8131 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
8133 ID3D11PixelShader_Release(ps);
8134 ID3D11VertexShader_Release(vs);
8135 ID3D11Buffer_Release(vb[2]);
8136 ID3D11Buffer_Release(vb[1]);
8137 ID3D11Buffer_Release(vb[0]);
8138 ID3D11InputLayout_Release(input_layout);
8139 release_test_context(&test_context);
8142 static void test_fragment_coords(void)
8144 struct d3d11_test_context test_context;
8145 ID3D11PixelShader *ps, *ps_frac;
8146 ID3D11DeviceContext *context;
8147 ID3D11Device *device;
8148 ID3D11Buffer *ps_cb;
8149 DWORD color;
8150 HRESULT hr;
8152 static const DWORD ps_code[] =
8154 #if 0
8155 float2 cutoff;
8157 float4 main(float4 position : SV_POSITION) : SV_TARGET
8159 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
8161 if (position.x > cutoff.x)
8162 ret.y = 1.0;
8163 if (position.y > cutoff.y)
8164 ret.z = 1.0;
8166 return ret;
8168 #endif
8169 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
8170 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8171 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8172 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8173 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
8174 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
8175 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
8176 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
8177 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
8178 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
8179 0x0100003e,
8181 static const DWORD ps_frac_code[] =
8183 #if 0
8184 float4 main(float4 position : SV_POSITION) : SV_TARGET
8186 return float4(frac(position.xy), 0.0, 1.0);
8188 #endif
8189 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
8190 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8191 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8192 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8193 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
8194 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8195 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
8196 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
8198 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8199 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
8201 if (!init_test_context(&test_context, NULL))
8202 return;
8204 device = test_context.device;
8205 context = test_context.immediate_context;
8207 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
8209 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8210 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8211 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
8212 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8214 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
8215 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8217 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8219 draw_quad(&test_context);
8221 color = get_texture_color(test_context.backbuffer, 319, 239);
8222 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
8223 color = get_texture_color(test_context.backbuffer, 320, 239);
8224 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8225 color = get_texture_color(test_context.backbuffer, 319, 240);
8226 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
8227 color = get_texture_color(test_context.backbuffer, 320, 240);
8228 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
8230 ID3D11Buffer_Release(ps_cb);
8231 cutoff.x = 16.0f;
8232 cutoff.y = 16.0f;
8233 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
8234 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
8236 draw_quad(&test_context);
8238 color = get_texture_color(test_context.backbuffer, 14, 14);
8239 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
8240 color = get_texture_color(test_context.backbuffer, 18, 14);
8241 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8242 color = get_texture_color(test_context.backbuffer, 14, 18);
8243 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
8244 color = get_texture_color(test_context.backbuffer, 18, 18);
8245 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
8247 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
8248 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8250 ID3D11DeviceContext_Draw(context, 4, 0);
8252 color = get_texture_color(test_context.backbuffer, 14, 14);
8253 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
8255 ID3D11Buffer_Release(ps_cb);
8256 ID3D11PixelShader_Release(ps_frac);
8257 ID3D11PixelShader_Release(ps);
8258 release_test_context(&test_context);
8261 static void test_update_subresource(void)
8263 struct d3d11_test_context test_context;
8264 D3D11_SUBRESOURCE_DATA resource_data;
8265 D3D11_TEXTURE2D_DESC texture_desc;
8266 ID3D11SamplerState *sampler_state;
8267 ID3D11ShaderResourceView *ps_srv;
8268 D3D11_SAMPLER_DESC sampler_desc;
8269 ID3D11DeviceContext *context;
8270 struct resource_readback rb;
8271 ID3D11Texture2D *texture;
8272 ID3D11PixelShader *ps;
8273 ID3D11Device *device;
8274 unsigned int i, j;
8275 D3D11_BOX box;
8276 DWORD color;
8277 HRESULT hr;
8279 static const DWORD ps_code[] =
8281 #if 0
8282 Texture2D t;
8283 SamplerState s;
8285 float4 main(float4 position : SV_POSITION) : SV_Target
8287 float2 p;
8289 p.x = position.x / 640.0f;
8290 p.y = position.y / 480.0f;
8291 return t.Sample(s, p);
8293 #endif
8294 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
8295 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8296 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8297 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8298 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
8299 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
8300 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
8301 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8302 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
8303 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
8305 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8306 static const DWORD initial_data[16] = {0};
8307 static const DWORD bitmap_data[] =
8309 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
8310 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
8311 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
8312 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
8314 static const DWORD expected_colors[] =
8316 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
8317 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
8318 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
8319 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
8322 if (!init_test_context(&test_context, NULL))
8323 return;
8325 device = test_context.device;
8326 context = test_context.immediate_context;
8328 texture_desc.Width = 4;
8329 texture_desc.Height = 4;
8330 texture_desc.MipLevels = 1;
8331 texture_desc.ArraySize = 1;
8332 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8333 texture_desc.SampleDesc.Count = 1;
8334 texture_desc.SampleDesc.Quality = 0;
8335 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8336 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
8337 texture_desc.CPUAccessFlags = 0;
8338 texture_desc.MiscFlags = 0;
8340 resource_data.pSysMem = initial_data;
8341 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
8342 resource_data.SysMemSlicePitch = 0;
8344 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
8345 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
8347 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
8348 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8350 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8351 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8352 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8353 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8354 sampler_desc.MipLODBias = 0.0f;
8355 sampler_desc.MaxAnisotropy = 0;
8356 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8357 sampler_desc.BorderColor[0] = 0.0f;
8358 sampler_desc.BorderColor[1] = 0.0f;
8359 sampler_desc.BorderColor[2] = 0.0f;
8360 sampler_desc.BorderColor[3] = 0.0f;
8361 sampler_desc.MinLOD = 0.0f;
8362 sampler_desc.MaxLOD = 0.0f;
8364 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
8365 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8367 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8368 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8370 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
8371 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
8372 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8374 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8375 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
8377 draw_quad(&test_context);
8378 check_texture_color(test_context.backbuffer, 0x00000000, 0);
8380 set_box(&box, 1, 1, 0, 3, 3, 1);
8381 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
8382 bitmap_data, 4 * sizeof(*bitmap_data), 0);
8383 set_box(&box, 0, 3, 0, 3, 4, 1);
8384 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
8385 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
8386 set_box(&box, 0, 0, 0, 4, 1, 1);
8387 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
8388 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
8389 set_box(&box, 0, 1, 0, 1, 3, 1);
8390 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
8391 &bitmap_data[2], sizeof(*bitmap_data), 0);
8392 set_box(&box, 4, 4, 0, 3, 1, 1);
8393 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
8394 bitmap_data, sizeof(*bitmap_data), 0);
8395 set_box(&box, 0, 0, 0, 4, 4, 0);
8396 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
8397 bitmap_data, 4 * sizeof(*bitmap_data), 0);
8398 draw_quad(&test_context);
8399 get_texture_readback(test_context.backbuffer, 0, &rb);
8400 for (i = 0; i < 4; ++i)
8402 for (j = 0; j < 4; ++j)
8404 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
8405 ok(compare_color(color, expected_colors[j + i * 4], 1),
8406 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
8407 color, j, i, expected_colors[j + i * 4]);
8410 release_resource_readback(&rb);
8412 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
8413 bitmap_data, 4 * sizeof(*bitmap_data), 0);
8414 draw_quad(&test_context);
8415 get_texture_readback(test_context.backbuffer, 0, &rb);
8416 for (i = 0; i < 4; ++i)
8418 for (j = 0; j < 4; ++j)
8420 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
8421 ok(compare_color(color, bitmap_data[j + i * 4], 1),
8422 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
8423 color, j, i, bitmap_data[j + i * 4]);
8426 release_resource_readback(&rb);
8428 ID3D11PixelShader_Release(ps);
8429 ID3D11SamplerState_Release(sampler_state);
8430 ID3D11ShaderResourceView_Release(ps_srv);
8431 ID3D11Texture2D_Release(texture);
8432 release_test_context(&test_context);
8435 static void test_copy_subresource_region(void)
8437 ID3D11Texture2D *dst_texture, *src_texture;
8438 struct d3d11_test_context test_context;
8439 ID3D11Buffer *dst_buffer, *src_buffer;
8440 D3D11_SUBRESOURCE_DATA resource_data;
8441 D3D11_TEXTURE2D_DESC texture_desc;
8442 ID3D11SamplerState *sampler_state;
8443 ID3D11ShaderResourceView *ps_srv;
8444 D3D11_SAMPLER_DESC sampler_desc;
8445 ID3D11DeviceContext *context;
8446 struct vec4 float_colors[16];
8447 struct resource_readback rb;
8448 ID3D11PixelShader *ps;
8449 ID3D11Device *device;
8450 unsigned int i, j;
8451 D3D11_BOX box;
8452 DWORD color;
8453 HRESULT hr;
8455 static const DWORD ps_code[] =
8457 #if 0
8458 Texture2D t;
8459 SamplerState s;
8461 float4 main(float4 position : SV_POSITION) : SV_Target
8463 float2 p;
8465 p.x = position.x / 640.0f;
8466 p.y = position.y / 480.0f;
8467 return t.Sample(s, p);
8469 #endif
8470 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
8471 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8472 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8473 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8474 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
8475 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
8476 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
8477 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8478 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
8479 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
8481 static const DWORD ps_buffer_code[] =
8483 #if 0
8484 float4 buffer[16];
8486 float4 main(float4 position : SV_POSITION) : SV_TARGET
8488 float2 p = (float2)4;
8489 p *= float2(position.x / 640.0f, position.y / 480.0f);
8490 return buffer[(int)p.y * 4 + (int)p.x];
8492 #endif
8493 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
8494 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8495 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8496 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8497 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
8498 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
8499 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
8500 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
8501 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
8502 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
8503 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
8504 0x0010000a, 0x00000000, 0x0100003e,
8506 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8507 static const DWORD initial_data[16] = {0};
8508 static const DWORD bitmap_data[] =
8510 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
8511 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
8512 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
8513 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
8515 static const DWORD expected_colors[] =
8517 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
8518 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
8519 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
8520 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
8523 if (!init_test_context(&test_context, NULL))
8524 return;
8526 device = test_context.device;
8527 context = test_context.immediate_context;
8529 texture_desc.Width = 4;
8530 texture_desc.Height = 4;
8531 texture_desc.MipLevels = 1;
8532 texture_desc.ArraySize = 1;
8533 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8534 texture_desc.SampleDesc.Count = 1;
8535 texture_desc.SampleDesc.Quality = 0;
8536 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8537 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
8538 texture_desc.CPUAccessFlags = 0;
8539 texture_desc.MiscFlags = 0;
8541 resource_data.pSysMem = initial_data;
8542 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
8543 resource_data.SysMemSlicePitch = 0;
8545 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
8546 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
8548 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
8550 resource_data.pSysMem = bitmap_data;
8551 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
8552 resource_data.SysMemSlicePitch = 0;
8554 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
8555 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
8557 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
8558 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8560 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8561 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8562 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8563 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8564 sampler_desc.MipLODBias = 0.0f;
8565 sampler_desc.MaxAnisotropy = 0;
8566 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8567 sampler_desc.BorderColor[0] = 0.0f;
8568 sampler_desc.BorderColor[1] = 0.0f;
8569 sampler_desc.BorderColor[2] = 0.0f;
8570 sampler_desc.BorderColor[3] = 0.0f;
8571 sampler_desc.MinLOD = 0.0f;
8572 sampler_desc.MaxLOD = 0.0f;
8574 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
8575 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8577 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8578 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8580 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
8581 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
8582 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8584 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8586 set_box(&box, 0, 0, 0, 2, 2, 1);
8587 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8588 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
8589 set_box(&box, 1, 2, 0, 4, 3, 1);
8590 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8591 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
8592 set_box(&box, 0, 3, 0, 4, 4, 1);
8593 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8594 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
8595 set_box(&box, 3, 0, 0, 4, 2, 1);
8596 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8597 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
8598 set_box(&box, 3, 1, 0, 4, 2, 1);
8599 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8600 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
8601 set_box(&box, 0, 0, 0, 4, 4, 0);
8602 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8603 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
8604 draw_quad(&test_context);
8605 get_texture_readback(test_context.backbuffer, 0, &rb);
8606 for (i = 0; i < 4; ++i)
8608 for (j = 0; j < 4; ++j)
8610 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
8611 ok(compare_color(color, expected_colors[j + i * 4], 1),
8612 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
8613 color, j, i, expected_colors[j + i * 4]);
8616 release_resource_readback(&rb);
8618 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8619 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
8620 draw_quad(&test_context);
8621 get_texture_readback(test_context.backbuffer, 0, &rb);
8622 for (i = 0; i < 4; ++i)
8624 for (j = 0; j < 4; ++j)
8626 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
8627 ok(compare_color(color, bitmap_data[j + i * 4], 1),
8628 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
8629 color, j, i, bitmap_data[j + i * 4]);
8632 release_resource_readback(&rb);
8634 ID3D11PixelShader_Release(ps);
8635 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
8636 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8638 ID3D11ShaderResourceView_Release(ps_srv);
8639 ps_srv = NULL;
8641 ID3D11SamplerState_Release(sampler_state);
8642 sampler_state = NULL;
8644 ID3D11Texture2D_Release(dst_texture);
8645 ID3D11Texture2D_Release(src_texture);
8647 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
8648 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
8649 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8651 memset(float_colors, 0, sizeof(float_colors));
8652 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
8653 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
8655 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
8657 for (i = 0; i < 4; ++i)
8659 for (j = 0; j < 4; ++j)
8661 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
8662 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
8663 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
8664 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
8667 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
8668 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
8670 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
8671 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
8672 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
8673 draw_quad(&test_context);
8674 check_texture_color(test_context.backbuffer, 0x00000000, 0);
8676 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
8677 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
8678 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
8679 draw_quad(&test_context);
8680 check_texture_color(test_context.backbuffer, 0x00000000, 0);
8682 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
8683 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
8684 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
8685 draw_quad(&test_context);
8686 check_texture_color(test_context.backbuffer, 0x00000000, 0);
8688 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
8689 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
8690 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
8691 draw_quad(&test_context);
8692 get_texture_readback(test_context.backbuffer, 0, &rb);
8693 for (i = 0; i < 4; ++i)
8695 for (j = 0; j < 4; ++j)
8697 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
8698 ok(compare_color(color, bitmap_data[j + i * 4], 1),
8699 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
8700 color, j, i, bitmap_data[j + i * 4]);
8703 release_resource_readback(&rb);
8705 ID3D11Buffer_Release(dst_buffer);
8706 ID3D11Buffer_Release(src_buffer);
8707 ID3D11PixelShader_Release(ps);
8708 release_test_context(&test_context);
8711 static void test_resource_map(void)
8713 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
8714 D3D11_TEXTURE3D_DESC texture3d_desc;
8715 D3D11_TEXTURE2D_DESC texture2d_desc;
8716 D3D11_BUFFER_DESC buffer_desc;
8717 ID3D11DeviceContext *context;
8718 ID3D11Texture3D *texture3d;
8719 ID3D11Texture2D *texture2d;
8720 ID3D11Buffer *buffer;
8721 ID3D11Device *device;
8722 ULONG refcount;
8723 HRESULT hr;
8724 DWORD data;
8726 if (!(device = create_device(NULL)))
8728 skip("Failed to create device.\n");
8729 return;
8732 ID3D11Device_GetImmediateContext(device, &context);
8734 buffer_desc.ByteWidth = 1024;
8735 buffer_desc.Usage = D3D11_USAGE_STAGING;
8736 buffer_desc.BindFlags = 0;
8737 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
8738 buffer_desc.MiscFlags = 0;
8739 buffer_desc.StructureByteStride = 0;
8741 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
8742 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
8744 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
8745 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8747 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8748 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
8749 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
8750 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8751 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
8752 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
8753 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
8755 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8756 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
8757 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
8758 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8759 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
8760 data = *((DWORD *)mapped_subresource.pData);
8761 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
8762 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
8764 refcount = ID3D11Buffer_Release(buffer);
8765 ok(!refcount, "Buffer has %u references left.\n", refcount);
8767 texture2d_desc.Width = 512;
8768 texture2d_desc.Height = 512;
8769 texture2d_desc.MipLevels = 1;
8770 texture2d_desc.ArraySize = 1;
8771 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8772 texture2d_desc.SampleDesc.Count = 1;
8773 texture2d_desc.SampleDesc.Quality = 0;
8774 texture2d_desc.Usage = D3D11_USAGE_STAGING;
8775 texture2d_desc.BindFlags = 0;
8776 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
8777 texture2d_desc.MiscFlags = 0;
8779 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
8780 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
8782 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
8783 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8785 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8786 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
8787 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
8788 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8789 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
8790 mapped_subresource.DepthPitch);
8791 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
8792 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
8794 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8795 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
8796 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
8797 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8798 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
8799 mapped_subresource.DepthPitch);
8800 data = *((DWORD *)mapped_subresource.pData);
8801 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
8802 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
8804 refcount = ID3D11Texture2D_Release(texture2d);
8805 ok(!refcount, "2D texture has %u references left.\n", refcount);
8807 texture3d_desc.Width = 64;
8808 texture3d_desc.Height = 64;
8809 texture3d_desc.Depth = 64;
8810 texture3d_desc.MipLevels = 1;
8811 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8812 texture3d_desc.Usage = D3D11_USAGE_STAGING;
8813 texture3d_desc.BindFlags = 0;
8814 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
8815 texture3d_desc.MiscFlags = 0;
8817 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
8818 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
8820 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
8821 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8823 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8824 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
8825 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
8826 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8827 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
8828 mapped_subresource.DepthPitch);
8829 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
8830 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
8832 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8833 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
8834 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
8835 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8836 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
8837 mapped_subresource.DepthPitch);
8838 data = *((DWORD *)mapped_subresource.pData);
8839 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
8840 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
8842 refcount = ID3D11Texture3D_Release(texture3d);
8843 ok(!refcount, "3D texture has %u references left.\n", refcount);
8845 ID3D11DeviceContext_Release(context);
8847 refcount = ID3D11Device_Release(device);
8848 ok(!refcount, "Device has %u references left.\n", refcount);
8851 static void test_check_multisample_quality_levels(void)
8853 ID3D11Device *device;
8854 UINT quality_levels;
8855 ULONG refcount;
8856 HRESULT hr;
8858 if (!(device = create_device(NULL)))
8860 skip("Failed to create device.\n");
8861 return;
8864 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
8865 if (!quality_levels)
8867 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
8868 goto done;
8871 quality_levels = 0xdeadbeef;
8872 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
8873 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8874 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8875 quality_levels = 0xdeadbeef;
8876 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
8877 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8878 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
8880 quality_levels = 0xdeadbeef;
8881 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
8882 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8883 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
8884 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
8885 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8887 quality_levels = 0xdeadbeef;
8888 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
8889 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8890 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
8891 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8892 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
8894 quality_levels = 0xdeadbeef;
8895 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
8896 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8897 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
8898 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8899 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8901 /* We assume 15 samples multisampling is never supported in practice. */
8902 quality_levels = 0xdeadbeef;
8903 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
8904 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8905 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8906 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
8907 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8908 quality_levels = 0xdeadbeef;
8909 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
8910 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
8911 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8912 quality_levels = 0xdeadbeef;
8913 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
8914 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
8915 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8917 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
8918 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8919 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8921 done:
8922 refcount = ID3D11Device_Release(device);
8923 ok(!refcount, "Device has %u references left.\n", refcount);
8926 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
8928 DXGI_SWAP_CHAIN_DESC swapchain_desc;
8929 struct device_desc device_desc;
8930 IDXGISwapChain *swapchain;
8931 IDXGIDevice *dxgi_device;
8932 HRESULT hr, expected_hr;
8933 IDXGIAdapter *adapter;
8934 IDXGIFactory *factory;
8935 ID3D11Device *device;
8936 unsigned int i;
8937 ULONG refcount;
8939 swapchain_desc.BufferDesc.Width = 800;
8940 swapchain_desc.BufferDesc.Height = 600;
8941 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
8942 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
8943 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
8944 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
8945 swapchain_desc.SampleDesc.Count = 1;
8946 swapchain_desc.SampleDesc.Quality = 0;
8947 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
8948 swapchain_desc.BufferCount = 1;
8949 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
8950 swapchain_desc.Windowed = TRUE;
8951 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
8952 swapchain_desc.Flags = 0;
8954 device_desc.feature_level = &feature_level;
8955 device_desc.flags = 0;
8956 if (!(device = create_device(&device_desc)))
8958 skip("Failed to create device for feature level %#x.\n", feature_level);
8959 return;
8962 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
8963 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
8964 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
8965 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
8966 IDXGIDevice_Release(dxgi_device);
8967 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
8968 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
8969 IDXGIAdapter_Release(adapter);
8971 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
8972 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
8973 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
8974 hr, feature_level);
8975 if (SUCCEEDED(hr))
8976 IDXGISwapChain_Release(swapchain);
8978 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
8980 DXGI_FORMAT format = display_format_support[i].format;
8981 BOOL todo = FALSE;
8983 if (display_format_support[i].fl_required <= feature_level)
8985 expected_hr = S_OK;
8986 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
8987 todo = TRUE;
8989 else if (!display_format_support[i].fl_optional
8990 || display_format_support[i].fl_optional > feature_level)
8992 expected_hr = E_INVALIDARG;
8993 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
8994 todo = TRUE;
8996 else
8998 continue;
9001 swapchain_desc.BufferDesc.Format = format;
9002 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
9003 todo_wine_if(todo)
9004 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
9005 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
9006 hr, expected_hr, feature_level, format);
9007 if (FAILED(hr))
9008 continue;
9009 refcount = IDXGISwapChain_Release(swapchain);
9010 ok(!refcount, "Swapchain has %u references left.\n", refcount);
9013 refcount = ID3D11Device_Release(device);
9014 ok(!refcount, "Device has %u references left.\n", refcount);
9015 refcount = IDXGIFactory_Release(factory);
9016 ok(!refcount, "Factory has %u references left.\n", refcount);
9017 DestroyWindow(swapchain_desc.OutputWindow);
9020 static void test_swapchain_views(void)
9022 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
9023 struct d3d11_test_context test_context;
9024 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
9025 ID3D11ShaderResourceView *srv;
9026 ID3D11DeviceContext *context;
9027 ID3D11RenderTargetView *rtv;
9028 ID3D11Device *device;
9029 ULONG refcount;
9030 HRESULT hr;
9032 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
9034 if (!init_test_context(&test_context, NULL))
9035 return;
9037 device = test_context.device;
9038 context = test_context.immediate_context;
9040 refcount = get_refcount(test_context.backbuffer);
9041 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
9043 draw_color_quad(&test_context, &color);
9044 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
9046 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
9047 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
9048 U(rtv_desc).Texture2D.MipSlice = 0;
9049 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
9050 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9051 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9053 refcount = get_refcount(test_context.backbuffer);
9054 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
9056 draw_color_quad(&test_context, &color);
9057 todo_wine check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
9059 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
9060 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
9061 U(srv_desc).Texture2D.MostDetailedMip = 0;
9062 U(srv_desc).Texture2D.MipLevels = 1;
9063 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
9064 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9065 if (SUCCEEDED(hr))
9066 ID3D11ShaderResourceView_Release(srv);
9068 ID3D11RenderTargetView_Release(rtv);
9069 release_test_context(&test_context);
9072 static void test_swapchain_flip(void)
9074 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
9075 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
9076 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
9077 D3D11_TEXTURE2D_DESC texture_desc;
9078 ID3D11InputLayout *input_layout;
9079 ID3D11DeviceContext *context;
9080 unsigned int stride, offset;
9081 struct swapchain_desc desc;
9082 IDXGISwapChain *swapchain;
9083 ID3D11VertexShader *vs;
9084 ID3D11PixelShader *ps;
9085 ID3D11Device *device;
9086 D3D11_VIEWPORT vp;
9087 ID3D11Buffer *vb;
9088 ULONG refcount;
9089 DWORD color;
9090 HWND window;
9091 HRESULT hr;
9092 RECT rect;
9094 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9096 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
9098 static const DWORD vs_code[] =
9100 #if 0
9101 float4 main(float4 position : POSITION) : SV_POSITION
9103 return position;
9105 #endif
9106 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
9107 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9108 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
9109 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
9110 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
9111 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
9112 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
9115 static const DWORD ps_code[] =
9117 #if 0
9118 Texture2D t0, t1;
9119 SamplerState s;
9121 float4 main(float4 position : SV_POSITION) : SV_Target
9123 float2 p;
9125 p.x = 0.5;
9126 p.y = 0.5;
9127 if (position.x < 320)
9128 return t0.Sample(s, p);
9129 return t1.Sample(s, p);
9131 #endif
9132 0x43425844, 0x1733542c, 0xf74c6b6a, 0x0fb11eac, 0x76f6a999, 0x00000001, 0x000002cc, 0x00000005,
9133 0x00000034, 0x000000f4, 0x00000128, 0x0000015c, 0x00000250, 0x46454452, 0x000000b8, 0x00000000,
9134 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x00000084, 0x0000007c, 0x00000003,
9135 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x0000007e, 0x00000002,
9136 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000c, 0x00000081, 0x00000002,
9137 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000c, 0x30740073, 0x00317400,
9138 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d,
9139 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00, 0x4e475349, 0x0000002c, 0x00000001,
9140 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653,
9141 0x5449534f, 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
9142 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
9143 0x000000ec, 0x00000040, 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000,
9144 0x00000000, 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012,
9145 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031,
9146 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a,
9147 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000,
9148 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045,
9149 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
9150 0x00000001, 0x00106000, 0x00000000, 0x0100003e, 0x54415453, 0x00000074, 0x00000007, 0x00000001,
9151 0x00000000, 0x00000002, 0x00000001, 0x00000000, 0x00000000, 0x00000002, 0x00000001, 0x00000000,
9152 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000,
9153 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
9154 0x00000000, 0x00000000, 0x00000000
9156 static const struct vec2 quad[] =
9158 {-1.0f, -1.0f},
9159 {-1.0f, 1.0f},
9160 { 1.0f, -1.0f},
9161 { 1.0f, 1.0f},
9163 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9164 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
9165 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
9167 if (!(device = create_device(NULL)))
9169 skip("Failed to create device, skipping tests.\n");
9170 return;
9172 SetRect(&rect, 0, 0, 640, 480);
9173 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
9174 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9175 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
9176 desc.buffer_count = 3;
9177 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
9178 desc.windowed = TRUE;
9179 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
9180 swapchain = create_swapchain(device, window, &desc);
9182 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
9183 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
9184 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
9185 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
9186 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
9187 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
9189 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
9190 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9191 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
9192 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9193 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
9194 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9196 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
9197 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
9198 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
9199 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
9200 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
9202 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
9203 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
9204 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
9205 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
9206 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
9208 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
9209 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9210 if (SUCCEEDED(hr))
9211 ID3D11RenderTargetView_Release(offscreen_rtv);
9213 ID3D11Device_GetImmediateContext(device, &context);
9215 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
9216 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
9218 texture_desc.Width = 640;
9219 texture_desc.Height = 480;
9220 texture_desc.MipLevels = 1;
9221 texture_desc.ArraySize = 1;
9222 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9223 texture_desc.SampleDesc.Count = 1;
9224 texture_desc.SampleDesc.Quality = 0;
9225 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9226 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9227 texture_desc.CPUAccessFlags = 0;
9228 texture_desc.MiscFlags = 0;
9229 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
9230 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
9231 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
9232 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9233 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
9234 vp.TopLeftX = 0;
9235 vp.TopLeftY = 0;
9236 vp.Width = 640;
9237 vp.Height = 480;
9238 vp.MinDepth = 0.0f;
9239 vp.MaxDepth = 1.0f;
9240 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
9242 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
9244 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
9245 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9246 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9247 vs_code, sizeof(vs_code), &input_layout);
9248 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9249 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
9250 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9251 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
9252 stride = sizeof(*quad);
9253 offset = 0;
9254 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
9256 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9257 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9258 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9260 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
9262 ID3D11DeviceContext_Draw(context, 4, 0);
9263 color = get_texture_color(offscreen, 120, 240);
9264 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9266 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
9267 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
9268 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
9270 * What is this good for? I don't know. Ad-hoc tests suggest that
9271 * Present() always waits for the next V-sync interval, even if there are
9272 * still untouched buffers. Buffer 0 is the buffer that is shown on the
9273 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
9274 * rendering finishes before the V-sync interval is over. I haven't found
9275 * any productive use for more than one buffer. */
9276 IDXGISwapChain_Present(swapchain, 0, 0);
9278 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
9280 ID3D11DeviceContext_Draw(context, 4, 0);
9281 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
9282 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9283 /* Buffer 1 is still untouched. */
9285 color = get_texture_color(backbuffer_0, 320, 240); /* green */
9286 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9287 color = get_texture_color(backbuffer_2, 320, 240); /* red */
9288 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9290 IDXGISwapChain_Present(swapchain, 0, 0);
9292 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
9294 ID3D11DeviceContext_Draw(context, 4, 0);
9295 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
9296 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
9297 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
9298 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9300 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
9301 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
9302 color = get_texture_color(backbuffer_1, 320, 240); /* red */
9303 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9304 color = get_texture_color(backbuffer_2, 320, 240); /* green */
9305 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9307 ID3D11VertexShader_Release(vs);
9308 ID3D11PixelShader_Release(ps);
9309 ID3D11Buffer_Release(vb);
9310 ID3D11InputLayout_Release(input_layout);
9311 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
9312 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
9313 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
9314 ID3D11RenderTargetView_Release(offscreen_rtv);
9315 ID3D11Texture2D_Release(offscreen);
9316 ID3D11Texture2D_Release(backbuffer_0);
9317 ID3D11Texture2D_Release(backbuffer_1);
9318 ID3D11Texture2D_Release(backbuffer_2);
9319 IDXGISwapChain_Release(swapchain);
9321 ID3D11DeviceContext_Release(context);
9322 refcount = ID3D11Device_Release(device);
9323 ok(!refcount, "Device has %u references left.\n", refcount);
9324 DestroyWindow(window);
9327 static void test_clear_render_target_view(void)
9329 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
9330 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
9331 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
9333 ID3D11Texture2D *texture, *srgb_texture;
9334 struct d3d11_test_context test_context;
9335 ID3D11RenderTargetView *rtv, *srgb_rtv;
9336 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
9337 D3D11_TEXTURE2D_DESC texture_desc;
9338 ID3D11DeviceContext *context;
9339 struct resource_readback rb;
9340 ID3D11Device *device;
9341 unsigned int i, j;
9342 HRESULT hr;
9344 if (!init_test_context(&test_context, NULL))
9345 return;
9347 device = test_context.device;
9348 context = test_context.immediate_context;
9350 texture_desc.Width = 640;
9351 texture_desc.Height = 480;
9352 texture_desc.MipLevels = 1;
9353 texture_desc.ArraySize = 1;
9354 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9355 texture_desc.SampleDesc.Count = 1;
9356 texture_desc.SampleDesc.Quality = 0;
9357 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9358 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9359 texture_desc.CPUAccessFlags = 0;
9360 texture_desc.MiscFlags = 0;
9361 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9362 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
9364 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
9365 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
9366 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
9368 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
9369 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9371 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
9372 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9374 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
9375 check_texture_color(test_context.backbuffer, expected_color, 1);
9377 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
9378 check_texture_color(texture, expected_color, 1);
9380 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
9381 check_texture_color(texture, expected_color, 1);
9383 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
9384 check_texture_color(srgb_texture, expected_srgb_color, 1);
9386 ID3D11RenderTargetView_Release(srgb_rtv);
9387 ID3D11RenderTargetView_Release(rtv);
9388 ID3D11Texture2D_Release(srgb_texture);
9389 ID3D11Texture2D_Release(texture);
9391 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
9392 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9393 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
9395 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
9396 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
9397 U(rtv_desc).Texture2D.MipSlice = 0;
9398 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
9399 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9401 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9402 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
9403 U(rtv_desc).Texture2D.MipSlice = 0;
9404 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
9405 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9407 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
9408 check_texture_color(texture, expected_color, 1);
9410 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
9411 get_texture_readback(texture, 0, &rb);
9412 for (i = 0; i < 4; ++i)
9414 for (j = 0; j < 4; ++j)
9416 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
9417 DWORD color = get_readback_color(&rb, 80 + i * 160, 60 + j * 120);
9418 ok(compare_color(color, expected_srgb_color, 1)
9419 || broken(compare_color(color, expected_color, 1) && broken_device),
9420 "Got unexpected color 0x%08x.\n", color);
9423 release_resource_readback(&rb);
9425 ID3D11RenderTargetView_Release(srgb_rtv);
9426 ID3D11RenderTargetView_Release(rtv);
9427 ID3D11Texture2D_Release(texture);
9428 release_test_context(&test_context);
9431 static void test_clear_depth_stencil_view(void)
9433 D3D11_TEXTURE2D_DESC texture_desc;
9434 ID3D11Texture2D *depth_texture;
9435 ID3D11DeviceContext *context;
9436 ID3D11DepthStencilView *dsv;
9437 ID3D11Device *device;
9438 ULONG refcount;
9439 HRESULT hr;
9441 if (!(device = create_device(NULL)))
9443 skip("Failed to create device.\n");
9444 return;
9447 ID3D11Device_GetImmediateContext(device, &context);
9449 texture_desc.Width = 640;
9450 texture_desc.Height = 480;
9451 texture_desc.MipLevels = 1;
9452 texture_desc.ArraySize = 1;
9453 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
9454 texture_desc.SampleDesc.Count = 1;
9455 texture_desc.SampleDesc.Quality = 0;
9456 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9457 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
9458 texture_desc.CPUAccessFlags = 0;
9459 texture_desc.MiscFlags = 0;
9460 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
9461 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
9463 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
9464 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
9466 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
9467 check_texture_float(depth_texture, 1.0f, 0);
9469 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
9470 check_texture_float(depth_texture, 0.25f, 0);
9472 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
9473 check_texture_float(depth_texture, 0.25f, 0);
9475 ID3D11Texture2D_Release(depth_texture);
9476 ID3D11DepthStencilView_Release(dsv);
9478 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
9479 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
9480 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
9482 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
9483 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
9485 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
9486 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
9488 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
9489 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
9491 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
9492 check_texture_color(depth_texture, 0xffffffff, 0);
9494 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
9495 check_texture_color(depth_texture, 0x00000000, 0);
9497 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
9498 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
9500 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
9501 check_texture_color(depth_texture, 0xffffffff, 0);
9503 ID3D11Texture2D_Release(depth_texture);
9504 ID3D11DepthStencilView_Release(dsv);
9506 ID3D11DeviceContext_Release(context);
9508 refcount = ID3D11Device_Release(device);
9509 ok(!refcount, "Device has %u references left.\n", refcount);
9512 static unsigned int to_sint8(unsigned int x)
9514 union
9516 signed int s;
9517 unsigned int u;
9518 } bits;
9519 bits.u = x;
9520 return min(max(bits.s, -128), 127) & 0xff;
9523 #define check_rgba_sint8(data, uvec) check_rgba_sint8_(__LINE__, data, uvec)
9524 static void check_rgba_sint8_(unsigned int line, DWORD data, const struct uvec4 *v)
9526 unsigned int x = to_sint8(v->x);
9527 unsigned int y = to_sint8(v->y);
9528 unsigned int z = to_sint8(v->z);
9529 unsigned int w = to_sint8(v->w);
9530 DWORD expected[] =
9532 /* Windows 7 - Nvidia, WARP */
9533 (v->x & 0xff) | (v->y & 0xff) << 8 | (v->z & 0xff) << 16 | (v->w & 0xff) << 24,
9534 /* Windows 10 - AMD */
9535 x | y << 8 | z << 16 | w << 24,
9536 /* Windows 10 - Intel */
9537 x | x << 8 | x << 16 | x << 24,
9540 ok_(__FILE__, line)(data == expected[0] || data == expected[1] || broken(data == expected[2]),
9541 "Got %#x, expected %#x or %#x at %u, uvec4 %#x, %#x, %#x, %#x.\n",
9542 data, expected[0], expected[1], x, v->x, v->y, v->z, v->w);
9545 static void test_clear_buffer_unordered_access_view(void)
9547 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
9548 ID3D11UnorderedAccessView *uav, *uav2;
9549 struct device_desc device_desc;
9550 D3D11_BUFFER_DESC buffer_desc;
9551 ID3D11DeviceContext *context;
9552 struct resource_readback rb;
9553 ID3D11Buffer *buffer;
9554 ID3D11Device *device;
9555 struct uvec4 uvec4;
9556 unsigned int i, x;
9557 ULONG refcount;
9558 HRESULT hr;
9560 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
9561 static const struct uvec4 fe_uvec4 = {0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe};
9562 static const struct uvec4 uvec4_data[] =
9564 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
9566 {0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
9567 {0xffffffff, 0x00000000, 0x00000000, 0x00000000},
9568 {0x00000000, 0xffffffff, 0x00000000, 0x00000000},
9569 {0x00000000, 0x00000000, 0xffffffff, 0x00000000},
9570 {0x00000000, 0x00000000, 0x00000000, 0xffffffff},
9572 {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff},
9573 {0x80000000, 0x80000000, 0x80000000, 0x80000000},
9574 {0x000000ff, 0x00000080, 0x80000080, 0x00000080},
9575 {0x000000ff, 0x0000007f, 0x000000ef, 0x000000fe},
9576 {0x800000ff, 0x8000007f, 0x800000ef, 0x800000fe},
9577 {0xfefefefe, 0xf0f0f0f0, 0xefefefef, 0x0f0f0f0f},
9578 {0xaaaaaaaa, 0xdeadbeef, 0xdeadbabe, 0xdeadf00d},
9580 {0x00000001, 0x00000002, 0x00000003, 0x00000004},
9581 {0x000000ff, 0x000000fe, 0x000000fd, 0x000000fc},
9582 {0x000000f2, 0x000000f1, 0x000000f0, 0x000000ef},
9583 {0x0000000a, 0x0000000d, 0x0000000e, 0x0000000f},
9584 {0x0000001a, 0x0000002d, 0x0000003e, 0x0000004f},
9585 {0x00000050, 0x00000060, 0x00000070, 0x00000080},
9586 {0x00000090, 0x000000a0, 0x000000b0, 0x000000c0},
9587 {0x000000d0, 0x000000e0, 0x000000f0, 0x000000ff},
9588 {0x00000073, 0x00000077, 0x0000007a, 0x0000007b},
9589 {0x0000007c, 0x0000007d, 0x0000007e, 0x0000007f},
9591 {0x80000001, 0x80000002, 0x80000003, 0x80000004},
9592 {0x800000ff, 0x800000fe, 0x800000fd, 0x800000fc},
9593 {0x800000f2, 0x800000f1, 0x800000f0, 0x800000ef},
9594 {0x8000000a, 0x0000000d, 0x8000000e, 0x8000000f},
9595 {0x8000001a, 0x8000002d, 0x8000003e, 0x8000004f},
9596 {0x80000050, 0x80000060, 0x80000070, 0x00000080},
9597 {0x80000090, 0x800000a0, 0x800000b0, 0x800000c0},
9598 {0x800000d0, 0x800000e0, 0x800000f0, 0x800000ff},
9599 {0x80000073, 0x80000077, 0x8000007a, 0x8000007b},
9600 {0x8000007c, 0x8000007d, 0x8000007e, 0x8000007f},
9602 {0x7fffff01, 0x7fffff02, 0x7fffff03, 0x7fffff04},
9603 {0x7fffffff, 0x7ffffffe, 0x7ffffffd, 0x7ffffffc},
9604 {0x7ffffff2, 0x7ffffff1, 0x7ffffff0, 0x7fffffef},
9605 {0x7fffff0a, 0x7fffff0d, 0x7fffff0e, 0x7fffff0f},
9606 {0x7fffff1a, 0x7fffff2d, 0x7fffff3e, 0x7fffff4f},
9607 {0x7fffff50, 0x7fffff60, 0x7fffff70, 0x7fffff80},
9608 {0x8fffff90, 0x7fffffa0, 0x7fffffb0, 0x7fffffc0},
9609 {0x7fffffd0, 0x7fffffe0, 0x7ffffff0, 0x7fffffff},
9610 {0x7fffff73, 0x7fffff77, 0x7fffff7a, 0x7fffff7b},
9611 {0x7fffff7c, 0x7fffff7d, 0x7fffff7e, 0x7fffff7f},
9613 {0xffffff01, 0xffffff02, 0xffffff03, 0xffffff04},
9614 {0xffffffff, 0xfffffffe, 0xfffffffd, 0xfffffffc},
9615 {0xfffffff2, 0xfffffff1, 0xfffffff0, 0xffffffef},
9616 {0xffffff0a, 0xffffff0d, 0xffffff0e, 0xffffff0f},
9617 {0xffffff1a, 0xffffff2d, 0xffffff3e, 0xffffff4f},
9618 {0xffffff50, 0xffffff60, 0xffffff70, 0xffffff80},
9619 {0xffffff90, 0xffffffa0, 0xffffffb0, 0xffffffc0},
9620 {0xffffffd0, 0xffffffe0, 0xfffffff0, 0xffffffff},
9621 {0xffffff73, 0xffffff77, 0xffffff7a, 0xffffff7b},
9622 {0xffffff7c, 0xffffff7d, 0xffffff7e, 0xffffff7f},
9625 device_desc.feature_level = &feature_level;
9626 device_desc.flags = 0;
9627 if (!(device = create_device(&device_desc)))
9629 skip("Failed to create device for feature level %#x.\n", feature_level);
9630 return;
9633 ID3D11Device_GetImmediateContext(device, &context);
9635 /* Structured buffer views */
9636 buffer_desc.ByteWidth = 64;
9637 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
9638 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
9639 buffer_desc.CPUAccessFlags = 0;
9640 buffer_desc.MiscFlags = 0;
9641 buffer_desc.StructureByteStride = 0;
9642 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
9643 buffer_desc.StructureByteStride = 4;
9644 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
9645 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
9647 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
9648 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
9650 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
9651 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
9652 U(uav_desc).Buffer.FirstElement = 0;
9653 U(uav_desc).Buffer.NumElements = 4;
9654 U(uav_desc).Buffer.Flags = 0;
9655 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
9656 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
9658 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
9660 uvec4 = uvec4_data[i];
9661 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
9662 get_buffer_readback(buffer, &rb);
9663 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
9665 DWORD data = get_readback_color(&rb, x, 0);
9666 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
9668 release_resource_readback(&rb);
9670 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
9671 get_buffer_readback(buffer, &rb);
9672 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
9674 DWORD data = get_readback_color(&rb, x, 0);
9675 uvec4 = x < U(uav_desc).Buffer.NumElements ? fe_uvec4 : uvec4_data[i];
9676 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
9678 release_resource_readback(&rb);
9681 ID3D11Buffer_Release(buffer);
9682 ID3D11UnorderedAccessView_Release(uav);
9683 ID3D11UnorderedAccessView_Release(uav2);
9685 /* Raw buffer views */
9686 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
9687 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
9688 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
9690 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
9691 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
9692 U(uav_desc).Buffer.FirstElement = 0;
9693 U(uav_desc).Buffer.NumElements = 16;
9694 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
9695 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
9696 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
9697 U(uav_desc).Buffer.FirstElement = 8;
9698 U(uav_desc).Buffer.NumElements = 8;
9699 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
9700 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
9702 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
9704 uvec4 = uvec4_data[i];
9705 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
9706 get_buffer_readback(buffer, &rb);
9707 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
9709 DWORD data = get_readback_color(&rb, x, 0);
9710 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
9712 release_resource_readback(&rb);
9714 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
9715 get_buffer_readback(buffer, &rb);
9716 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
9718 DWORD data = get_readback_color(&rb, x, 0);
9719 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
9720 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
9722 release_resource_readback(&rb);
9725 ID3D11Buffer_Release(buffer);
9726 ID3D11UnorderedAccessView_Release(uav);
9727 ID3D11UnorderedAccessView_Release(uav2);
9729 /* Typed buffer views */
9730 buffer_desc.MiscFlags = 0;
9731 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
9732 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
9734 uav_desc.Format = DXGI_FORMAT_R32_SINT;
9735 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
9736 U(uav_desc).Buffer.FirstElement = 0;
9737 U(uav_desc).Buffer.NumElements = 16;
9738 U(uav_desc).Buffer.Flags = 0;
9739 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
9740 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
9741 U(uav_desc).Buffer.FirstElement = 9;
9742 U(uav_desc).Buffer.NumElements = 7;
9743 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
9744 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
9746 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
9748 uvec4 = uvec4_data[i];
9749 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
9750 get_buffer_readback(buffer, &rb);
9751 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
9753 DWORD data = get_readback_color(&rb, x, 0);
9754 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
9756 release_resource_readback(&rb);
9758 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
9759 get_buffer_readback(buffer, &rb);
9760 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
9762 DWORD data = get_readback_color(&rb, x, 0);
9763 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
9764 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
9766 release_resource_readback(&rb);
9769 ID3D11UnorderedAccessView_Release(uav);
9770 ID3D11UnorderedAccessView_Release(uav2);
9772 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
9773 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
9774 U(uav_desc).Buffer.FirstElement = 0;
9775 U(uav_desc).Buffer.NumElements = 4;
9776 U(uav_desc).Buffer.Flags = 0;
9777 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
9778 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
9779 U(uav_desc).Buffer.FirstElement = 2;
9780 U(uav_desc).Buffer.NumElements = 2;
9781 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
9782 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
9784 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
9786 uvec4 = uvec4_data[i];
9787 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
9788 get_buffer_readback(buffer, &rb);
9789 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
9791 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
9792 const struct uvec4 broken_result = {uvec4.x, uvec4.x, uvec4.x, uvec4.x}; /* Intel */
9793 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
9794 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
9795 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
9797 release_resource_readback(&rb);
9799 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
9800 get_buffer_readback(buffer, &rb);
9801 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
9803 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
9804 struct uvec4 broken_result;
9805 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
9806 broken_result.x = broken_result.y = broken_result.z = broken_result.w = uvec4.x;
9807 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
9808 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
9809 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
9811 release_resource_readback(&rb);
9814 uvec4.x = uvec4.y = uvec4.z = uvec4.w = 0xdeadbeef;
9815 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
9816 ID3D11UnorderedAccessView_Release(uav);
9817 ID3D11UnorderedAccessView_Release(uav2);
9819 uav_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT;
9820 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
9821 U(uav_desc).Buffer.FirstElement = 0;
9822 U(uav_desc).Buffer.NumElements = 16;
9823 U(uav_desc).Buffer.Flags = 0;
9824 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
9825 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
9826 U(uav_desc).Buffer.FirstElement = 8;
9827 U(uav_desc).Buffer.NumElements = 8;
9828 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
9829 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
9831 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
9833 uvec4 = uvec4_data[i];
9834 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
9835 get_buffer_readback(buffer, &rb);
9836 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
9837 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0), &uvec4);
9838 release_resource_readback(&rb);
9840 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
9841 get_buffer_readback(buffer, &rb);
9842 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
9844 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
9845 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0), &uvec4);
9847 release_resource_readback(&rb);
9850 ID3D11UnorderedAccessView_Release(uav);
9851 ID3D11UnorderedAccessView_Release(uav2);
9853 ID3D11Buffer_Release(buffer);
9855 ID3D11DeviceContext_Release(context);
9856 refcount = ID3D11Device_Release(device);
9857 ok(!refcount, "Device has %u references left.\n", refcount);
9860 static void test_draw_depth_only(void)
9862 ID3D11DepthStencilState *depth_stencil_state;
9863 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
9864 struct d3d11_test_context test_context;
9865 ID3D11PixelShader *ps_color, *ps_depth;
9866 D3D11_TEXTURE2D_DESC texture_desc;
9867 ID3D11DeviceContext *context;
9868 ID3D11DepthStencilView *dsv;
9869 struct resource_readback rb;
9870 ID3D11Texture2D *texture;
9871 ID3D11Device *device;
9872 unsigned int i, j;
9873 D3D11_VIEWPORT vp;
9874 struct vec4 depth;
9875 ID3D11Buffer *cb;
9876 HRESULT hr;
9878 static const DWORD ps_color_code[] =
9880 #if 0
9881 float4 main(float4 position : SV_POSITION) : SV_Target
9883 return float4(0.0, 1.0, 0.0, 1.0);
9885 #endif
9886 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
9887 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9888 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
9889 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9890 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
9891 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
9892 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
9894 static const DWORD ps_depth_code[] =
9896 #if 0
9897 float depth;
9899 float main() : SV_Depth
9901 return depth;
9903 #endif
9904 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
9905 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9906 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
9907 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
9908 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
9909 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
9912 if (!init_test_context(&test_context, NULL))
9913 return;
9915 device = test_context.device;
9916 context = test_context.immediate_context;
9918 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
9920 texture_desc.Width = 640;
9921 texture_desc.Height = 480;
9922 texture_desc.MipLevels = 1;
9923 texture_desc.ArraySize = 1;
9924 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
9925 texture_desc.SampleDesc.Count = 1;
9926 texture_desc.SampleDesc.Quality = 0;
9927 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9928 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
9929 texture_desc.CPUAccessFlags = 0;
9930 texture_desc.MiscFlags = 0;
9932 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9933 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9935 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
9936 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
9938 depth_stencil_desc.DepthEnable = TRUE;
9939 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
9940 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS;
9941 depth_stencil_desc.StencilEnable = FALSE;
9943 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
9944 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
9946 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
9947 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9948 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
9949 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9951 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9952 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
9953 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
9954 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
9956 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
9957 check_texture_float(texture, 1.0f, 1);
9958 draw_quad(&test_context);
9959 check_texture_float(texture, 0.0f, 1);
9961 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
9963 depth.x = 0.7f;
9964 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
9965 draw_quad(&test_context);
9966 check_texture_float(texture, 0.0f, 1);
9967 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
9968 check_texture_float(texture, 1.0f, 1);
9969 draw_quad(&test_context);
9970 check_texture_float(texture, 0.7f, 1);
9971 depth.x = 0.8f;
9972 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
9973 draw_quad(&test_context);
9974 check_texture_float(texture, 0.7f, 1);
9975 depth.x = 0.5f;
9976 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
9977 draw_quad(&test_context);
9978 check_texture_float(texture, 0.5f, 1);
9980 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
9981 depth.x = 0.1f;
9982 for (i = 0; i < 4; ++i)
9984 for (j = 0; j < 4; ++j)
9986 depth.x = 1.0f / 16.0f * (j + 4 * i);
9987 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
9989 vp.TopLeftX = 160.0f * j;
9990 vp.TopLeftY = 120.0f * i;
9991 vp.Width = 160.0f;
9992 vp.Height = 120.0f;
9993 vp.MinDepth = 0.0f;
9994 vp.MaxDepth = 1.0f;
9995 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
9997 draw_quad(&test_context);
10000 get_texture_readback(texture, 0, &rb);
10001 for (i = 0; i < 4; ++i)
10003 for (j = 0; j < 4; ++j)
10005 float obtained_depth, expected_depth;
10007 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
10008 expected_depth = 1.0f / 16.0f * (j + 4 * i);
10009 ok(compare_float(obtained_depth, expected_depth, 1),
10010 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
10011 obtained_depth, j, i, expected_depth);
10014 release_resource_readback(&rb);
10016 ID3D11Buffer_Release(cb);
10017 ID3D11PixelShader_Release(ps_color);
10018 ID3D11PixelShader_Release(ps_depth);
10019 ID3D11DepthStencilView_Release(dsv);
10020 ID3D11DepthStencilState_Release(depth_stencil_state);
10021 ID3D11Texture2D_Release(texture);
10022 release_test_context(&test_context);
10025 static void test_draw_uav_only(void)
10027 struct d3d11_test_context test_context;
10028 D3D11_TEXTURE2D_DESC texture_desc;
10029 ID3D11UnorderedAccessView *uav;
10030 ID3D11DeviceContext *context;
10031 ID3D11Texture2D *texture;
10032 ID3D11PixelShader *ps;
10033 ID3D11Device *device;
10034 D3D11_VIEWPORT vp;
10035 HRESULT hr;
10037 static const DWORD ps_code[] =
10039 #if 0
10040 RWTexture2D<int> u;
10042 void main()
10044 InterlockedAdd(u[uint2(0, 0)], 1);
10046 #endif
10047 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
10048 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10049 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
10050 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
10051 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
10053 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
10054 static const UINT values[4] = {0};
10056 if (!init_test_context(&test_context, &feature_level))
10057 return;
10059 device = test_context.device;
10060 context = test_context.immediate_context;
10062 texture_desc.Width = 1;
10063 texture_desc.Height = 1;
10064 texture_desc.MipLevels = 1;
10065 texture_desc.ArraySize = 1;
10066 texture_desc.Format = DXGI_FORMAT_R32_SINT;
10067 texture_desc.SampleDesc.Count = 1;
10068 texture_desc.SampleDesc.Quality = 0;
10069 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10070 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
10071 texture_desc.CPUAccessFlags = 0;
10072 texture_desc.MiscFlags = 0;
10074 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10075 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10077 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
10078 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
10080 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10081 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10083 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10084 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
10085 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &test_context.backbuffer_rtv, NULL,
10086 0, 1, &uav, NULL);
10088 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
10089 memset(&vp, 0, sizeof(vp));
10090 vp.Width = 1.0f;
10091 vp.Height = 100.0f;
10092 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
10093 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
10094 draw_quad(&test_context);
10095 check_texture_color(texture, 100, 1);
10097 draw_quad(&test_context);
10098 draw_quad(&test_context);
10099 draw_quad(&test_context);
10100 draw_quad(&test_context);
10101 check_texture_color(texture, 500, 1);
10103 ID3D11PixelShader_Release(ps);
10104 ID3D11Texture2D_Release(texture);
10105 ID3D11UnorderedAccessView_Release(uav);
10106 release_test_context(&test_context);
10109 static void test_cb_relative_addressing(void)
10111 struct d3d11_test_context test_context;
10112 ID3D11Buffer *colors_cb, *index_cb;
10113 unsigned int i, index[4] = {0};
10114 ID3D11DeviceContext *context;
10115 ID3D11PixelShader *ps;
10116 ID3D11Device *device;
10117 HRESULT hr;
10119 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
10121 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10123 static const DWORD vs_code[] =
10125 #if 0
10126 int color_index;
10128 cbuffer colors
10130 float4 colors[8];
10133 struct vs_in
10135 float4 position : POSITION;
10138 struct vs_out
10140 float4 position : SV_POSITION;
10141 float4 color : COLOR;
10144 vs_out main(const vs_in v)
10146 vs_out o;
10148 o.position = v.position;
10149 o.color = colors[color_index];
10151 return o;
10153 #endif
10154 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
10155 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10156 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10157 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10158 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10159 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
10160 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
10161 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
10162 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
10163 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
10164 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
10165 0x0100003e,
10167 static const DWORD ps_code[] =
10169 #if 0
10170 struct ps_in
10172 float4 position : SV_POSITION;
10173 float4 color : COLOR;
10176 float4 main(const ps_in v) : SV_TARGET
10178 return v.color;
10180 #endif
10181 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
10182 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10183 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
10184 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
10185 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10186 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
10187 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10188 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
10190 static const struct vec2 quad[] =
10192 {-1.0f, -1.0f},
10193 {-1.0f, 1.0f},
10194 { 1.0f, -1.0f},
10195 { 1.0f, 1.0f},
10197 static const struct
10199 float color[4];
10201 colors[10] =
10203 {{0.0f, 0.0f, 0.0f, 1.0f}},
10204 {{0.0f, 0.0f, 1.0f, 0.0f}},
10205 {{0.0f, 0.0f, 1.0f, 1.0f}},
10206 {{0.0f, 1.0f, 0.0f, 0.0f}},
10207 {{0.0f, 1.0f, 0.0f, 1.0f}},
10208 {{0.0f, 1.0f, 1.0f, 0.0f}},
10209 {{0.0f, 1.0f, 1.0f, 1.0f}},
10210 {{1.0f, 0.0f, 0.0f, 0.0f}},
10211 {{1.0f, 0.0f, 0.0f, 1.0f}},
10212 {{1.0f, 0.0f, 1.0f, 0.0f}},
10214 static const struct
10216 unsigned int index;
10217 DWORD expected;
10219 test_data[] =
10221 {0, 0xff000000},
10222 {1, 0x00ff0000},
10223 {2, 0xffff0000},
10224 {3, 0x0000ff00},
10225 {4, 0xff00ff00},
10226 {5, 0x00ffff00},
10227 {6, 0xffffff00},
10228 {7, 0x000000ff},
10230 {8, 0xff0000ff},
10231 {9, 0x00ff00ff},
10233 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
10234 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
10236 if (!init_test_context(&test_context, &feature_level))
10237 return;
10239 device = test_context.device;
10240 context = test_context.immediate_context;
10242 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10243 vs_code, sizeof(vs_code), &test_context.input_layout);
10244 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10246 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
10247 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
10248 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
10250 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
10251 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10252 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10253 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10255 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
10256 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
10257 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10259 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
10261 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
10263 index[0] = test_data[i].index;
10264 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
10266 draw_quad(&test_context);
10267 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
10270 ID3D11Buffer_Release(index_cb);
10271 ID3D11Buffer_Release(colors_cb);
10272 ID3D11PixelShader_Release(ps);
10274 release_test_context(&test_context);
10277 static void test_getdc(void)
10279 static const struct
10281 const char *name;
10282 DXGI_FORMAT format;
10283 BOOL getdc_supported;
10285 testdata[] =
10287 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
10288 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
10289 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
10290 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
10291 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
10292 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
10294 struct device_desc device_desc;
10295 D3D11_TEXTURE2D_DESC desc;
10296 ID3D11Texture2D *texture;
10297 IDXGISurface1 *surface;
10298 ID3D11Device *device;
10299 unsigned int i;
10300 ULONG refcount;
10301 HRESULT hr;
10302 HDC dc;
10304 device_desc.feature_level = NULL;
10305 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
10306 if (!(device = create_device(&device_desc)))
10308 skip("Failed to create device.\n");
10309 return;
10312 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
10313 desc.Width = 512;
10314 desc.Height = 512;
10315 desc.MipLevels = 1;
10316 desc.ArraySize = 1;
10317 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
10318 desc.SampleDesc.Count = 1;
10319 desc.SampleDesc.Quality = 0;
10320 desc.Usage = D3D11_USAGE_DEFAULT;
10321 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10322 desc.CPUAccessFlags = 0;
10323 desc.MiscFlags = 0;
10324 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
10325 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10327 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
10328 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
10330 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
10331 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
10333 IDXGISurface1_Release(surface);
10334 ID3D11Texture2D_Release(texture);
10336 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
10337 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
10338 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10340 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
10341 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
10343 hr = IDXGISurface1_ReleaseDC(surface, NULL);
10344 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
10346 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
10347 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
10349 hr = IDXGISurface1_ReleaseDC(surface, NULL);
10350 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
10352 IDXGISurface1_Release(surface);
10353 ID3D11Texture2D_Release(texture);
10355 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
10357 static const unsigned int bit_count = 32;
10358 unsigned int width_bytes;
10359 DIBSECTION dib;
10360 HBITMAP bitmap;
10361 DWORD type;
10362 int size;
10364 desc.Width = 64;
10365 desc.Height = 64;
10366 desc.MipLevels = 1;
10367 desc.ArraySize = 1;
10368 desc.Format = testdata[i].format;
10369 desc.SampleDesc.Count = 1;
10370 desc.SampleDesc.Quality = 0;
10371 desc.Usage = D3D11_USAGE_STAGING;
10372 desc.BindFlags = 0;
10373 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
10374 desc.MiscFlags = 0;
10376 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
10377 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10378 ID3D11Texture2D_Release(texture);
10380 /* STAGING usage, requesting GDI compatibility mode. */
10381 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
10382 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
10383 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
10385 desc.Usage = D3D11_USAGE_DEFAULT;
10386 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10387 desc.CPUAccessFlags = 0;
10388 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
10389 if (testdata[i].getdc_supported)
10390 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
10391 else
10392 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
10394 if (FAILED(hr))
10395 continue;
10397 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
10398 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
10400 dc = (void *)0x1234;
10401 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
10402 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
10404 if (FAILED(hr))
10406 IDXGISurface1_Release(surface);
10407 ID3D11Texture2D_Release(texture);
10408 continue;
10411 type = GetObjectType(dc);
10412 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
10413 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
10414 type = GetObjectType(bitmap);
10415 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
10417 size = GetObjectA(bitmap, sizeof(dib), &dib);
10418 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
10419 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
10421 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
10422 dib.dsBm.bmType, testdata[i].name);
10423 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
10424 dib.dsBm.bmWidth, testdata[i].name);
10425 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
10426 dib.dsBm.bmHeight, testdata[i].name);
10427 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
10428 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
10429 dib.dsBm.bmWidthBytes, testdata[i].name);
10430 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
10431 dib.dsBm.bmPlanes, testdata[i].name);
10432 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
10433 dib.dsBm.bmBitsPixel, testdata[i].name);
10435 if (size == sizeof(dib))
10436 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
10437 dib.dsBm.bmBits, testdata[i].name);
10438 else
10439 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
10440 dib.dsBm.bmBits, testdata[i].name);
10442 if (size == sizeof(dib))
10444 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
10445 dib.dsBmih.biSize, testdata[i].name);
10446 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
10447 dib.dsBmih.biHeight, testdata[i].name);
10448 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
10449 dib.dsBmih.biHeight, testdata[i].name);
10450 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
10451 dib.dsBmih.biPlanes, testdata[i].name);
10452 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
10453 dib.dsBmih.biBitCount, testdata[i].name);
10454 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
10455 dib.dsBmih.biCompression, testdata[i].name);
10456 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
10457 dib.dsBmih.biSizeImage, testdata[i].name);
10458 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
10459 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
10460 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
10461 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
10462 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
10463 dib.dsBmih.biClrUsed, testdata[i].name);
10464 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
10465 dib.dsBmih.biClrImportant, testdata[i].name);
10466 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
10467 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
10468 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
10469 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
10470 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
10473 hr = IDXGISurface1_ReleaseDC(surface, NULL);
10474 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
10476 IDXGISurface1_Release(surface);
10477 ID3D11Texture2D_Release(texture);
10480 refcount = ID3D11Device_Release(device);
10481 ok(!refcount, "Device has %u references left.\n", refcount);
10484 static void test_shader_stage_input_output_matching(void)
10486 struct d3d11_test_context test_context;
10487 D3D11_TEXTURE2D_DESC texture_desc;
10488 ID3D11Texture2D *render_target;
10489 ID3D11RenderTargetView *rtv[2];
10490 ID3D11DeviceContext *context;
10491 ID3D11VertexShader *vs;
10492 ID3D11PixelShader *ps;
10493 ID3D11Device *device;
10494 HRESULT hr;
10496 static const DWORD vs_code[] =
10498 #if 0
10499 struct output
10501 float4 position : SV_PoSiTion;
10502 float4 color0 : COLOR0;
10503 float4 color1 : COLOR1;
10506 void main(uint id : SV_VertexID, out output o)
10508 float2 coords = float2((id << 1) & 2, id & 2);
10509 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
10510 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
10511 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
10513 #endif
10514 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
10515 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10516 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
10517 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
10518 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10519 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
10520 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
10521 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
10522 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
10523 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
10524 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
10525 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
10526 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
10527 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
10528 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
10529 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
10530 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
10531 0x0100003e,
10533 static const DWORD ps_code[] =
10535 #if 0
10536 struct input
10538 float4 position : SV_PoSiTiOn;
10539 float4 color1 : COLOR1;
10540 float4 color0 : COLOR0;
10543 struct output
10545 float4 target0 : SV_Target0;
10546 float4 target1 : SV_Target1;
10549 void main(const in input i, out output o)
10551 o.target0 = i.color0;
10552 o.target1 = i.color1;
10554 #endif
10555 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
10556 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
10557 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
10558 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
10559 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
10560 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
10561 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
10562 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
10563 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
10564 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
10565 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
10568 if (!init_test_context(&test_context, NULL))
10569 return;
10571 device = test_context.device;
10572 context = test_context.immediate_context;
10574 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
10575 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10576 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10577 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10579 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10580 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
10581 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10583 rtv[0] = test_context.backbuffer_rtv;
10584 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
10585 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10587 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
10588 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10589 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
10590 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
10591 ID3D11DeviceContext_Draw(context, 3, 0);
10593 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10594 check_texture_color(render_target, 0xff0000ff, 0);
10596 ID3D11RenderTargetView_Release(rtv[1]);
10597 ID3D11Texture2D_Release(render_target);
10598 ID3D11PixelShader_Release(ps);
10599 ID3D11VertexShader_Release(vs);
10600 release_test_context(&test_context);
10603 static void test_sm4_if_instruction(void)
10605 struct d3d11_test_context test_context;
10606 ID3D11PixelShader *ps_if_nz, *ps_if_z;
10607 ID3D11DeviceContext *context;
10608 ID3D11Device *device;
10609 unsigned int bits[4];
10610 DWORD expected_color;
10611 ID3D11Buffer *cb;
10612 unsigned int i;
10613 HRESULT hr;
10615 static const DWORD ps_if_nz_code[] =
10617 #if 0
10618 uint bits;
10620 float4 main() : SV_TARGET
10622 if (bits)
10623 return float4(0.0f, 1.0f, 0.0f, 1.0f);
10624 else
10625 return float4(1.0f, 0.0f, 0.0f, 1.0f);
10627 #endif
10628 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
10629 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10630 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10631 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
10632 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
10633 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
10634 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
10635 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
10637 static const DWORD ps_if_z_code[] =
10639 #if 0
10640 uint bits;
10642 float4 main() : SV_TARGET
10644 if (!bits)
10645 return float4(0.0f, 1.0f, 0.0f, 1.0f);
10646 else
10647 return float4(1.0f, 0.0f, 0.0f, 1.0f);
10649 #endif
10650 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
10651 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10652 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10653 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
10654 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
10655 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
10656 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
10657 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
10659 static unsigned int bit_patterns[] =
10661 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
10664 if (!init_test_context(&test_context, NULL))
10665 return;
10667 device = test_context.device;
10668 context = test_context.immediate_context;
10670 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
10671 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
10672 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
10673 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
10675 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
10676 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10678 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
10680 *bits = bit_patterns[i];
10681 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
10683 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
10684 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
10685 draw_quad(&test_context);
10686 check_texture_color(test_context.backbuffer, expected_color, 0);
10688 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
10689 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
10690 draw_quad(&test_context);
10691 check_texture_color(test_context.backbuffer, expected_color, 0);
10694 ID3D11Buffer_Release(cb);
10695 ID3D11PixelShader_Release(ps_if_z);
10696 ID3D11PixelShader_Release(ps_if_nz);
10697 release_test_context(&test_context);
10700 static void test_sm4_breakc_instruction(void)
10702 struct d3d11_test_context test_context;
10703 ID3D11DeviceContext *context;
10704 ID3D11PixelShader *ps;
10705 ID3D11Device *device;
10706 HRESULT hr;
10708 static const DWORD ps_breakc_nz_code[] =
10710 #if 0
10711 float4 main() : SV_TARGET
10713 uint counter = 0;
10715 for (uint i = 0; i < 255; ++i)
10716 ++counter;
10718 if (counter == 255)
10719 return float4(0.0f, 1.0f, 0.0f, 1.0f);
10720 else
10721 return float4(1.0f, 0.0f, 0.0f, 1.0f);
10723 #endif
10724 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
10725 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10726 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10727 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
10728 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
10729 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
10730 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
10731 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
10732 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
10733 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
10734 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
10735 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
10736 0x01000015, 0x0100003e,
10738 static const DWORD ps_breakc_z_code[] =
10740 #if 0
10741 float4 main() : SV_TARGET
10743 uint counter = 0;
10745 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
10746 ++counter;
10748 if (counter == 255)
10749 return float4(0.0f, 1.0f, 0.0f, 1.0f);
10750 else
10751 return float4(1.0f, 0.0f, 0.0f, 1.0f);
10753 #endif
10754 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
10755 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10756 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10757 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
10758 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
10759 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
10760 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
10761 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
10762 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
10763 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
10764 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
10765 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
10766 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
10767 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
10770 if (!init_test_context(&test_context, NULL))
10771 return;
10773 device = test_context.device;
10774 context = test_context.immediate_context;
10776 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
10777 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
10778 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10779 draw_quad(&test_context);
10780 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10781 ID3D11PixelShader_Release(ps);
10783 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
10784 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
10785 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10786 draw_quad(&test_context);
10787 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10788 ID3D11PixelShader_Release(ps);
10790 release_test_context(&test_context);
10793 static void test_create_input_layout(void)
10795 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
10797 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10799 ULONG refcount, expected_refcount;
10800 ID3D11InputLayout *input_layout;
10801 ID3D11Device *device;
10802 unsigned int i;
10803 HRESULT hr;
10805 static const DWORD vs_code[] =
10807 #if 0
10808 float4 main(float4 position : POSITION) : SV_POSITION
10810 return position;
10812 #endif
10813 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
10814 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10815 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10816 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
10817 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
10818 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10819 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
10821 static const DXGI_FORMAT vertex_formats[] =
10823 DXGI_FORMAT_R32G32_FLOAT,
10824 DXGI_FORMAT_R32G32_UINT,
10825 DXGI_FORMAT_R32G32_SINT,
10826 DXGI_FORMAT_R16G16_FLOAT,
10827 DXGI_FORMAT_R16G16_UINT,
10828 DXGI_FORMAT_R16G16_SINT,
10829 DXGI_FORMAT_R32_FLOAT,
10830 DXGI_FORMAT_R32_UINT,
10831 DXGI_FORMAT_R32_SINT,
10832 DXGI_FORMAT_R16_UINT,
10833 DXGI_FORMAT_R16_SINT,
10834 DXGI_FORMAT_R8_UINT,
10835 DXGI_FORMAT_R8_SINT,
10838 if (!(device = create_device(NULL)))
10840 skip("Failed to create device.\n");
10841 return;
10844 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
10846 expected_refcount = get_refcount(device) + 1;
10847 layout_desc->Format = vertex_formats[i];
10848 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10849 vs_code, sizeof(vs_code), &input_layout);
10850 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
10851 vertex_formats[i], hr);
10852 refcount = get_refcount(device);
10853 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
10854 refcount, expected_refcount);
10855 ID3D11InputLayout_Release(input_layout);
10858 refcount = ID3D11Device_Release(device);
10859 ok(!refcount, "Device has %u references left.\n", refcount);
10862 static void test_input_assembler(void)
10864 enum layout_id
10866 LAYOUT_FLOAT32,
10867 LAYOUT_UINT16,
10868 LAYOUT_SINT16,
10869 LAYOUT_UNORM16,
10870 LAYOUT_SNORM16,
10871 LAYOUT_UINT8,
10872 LAYOUT_SINT8,
10873 LAYOUT_UNORM8,
10874 LAYOUT_SNORM8,
10875 LAYOUT_UNORM10_2,
10876 LAYOUT_UINT10_2,
10878 LAYOUT_COUNT,
10881 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
10883 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10884 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10886 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
10887 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
10888 ID3D11Buffer *vb_position, *vb_attribute;
10889 struct d3d11_test_context test_context;
10890 D3D11_TEXTURE2D_DESC texture_desc;
10891 unsigned int i, j, stride, offset;
10892 ID3D11Texture2D *render_target;
10893 ID3D11DeviceContext *context;
10894 ID3D11RenderTargetView *rtv;
10895 ID3D11PixelShader *ps;
10896 ID3D11Device *device;
10897 HRESULT hr;
10899 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
10901 DXGI_FORMAT_R32G32B32A32_FLOAT,
10902 DXGI_FORMAT_R16G16B16A16_UINT,
10903 DXGI_FORMAT_R16G16B16A16_SINT,
10904 DXGI_FORMAT_R16G16B16A16_UNORM,
10905 DXGI_FORMAT_R16G16B16A16_SNORM,
10906 DXGI_FORMAT_R8G8B8A8_UINT,
10907 DXGI_FORMAT_R8G8B8A8_SINT,
10908 DXGI_FORMAT_R8G8B8A8_UNORM,
10909 DXGI_FORMAT_R8G8B8A8_SNORM,
10910 DXGI_FORMAT_R10G10B10A2_UNORM,
10911 DXGI_FORMAT_R10G10B10A2_UINT,
10913 static const struct vec2 quad[] =
10915 {-1.0f, -1.0f},
10916 {-1.0f, 1.0f},
10917 { 1.0f, -1.0f},
10918 { 1.0f, 1.0f},
10920 static const DWORD ps_code[] =
10922 #if 0
10923 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
10925 return color;
10927 #endif
10928 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
10929 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
10930 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
10931 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
10932 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10933 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
10934 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
10935 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
10937 static const DWORD vs_float_code[] =
10939 #if 0
10940 struct output
10942 float4 position : SV_Position;
10943 float4 color : COLOR;
10946 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
10948 o.position = position;
10949 o.color = color;
10951 #endif
10952 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
10953 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10954 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
10955 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
10956 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10957 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10958 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
10959 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
10960 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
10961 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
10962 0x0100003e,
10964 static const DWORD vs_uint_code[] =
10966 #if 0
10967 struct output
10969 float4 position : SV_Position;
10970 float4 color : COLOR;
10973 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
10975 o.position = position;
10976 o.color = color;
10978 #endif
10979 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
10980 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10981 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
10982 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
10983 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10984 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10985 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
10986 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
10987 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
10988 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
10989 0x0100003e,
10991 static const DWORD vs_sint_code[] =
10993 #if 0
10994 struct output
10996 float4 position : SV_Position;
10997 float4 color : COLOR;
11000 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
11002 o.position = position;
11003 o.color = color;
11005 #endif
11006 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
11007 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11008 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
11009 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
11010 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11011 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11012 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
11013 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
11014 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
11015 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
11016 0x0100003e,
11018 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
11019 static const unsigned short uint16_data[] = {6, 8, 55, 777};
11020 static const short sint16_data[] = {-1, 33, 8, -77};
11021 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
11022 static const short snorm16_data[] = {-32768, 0, 32767, 0};
11023 static const unsigned char uint8_data[] = {0, 64, 128, 255};
11024 static const signed char sint8_data[] = {-128, 0, 127, 64};
11025 static const unsigned int uint32_zero = 0;
11026 static const unsigned int uint32_max = 0xffffffff;
11027 static const unsigned int unorm10_2_data= 0xa00003ff;
11028 static const unsigned int g10_data = 0x000ffc00;
11029 static const unsigned int a2_data = 0xc0000000;
11030 static const struct
11032 enum layout_id layout_id;
11033 unsigned int stride;
11034 const void *data;
11035 struct vec4 expected_color;
11036 BOOL todo;
11038 tests[] =
11040 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
11041 {1.0f, 2.0f, 3.0f, 4.0f}},
11042 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
11043 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
11044 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
11045 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
11046 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
11047 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
11048 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
11049 {-1.0f, 0.0f, 1.0f, 0.0f}},
11050 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
11051 {0.0f, 0.0f, 0.0f, 0.0f}},
11052 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
11053 {255.0f, 255.0f, 255.0f, 255.0f}},
11054 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
11055 {0.0f, 64.0f, 128.0f, 255.0f}},
11056 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
11057 {0.0f, 0.0f, 0.0f, 0.0f}},
11058 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
11059 {-1.0f, -1.0f, -1.0f, -1.0f}},
11060 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
11061 {-128.0f, 0.0f, 127.0f, 64.0f}},
11062 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
11063 {0.0f, 0.0f, 0.0f, 0.0f}},
11064 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
11065 {1.0f, 1.0f, 1.0f, 1.0f}},
11066 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
11067 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
11068 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
11069 {0.0f, 0.0f, 0.0f, 0.0f}},
11070 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
11071 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
11072 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
11073 {0.0f, 0.0f, 0.0f, 0.0f}},
11074 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
11075 {1.0f, 1.0f, 1.0f, 1.0f}},
11076 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
11077 {0.0f, 1.0f, 0.0f, 0.0f}},
11078 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
11079 {0.0f, 0.0f, 0.0f, 1.0f}},
11080 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
11081 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
11082 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
11083 {0.0f, 0.0f, 0.0f, 0.0f}},
11084 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
11085 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
11086 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
11087 {0.0f, 1023.0f, 0.0f, 0.0f}},
11088 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
11089 {0.0f, 0.0f, 0.0f, 3.0f}},
11090 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
11091 {1023.0f, 0.0f, 512.0f, 2.0f}},
11094 if (!init_test_context(&test_context, NULL))
11095 return;
11097 device = test_context.device;
11098 context = test_context.immediate_context;
11100 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11101 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11103 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
11104 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
11105 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
11106 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
11107 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
11108 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
11110 for (i = 0; i < LAYOUT_COUNT; ++i)
11112 input_layout_desc[1].Format = layout_formats[i];
11113 input_layout[i] = NULL;
11114 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
11115 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
11116 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
11117 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
11120 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11121 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
11123 texture_desc.Width = 640;
11124 texture_desc.Height = 480;
11125 texture_desc.MipLevels = 1;
11126 texture_desc.ArraySize = 1;
11127 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11128 texture_desc.SampleDesc.Count = 1;
11129 texture_desc.SampleDesc.Quality = 0;
11130 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11131 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11132 texture_desc.CPUAccessFlags = 0;
11133 texture_desc.MiscFlags = 0;
11135 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
11136 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
11138 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
11139 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11141 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11142 offset = 0;
11143 stride = sizeof(*quad);
11144 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
11145 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11146 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11148 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11150 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
11152 if (tests[i].layout_id == LAYOUT_UINT10_2)
11153 continue;
11155 assert(tests[i].layout_id < LAYOUT_COUNT);
11156 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
11158 assert(4 * tests[i].stride <= 1024);
11159 box.right = tests[i].stride;
11160 for (j = 0; j < 4; ++j)
11162 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
11163 &box, tests[i].data, 0, 0);
11164 box.left += tests[i].stride;
11165 box.right += tests[i].stride;
11168 stride = tests[i].stride;
11169 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
11171 switch (layout_formats[tests[i].layout_id])
11173 case DXGI_FORMAT_R16G16B16A16_UINT:
11174 case DXGI_FORMAT_R10G10B10A2_UINT:
11175 case DXGI_FORMAT_R8G8B8A8_UINT:
11176 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
11177 break;
11178 case DXGI_FORMAT_R16G16B16A16_SINT:
11179 case DXGI_FORMAT_R8G8B8A8_SINT:
11180 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
11181 break;
11183 default:
11184 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
11185 /* Fall through. */
11186 case DXGI_FORMAT_R32G32B32A32_FLOAT:
11187 case DXGI_FORMAT_R16G16B16A16_UNORM:
11188 case DXGI_FORMAT_R16G16B16A16_SNORM:
11189 case DXGI_FORMAT_R10G10B10A2_UNORM:
11190 case DXGI_FORMAT_R8G8B8A8_UNORM:
11191 case DXGI_FORMAT_R8G8B8A8_SNORM:
11192 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
11193 break;
11196 ID3D11DeviceContext_Draw(context, 4, 0);
11197 check_texture_vec4(render_target, &tests[i].expected_color, 2);
11200 ID3D11Texture2D_Release(render_target);
11201 ID3D11RenderTargetView_Release(rtv);
11202 ID3D11Buffer_Release(vb_attribute);
11203 ID3D11Buffer_Release(vb_position);
11204 for (i = 0; i < LAYOUT_COUNT; ++i)
11206 if (input_layout[i])
11207 ID3D11InputLayout_Release(input_layout[i]);
11209 ID3D11PixelShader_Release(ps);
11210 ID3D11VertexShader_Release(vs_float);
11211 ID3D11VertexShader_Release(vs_uint);
11212 ID3D11VertexShader_Release(vs_sint);
11213 release_test_context(&test_context);
11216 static void test_null_sampler(void)
11218 struct d3d11_test_context test_context;
11219 D3D11_TEXTURE2D_DESC texture_desc;
11220 ID3D11ShaderResourceView *srv;
11221 ID3D11DeviceContext *context;
11222 ID3D11RenderTargetView *rtv;
11223 ID3D11SamplerState *sampler;
11224 ID3D11Texture2D *texture;
11225 ID3D11PixelShader *ps;
11226 ID3D11Device *device;
11227 HRESULT hr;
11229 static const DWORD ps_code[] =
11231 #if 0
11232 Texture2D t;
11233 SamplerState s;
11235 float4 main(float4 position : SV_POSITION) : SV_Target
11237 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
11239 #endif
11240 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
11241 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11242 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
11243 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11244 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
11245 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
11246 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
11247 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
11248 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
11249 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
11251 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
11253 if (!init_test_context(&test_context, NULL))
11254 return;
11256 device = test_context.device;
11257 context = test_context.immediate_context;
11259 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11260 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11262 texture_desc.Width = 64;
11263 texture_desc.Height = 64;
11264 texture_desc.MipLevels = 1;
11265 texture_desc.ArraySize = 1;
11266 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11267 texture_desc.SampleDesc.Count = 1;
11268 texture_desc.SampleDesc.Quality = 0;
11269 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11270 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
11271 texture_desc.CPUAccessFlags = 0;
11272 texture_desc.MiscFlags = 0;
11274 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11275 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11277 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11278 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11280 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
11281 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11283 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
11285 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11286 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
11287 sampler = NULL;
11288 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
11289 draw_quad(&test_context);
11290 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
11292 ID3D11ShaderResourceView_Release(srv);
11293 ID3D11RenderTargetView_Release(rtv);
11294 ID3D11Texture2D_Release(texture);
11295 ID3D11PixelShader_Release(ps);
11296 release_test_context(&test_context);
11299 static void test_check_feature_support(void)
11301 D3D11_FEATURE_DATA_THREADING threading[2];
11302 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
11303 ID3D11Device *device;
11304 ULONG refcount;
11305 HRESULT hr;
11307 if (!(device = create_device(NULL)))
11309 skip("Failed to create device.\n");
11310 return;
11313 memset(threading, 0xef, sizeof(threading));
11315 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
11316 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11317 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
11318 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11319 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
11320 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11321 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
11322 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11323 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
11324 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11325 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
11326 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11328 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
11329 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
11330 ok(threading[0].DriverCommandLists == 0xefefefef,
11331 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
11332 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
11333 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
11334 ok(threading[1].DriverCommandLists == 0xefefefef,
11335 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
11337 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
11338 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
11339 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
11340 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
11341 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
11342 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
11344 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
11345 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11346 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
11347 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11348 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
11349 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11350 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
11351 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11352 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
11353 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11354 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
11355 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11357 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
11358 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
11359 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
11361 refcount = ID3D11Device_Release(device);
11362 ok(!refcount, "Device has %u references left.\n", refcount);
11365 static void test_create_unordered_access_view(void)
11367 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11368 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
11369 D3D11_TEXTURE3D_DESC texture3d_desc;
11370 D3D11_TEXTURE2D_DESC texture2d_desc;
11371 ULONG refcount, expected_refcount;
11372 D3D11_SUBRESOURCE_DATA data = {0};
11373 ID3D11UnorderedAccessView *uav;
11374 struct device_desc device_desc;
11375 D3D11_BUFFER_DESC buffer_desc;
11376 ID3D11Device *device, *tmp;
11377 ID3D11Texture3D *texture3d;
11378 ID3D11Texture2D *texture2d;
11379 ID3D11Resource *texture;
11380 ID3D11Buffer *buffer;
11381 unsigned int i;
11382 HRESULT hr;
11384 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
11385 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
11386 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
11387 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
11388 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
11389 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
11390 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
11391 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
11392 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
11393 static const struct
11395 struct
11397 unsigned int miplevel_count;
11398 unsigned int depth_or_array_size;
11399 DXGI_FORMAT format;
11400 } texture;
11401 struct uav_desc uav_desc;
11402 struct uav_desc expected_uav_desc;
11404 tests[] =
11406 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
11407 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
11408 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
11409 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
11410 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
11411 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
11412 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
11413 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
11414 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
11415 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
11416 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
11417 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
11418 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
11419 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
11420 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
11421 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
11422 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
11423 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
11424 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
11425 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
11426 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
11427 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
11428 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
11429 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
11430 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
11431 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
11432 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
11433 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
11434 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
11435 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
11436 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
11437 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
11438 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
11439 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
11441 static const struct
11443 struct
11445 D3D11_UAV_DIMENSION dimension;
11446 unsigned int miplevel_count;
11447 unsigned int depth_or_array_size;
11448 DXGI_FORMAT format;
11449 } texture;
11450 struct uav_desc uav_desc;
11452 invalid_desc_tests[] =
11454 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
11455 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
11456 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
11457 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
11458 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
11459 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
11460 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
11461 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
11462 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
11463 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
11464 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
11465 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
11466 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
11467 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
11468 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
11469 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
11470 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
11471 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
11472 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
11473 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
11474 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
11475 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
11476 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
11477 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
11478 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
11479 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
11480 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
11481 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
11482 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
11483 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
11484 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
11485 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
11486 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
11488 #undef FMT_UNKNOWN
11489 #undef RGBA8_UNORM
11490 #undef RGBA8_TL
11491 #undef DIM_UNKNOWN
11492 #undef TEX_1D
11493 #undef TEX_1D_ARRAY
11494 #undef TEX_2D
11495 #undef TEX_2D_ARRAY
11496 #undef TEX_3D
11498 device_desc.feature_level = &feature_level;
11499 device_desc.flags = 0;
11500 if (!(device = create_device(&device_desc)))
11502 skip("Failed to create device.\n");
11503 return;
11506 buffer_desc.ByteWidth = 1024;
11507 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
11508 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
11509 buffer_desc.CPUAccessFlags = 0;
11510 buffer_desc.MiscFlags = 0;
11511 buffer_desc.StructureByteStride = 0;
11513 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
11514 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11516 expected_refcount = get_refcount(device) + 1;
11517 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11518 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11519 refcount = get_refcount(device);
11520 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
11521 tmp = NULL;
11522 expected_refcount = refcount + 1;
11523 ID3D11Buffer_GetDevice(buffer, &tmp);
11524 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
11525 refcount = get_refcount(device);
11526 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
11527 ID3D11Device_Release(tmp);
11529 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11530 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11531 U(uav_desc).Buffer.FirstElement = 0;
11532 U(uav_desc).Buffer.NumElements = 64;
11533 U(uav_desc).Buffer.Flags = 0;
11535 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
11536 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11538 expected_refcount = get_refcount(device) + 1;
11539 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11540 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11541 refcount = get_refcount(device);
11542 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
11543 tmp = NULL;
11544 expected_refcount = refcount + 1;
11545 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
11546 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
11547 refcount = get_refcount(device);
11548 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
11549 ID3D11Device_Release(tmp);
11551 ID3D11UnorderedAccessView_Release(uav);
11552 ID3D11Buffer_Release(buffer);
11554 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
11555 buffer_desc.StructureByteStride = 4;
11557 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11558 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11560 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
11561 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
11563 memset(&uav_desc, 0, sizeof(uav_desc));
11564 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
11566 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
11567 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
11568 uav_desc.ViewDimension);
11569 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
11570 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
11571 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
11573 ID3D11UnorderedAccessView_Release(uav);
11574 ID3D11Buffer_Release(buffer);
11576 texture2d_desc.Width = 512;
11577 texture2d_desc.Height = 512;
11578 texture2d_desc.SampleDesc.Count = 1;
11579 texture2d_desc.SampleDesc.Quality = 0;
11580 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
11581 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
11582 texture2d_desc.CPUAccessFlags = 0;
11583 texture2d_desc.MiscFlags = 0;
11585 texture3d_desc.Width = 64;
11586 texture3d_desc.Height = 64;
11587 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
11588 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
11589 texture3d_desc.CPUAccessFlags = 0;
11590 texture3d_desc.MiscFlags = 0;
11592 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11594 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
11596 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
11598 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
11599 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
11600 texture2d_desc.Format = tests[i].texture.format;
11602 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
11603 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
11604 texture = (ID3D11Resource *)texture2d;
11606 else
11608 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
11609 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
11610 texture3d_desc.Format = tests[i].texture.format;
11612 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
11613 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
11614 texture = (ID3D11Resource *)texture3d;
11617 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
11619 current_desc = NULL;
11621 else
11623 current_desc = &uav_desc;
11624 get_uav_desc(current_desc, &tests[i].uav_desc);
11627 expected_refcount = get_refcount(texture);
11628 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
11629 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
11630 refcount = get_refcount(texture);
11631 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
11633 memset(&uav_desc, 0, sizeof(uav_desc));
11634 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
11635 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
11637 ID3D11UnorderedAccessView_Release(uav);
11638 ID3D11Resource_Release(texture);
11641 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
11643 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
11644 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
11646 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
11648 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
11649 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
11650 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
11652 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
11653 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
11654 texture = (ID3D11Resource *)texture2d;
11656 else
11658 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
11659 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
11660 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
11662 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
11663 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
11664 texture = (ID3D11Resource *)texture3d;
11667 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
11668 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
11669 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
11671 ID3D11Resource_Release(texture);
11674 refcount = ID3D11Device_Release(device);
11675 ok(!refcount, "Device has %u references left.\n", refcount);
11678 static void test_immediate_constant_buffer(void)
11680 struct d3d11_test_context test_context;
11681 D3D11_TEXTURE2D_DESC texture_desc;
11682 ID3D11DeviceContext *context;
11683 ID3D11RenderTargetView *rtv;
11684 unsigned int index[4] = {0};
11685 ID3D11Texture2D *texture;
11686 ID3D11PixelShader *ps;
11687 ID3D11Device *device;
11688 ID3D11Buffer *cb;
11689 unsigned int i;
11690 HRESULT hr;
11692 static const DWORD ps_code[] =
11694 #if 0
11695 uint index;
11697 static const int int_array[6] =
11699 310, 111, 212, -513, -318, 0,
11702 static const uint uint_array[6] =
11704 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
11707 static const float float_array[6] =
11709 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
11712 float4 main() : SV_Target
11714 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
11716 #endif
11717 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
11718 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11719 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11720 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
11721 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
11722 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
11723 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
11724 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
11725 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
11726 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
11727 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
11728 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
11729 0x0100003e,
11731 static struct vec4 expected_result[] =
11733 { 310.0f, 2.0f, 76.00f, 1.0f},
11734 { 111.0f, 7.0f, 83.50f, 1.0f},
11735 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
11736 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
11737 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
11738 { 0.0f, 0.0f, 0.0f, 1.0f},
11741 if (!init_test_context(&test_context, NULL))
11742 return;
11744 device = test_context.device;
11745 context = test_context.immediate_context;
11747 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11748 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11749 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11751 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
11752 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11754 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11755 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11756 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11757 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11759 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11760 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11761 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11763 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
11765 *index = i;
11766 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
11768 draw_quad(&test_context);
11769 check_texture_vec4(texture, &expected_result[i], 0);
11772 ID3D11Buffer_Release(cb);
11773 ID3D11PixelShader_Release(ps);
11774 ID3D11Texture2D_Release(texture);
11775 ID3D11RenderTargetView_Release(rtv);
11776 release_test_context(&test_context);
11779 static void test_fp_specials(void)
11781 struct d3d11_test_context test_context;
11782 D3D11_TEXTURE2D_DESC texture_desc;
11783 ID3D11DeviceContext *context;
11784 ID3D11RenderTargetView *rtv;
11785 ID3D11Texture2D *texture;
11786 ID3D11PixelShader *ps;
11787 ID3D11Device *device;
11788 HRESULT hr;
11790 static const DWORD ps_code[] =
11792 #if 0
11793 float4 main() : SV_Target
11795 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
11797 #endif
11798 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
11799 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11800 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11801 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11802 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
11803 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
11805 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
11807 if (!init_test_context(&test_context, NULL))
11808 return;
11810 device = test_context.device;
11811 context = test_context.immediate_context;
11813 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11814 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11815 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11817 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11818 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11819 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11820 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11822 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11823 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11825 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11827 draw_quad(&test_context);
11828 check_texture_uvec4(texture, &expected_result);
11830 ID3D11PixelShader_Release(ps);
11831 ID3D11Texture2D_Release(texture);
11832 ID3D11RenderTargetView_Release(rtv);
11833 release_test_context(&test_context);
11836 static void test_uint_shader_instructions(void)
11838 struct shader
11840 const DWORD *code;
11841 size_t size;
11842 D3D_FEATURE_LEVEL required_feature_level;
11845 struct d3d11_test_context test_context;
11846 D3D11_TEXTURE2D_DESC texture_desc;
11847 D3D_FEATURE_LEVEL feature_level;
11848 ID3D11DeviceContext *context;
11849 ID3D11RenderTargetView *rtv;
11850 ID3D11Texture2D *texture;
11851 ID3D11PixelShader *ps;
11852 ID3D11Device *device;
11853 ID3D11Buffer *cb;
11854 unsigned int i;
11855 HRESULT hr;
11857 static const DWORD ps_bfi_code[] =
11859 #if 0
11860 uint bits, offset, insert, base;
11862 uint4 main() : SV_Target
11864 uint mask = ((1 << bits) - 1) << offset;
11865 return ((insert << offset) & mask) | (base & ~mask);
11867 #endif
11868 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
11869 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11870 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11871 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
11872 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11873 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
11874 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
11876 static const DWORD ps_ibfe_code[] =
11878 #if 0
11879 ps_5_0
11880 dcl_globalFlags refactoringAllowed
11881 dcl_constantbuffer cb0[1], immediateIndexed
11882 dcl_output o0.xyzw
11883 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
11885 #endif
11886 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
11887 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11888 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11889 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
11890 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11891 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
11892 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
11894 static const DWORD ps_ubfe_code[] =
11896 #if 0
11897 uint u;
11899 uint4 main() : SV_Target
11901 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
11903 #endif
11904 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
11905 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11906 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11907 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
11908 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11909 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
11910 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
11911 0x0100003e,
11913 static const DWORD ps_bfrev_code[] =
11915 #if 0
11916 uint bits;
11918 uint4 main() : SV_Target
11920 return uint4(reversebits(bits), reversebits(reversebits(bits)),
11921 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
11923 #endif
11924 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
11925 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11926 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11927 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
11928 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11929 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
11930 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
11931 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
11932 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
11933 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
11934 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
11936 static const DWORD ps_bits_code[] =
11938 #if 0
11939 uint u;
11940 int i;
11942 uint4 main() : SV_Target
11944 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
11946 #endif
11947 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
11948 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11949 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11950 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
11951 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11952 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
11953 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
11954 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
11955 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
11956 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
11957 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
11958 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
11959 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
11960 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
11962 static const DWORD ps_ftou_code[] =
11964 #if 0
11965 float f;
11967 uint4 main() : SV_Target
11969 return uint4(f, -f, 0, 0);
11971 #endif
11972 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
11973 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11974 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11975 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
11976 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
11977 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
11978 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
11979 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
11981 static const DWORD ps_f16tof32_code[] =
11983 #if 0
11984 uint4 hf;
11986 uint4 main() : SV_Target
11988 return f16tof32(hf);
11990 #endif
11991 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
11992 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11993 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11994 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
11995 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11996 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
11997 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
11999 static const DWORD ps_f32tof16_code[] =
12001 #if 0
12002 float4 f;
12004 uint4 main() : SV_Target
12006 return f32tof16(f);
12008 #endif
12009 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
12010 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12011 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
12012 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
12013 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
12014 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
12016 static const DWORD ps_not_code[] =
12018 #if 0
12019 uint2 bits;
12021 uint4 main() : SV_Target
12023 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
12025 #endif
12026 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
12027 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12028 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
12029 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
12030 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12031 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
12032 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
12033 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
12035 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
12036 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
12037 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
12038 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
12039 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
12040 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
12041 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
12042 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
12043 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
12044 static const struct
12046 const struct shader *ps;
12047 unsigned int bits[4];
12048 struct uvec4 expected_result;
12050 tests[] =
12052 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
12053 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
12054 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
12055 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
12056 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
12057 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
12058 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
12059 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
12060 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
12061 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
12062 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
12063 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
12064 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
12065 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
12066 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
12067 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
12068 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
12069 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
12070 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
12072 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
12073 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
12074 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
12075 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
12076 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
12077 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
12078 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
12079 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
12080 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
12081 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
12082 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
12083 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
12084 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
12085 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
12086 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
12087 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
12088 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
12089 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
12090 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
12091 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
12092 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
12093 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
12094 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
12095 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
12096 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
12097 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
12099 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
12100 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
12101 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
12102 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
12103 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
12104 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
12105 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
12107 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
12108 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
12109 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
12111 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
12112 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
12113 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
12114 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
12115 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
12116 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
12117 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
12118 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
12119 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
12120 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
12121 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
12122 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
12124 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
12125 {&ps_ftou, {BITS_NAN}, { 0, 0}},
12126 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
12127 {&ps_ftou, {BITS_INF}, {~0u, 0}},
12128 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
12129 {&ps_ftou, {BITS_1_0}, { 1, 0}},
12131 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
12132 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
12133 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
12134 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
12136 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
12138 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
12139 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
12142 if (!init_test_context(&test_context, NULL))
12143 return;
12145 device = test_context.device;
12146 context = test_context.immediate_context;
12147 feature_level = ID3D11Device_GetFeatureLevel(device);
12149 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
12150 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
12152 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12153 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
12154 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12155 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12157 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
12158 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12160 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
12162 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12164 if (feature_level < tests[i].ps->required_feature_level)
12165 continue;
12167 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
12168 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12169 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12171 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
12173 draw_quad(&test_context);
12174 check_texture_uvec4(texture, &tests[i].expected_result);
12176 ID3D11PixelShader_Release(ps);
12179 ID3D11Buffer_Release(cb);
12180 ID3D11Texture2D_Release(texture);
12181 ID3D11RenderTargetView_Release(rtv);
12182 release_test_context(&test_context);
12185 static void test_index_buffer_offset(void)
12187 struct d3d11_test_context test_context;
12188 ID3D11Buffer *vb, *ib, *so_buffer;
12189 ID3D11InputLayout *input_layout;
12190 ID3D11DeviceContext *context;
12191 struct resource_readback rb;
12192 ID3D11GeometryShader *gs;
12193 const struct vec4 *data;
12194 ID3D11VertexShader *vs;
12195 ID3D11Device *device;
12196 UINT stride, offset;
12197 unsigned int i;
12198 HRESULT hr;
12200 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12201 static const DWORD vs_code[] =
12203 #if 0
12204 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
12205 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
12207 out_position = position;
12208 out_attrib = attrib;
12210 #endif
12211 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
12212 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12213 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
12214 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
12215 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12216 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12217 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
12218 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12219 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12220 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12221 0x0100003e,
12223 static const DWORD gs_code[] =
12225 #if 0
12226 struct vertex
12228 float4 position : SV_POSITION;
12229 float4 attrib : ATTRIB;
12232 [maxvertexcount(1)]
12233 void main(point vertex input[1], inout PointStream<vertex> output)
12235 output.Append(input[0]);
12236 output.RestartStrip();
12238 #endif
12239 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
12240 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12241 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
12242 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
12243 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12244 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12245 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
12246 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
12247 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
12248 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
12249 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
12250 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
12252 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
12254 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12255 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
12257 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
12259 {0, "SV_Position", 0, 0, 4, 0},
12260 {0, "ATTRIB", 0, 0, 4, 0},
12262 static const struct
12264 struct vec4 position;
12265 struct vec4 attrib;
12267 vertices[] =
12269 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
12270 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
12271 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
12272 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
12274 static const unsigned int indices[] =
12276 0, 1, 2, 3,
12277 3, 2, 1, 0,
12278 1, 3, 2, 0,
12280 static const struct vec4 expected_data[] =
12282 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
12283 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
12284 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
12285 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
12287 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
12288 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
12289 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
12290 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
12292 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
12293 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
12294 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
12295 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
12297 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
12299 if (!init_test_context(&test_context, &feature_level))
12300 return;
12302 device = test_context.device;
12303 context = test_context.immediate_context;
12305 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
12306 vs_code, sizeof(vs_code), &input_layout);
12307 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12309 stride = 32;
12310 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
12311 so_declaration, ARRAY_SIZE(so_declaration),
12312 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
12313 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
12315 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12316 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12318 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
12319 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
12320 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
12322 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12323 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
12325 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12326 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
12327 stride = sizeof(*vertices);
12328 offset = 0;
12329 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
12331 offset = 0;
12332 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
12334 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
12335 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
12337 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
12338 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
12340 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
12341 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
12343 get_buffer_readback(so_buffer, &rb);
12344 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
12346 data = get_readback_vec4(&rb, i, 0);
12347 ok(compare_vec4(data, &expected_data[i], 0)
12348 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
12349 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
12350 data->x, data->y, data->z, data->w, i);
12352 release_resource_readback(&rb);
12354 ID3D11Buffer_Release(so_buffer);
12355 ID3D11Buffer_Release(ib);
12356 ID3D11Buffer_Release(vb);
12357 ID3D11VertexShader_Release(vs);
12358 ID3D11GeometryShader_Release(gs);
12359 ID3D11InputLayout_Release(input_layout);
12360 release_test_context(&test_context);
12363 static void test_face_culling(void)
12365 struct d3d11_test_context test_context;
12366 D3D11_RASTERIZER_DESC rasterizer_desc;
12367 ID3D11RasterizerState *state;
12368 ID3D11DeviceContext *context;
12369 ID3D11Buffer *cw_vb, *ccw_vb;
12370 ID3D11Device *device;
12371 BOOL broken_warp;
12372 unsigned int i;
12373 HRESULT hr;
12375 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
12376 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
12377 static const DWORD ps_code[] =
12379 #if 0
12380 float4 main(uint front : SV_IsFrontFace) : SV_Target
12382 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
12384 #endif
12385 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
12386 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
12387 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
12388 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
12389 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
12390 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
12391 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
12392 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
12393 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
12394 0x3f800000, 0x0100003e,
12396 static const struct vec2 ccw_quad[] =
12398 {-1.0f, 1.0f},
12399 {-1.0f, -1.0f},
12400 { 1.0f, 1.0f},
12401 { 1.0f, -1.0f},
12403 static const struct
12405 D3D11_CULL_MODE cull_mode;
12406 BOOL front_ccw;
12407 BOOL expected_cw;
12408 BOOL expected_ccw;
12410 tests[] =
12412 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
12413 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
12414 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
12415 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
12416 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
12417 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
12420 if (!init_test_context(&test_context, NULL))
12421 return;
12423 device = test_context.device;
12424 context = test_context.immediate_context;
12426 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
12427 draw_color_quad(&test_context, &green);
12428 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12430 cw_vb = test_context.vb;
12431 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
12433 test_context.vb = ccw_vb;
12434 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
12435 draw_color_quad(&test_context, &green);
12436 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
12438 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
12439 rasterizer_desc.CullMode = D3D11_CULL_BACK;
12440 rasterizer_desc.FrontCounterClockwise = FALSE;
12441 rasterizer_desc.DepthBias = 0;
12442 rasterizer_desc.DepthBiasClamp = 0.0f;
12443 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
12444 rasterizer_desc.DepthClipEnable = TRUE;
12445 rasterizer_desc.ScissorEnable = FALSE;
12446 rasterizer_desc.MultisampleEnable = FALSE;
12447 rasterizer_desc.AntialiasedLineEnable = FALSE;
12449 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12451 rasterizer_desc.CullMode = tests[i].cull_mode;
12452 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
12453 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
12454 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
12456 ID3D11DeviceContext_RSSetState(context, state);
12458 test_context.vb = cw_vb;
12459 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
12460 draw_color_quad(&test_context, &green);
12461 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
12463 test_context.vb = ccw_vb;
12464 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
12465 draw_color_quad(&test_context, &green);
12466 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
12468 ID3D11RasterizerState_Release(state);
12471 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1;
12473 /* Test SV_IsFrontFace. */
12474 ID3D11PixelShader_Release(test_context.ps);
12475 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
12476 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12478 rasterizer_desc.CullMode = D3D11_CULL_NONE;
12479 rasterizer_desc.FrontCounterClockwise = FALSE;
12480 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
12481 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12482 ID3D11DeviceContext_RSSetState(context, state);
12484 test_context.vb = cw_vb;
12485 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
12486 draw_color_quad(&test_context, &green);
12487 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12488 test_context.vb = ccw_vb;
12489 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
12490 draw_color_quad(&test_context, &green);
12491 if (!broken_warp)
12492 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
12493 else
12494 win_skip("Broken WARP.\n");
12496 ID3D11RasterizerState_Release(state);
12498 rasterizer_desc.CullMode = D3D11_CULL_NONE;
12499 rasterizer_desc.FrontCounterClockwise = TRUE;
12500 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
12501 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12502 ID3D11DeviceContext_RSSetState(context, state);
12504 test_context.vb = cw_vb;
12505 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
12506 draw_color_quad(&test_context, &green);
12507 if (!broken_warp)
12508 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
12509 else
12510 win_skip("Broken WARP.\n");
12511 test_context.vb = ccw_vb;
12512 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
12513 draw_color_quad(&test_context, &green);
12514 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12516 ID3D11RasterizerState_Release(state);
12518 test_context.vb = cw_vb;
12519 ID3D11Buffer_Release(ccw_vb);
12520 release_test_context(&test_context);
12523 static void test_line_antialiasing_blending(void)
12525 ID3D11RasterizerState *rasterizer_state;
12526 struct d3d11_test_context test_context;
12527 D3D11_RASTERIZER_DESC rasterizer_desc;
12528 ID3D11BlendState *blend_state;
12529 ID3D11DeviceContext *context;
12530 D3D11_BLEND_DESC blend_desc;
12531 ID3D11Device *device;
12532 HRESULT hr;
12534 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
12535 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
12537 if (!init_test_context(&test_context, NULL))
12538 return;
12540 device = test_context.device;
12541 context = test_context.immediate_context;
12543 memset(&blend_desc, 0, sizeof(blend_desc));
12544 blend_desc.AlphaToCoverageEnable = FALSE;
12545 blend_desc.IndependentBlendEnable = FALSE;
12546 blend_desc.RenderTarget[0].BlendEnable = TRUE;
12547 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
12548 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
12549 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
12550 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
12551 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
12552 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
12553 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
12555 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
12556 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
12557 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
12559 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
12560 draw_color_quad(&test_context, &green);
12561 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
12563 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
12564 draw_color_quad(&test_context, &red);
12565 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
12567 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
12568 ID3D11BlendState_Release(blend_state);
12570 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
12571 draw_color_quad(&test_context, &green);
12572 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
12574 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
12575 draw_color_quad(&test_context, &red);
12576 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
12578 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
12579 rasterizer_desc.CullMode = D3D11_CULL_BACK;
12580 rasterizer_desc.FrontCounterClockwise = FALSE;
12581 rasterizer_desc.DepthBias = 0;
12582 rasterizer_desc.DepthBiasClamp = 0.0f;
12583 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
12584 rasterizer_desc.DepthClipEnable = TRUE;
12585 rasterizer_desc.ScissorEnable = FALSE;
12586 rasterizer_desc.MultisampleEnable = FALSE;
12587 rasterizer_desc.AntialiasedLineEnable = TRUE;
12589 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
12590 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12591 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
12593 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
12594 draw_color_quad(&test_context, &green);
12595 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
12597 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
12598 draw_color_quad(&test_context, &red);
12599 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
12601 ID3D11RasterizerState_Release(rasterizer_state);
12602 release_test_context(&test_context);
12605 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
12606 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
12607 const char *feature_name)
12609 unsigned int i;
12611 for (i = 0; i < format_count; ++i)
12613 DXGI_FORMAT format = formats[i].format;
12614 unsigned int supported = format_support[format] & feature_flag;
12616 if (formats[i].fl_required <= feature_level)
12618 ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
12619 format, feature_name, feature_level, format_support[format]);
12620 continue;
12623 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
12625 if (supported)
12626 trace("Optional format %#x - %s supported, feature level %#x.\n",
12627 format, feature_name, feature_level);
12628 continue;
12631 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
12632 format, feature_name, feature_level, format_support[format]);
12636 static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
12638 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
12639 struct device_desc device_desc;
12640 ID3D11Device *device;
12641 DXGI_FORMAT format;
12642 ULONG refcount;
12643 HRESULT hr;
12645 static const struct format_support index_buffers[] =
12647 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
12648 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
12651 device_desc.feature_level = &feature_level;
12652 device_desc.flags = 0;
12653 if (!(device = create_device(&device_desc)))
12655 skip("Failed to create device for feature level %#x.\n", feature_level);
12656 return;
12659 memset(format_support, 0, sizeof(format_support));
12660 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
12662 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
12663 todo_wine ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
12664 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
12665 format, hr, format_support[format]);
12667 if (hr == E_NOTIMPL)
12669 skip("CheckFormatSupport not implemented.\n");
12670 ID3D11Device_Release(device);
12671 return;
12674 check_format_support(format_support, feature_level,
12675 index_buffers, ARRAY_SIZE(index_buffers),
12676 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
12678 check_format_support(format_support, feature_level,
12679 display_format_support, ARRAY_SIZE(display_format_support),
12680 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
12682 refcount = ID3D11Device_Release(device);
12683 ok(!refcount, "Device has %u references left.\n", refcount);
12686 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
12688 struct d3d11_test_context test_context;
12689 D3D11_SUBRESOURCE_DATA resource_data;
12690 D3D11_TEXTURE2D_DESC texture_desc;
12691 ID3D11ShaderResourceView *srv;
12692 ID3D11DeviceContext *context;
12693 ID3D11Texture2D *texture;
12694 ID3D11PixelShader *ps;
12695 ID3D11Device *device;
12696 HRESULT hr;
12698 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
12699 static const DWORD ps_code[] =
12701 #if 0
12702 float4 main() : SV_TARGET
12704 return float4(1.0f, 0.0f, 0.0f, 0.5f);
12706 #endif
12707 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
12708 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
12709 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
12710 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
12711 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
12712 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
12713 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
12714 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
12715 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
12716 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
12717 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
12718 0x45475241, 0xabab0054,
12720 static const DWORD ps_texture_code[] =
12722 #if 0
12723 Texture2D t;
12724 SamplerState s;
12726 float4 main() : SV_TARGET
12728 return t.Sample(s, (float2)0);
12730 #endif
12731 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
12732 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
12733 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
12734 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
12735 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
12736 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
12737 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
12738 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
12739 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
12740 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
12741 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
12742 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
12743 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
12744 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12745 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
12747 static const DWORD texture_data[] = {0xffffff00};
12749 if (!init_test_context(&test_context, &feature_level))
12750 return;
12752 device = test_context.device;
12753 context = test_context.immediate_context;
12755 texture_desc.Width = 1;
12756 texture_desc.Height = 1;
12757 texture_desc.MipLevels = 0;
12758 texture_desc.ArraySize = 1;
12759 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12760 texture_desc.SampleDesc.Count = 1;
12761 texture_desc.SampleDesc.Quality = 0;
12762 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12763 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
12764 texture_desc.CPUAccessFlags = 0;
12765 texture_desc.MiscFlags = 0;
12766 resource_data.pSysMem = texture_data;
12767 resource_data.SysMemPitch = sizeof(texture_data);
12768 resource_data.SysMemSlicePitch = 0;
12769 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
12770 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
12771 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
12772 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12774 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12775 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
12776 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12777 draw_quad(&test_context);
12778 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
12779 ID3D11PixelShader_Release(ps);
12781 draw_color_quad(&test_context, &color);
12782 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
12784 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
12785 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
12786 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12787 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
12788 draw_quad(&test_context);
12789 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
12790 ID3D11PixelShader_Release(ps);
12792 ID3D11ShaderResourceView_Release(srv);
12793 ID3D11Texture2D_Release(texture);
12794 release_test_context(&test_context);
12797 static void run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
12798 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
12800 static const D3D_FEATURE_LEVEL feature_levels[] =
12802 D3D_FEATURE_LEVEL_11_1,
12803 D3D_FEATURE_LEVEL_11_0,
12804 D3D_FEATURE_LEVEL_10_1,
12805 D3D_FEATURE_LEVEL_10_0,
12806 D3D_FEATURE_LEVEL_9_3,
12807 D3D_FEATURE_LEVEL_9_2,
12808 D3D_FEATURE_LEVEL_9_1
12810 unsigned int i;
12812 assert(begin <= end);
12813 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
12815 if (begin <= feature_levels[i] && feature_levels[i] <= end)
12816 test_func(feature_levels[i]);
12820 static void run_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
12822 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
12823 D3D_FEATURE_LEVEL_11_1, test_func);
12826 static void run_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
12828 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
12829 D3D_FEATURE_LEVEL_9_3, test_func);
12832 static void test_ddy(void)
12834 static const struct
12836 struct vec4 position;
12837 unsigned int color;
12839 quad[] =
12841 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
12842 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
12843 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
12844 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
12846 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12848 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12849 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
12851 #if 0
12852 struct vs_data
12854 float4 pos : SV_POSITION;
12855 float4 color : COLOR;
12858 void main(in struct vs_data vs_input, out struct vs_data vs_output)
12860 vs_output.pos = vs_input.pos;
12861 vs_output.color = vs_input.color;
12863 #endif
12864 static const DWORD vs_code[] =
12866 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
12867 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12868 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
12869 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12870 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12871 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12872 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12873 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12874 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12875 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12876 0x0100003e,
12878 #if 0
12879 struct ps_data
12881 float4 pos : SV_POSITION;
12882 float4 color : COLOR;
12885 float4 main(struct ps_data ps_input) : SV_Target
12887 return ddy(ps_input.color) * 240.0 + 0.5;
12889 #endif
12890 static const DWORD ps_code_ddy[] =
12892 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
12893 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12894 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12895 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12896 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12897 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
12898 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12899 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
12900 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
12901 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
12903 #if 0
12904 struct ps_data
12906 float4 pos : SV_POSITION;
12907 float4 color : COLOR;
12910 float4 main(struct ps_data ps_input) : SV_Target
12912 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
12914 #endif
12915 static const DWORD ps_code_ddy_coarse[] =
12917 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
12918 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12919 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12920 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12921 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12922 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
12923 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
12924 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
12925 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
12926 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
12928 #if 0
12929 struct ps_data
12931 float4 pos : SV_POSITION;
12932 float4 color : COLOR;
12935 float4 main(struct ps_data ps_input) : SV_Target
12937 return ddy_fine(ps_input.color) * 240.0 + 0.5;
12939 #endif
12940 static const DWORD ps_code_ddy_fine[] =
12942 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
12943 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12944 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12945 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12946 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12947 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
12948 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
12949 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
12950 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
12951 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
12953 static const struct
12955 D3D_FEATURE_LEVEL min_feature_level;
12956 const DWORD *ps_code;
12957 unsigned int ps_code_size;
12959 tests[] =
12961 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
12962 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
12963 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
12965 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
12966 struct d3d11_test_context test_context;
12967 D3D11_TEXTURE2D_DESC texture_desc;
12968 D3D_FEATURE_LEVEL feature_level;
12969 ID3D11InputLayout *input_layout;
12970 ID3D11DeviceContext *context;
12971 unsigned int stride, offset;
12972 struct resource_readback rb;
12973 ID3D11RenderTargetView *rtv;
12974 ID3D11Texture2D *texture;
12975 ID3D11VertexShader *vs;
12976 ID3D11PixelShader *ps;
12977 ID3D11Device *device;
12978 ID3D11Buffer *vb;
12979 unsigned int i;
12980 DWORD color;
12981 HRESULT hr;
12983 if (!init_test_context(&test_context, NULL))
12984 return;
12986 device = test_context.device;
12987 context = test_context.immediate_context;
12988 feature_level = ID3D11Device_GetFeatureLevel(device);
12990 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12991 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12992 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12994 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
12995 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12997 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12998 vs_code, sizeof(vs_code), &input_layout);
12999 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13001 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
13003 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13004 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13006 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13007 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13008 stride = sizeof(*quad);
13009 offset = 0;
13010 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
13011 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13013 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13015 if (feature_level < tests[i].min_feature_level)
13017 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
13018 feature_level, tests[i].min_feature_level);
13019 continue;
13022 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
13023 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13025 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13027 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13028 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
13029 ID3D11DeviceContext_Draw(context, 4, 0);
13031 get_texture_readback(texture, 0, &rb);
13032 color = get_readback_color(&rb, 320, 190);
13033 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13034 color = get_readback_color(&rb, 255, 240);
13035 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13036 color = get_readback_color(&rb, 320, 240);
13037 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13038 color = get_readback_color(&rb, 385, 240);
13039 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13040 color = get_readback_color(&rb, 320, 290);
13041 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13042 release_resource_readback(&rb);
13044 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
13045 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13046 ID3D11DeviceContext_Draw(context, 4, 0);
13048 get_texture_readback(test_context.backbuffer, 0, &rb);
13049 color = get_readback_color(&rb, 320, 190);
13050 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13051 color = get_readback_color(&rb, 255, 240);
13052 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13053 color = get_readback_color(&rb, 320, 240);
13054 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13055 color = get_readback_color(&rb, 385, 240);
13056 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13057 color = get_readback_color(&rb, 320, 290);
13058 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13059 release_resource_readback(&rb);
13061 ID3D11PixelShader_Release(ps);
13064 ID3D11VertexShader_Release(vs);
13065 ID3D11Buffer_Release(vb);
13066 ID3D11InputLayout_Release(input_layout);
13067 ID3D11Texture2D_Release(texture);
13068 ID3D11RenderTargetView_Release(rtv);
13069 release_test_context(&test_context);
13072 static void test_shader_input_registers_limits(void)
13074 struct d3d11_test_context test_context;
13075 D3D11_SUBRESOURCE_DATA resource_data;
13076 D3D11_TEXTURE2D_DESC texture_desc;
13077 D3D11_SAMPLER_DESC sampler_desc;
13078 ID3D11ShaderResourceView *srv;
13079 ID3D11DeviceContext *context;
13080 ID3D11SamplerState *sampler;
13081 ID3D11Texture2D *texture;
13082 ID3D11PixelShader *ps;
13083 ID3D11Device *device;
13084 HRESULT hr;
13086 static const DWORD ps_last_register_code[] =
13088 #if 0
13089 Texture2D t : register(t127);
13090 SamplerState s : register(s15);
13092 void main(out float4 target : SV_Target)
13094 target = t.Sample(s, float2(0, 0));
13096 #endif
13097 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
13098 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13099 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13100 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
13101 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
13102 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
13103 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
13105 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13106 static const DWORD texture_data[] = {0xff00ff00};
13108 if (!init_test_context(&test_context, NULL))
13109 return;
13111 device = test_context.device;
13112 context = test_context.immediate_context;
13114 texture_desc.Width = 1;
13115 texture_desc.Height = 1;
13116 texture_desc.MipLevels = 0;
13117 texture_desc.ArraySize = 1;
13118 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13119 texture_desc.SampleDesc.Count = 1;
13120 texture_desc.SampleDesc.Quality = 0;
13121 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13122 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13123 texture_desc.CPUAccessFlags = 0;
13124 texture_desc.MiscFlags = 0;
13126 resource_data.pSysMem = texture_data;
13127 resource_data.SysMemPitch = sizeof(texture_data);
13128 resource_data.SysMemSlicePitch = 0;
13130 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
13131 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
13133 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
13134 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13136 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
13137 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
13138 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
13139 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
13140 sampler_desc.MipLODBias = 0.0f;
13141 sampler_desc.MaxAnisotropy = 0;
13142 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
13143 sampler_desc.BorderColor[0] = 0.0f;
13144 sampler_desc.BorderColor[1] = 0.0f;
13145 sampler_desc.BorderColor[2] = 0.0f;
13146 sampler_desc.BorderColor[3] = 0.0f;
13147 sampler_desc.MinLOD = 0.0f;
13148 sampler_desc.MaxLOD = 0.0f;
13150 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
13151 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
13153 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
13154 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13155 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13157 ID3D11DeviceContext_PSSetShaderResources(context,
13158 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
13159 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
13160 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
13161 draw_quad(&test_context);
13162 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
13164 ID3D11PixelShader_Release(ps);
13165 ID3D11SamplerState_Release(sampler);
13166 ID3D11ShaderResourceView_Release(srv);
13167 ID3D11Texture2D_Release(texture);
13168 release_test_context(&test_context);
13171 static void test_unbind_shader_resource_view(void)
13173 struct d3d11_test_context test_context;
13174 D3D11_SUBRESOURCE_DATA resource_data;
13175 ID3D11ShaderResourceView *srv, *srv2;
13176 D3D11_TEXTURE2D_DESC texture_desc;
13177 ID3D11DeviceContext *context;
13178 ID3D11Texture2D *texture;
13179 ID3D11PixelShader *ps;
13180 ID3D11Device *device;
13181 HRESULT hr;
13183 static const DWORD ps_code[] =
13185 #if 0
13186 Texture2D t0;
13187 Texture2D t1;
13188 SamplerState s;
13190 float4 main() : SV_Target
13192 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
13194 #endif
13195 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
13196 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13197 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13198 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
13199 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
13200 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
13201 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
13202 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
13203 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
13204 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
13205 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
13206 0x3f800000, 0x0100003e,
13208 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13209 static const DWORD texture_data[] = {0xff00ff00};
13211 if (!init_test_context(&test_context, NULL))
13212 return;
13214 device = test_context.device;
13215 context = test_context.immediate_context;
13217 texture_desc.Width = 1;
13218 texture_desc.Height = 1;
13219 texture_desc.MipLevels = 0;
13220 texture_desc.ArraySize = 1;
13221 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13222 texture_desc.SampleDesc.Count = 1;
13223 texture_desc.SampleDesc.Quality = 0;
13224 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13225 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13226 texture_desc.CPUAccessFlags = 0;
13227 texture_desc.MiscFlags = 0;
13229 resource_data.pSysMem = texture_data;
13230 resource_data.SysMemPitch = sizeof(texture_data);
13231 resource_data.SysMemSlicePitch = 0;
13233 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
13234 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
13235 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
13236 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13237 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13238 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13239 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13241 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
13242 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
13243 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
13244 draw_quad(&test_context);
13245 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
13247 srv2 = NULL;
13248 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
13249 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
13250 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
13251 draw_quad(&test_context);
13252 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
13254 ID3D11PixelShader_Release(ps);
13255 ID3D11ShaderResourceView_Release(srv);
13256 ID3D11Texture2D_Release(texture);
13257 release_test_context(&test_context);
13260 static void test_stencil_separate(void)
13262 struct d3d11_test_context test_context;
13263 D3D11_TEXTURE2D_DESC texture_desc;
13264 D3D11_DEPTH_STENCIL_DESC ds_desc;
13265 ID3D11DepthStencilState *ds_state;
13266 ID3D11DepthStencilView *ds_view;
13267 D3D11_RASTERIZER_DESC rs_desc;
13268 ID3D11DeviceContext *context;
13269 ID3D11RasterizerState *rs;
13270 ID3D11Texture2D *texture;
13271 ID3D11Device *device;
13272 HRESULT hr;
13274 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
13275 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
13276 static const struct vec2 ccw_quad[] =
13278 {-1.0f, -1.0f},
13279 { 1.0f, -1.0f},
13280 {-1.0f, 1.0f},
13281 { 1.0f, 1.0f},
13284 if (!init_test_context(&test_context, NULL))
13285 return;
13287 device = test_context.device;
13288 context = test_context.immediate_context;
13290 texture_desc.Width = 640;
13291 texture_desc.Height = 480;
13292 texture_desc.MipLevels = 1;
13293 texture_desc.ArraySize = 1;
13294 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
13295 texture_desc.SampleDesc.Count = 1;
13296 texture_desc.SampleDesc.Quality = 0;
13297 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13298 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
13299 texture_desc.CPUAccessFlags = 0;
13300 texture_desc.MiscFlags = 0;
13301 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13302 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13303 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
13304 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
13306 ds_desc.DepthEnable = TRUE;
13307 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
13308 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
13309 ds_desc.StencilEnable = TRUE;
13310 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
13311 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
13312 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
13313 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
13314 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
13315 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
13316 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
13317 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
13318 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
13319 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
13320 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
13321 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
13323 rs_desc.FillMode = D3D11_FILL_SOLID;
13324 rs_desc.CullMode = D3D11_CULL_NONE;
13325 rs_desc.FrontCounterClockwise = FALSE;
13326 rs_desc.DepthBias = 0;
13327 rs_desc.DepthBiasClamp = 0.0f;
13328 rs_desc.SlopeScaledDepthBias = 0.0f;
13329 rs_desc.DepthClipEnable = TRUE;
13330 rs_desc.ScissorEnable = FALSE;
13331 rs_desc.MultisampleEnable = FALSE;
13332 rs_desc.AntialiasedLineEnable = FALSE;
13333 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
13334 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13336 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13337 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
13338 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
13339 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
13340 ID3D11DeviceContext_RSSetState(context, rs);
13342 draw_color_quad(&test_context, &green);
13343 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
13345 ID3D11Buffer_Release(test_context.vb);
13346 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
13348 draw_color_quad(&test_context, &green);
13349 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
13351 ID3D11RasterizerState_Release(rs);
13352 rs_desc.FrontCounterClockwise = TRUE;
13353 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
13354 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13355 ID3D11DeviceContext_RSSetState(context, rs);
13357 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13358 draw_color_quad(&test_context, &green);
13359 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
13361 ID3D11DepthStencilState_Release(ds_state);
13362 ID3D11DepthStencilView_Release(ds_view);
13363 ID3D11RasterizerState_Release(rs);
13364 ID3D11Texture2D_Release(texture);
13365 release_test_context(&test_context);
13368 static void test_uav_load(void)
13370 struct shader
13372 const DWORD *code;
13373 size_t size;
13375 struct texture
13377 UINT width;
13378 UINT height;
13379 UINT miplevel_count;
13380 UINT array_size;
13381 DXGI_FORMAT format;
13382 D3D11_SUBRESOURCE_DATA data[3];
13385 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
13386 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
13387 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
13388 struct d3d11_test_context test_context;
13389 const struct texture *current_texture;
13390 ID3D11Texture2D *texture, *rt_texture;
13391 D3D11_TEXTURE2D_DESC texture_desc;
13392 const struct shader *current_ps;
13393 ID3D11UnorderedAccessView *uav;
13394 ID3D11DeviceContext *context;
13395 struct resource_readback rb;
13396 ID3D11PixelShader *ps;
13397 ID3D11Device *device;
13398 unsigned int i, x, y;
13399 ID3D11Buffer *cb;
13400 HRESULT hr;
13402 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13403 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13404 static const DWORD ps_ld_2d_float_code[] =
13406 #if 0
13407 RWTexture2D<float> u;
13409 float main(float4 position : SV_Position) : SV_Target
13411 float2 s;
13412 u.GetDimensions(s.x, s.y);
13413 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
13415 #endif
13416 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
13417 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13418 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
13419 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13420 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
13421 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
13422 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
13423 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
13424 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
13425 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
13426 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
13427 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
13428 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
13430 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
13431 static const DWORD ps_ld_2d_uint_code[] =
13433 #if 0
13434 RWTexture2D<uint> u;
13436 uint main(float4 position : SV_Position) : SV_Target
13438 float2 s;
13439 u.GetDimensions(s.x, s.y);
13440 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
13442 #endif
13443 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
13444 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13445 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
13446 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
13447 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
13448 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
13449 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
13450 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
13451 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
13452 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
13453 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
13454 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
13455 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
13457 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
13458 static const DWORD ps_ld_2d_int_code[] =
13460 #if 0
13461 RWTexture2D<int> u;
13463 int main(float4 position : SV_Position) : SV_Target
13465 float2 s;
13466 u.GetDimensions(s.x, s.y);
13467 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
13469 #endif
13470 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
13471 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13472 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
13473 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
13474 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
13475 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
13476 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
13477 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
13478 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
13479 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
13480 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
13481 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
13482 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
13484 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
13485 static const DWORD ps_ld_2d_uint_arr_code[] =
13487 #if 0
13488 RWTexture2DArray<uint> u;
13490 uint layer;
13492 uint main(float4 position : SV_Position) : SV_Target
13494 float3 s;
13495 u.GetDimensions(s.x, s.y, s.z);
13496 s.z = layer;
13497 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
13499 #endif
13500 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
13501 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13502 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
13503 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
13504 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
13505 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
13506 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
13507 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
13508 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
13509 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
13510 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
13511 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
13512 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
13513 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
13515 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
13516 static const float float_data[] =
13518 0.50f, 0.25f, 1.00f, 0.00f,
13519 -1.00f, -2.00f, -3.00f, -4.00f,
13520 -0.50f, -0.25f, -1.00f, -0.00f,
13521 1.00f, 2.00f, 3.00f, 4.00f,
13523 static const unsigned int uint_data[] =
13525 0x00, 0x10, 0x20, 0x30,
13526 0x40, 0x50, 0x60, 0x70,
13527 0x80, 0x90, 0xa0, 0xb0,
13528 0xc0, 0xd0, 0xe0, 0xf0,
13530 static const unsigned int uint_data2[] =
13532 0xffff, 0xffff, 0xffff, 0xffff,
13533 0xffff, 0xc000, 0xc000, 0xffff,
13534 0xffff, 0xc000, 0xc000, 0xffff,
13535 0xffff, 0xffff, 0xffff, 0xffff,
13537 static const unsigned int uint_data3[] =
13539 0xaa, 0xaa, 0xcc, 0xcc,
13540 0xaa, 0xaa, 0xdd, 0xdd,
13541 0xbb, 0xbb, 0xee, 0xee,
13542 0xbb, 0xbb, 0xff, 0xff,
13544 static const int int_data[] =
13546 -1, 0x10, 0x20, 0x30,
13547 0x40, 0x50, 0x60, -777,
13548 -666, 0x90, -555, 0xb0,
13549 0xc0, 0xd0, 0xe0, -101,
13551 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
13552 {{float_data, 4 * sizeof(*float_data), 0}}};
13553 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
13554 {{uint_data, 4 * sizeof(*uint_data), 0}}};
13555 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
13556 {{uint_data, 4 * sizeof(*uint_data), 0},
13557 {uint_data2, 4 * sizeof(*uint_data2), 0},
13558 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
13559 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
13560 {{int_data, 4 * sizeof(*int_data), 0}}};
13562 static const struct test
13564 const struct shader *ps;
13565 const struct texture *texture;
13566 struct uav_desc uav_desc;
13567 struct uvec4 constant;
13568 const DWORD *expected_colors;
13570 tests[] =
13572 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
13573 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
13574 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
13575 #define R32_UINT DXGI_FORMAT_R32_UINT
13576 #define R32_SINT DXGI_FORMAT_R32_SINT
13577 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {}, (const DWORD *)float_data},
13578 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {}, (const DWORD *)uint_data},
13579 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {}, (const DWORD *)int_data},
13580 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
13581 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
13582 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
13583 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
13584 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
13585 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
13586 #undef TEX_2D
13587 #undef TEX_2D_ARRAY
13588 #undef R32_FLOAT
13589 #undef R32_UINT
13590 #undef R32_SINT
13593 if (!init_test_context(&test_context, &feature_level))
13594 return;
13596 device = test_context.device;
13597 context = test_context.immediate_context;
13599 texture_desc.Width = 640;
13600 texture_desc.Height = 480;
13601 texture_desc.MipLevels = 1;
13602 texture_desc.ArraySize = 1;
13603 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
13604 texture_desc.SampleDesc.Count = 1;
13605 texture_desc.SampleDesc.Quality = 0;
13606 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13607 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
13608 texture_desc.CPUAccessFlags = 0;
13609 texture_desc.MiscFlags = 0;
13610 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
13611 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13613 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
13614 U(rtv_desc).Texture2D.MipSlice = 0;
13616 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
13617 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
13618 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13620 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
13621 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
13622 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13624 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
13625 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
13626 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13628 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
13630 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
13631 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13633 ps = NULL;
13634 uav = NULL;
13635 texture = NULL;
13636 current_ps = NULL;
13637 current_texture = NULL;
13638 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13640 const struct test *test = &tests[i];
13641 ID3D11RenderTargetView *current_rtv;
13643 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
13644 NULL, &test->constant, 0, 0);
13646 if (current_ps != test->ps)
13648 if (ps)
13649 ID3D11PixelShader_Release(ps);
13651 current_ps = test->ps;
13653 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
13654 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
13656 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13659 if (current_texture != test->texture)
13661 if (texture)
13662 ID3D11Texture2D_Release(texture);
13664 current_texture = test->texture;
13666 texture_desc.Width = current_texture->width;
13667 texture_desc.Height = current_texture->height;
13668 texture_desc.MipLevels = current_texture->miplevel_count;
13669 texture_desc.ArraySize = current_texture->array_size;
13670 texture_desc.Format = current_texture->format;
13672 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
13673 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
13676 if (uav)
13677 ID3D11UnorderedAccessView_Release(uav);
13679 get_uav_desc(&uav_desc, &test->uav_desc);
13680 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
13681 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
13683 switch (uav_desc.Format)
13685 case DXGI_FORMAT_R32_FLOAT:
13686 current_rtv = rtv_float;
13687 break;
13688 case DXGI_FORMAT_R32_UINT:
13689 current_rtv = rtv_uint;
13690 break;
13691 case DXGI_FORMAT_R32_SINT:
13692 current_rtv = rtv_sint;
13693 break;
13694 default:
13695 trace("Unhandled format %#x.\n", uav_desc.Format);
13696 current_rtv = NULL;
13697 break;
13700 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
13702 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
13703 1, 1, &uav, NULL);
13705 draw_quad(&test_context);
13707 get_texture_readback(rt_texture, 0, &rb);
13708 for (y = 0; y < 4; ++y)
13710 for (x = 0; x < 4; ++x)
13712 DWORD expected = test->expected_colors[y * 4 + x];
13713 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
13714 ok(compare_color(color, expected, 0),
13715 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
13716 i, color, expected, x, y);
13719 release_resource_readback(&rb);
13721 ID3D11PixelShader_Release(ps);
13722 ID3D11Texture2D_Release(texture);
13723 ID3D11UnorderedAccessView_Release(uav);
13725 ID3D11Buffer_Release(cb);
13726 ID3D11RenderTargetView_Release(rtv_float);
13727 ID3D11RenderTargetView_Release(rtv_sint);
13728 ID3D11RenderTargetView_Release(rtv_uint);
13729 ID3D11Texture2D_Release(rt_texture);
13730 release_test_context(&test_context);
13733 static void test_cs_uav_store(void)
13735 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13736 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
13737 static const float zero[4] = {0.0f};
13738 D3D11_TEXTURE2D_DESC texture_desc;
13739 ID3D11UnorderedAccessView *uav;
13740 struct device_desc device_desc;
13741 ID3D11DeviceContext *context;
13742 struct vec4 input = {1.0f};
13743 ID3D11Texture2D *texture;
13744 ID3D11ComputeShader *cs;
13745 ID3D11Device *device;
13746 ID3D11Buffer *cb;
13747 ULONG refcount;
13748 HRESULT hr;
13749 RECT rect;
13751 static const DWORD cs_1_thread_code[] =
13753 #if 0
13754 RWTexture2D<float> u;
13756 float value;
13758 [numthreads(1, 1, 1)]
13759 void main()
13761 uint x, y, width, height;
13762 u.GetDimensions(width, height);
13763 for (y = 0; y < height; ++y)
13765 for (x = 0; x < width; ++x)
13766 u[uint2(x, y)] = value;
13769 #endif
13770 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
13771 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13772 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
13773 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
13774 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
13775 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
13776 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
13777 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
13778 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
13779 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
13780 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
13781 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
13782 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
13783 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
13784 0x01000016, 0x0100003e,
13786 static const DWORD cs_1_group_code[] =
13788 #if 0
13789 RWTexture2D<float> u;
13791 float value;
13793 [numthreads(16, 16, 1)]
13794 void main(uint3 threadID : SV_GroupThreadID)
13796 uint2 count, size ;
13797 u.GetDimensions(size.x, size.y);
13798 count = size / (uint2)16;
13799 for (uint y = 0; y < count.y; ++y)
13800 for (uint x = 0; x < count.x; ++x)
13801 u[count * threadID.xy + uint2(x, y)] = value;
13803 #endif
13804 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
13805 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13806 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
13807 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
13808 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
13809 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
13810 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
13811 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
13812 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
13813 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
13814 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
13815 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
13816 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
13817 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
13818 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
13819 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
13820 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
13822 static const DWORD cs_1_store_code[] =
13824 #if 0
13825 RWTexture2D<float> u;
13827 float value;
13829 [numthreads(1, 1, 1)]
13830 void main(uint3 groupID : SV_GroupID)
13832 u[groupID.xy] = value;
13834 #endif
13835 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
13836 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13837 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
13838 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
13839 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
13840 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
13842 static const DWORD cs_dispatch_id_code[] =
13844 #if 0
13845 RWTexture2D<float> u;
13847 float value;
13849 [numthreads(4, 4, 1)]
13850 void main(uint3 id : SV_DispatchThreadID)
13852 u[id.xy] = value;
13854 #endif
13855 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
13856 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13857 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
13858 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
13859 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
13860 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
13862 static const DWORD cs_group_index_code[] =
13864 #if 0
13865 RWTexture2D<float> u;
13867 float value;
13869 [numthreads(32, 1, 1)]
13870 void main(uint index : SV_GroupIndex)
13872 uint2 size;
13873 u.GetDimensions(size.x, size.y);
13874 uint count = size.x * size.y / 32;
13875 index *= count;
13876 for (uint i = 0; i < count; ++i, ++index)
13877 u[uint2(index % size.x, index / size.x)] = value;
13879 #endif
13880 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
13881 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13882 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
13883 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
13884 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
13885 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
13886 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
13887 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
13888 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
13889 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
13890 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
13891 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
13892 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
13893 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
13894 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
13895 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
13898 device_desc.feature_level = &feature_level;
13899 device_desc.flags = 0;
13900 if (!(device = create_device(&device_desc)))
13902 skip("Failed to create device for feature level %#x.\n", feature_level);
13903 return;
13906 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
13908 texture_desc.Width = 64;
13909 texture_desc.Height = 64;
13910 texture_desc.MipLevels = 1;
13911 texture_desc.ArraySize = 1;
13912 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
13913 texture_desc.SampleDesc.Count = 1;
13914 texture_desc.SampleDesc.Quality = 0;
13915 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13916 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
13917 texture_desc.CPUAccessFlags = 0;
13918 texture_desc.MiscFlags = 0;
13920 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13921 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13923 uav_desc.Format = texture_desc.Format;
13924 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
13925 U(uav_desc).Texture2D.MipSlice = 0;
13927 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
13928 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13930 ID3D11Device_GetImmediateContext(device, &context);
13932 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
13933 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
13935 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
13936 check_texture_float(texture, 0.0f, 2);
13938 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
13939 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
13940 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
13942 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13943 check_texture_float(texture, 1.0f, 2);
13945 input.x = 0.5f;
13946 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13947 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13948 check_texture_float(texture, 0.5f, 2);
13950 ID3D11ComputeShader_Release(cs);
13952 input.x = 2.0f;
13953 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13954 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
13955 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13956 check_texture_float(texture, 0.5f, 2);
13958 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
13959 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
13960 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
13962 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13963 check_texture_float(texture, 2.0f, 2);
13965 input.x = 4.0f;
13966 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13967 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13968 check_texture_float(texture, 4.0f, 2);
13970 ID3D11ComputeShader_Release(cs);
13972 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
13973 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
13974 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
13976 input.x = 1.0f;
13977 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13978 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
13979 check_texture_float(texture, 1.0f, 2);
13981 input.x = 0.5f;
13982 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13983 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
13984 SetRect(&rect, 0, 0, 16, 32);
13985 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
13986 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
13987 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
13988 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
13989 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
13991 ID3D11ComputeShader_Release(cs);
13993 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
13994 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
13995 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
13997 input.x = 0.6f;
13998 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13999 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
14000 SetRect(&rect, 0, 0, 60, 60);
14001 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
14002 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
14003 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
14004 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
14005 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
14007 input.x = 0.7f;
14008 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
14009 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
14010 check_texture_float(texture, 0.7f, 2);
14012 ID3D11ComputeShader_Release(cs);
14014 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
14015 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
14016 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
14018 input.x = 0.3f;
14019 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
14020 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
14021 check_texture_float(texture, 0.3f, 2);
14023 input.x = 0.1f;
14024 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
14025 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
14026 check_texture_float(texture, 0.1f, 2);
14028 ID3D11ComputeShader_Release(cs);
14030 ID3D11Buffer_Release(cb);
14031 ID3D11Texture2D_Release(texture);
14032 ID3D11UnorderedAccessView_Release(uav);
14033 ID3D11DeviceContext_Release(context);
14034 refcount = ID3D11Device_Release(device);
14035 ok(!refcount, "Device has %u references left.\n", refcount);
14038 static void test_ps_cs_uav_binding(void)
14040 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
14041 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
14042 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
14043 ID3D11Texture2D *cs_texture, *ps_texture;
14044 struct d3d11_test_context test_context;
14045 static const float zero[4] = {0.0f};
14046 D3D11_TEXTURE2D_DESC texture_desc;
14047 ID3D11DeviceContext *context;
14048 ID3D11Buffer *cs_cb, *ps_cb;
14049 struct vec4 input = {1.0f};
14050 ID3D11ComputeShader *cs;
14051 ID3D11PixelShader *ps;
14052 ID3D11Device *device;
14053 HRESULT hr;
14055 static const DWORD cs_code[] =
14057 #if 0
14058 RWTexture2D<float> u;
14060 float value;
14062 [numthreads(1, 1, 1)]
14063 void main()
14065 uint x, y, width, height;
14066 u.GetDimensions(width, height);
14067 for (y = 0; y < height; ++y)
14069 for (x = 0; x < width; ++x)
14070 u[uint2(x, y)] = value;
14073 #endif
14074 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
14075 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14076 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
14077 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
14078 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
14079 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
14080 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
14081 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
14082 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
14083 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
14084 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
14085 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
14086 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
14087 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
14088 0x01000016, 0x0100003e,
14090 static const DWORD ps_code[] =
14092 #if 0
14093 RWTexture2D<float> u : register(u1);
14095 float value;
14097 void main()
14099 uint x, y, width, height;
14100 u.GetDimensions(width, height);
14101 for (y = 0; y < height; ++y)
14103 for (x = 0; x < width; ++x)
14104 u[uint2(x, y)] = value;
14107 #endif
14108 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
14109 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14110 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
14111 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
14112 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
14113 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
14114 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
14115 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
14116 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
14117 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
14118 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
14119 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
14120 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
14121 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
14124 if (!init_test_context(&test_context, &feature_level))
14125 return;
14127 device = test_context.device;
14128 context = test_context.immediate_context;
14130 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
14131 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
14133 texture_desc.Width = 64;
14134 texture_desc.Height = 64;
14135 texture_desc.MipLevels = 1;
14136 texture_desc.ArraySize = 1;
14137 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
14138 texture_desc.SampleDesc.Count = 1;
14139 texture_desc.SampleDesc.Quality = 0;
14140 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14141 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14142 texture_desc.CPUAccessFlags = 0;
14143 texture_desc.MiscFlags = 0;
14144 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
14145 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14146 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
14147 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14149 uav_desc.Format = texture_desc.Format;
14150 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
14151 U(uav_desc).Texture2D.MipSlice = 0;
14152 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
14153 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
14154 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
14155 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
14157 ID3D11Device_GetImmediateContext(device, &context);
14159 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
14160 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
14161 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
14162 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
14163 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
14164 1, &test_context.backbuffer_rtv, NULL, 1, 1, &ps_uav, NULL);
14166 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
14167 check_texture_float(cs_texture, 0.0f, 2);
14168 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
14169 check_texture_float(ps_texture, 0.0f, 2);
14171 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
14172 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
14173 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
14174 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14175 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14176 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14178 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
14179 check_texture_float(cs_texture, 1.0f, 2);
14180 check_texture_float(ps_texture, 0.0f, 2);
14181 draw_quad(&test_context);
14182 check_texture_float(cs_texture, 1.0f, 2);
14183 check_texture_float(ps_texture, 1.0f, 2);
14185 input.x = 0.5f;
14186 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
14187 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
14188 check_texture_float(cs_texture, 0.5f, 2);
14189 check_texture_float(ps_texture, 1.0f, 2);
14190 input.x = 2.0f;
14191 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
14192 draw_quad(&test_context);
14193 check_texture_float(cs_texture, 0.5f, 2);
14194 check_texture_float(ps_texture, 2.0f, 2);
14196 input.x = 8.0f;
14197 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
14198 input.x = 4.0f;
14199 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
14200 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
14201 check_texture_float(cs_texture, 8.0f, 2);
14202 check_texture_float(ps_texture, 2.0f, 2);
14203 draw_quad(&test_context);
14204 check_texture_float(cs_texture, 8.0f, 2);
14205 check_texture_float(ps_texture, 4.0f, 2);
14207 ID3D11ComputeShader_Release(cs);
14208 ID3D11PixelShader_Release(ps);
14209 ID3D11Buffer_Release(cs_cb);
14210 ID3D11Buffer_Release(ps_cb);
14211 ID3D11Texture2D_Release(cs_texture);
14212 ID3D11Texture2D_Release(ps_texture);
14213 ID3D11UnorderedAccessView_Release(cs_uav);
14214 ID3D11UnorderedAccessView_Release(ps_uav);
14215 ID3D11DeviceContext_Release(context);
14216 release_test_context(&test_context);
14219 static void test_atomic_instructions(void)
14221 ID3D11UnorderedAccessView *in_uav, *out_uav;
14222 ID3D11Buffer *cb, *in_buffer, *out_buffer;
14223 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
14224 struct d3d11_test_context test_context;
14225 struct resource_readback rb, out_rb;
14226 D3D11_TEXTURE2D_DESC texture_desc;
14227 D3D11_BUFFER_DESC buffer_desc;
14228 ID3D11DeviceContext *context;
14229 ID3D11RenderTargetView *rtv;
14230 ID3D11Texture2D *texture;
14231 ID3D11ComputeShader *cs;
14232 ID3D11PixelShader *ps;
14233 ID3D11Device *device;
14234 D3D11_VIEWPORT vp;
14235 unsigned int i, j;
14236 HRESULT hr;
14238 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
14239 static const unsigned int zero[4] = {0, 0, 0, 0};
14240 static const DWORD ps_atomics_code[] =
14242 #if 0
14243 RWByteAddressBuffer u;
14245 uint4 v;
14246 int4 i;
14248 void main()
14250 u.InterlockedAnd(0 * 4, v.x);
14251 u.InterlockedCompareStore(1 * 4, v.y, v.x);
14252 u.InterlockedAdd(2 * 4, v.x);
14253 u.InterlockedOr(3 * 4, v.x);
14254 u.InterlockedMax(4 * 4, i.x);
14255 u.InterlockedMin(5 * 4, i.x);
14256 u.InterlockedMax(6 * 4, v.x);
14257 u.InterlockedMin(7 * 4, v.x);
14258 u.InterlockedXor(8 * 4, v.x);
14260 #endif
14261 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
14262 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14263 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
14264 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
14265 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
14266 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
14267 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
14268 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
14269 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
14270 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
14271 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
14272 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
14273 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
14274 0x00000000, 0x00000000, 0x0100003e,
14276 static const DWORD cs_atomics_code[] =
14278 #if 0
14279 RWByteAddressBuffer u;
14280 RWByteAddressBuffer u2;
14282 uint4 v;
14283 int4 i;
14285 [numthreads(1, 1, 1)]
14286 void main()
14288 uint r;
14289 u.InterlockedAnd(0 * 4, v.x, r);
14290 u2.Store(0 * 4, r);
14291 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
14292 u2.Store(1 * 4, r);
14293 u.InterlockedAdd(2 * 4, v.x, r);
14294 u2.Store(2 * 4, r);
14295 u.InterlockedOr(3 * 4, v.x, r);
14296 u2.Store(3 * 4, r);
14297 u.InterlockedMax(4 * 4, i.x, r);
14298 u2.Store(4 * 4, r);
14299 u.InterlockedMin(5 * 4, i.x, r);
14300 u2.Store(5 * 4, r);
14301 u.InterlockedMax(6 * 4, v.x, r);
14302 u2.Store(6 * 4, r);
14303 u.InterlockedMin(7 * 4, v.x, r);
14304 u2.Store(7 * 4, r);
14305 u.InterlockedXor(8 * 4, v.x, r);
14306 u2.Store(8 * 4, r);
14308 #endif
14309 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
14310 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14311 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
14312 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
14313 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
14314 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
14315 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
14316 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
14317 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
14318 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
14319 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
14320 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
14321 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
14322 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
14323 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
14324 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
14325 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
14326 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
14327 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
14328 0x0010000a, 0x00000000, 0x0100003e,
14331 static const char * const instructions[] =
14333 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
14334 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
14336 static const char * const imm_instructions[] =
14338 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
14339 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
14341 static const struct test
14343 struct uvec4 v;
14344 struct ivec4 i;
14345 unsigned int input[ARRAY_SIZE(instructions)];
14346 unsigned int expected_result[ARRAY_SIZE(instructions)];
14348 tests[] =
14350 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
14351 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
14354 if (!init_test_context(&test_context, &feature_level))
14355 return;
14357 device = test_context.device;
14358 context = test_context.immediate_context;
14360 texture_desc.Width = 1;
14361 texture_desc.Height = 1;
14362 texture_desc.MipLevels = 1;
14363 texture_desc.ArraySize = 1;
14364 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
14365 texture_desc.SampleDesc.Count = 1;
14366 texture_desc.SampleDesc.Quality = 0;
14367 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14368 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
14369 texture_desc.CPUAccessFlags = 0;
14370 texture_desc.MiscFlags = 0;
14371 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14372 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14373 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14374 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
14376 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
14377 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14378 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
14380 buffer_desc.ByteWidth = sizeof(tests->input);
14381 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
14382 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14383 buffer_desc.CPUAccessFlags = 0;
14384 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
14385 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
14386 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
14387 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
14388 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
14390 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
14391 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
14392 U(uav_desc).Buffer.FirstElement = 0;
14393 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
14394 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
14395 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
14396 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
14397 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
14398 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
14400 vp.TopLeftX = 0.0f;
14401 vp.TopLeftY = 0.0f;
14402 vp.Width = texture_desc.Width;
14403 vp.Height = texture_desc.Height;
14404 vp.MinDepth = 0.0f;
14405 vp.MaxDepth = 1.0f;
14406 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
14408 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
14409 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14410 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14412 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
14413 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
14414 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
14416 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14418 const struct test *test = &tests[i];
14420 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
14421 NULL, &test->v, 0, 0);
14423 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
14424 NULL, test->input, 0, 0);
14426 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
14427 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
14428 0, 1, &in_uav, NULL);
14430 draw_quad(&test_context);
14431 get_buffer_readback(in_buffer, &rb);
14432 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
14434 unsigned int value = get_readback_color(&rb, j, 0);
14435 unsigned int expected = test->expected_result[j];
14437 todo_wine_if(expected != test->input[j]
14438 && (!strcmp(instructions[j], "atomic_imax")
14439 || !strcmp(instructions[j], "atomic_imin")))
14440 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
14441 "with inputs (%u, %u), (%d), %#x (%d).\n",
14442 i, value, value, expected, expected, instructions[j],
14443 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
14445 release_resource_readback(&rb);
14447 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
14448 NULL, test->input, 0, 0);
14449 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
14451 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
14452 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
14454 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
14455 get_buffer_readback(in_buffer, &rb);
14456 get_buffer_readback(out_buffer, &out_rb);
14457 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
14459 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
14460 || !strcmp(imm_instructions[j], "imm_atomic_imin");
14461 unsigned int out_value = get_readback_color(&out_rb, j, 0);
14462 unsigned int value = get_readback_color(&rb, j, 0);
14463 unsigned int expected = test->expected_result[j];
14465 todo_wine_if(expected != test->input[j] && todo_instruction)
14466 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
14467 "with inputs (%u, %u), (%d), %#x (%d).\n",
14468 i, value, value, expected, expected, imm_instructions[j],
14469 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
14471 todo_wine_if(todo_instruction && out_value != test->input[j])
14472 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
14473 out_value, test->input[j], imm_instructions[j]);
14475 release_resource_readback(&out_rb);
14476 release_resource_readback(&rb);
14479 ID3D11Buffer_Release(cb);
14480 ID3D11Buffer_Release(in_buffer);
14481 ID3D11Buffer_Release(out_buffer);
14482 ID3D11ComputeShader_Release(cs);
14483 ID3D11PixelShader_Release(ps);
14484 ID3D11RenderTargetView_Release(rtv);
14485 ID3D11Texture2D_Release(texture);
14486 ID3D11UnorderedAccessView_Release(in_uav);
14487 ID3D11UnorderedAccessView_Release(out_uav);
14488 release_test_context(&test_context);
14491 static void test_sm4_ret_instruction(void)
14493 struct d3d11_test_context test_context;
14494 ID3D11DeviceContext *context;
14495 ID3D11PixelShader *ps;
14496 struct uvec4 constant;
14497 ID3D11Device *device;
14498 ID3D11Buffer *cb;
14499 HRESULT hr;
14501 static const DWORD ps_code[] =
14503 #if 0
14504 uint c;
14506 float4 main() : SV_TARGET
14508 if (c == 1)
14509 return float4(1, 0, 0, 1);
14510 if (c == 2)
14511 return float4(0, 1, 0, 1);
14512 if (c == 3)
14513 return float4(0, 0, 1, 1);
14514 return float4(1, 1, 1, 1);
14516 #endif
14517 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
14518 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14519 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14520 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
14521 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14522 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
14523 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
14524 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
14525 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
14526 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
14527 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
14528 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
14529 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
14530 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
14531 0x0100003e,
14534 if (!init_test_context(&test_context, NULL))
14535 return;
14537 device = test_context.device;
14538 context = test_context.immediate_context;
14540 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14541 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
14542 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14543 memset(&constant, 0, sizeof(constant));
14544 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
14545 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14547 draw_quad(&test_context);
14548 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
14550 constant.x = 1;
14551 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
14552 draw_quad(&test_context);
14553 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
14555 constant.x = 2;
14556 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
14557 draw_quad(&test_context);
14558 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
14560 constant.x = 3;
14561 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
14562 draw_quad(&test_context);
14563 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
14565 constant.x = 4;
14566 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
14567 draw_quad(&test_context);
14568 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
14570 ID3D11Buffer_Release(cb);
14571 ID3D11PixelShader_Release(ps);
14572 release_test_context(&test_context);
14575 static void test_primitive_restart(void)
14577 struct d3d11_test_context test_context;
14578 ID3D11Buffer *ib32, *ib16, *vb;
14579 ID3D11DeviceContext *context;
14580 unsigned int stride, offset;
14581 ID3D11InputLayout *layout;
14582 ID3D11VertexShader *vs;
14583 ID3D11PixelShader *ps;
14584 ID3D11Device *device;
14585 unsigned int i;
14586 HRESULT hr;
14587 RECT rect;
14589 static const DWORD ps_code[] =
14591 #if 0
14592 struct vs_out
14594 float4 position : SV_Position;
14595 float4 color : color;
14598 float4 main(vs_out input) : SV_TARGET
14600 return input.color;
14602 #endif
14603 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
14604 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14605 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14606 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
14607 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14608 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
14609 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
14610 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
14612 static const DWORD vs_code[] =
14614 #if 0
14615 struct vs_out
14617 float4 position : SV_Position;
14618 float4 color : color;
14621 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
14623 output.position = position;
14624 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
14626 #endif
14627 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
14628 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
14629 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
14630 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
14631 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
14632 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
14633 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
14634 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
14635 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
14636 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
14637 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
14638 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
14639 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
14641 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
14643 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
14645 static const struct vec2 vertices[] =
14647 {-1.00f, -1.0f},
14648 {-1.00f, 1.0f},
14649 {-0.25f, -1.0f},
14650 {-0.25f, 1.0f},
14651 { 0.25f, -1.0f},
14652 { 0.25f, 1.0f},
14653 { 1.00f, -1.0f},
14654 { 1.00f, 1.0f},
14656 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
14657 static const unsigned short indices16[] =
14659 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
14661 static const unsigned int indices32[] =
14663 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
14666 if (!init_test_context(&test_context, NULL))
14667 return;
14669 device = test_context.device;
14670 context = test_context.immediate_context;
14672 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
14673 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
14674 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14675 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
14677 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
14678 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
14680 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
14681 vs_code, sizeof(vs_code), &layout);
14682 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
14684 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
14686 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
14687 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14689 ID3D11DeviceContext_IASetInputLayout(context, layout);
14690 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
14691 stride = sizeof(*vertices);
14692 offset = 0;
14693 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
14695 for (i = 0; i < 2; ++i)
14697 if (!i)
14698 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
14699 else
14700 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
14702 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
14703 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
14704 SetRect(&rect, 0, 0, 240, 480);
14705 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
14706 SetRect(&rect, 240, 0, 400, 480);
14707 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
14708 SetRect(&rect, 400, 0, 640, 480);
14709 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
14712 ID3D11Buffer_Release(ib16);
14713 ID3D11Buffer_Release(ib32);
14714 ID3D11Buffer_Release(vb);
14715 ID3D11InputLayout_Release(layout);
14716 ID3D11PixelShader_Release(ps);
14717 ID3D11VertexShader_Release(vs);
14718 release_test_context(&test_context);
14721 static void test_resinfo_instruction(void)
14723 struct shader
14725 const DWORD *code;
14726 size_t size;
14729 struct d3d11_test_context test_context;
14730 D3D11_TEXTURE3D_DESC texture3d_desc;
14731 D3D11_TEXTURE2D_DESC texture_desc;
14732 const struct shader *current_ps;
14733 D3D_FEATURE_LEVEL feature_level;
14734 ID3D11ShaderResourceView *srv;
14735 ID3D11DeviceContext *context;
14736 ID3D11Texture2D *rtv_texture;
14737 ID3D11RenderTargetView *rtv;
14738 ID3D11Resource *texture;
14739 struct uvec4 constant;
14740 ID3D11PixelShader *ps;
14741 ID3D11Device *device;
14742 unsigned int i, type;
14743 ID3D11Buffer *cb;
14744 HRESULT hr;
14746 static const DWORD ps_2d_code[] =
14748 #if 0
14749 Texture2D t;
14751 uint type;
14752 uint level;
14754 float4 main() : SV_TARGET
14756 if (!type)
14758 float width, height, miplevels;
14759 t.GetDimensions(level, width, height, miplevels);
14760 return float4(width, height, miplevels, 0);
14762 else
14764 uint width, height, miplevels;
14765 t.GetDimensions(level, width, height, miplevels);
14766 return float4(width, height, miplevels, 0);
14769 #endif
14770 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
14771 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14772 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14773 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
14774 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
14775 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14776 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14777 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
14778 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
14779 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
14780 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
14781 0x01000015, 0x0100003e,
14783 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
14784 static const DWORD ps_2d_array_code[] =
14786 #if 0
14787 Texture2DArray t;
14789 uint type;
14790 uint level;
14792 float4 main() : SV_TARGET
14794 if (!type)
14796 float width, height, elements, miplevels;
14797 t.GetDimensions(level, width, height, elements, miplevels);
14798 return float4(width, height, elements, miplevels);
14800 else
14802 uint width, height, elements, miplevels;
14803 t.GetDimensions(level, width, height, elements, miplevels);
14804 return float4(width, height, elements, miplevels);
14807 #endif
14808 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
14809 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14810 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14811 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
14812 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
14813 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14814 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14815 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
14816 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
14817 0x0100003e, 0x01000015, 0x0100003e,
14819 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
14820 static const DWORD ps_3d_code[] =
14822 #if 0
14823 Texture3D t;
14825 uint type;
14826 uint level;
14828 float4 main() : SV_TARGET
14830 if (!type)
14832 float width, height, depth, miplevels;
14833 t.GetDimensions(level, width, height, depth, miplevels);
14834 return float4(width, height, depth, miplevels);
14836 else
14838 uint width, height, depth, miplevels;
14839 t.GetDimensions(level, width, height, depth, miplevels);
14840 return float4(width, height, depth, miplevels);
14843 #endif
14844 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
14845 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14846 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14847 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
14848 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
14849 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14850 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14851 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
14852 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
14853 0x0100003e, 0x01000015, 0x0100003e,
14855 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
14856 static const DWORD ps_cube_code[] =
14858 #if 0
14859 TextureCube t;
14861 uint type;
14862 uint level;
14864 float4 main() : SV_TARGET
14866 if (!type)
14868 float width, height, miplevels;
14869 t.GetDimensions(level, width, height, miplevels);
14870 return float4(width, height, miplevels, 0);
14872 else
14874 uint width, height, miplevels;
14875 t.GetDimensions(level, width, height, miplevels);
14876 return float4(width, height, miplevels, 0);
14879 #endif
14880 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
14881 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14882 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14883 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
14884 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
14885 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14886 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14887 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
14888 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
14889 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
14890 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
14891 0x01000015, 0x0100003e,
14893 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
14894 static const DWORD ps_cube_array_code[] =
14896 #if 0
14897 TextureCubeArray t;
14899 uint type;
14900 uint level;
14902 float4 main() : SV_TARGET
14904 if (!type)
14906 float width, height, elements, miplevels;
14907 t.GetDimensions(level, width, height, elements, miplevels);
14908 return float4(width, height, miplevels, 0);
14910 else
14912 uint width, height, elements, miplevels;
14913 t.GetDimensions(level, width, height, elements, miplevels);
14914 return float4(width, height, miplevels, 0);
14917 #endif
14918 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
14919 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14920 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14921 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
14922 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
14923 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
14924 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
14925 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
14926 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
14927 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
14928 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
14929 0x0100003e, 0x01000015, 0x0100003e,
14931 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
14932 static const struct ps_test
14934 const struct shader *ps;
14935 struct
14937 unsigned int width;
14938 unsigned int height;
14939 unsigned int depth;
14940 unsigned int miplevel_count;
14941 unsigned int array_size;
14942 unsigned int cube_count;
14943 } texture_desc;
14944 unsigned int miplevel;
14945 struct vec4 expected_result;
14947 ps_tests[] =
14949 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
14950 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
14951 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
14952 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
14954 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
14955 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
14956 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
14957 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
14959 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
14960 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
14961 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
14962 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
14963 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
14964 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
14965 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
14966 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
14967 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
14969 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
14970 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
14971 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
14972 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
14973 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
14975 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
14976 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
14977 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
14980 if (!init_test_context(&test_context, NULL))
14981 return;
14983 device = test_context.device;
14984 context = test_context.immediate_context;
14985 feature_level = ID3D11Device_GetFeatureLevel(device);
14987 texture_desc.Width = 64;
14988 texture_desc.Height = 64;
14989 texture_desc.MipLevels = 1;
14990 texture_desc.ArraySize = 1;
14991 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14992 texture_desc.SampleDesc.Count = 1;
14993 texture_desc.SampleDesc.Quality = 0;
14994 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14995 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
14996 texture_desc.CPUAccessFlags = 0;
14997 texture_desc.MiscFlags = 0;
14998 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
14999 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15000 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
15001 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15003 memset(&constant, 0, sizeof(constant));
15004 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
15006 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15007 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
15009 ps = NULL;
15010 current_ps = NULL;
15011 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
15013 const struct ps_test *test = &ps_tests[i];
15015 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
15017 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
15018 continue;
15021 if (current_ps != test->ps)
15023 if (ps)
15024 ID3D11PixelShader_Release(ps);
15026 current_ps = test->ps;
15028 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
15029 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
15030 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15033 if (test->texture_desc.depth != 1)
15035 texture3d_desc.Width = test->texture_desc.width;
15036 texture3d_desc.Height = test->texture_desc.height;
15037 texture3d_desc.Depth = test->texture_desc.depth;
15038 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
15039 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
15040 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
15041 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15042 texture3d_desc.CPUAccessFlags = 0;
15043 texture3d_desc.MiscFlags = 0;
15044 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
15045 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
15047 else
15049 texture_desc.Width = test->texture_desc.width;
15050 texture_desc.Height = test->texture_desc.height;
15051 texture_desc.MipLevels = test->texture_desc.miplevel_count;
15052 texture_desc.ArraySize = test->texture_desc.array_size;
15053 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
15054 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15055 texture_desc.MiscFlags = 0;
15056 if (test->texture_desc.cube_count)
15057 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
15058 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
15059 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
15062 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
15063 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
15064 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
15066 for (type = 0; type < 2; ++type)
15068 constant.x = type;
15069 constant.y = test->miplevel;
15070 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
15072 draw_quad(&test_context);
15073 check_texture_vec4(rtv_texture, &test->expected_result, 0);
15076 ID3D11Resource_Release(texture);
15077 ID3D11ShaderResourceView_Release(srv);
15079 ID3D11PixelShader_Release(ps);
15081 ID3D11Buffer_Release(cb);
15082 ID3D11RenderTargetView_Release(rtv);
15083 ID3D11Texture2D_Release(rtv_texture);
15084 release_test_context(&test_context);
15087 static void test_sm5_bufinfo_instruction(void)
15089 struct shader
15091 const DWORD *code;
15092 size_t size;
15095 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
15096 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
15097 struct d3d11_test_context test_context;
15098 D3D11_TEXTURE2D_DESC texture_desc;
15099 const struct shader *current_ps;
15100 ID3D11UnorderedAccessView *uav;
15101 ID3D11ShaderResourceView *srv;
15102 D3D11_BUFFER_DESC buffer_desc;
15103 ID3D11DeviceContext *context;
15104 ID3D11RenderTargetView *rtv;
15105 ID3D11Texture2D *texture;
15106 ID3D11PixelShader *ps;
15107 ID3D11Buffer *buffer;
15108 ID3D11Device *device;
15109 unsigned int i;
15110 HRESULT hr;
15112 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15113 static const DWORD ps_uav_structured_code[] =
15115 #if 0
15116 struct s
15118 uint4 u;
15119 bool b;
15122 RWStructuredBuffer<s> b;
15124 uint4 main(void) : SV_Target
15126 uint count, stride;
15127 b.GetDimensions(count, stride);
15128 return uint4(count, stride, 0, 1);
15130 #endif
15131 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
15132 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15133 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
15134 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
15135 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
15136 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
15137 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
15138 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
15140 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
15141 static const DWORD ps_uav_structured32_code[] =
15143 #if 0
15144 struct s
15146 uint4 u;
15147 bool4 b;
15150 RWStructuredBuffer<s> b;
15152 uint4 main(void) : SV_Target
15154 uint count, stride;
15155 b.GetDimensions(count, stride);
15156 return uint4(count, stride, 0, 1);
15158 #endif
15159 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
15160 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15161 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
15162 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
15163 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
15164 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
15165 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
15166 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
15168 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
15169 static const DWORD ps_srv_structured_code[] =
15171 #if 0
15172 StructuredBuffer<bool> b;
15174 uint4 main(void) : SV_Target
15176 uint count, stride;
15177 b.GetDimensions(count, stride);
15178 return uint4(count, stride, 0, 1);
15180 #endif
15181 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
15182 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15183 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
15184 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
15185 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
15186 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
15187 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
15188 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
15190 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
15191 static const DWORD ps_uav_raw_code[] =
15193 #if 0
15194 RWByteAddressBuffer b;
15196 uint4 main(void) : SV_Target
15198 uint width;
15199 b.GetDimensions(width);
15200 return width;
15202 #endif
15203 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
15204 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15205 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
15206 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
15207 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
15208 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
15209 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
15211 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
15212 static const DWORD ps_srv_raw_code[] =
15214 #if 0
15215 ByteAddressBuffer b;
15217 uint4 main(void) : SV_Target
15219 uint width;
15220 b.GetDimensions(width);
15221 return width;
15223 #endif
15224 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
15225 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15226 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
15227 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
15228 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
15229 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
15230 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
15232 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
15233 static const DWORD ps_uav_typed_code[] =
15235 #if 0
15236 RWBuffer<float> b;
15238 uint4 main(void) : SV_Target
15240 uint width;
15241 b.GetDimensions(width);
15242 return width;
15244 #endif
15245 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
15246 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15247 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
15248 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
15249 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
15250 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
15251 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
15253 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
15254 static const DWORD ps_srv_typed_code[] =
15256 #if 0
15257 Buffer<float> b;
15259 uint4 main(void) : SV_Target
15261 uint width;
15262 b.GetDimensions(width);
15263 return width;
15265 #endif
15266 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
15267 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15268 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
15269 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
15270 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
15271 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
15272 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
15274 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
15275 static const struct test
15277 const struct shader *ps;
15278 BOOL uav;
15279 unsigned int buffer_size;
15280 unsigned int buffer_misc_flags;
15281 unsigned int buffer_structure_byte_stride;
15282 DXGI_FORMAT view_format;
15283 unsigned int view_element_idx;
15284 unsigned int view_element_count;
15285 struct uvec4 expected_result;
15287 tests[] =
15289 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
15290 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
15291 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
15292 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
15293 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
15294 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
15295 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
15296 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
15297 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
15298 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
15299 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
15300 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
15301 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
15302 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
15303 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
15304 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
15305 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
15306 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
15307 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
15308 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
15309 #undef RAW
15310 #undef STRUCTURED
15313 if (!init_test_context(&test_context, &feature_level))
15314 return;
15316 device = test_context.device;
15317 context = test_context.immediate_context;
15319 texture_desc.Width = 64;
15320 texture_desc.Height = 64;
15321 texture_desc.MipLevels = 1;
15322 texture_desc.ArraySize = 1;
15323 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
15324 texture_desc.SampleDesc.Count = 1;
15325 texture_desc.SampleDesc.Quality = 0;
15326 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15327 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15328 texture_desc.CPUAccessFlags = 0;
15329 texture_desc.MiscFlags = 0;
15330 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15331 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15332 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15333 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15335 ps = NULL;
15336 current_ps = NULL;
15337 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15339 const struct test *test = &tests[i];
15341 if (current_ps != test->ps)
15343 if (ps)
15344 ID3D11PixelShader_Release(ps);
15346 current_ps = test->ps;
15348 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
15349 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
15350 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15353 buffer_desc.ByteWidth = test->buffer_size;
15354 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
15355 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
15356 buffer_desc.CPUAccessFlags = 0;
15357 buffer_desc.MiscFlags = test->buffer_misc_flags;
15358 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
15359 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
15360 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
15362 if (test->uav)
15364 uav_desc.Format = test->view_format;
15365 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
15366 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
15367 U(uav_desc).Buffer.NumElements = test->view_element_count;
15368 U(uav_desc).Buffer.Flags = 0;
15369 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
15370 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
15371 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
15372 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
15373 srv = NULL;
15375 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
15376 1, 1, &uav, NULL);
15378 else
15380 srv_desc.Format = test->view_format;
15381 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
15382 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
15383 U(srv_desc).BufferEx.NumElements = test->view_element_count;
15384 U(srv_desc).BufferEx.Flags = 0;
15385 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
15386 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
15387 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
15388 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
15389 uav = NULL;
15391 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
15392 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15395 draw_quad(&test_context);
15396 check_texture_uvec4(texture, &test->expected_result);
15398 if (srv)
15399 ID3D11ShaderResourceView_Release(srv);
15400 if (uav)
15401 ID3D11UnorderedAccessView_Release(uav);
15402 ID3D11Buffer_Release(buffer);
15404 ID3D11PixelShader_Release(ps);
15406 ID3D11RenderTargetView_Release(rtv);
15407 ID3D11Texture2D_Release(texture);
15408 release_test_context(&test_context);
15411 static void test_render_target_device_mismatch(void)
15413 struct d3d11_test_context test_context;
15414 struct device_desc device_desc = {0};
15415 ID3D11DeviceContext *context;
15416 ID3D11RenderTargetView *rtv;
15417 ID3D11Device *device;
15418 ULONG refcount;
15420 if (!init_test_context(&test_context, NULL))
15421 return;
15423 device = create_device(&device_desc);
15424 ok(!!device, "Failed to create device.\n");
15426 ID3D11Device_GetImmediateContext(device, &context);
15428 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
15429 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
15430 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
15431 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
15432 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
15433 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
15434 ID3D11RenderTargetView_Release(rtv);
15436 rtv = NULL;
15437 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15439 ID3D11DeviceContext_Release(context);
15440 refcount = ID3D11Device_Release(device);
15441 ok(!refcount, "Device has %u references left.\n", refcount);
15442 release_test_context(&test_context);
15445 static void test_buffer_srv(void)
15447 struct shader
15449 const DWORD *code;
15450 size_t size;
15451 BOOL requires_raw_and_structured_buffers;
15453 struct buffer
15455 unsigned int byte_count;
15456 unsigned int data_offset;
15457 const void *data;
15458 unsigned int structure_byte_stride;
15461 BOOL raw_and_structured_buffers_supported;
15462 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
15463 struct d3d11_test_context test_context;
15464 D3D11_SUBRESOURCE_DATA resource_data;
15465 const struct buffer *current_buffer;
15466 const struct shader *current_shader;
15467 ID3D11ShaderResourceView *srv;
15468 D3D11_BUFFER_DESC buffer_desc;
15469 ID3D11DeviceContext *context;
15470 DWORD color, expected_color;
15471 struct resource_readback rb;
15472 ID3D11Buffer *cb, *buffer;
15473 ID3D11PixelShader *ps;
15474 ID3D11Device *device;
15475 unsigned int i, x, y;
15476 struct vec4 cb_size;
15477 HRESULT hr;
15479 static const DWORD ps_float4_code[] =
15481 #if 0
15482 Buffer<float4> b;
15484 float2 size;
15486 float4 main(float4 position : SV_POSITION) : SV_Target
15488 float2 p;
15489 int2 coords;
15490 p.x = position.x / 640.0f;
15491 p.y = position.y / 480.0f;
15492 coords = int2(p.x * size.x, p.y * size.y);
15493 return b.Load(coords.y * size.x + coords.x);
15495 #endif
15496 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
15497 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15498 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
15499 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15500 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
15501 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
15502 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
15503 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
15504 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
15505 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
15506 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
15507 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
15508 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
15510 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
15511 static const DWORD ps_structured_code[] =
15513 #if 0
15514 StructuredBuffer<float4> b;
15516 float2 size;
15518 float4 main(float4 position : SV_POSITION) : SV_Target
15520 float2 p;
15521 int2 coords;
15522 p.x = position.x / 640.0f;
15523 p.y = position.y / 480.0f;
15524 coords = int2(p.x * size.x, p.y * size.y);
15525 return b[coords.y * size.x + coords.x];
15527 #endif
15528 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
15529 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
15530 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
15531 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
15532 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
15533 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
15534 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
15535 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
15536 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
15537 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
15538 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
15539 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
15540 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
15541 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
15543 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
15544 static const DWORD rgba16[] =
15546 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
15547 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
15548 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
15549 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
15551 static const DWORD rgba4[] =
15553 0xffffffff, 0xff0000ff,
15554 0xff000000, 0xff00ff00,
15556 static const BYTE r4[] =
15558 0xde, 0xad,
15559 0xba, 0xbe,
15561 static const struct vec4 rgba_float[] =
15563 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
15564 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
15566 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
15567 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
15568 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
15569 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
15570 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
15571 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
15572 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
15573 &rgba_float, sizeof(*rgba_float)};
15574 static const DWORD rgba16_colors2x2[] =
15576 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
15577 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
15578 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
15579 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
15581 static const DWORD rgba16_colors1x1[] =
15583 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
15584 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
15585 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
15586 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
15588 static const DWORD rgba4_colors[] =
15590 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
15591 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
15592 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
15593 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
15595 static const DWORD r4_colors[] =
15597 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
15598 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
15599 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
15600 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
15602 static const DWORD zero_colors[16] = {0};
15603 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
15605 static const struct test
15607 const struct shader *shader;
15608 const struct buffer *buffer;
15609 DXGI_FORMAT srv_format;
15610 unsigned int srv_first_element;
15611 unsigned int srv_element_count;
15612 struct vec2 size;
15613 const DWORD *expected_colors;
15615 tests[] =
15617 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
15618 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
15619 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
15620 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
15621 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
15622 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
15623 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
15624 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
15625 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
15626 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
15627 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
15630 if (!init_test_context(&test_context, NULL))
15631 return;
15633 device = test_context.device;
15634 context = test_context.immediate_context;
15635 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
15636 || check_compute_shaders_via_sm4_support(device);
15638 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
15639 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
15641 ps = NULL;
15642 srv = NULL;
15643 buffer = NULL;
15644 current_shader = NULL;
15645 current_buffer = NULL;
15646 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15648 const struct test *test = &tests[i];
15650 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
15652 skip("Test %u: Raw and structured buffers are not supported.\n", i);
15653 continue;
15655 /* Structured buffer views with an offset don't seem to work on WARP. */
15656 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
15657 && is_warp_device(device))
15659 skip("Test %u: Broken WARP.\n", i);
15660 continue;
15663 if (current_shader != test->shader)
15665 if (ps)
15666 ID3D11PixelShader_Release(ps);
15668 current_shader = test->shader;
15670 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
15671 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
15672 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15675 if (current_buffer != test->buffer)
15677 if (buffer)
15678 ID3D11Buffer_Release(buffer);
15680 current_buffer = test->buffer;
15681 if (current_buffer)
15683 BYTE *data = NULL;
15685 buffer_desc.ByteWidth = current_buffer->byte_count;
15686 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
15687 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15688 buffer_desc.CPUAccessFlags = 0;
15689 buffer_desc.MiscFlags = 0;
15690 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
15691 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
15692 resource_data.SysMemPitch = 0;
15693 resource_data.SysMemSlicePitch = 0;
15694 if (current_buffer->data_offset)
15696 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, current_buffer->byte_count);
15697 ok(!!data, "Failed to allocate memory.\n");
15698 memcpy(data + current_buffer->data_offset, current_buffer->data,
15699 current_buffer->byte_count - current_buffer->data_offset);
15700 resource_data.pSysMem = data;
15702 else
15704 resource_data.pSysMem = current_buffer->data;
15706 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
15707 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
15708 HeapFree(GetProcessHeap(), 0, data);
15710 else
15712 buffer = NULL;
15716 if (srv)
15717 ID3D11ShaderResourceView_Release(srv);
15718 if (current_buffer)
15720 srv_desc.Format = test->srv_format;
15721 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
15722 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
15723 U(srv_desc).Buffer.NumElements = test->srv_element_count;
15724 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
15725 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
15727 else
15729 srv = NULL;
15731 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
15733 cb_size.x = test->size.x;
15734 cb_size.y = test->size.y;
15735 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
15737 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
15738 draw_quad(&test_context);
15740 get_texture_readback(test_context.backbuffer, 0, &rb);
15741 for (y = 0; y < 4; ++y)
15743 for (x = 0; x < 4; ++x)
15745 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
15746 expected_color = test->expected_colors[y * 4 + x];
15747 ok(compare_color(color, expected_color, 1),
15748 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
15749 i, color, expected_color, x, y);
15752 release_resource_readback(&rb);
15754 if (srv)
15755 ID3D11ShaderResourceView_Release(srv);
15756 if (buffer)
15757 ID3D11Buffer_Release(buffer);
15759 ID3D11Buffer_Release(cb);
15760 ID3D11PixelShader_Release(ps);
15761 release_test_context(&test_context);
15764 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
15766 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
15767 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
15768 struct d3d11_test_context test_context;
15769 D3D11_SUBRESOURCE_DATA resource_data;
15770 D3D11_TEXTURE2D_DESC texture_desc;
15771 ID3D11UnorderedAccessView *uav;
15772 ID3D11ShaderResourceView *srv;
15773 D3D11_BUFFER_DESC buffer_desc;
15774 ID3D11Buffer *cb, *raw_buffer;
15775 ID3D11DeviceContext *context;
15776 struct resource_readback rb;
15777 ID3D11RenderTargetView *rtv;
15778 ID3D11Texture2D *texture;
15779 ID3D11ComputeShader *cs;
15780 ID3D11PixelShader *ps;
15781 ID3D11Device *device;
15782 unsigned int i, data;
15783 struct uvec4 offset;
15784 HRESULT hr;
15786 static const unsigned int buffer_data[] =
15788 0xffffffff, 0x00000000,
15790 static const DWORD ps_code[] =
15792 #if 0
15793 ByteAddressBuffer buffer;
15795 uint offset;
15797 uint main() : SV_Target0
15799 return buffer.Load(offset);
15801 #endif
15802 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
15803 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
15804 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
15805 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
15806 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
15807 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
15808 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
15809 0x00000000,
15811 static const DWORD cs_code[] =
15813 #if 0
15814 RWByteAddressBuffer buffer;
15816 uint2 input;
15818 [numthreads(1, 1, 1)]
15819 void main()
15821 buffer.Store(input.x, input.y);
15823 #endif
15824 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
15825 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15826 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
15827 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
15828 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
15829 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
15831 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
15833 if (!init_test_context(&test_context, &feature_level))
15834 return;
15836 device = test_context.device;
15837 context = test_context.immediate_context;
15839 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
15841 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15842 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15843 if (SUCCEEDED(hr))
15844 ID3D11PixelShader_Release(ps);
15845 skip("Raw buffers are not supported.\n");
15846 release_test_context(&test_context);
15847 return;
15850 if (is_intel_device(device))
15852 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
15853 * This test checks what happens when offsets are not properly aligned.
15854 * The behavior seems to be undefined on Intel hardware. */
15855 win_skip("Skipping the test on Intel hardware.\n");
15856 release_test_context(&test_context);
15857 return;
15860 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15861 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15863 memset(&offset, 0, sizeof(offset));
15864 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
15866 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
15867 texture_desc.Format = DXGI_FORMAT_R32_UINT;
15868 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15869 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15870 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15871 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15873 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15875 buffer_desc.ByteWidth = sizeof(buffer_data);
15876 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
15877 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15878 buffer_desc.CPUAccessFlags = 0;
15879 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
15880 resource_data.pSysMem = buffer_data;
15881 resource_data.SysMemPitch = 0;
15882 resource_data.SysMemSlicePitch = 0;
15883 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
15884 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
15886 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
15887 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
15888 U(srv_desc).BufferEx.FirstElement = 0;
15889 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
15890 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
15891 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
15892 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15894 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15895 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
15896 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
15898 offset.x = 0;
15899 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15900 NULL, &offset, 0, 0);
15901 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
15902 draw_quad(&test_context);
15903 check_texture_color(texture, buffer_data[0], 0);
15904 offset.x = 1;
15905 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15906 NULL, &offset, 0, 0);
15907 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
15908 draw_quad(&test_context);
15909 check_texture_color(texture, buffer_data[0], 0);
15910 offset.x = 2;
15911 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15912 NULL, &offset, 0, 0);
15913 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
15914 draw_quad(&test_context);
15915 check_texture_color(texture, buffer_data[0], 0);
15916 offset.x = 3;
15917 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15918 NULL, &offset, 0, 0);
15919 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
15920 draw_quad(&test_context);
15921 check_texture_color(texture, buffer_data[0], 0);
15923 offset.x = 4;
15924 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15925 NULL, &offset, 0, 0);
15926 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
15927 draw_quad(&test_context);
15928 check_texture_color(texture, buffer_data[1], 0);
15929 offset.x = 7;
15930 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15931 NULL, &offset, 0, 0);
15932 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
15933 draw_quad(&test_context);
15934 check_texture_color(texture, buffer_data[1], 0);
15936 if (feature_level < D3D_FEATURE_LEVEL_11_0)
15938 skip("Feature level 11_0 required for unaligned UAV test.\n");
15939 goto done;
15942 ID3D11Buffer_Release(raw_buffer);
15943 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15944 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
15945 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
15947 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
15948 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
15949 U(uav_desc).Buffer.FirstElement = 0;
15950 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
15951 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
15952 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
15953 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15955 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
15956 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15958 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15959 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
15960 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
15962 offset.x = 0;
15963 offset.y = 0xffffffff;
15964 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15965 NULL, &offset, 0, 0);
15966 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
15967 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15968 get_buffer_readback(raw_buffer, &rb);
15969 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
15971 data = get_readback_color(&rb, i, 0);
15972 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
15974 release_resource_readback(&rb);
15976 offset.x = 1;
15977 offset.y = 0xffffffff;
15978 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15979 NULL, &offset, 0, 0);
15980 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
15981 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15982 get_buffer_readback(raw_buffer, &rb);
15983 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
15985 data = get_readback_color(&rb, i, 0);
15986 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
15988 release_resource_readback(&rb);
15990 offset.x = 2;
15991 offset.y = 0xffffffff;
15992 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15993 NULL, &offset, 0, 0);
15994 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
15995 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15996 get_buffer_readback(raw_buffer, &rb);
15997 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
15999 data = get_readback_color(&rb, i, 0);
16000 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
16002 release_resource_readback(&rb);
16004 offset.x = 3;
16005 offset.y = 0xffffffff;
16006 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
16007 NULL, &offset, 0, 0);
16008 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
16009 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16010 get_buffer_readback(raw_buffer, &rb);
16011 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
16013 data = get_readback_color(&rb, i, 0);
16014 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
16016 release_resource_readback(&rb);
16018 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
16019 offset.x = 3;
16020 offset.y = 0xffff;
16021 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
16022 NULL, &offset, 0, 0);
16023 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16024 offset.x = 4;
16025 offset.y = 0xa;
16026 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
16027 NULL, &offset, 0, 0);
16028 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16029 get_buffer_readback(raw_buffer, &rb);
16030 data = get_readback_color(&rb, 0, 0);
16031 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
16032 data = get_readback_color(&rb, 1, 0);
16033 ok(data == 0xa, "Got unexpected result %#x.\n", data);
16034 release_resource_readback(&rb);
16036 ID3D11ComputeShader_Release(cs);
16037 ID3D11UnorderedAccessView_Release(uav);
16039 done:
16040 ID3D11Buffer_Release(cb);
16041 ID3D11Buffer_Release(raw_buffer);
16042 ID3D11PixelShader_Release(ps);
16043 ID3D11RenderTargetView_Release(rtv);
16044 ID3D11ShaderResourceView_Release(srv);
16045 ID3D11Texture2D_Release(texture);
16046 release_test_context(&test_context);
16049 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
16050 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
16052 D3D11_MAPPED_SUBRESOURCE map_desc;
16053 unsigned int counter;
16055 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
16057 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
16058 D3D11_MAP_READ, 0, &map_desc)))
16059 return 0xdeadbeef;
16060 counter = *(unsigned int *)map_desc.pData;
16061 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
16062 return counter;
16065 static int compare_id(const void *a, const void *b)
16067 return *(int *)a - *(int *)b;
16070 static void test_uav_counters(void)
16072 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
16073 ID3D11ComputeShader *cs_producer, *cs_consumer;
16074 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16075 struct d3d11_test_context test_context;
16076 ID3D11UnorderedAccessView *uav, *uav2;
16077 unsigned int data, id[128], i;
16078 D3D11_BUFFER_DESC buffer_desc;
16079 ID3D11DeviceContext *context;
16080 struct resource_readback rb;
16081 ID3D11Device *device;
16082 D3D11_BOX box;
16083 HRESULT hr;
16085 static const DWORD cs_producer_code[] =
16087 #if 0
16088 RWStructuredBuffer<uint> u;
16090 [numthreads(4, 1, 1)]
16091 void main(uint3 dispatch_id : SV_DispatchThreadID)
16093 uint counter = u.IncrementCounter();
16094 u[counter] = dispatch_id.x;
16096 #endif
16097 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
16098 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16099 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
16100 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
16101 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
16102 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
16103 0x0002000a, 0x0100003e,
16105 static const DWORD cs_consumer_code[] =
16107 #if 0
16108 RWStructuredBuffer<uint> u;
16109 RWStructuredBuffer<uint> u2;
16111 [numthreads(4, 1, 1)]
16112 void main()
16114 uint counter = u.DecrementCounter();
16115 u2[counter] = u[counter];
16117 #endif
16118 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
16119 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16120 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
16121 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
16122 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
16123 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
16124 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
16125 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
16127 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16129 if (!init_test_context(&test_context, &feature_level))
16130 return;
16132 device = test_context.device;
16133 context = test_context.immediate_context;
16135 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
16136 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16137 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
16138 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16140 memset(&buffer_desc, 0, sizeof(buffer_desc));
16141 buffer_desc.ByteWidth = sizeof(unsigned int);
16142 buffer_desc.Usage = D3D11_USAGE_STAGING;
16143 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
16144 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
16145 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
16147 buffer_desc.ByteWidth = 1024;
16148 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
16149 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16150 buffer_desc.CPUAccessFlags = 0;
16151 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
16152 buffer_desc.StructureByteStride = sizeof(unsigned int);
16153 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16154 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
16155 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
16156 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16157 U(uav_desc).Buffer.FirstElement = 0;
16158 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
16159 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
16160 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16161 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16162 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
16163 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
16164 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
16165 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16167 data = read_uav_counter(context, staging_buffer, uav);
16168 ok(!data, "Got unexpected initial value %u.\n", data);
16169 data = 8;
16170 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
16171 data = read_uav_counter(context, staging_buffer, uav);
16172 todo_wine ok(data == 8, "Got unexpected value %u.\n", data);
16174 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
16175 data = 0;
16176 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
16177 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
16178 data = read_uav_counter(context, staging_buffer, uav);
16179 ok(!data, "Got unexpected value %u.\n", data);
16181 /* produce */
16182 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
16183 data = read_uav_counter(context, staging_buffer, uav);
16184 todo_wine ok(data == 64, "Got unexpected value %u.\n", data);
16185 get_buffer_readback(buffer, &rb);
16186 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
16187 release_resource_readback(&rb);
16188 qsort(id, 64, sizeof(*id), compare_id);
16189 for (i = 0; i < 64; ++i)
16191 if (id[i] != i)
16192 break;
16194 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
16196 /* consume */
16197 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
16198 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
16199 data = read_uav_counter(context, staging_buffer, uav);
16200 ok(!data, "Got unexpected value %u.\n", data);
16201 get_buffer_readback(buffer2, &rb);
16202 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
16203 release_resource_readback(&rb);
16204 qsort(id, 64, sizeof(*id), compare_id);
16205 for (i = 0; i < 64; ++i)
16207 if (id[i] != i)
16208 break;
16210 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
16212 /* produce on CPU */
16213 for (i = 0; i < 8; ++i)
16214 id[i] = 0xdeadbeef;
16215 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
16216 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
16217 data = 8;
16218 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
16219 data = read_uav_counter(context, staging_buffer, uav);
16220 todo_wine ok(data == 8, "Got unexpected value %u.\n", data);
16222 /* consume */
16223 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16224 data = read_uav_counter(context, staging_buffer, uav);
16225 todo_wine ok(data == 4, "Got unexpected value %u.\n", data);
16226 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16227 data = read_uav_counter(context, staging_buffer, uav);
16228 ok(!data, "Got unexpected value %u.\n", data);
16229 get_buffer_readback(buffer2, &rb);
16230 for (i = 0; i < 8; ++i)
16232 data = get_readback_color(&rb, i, 0);
16233 todo_wine ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
16235 release_resource_readback(&rb);
16237 ID3D11Buffer_Release(buffer);
16238 ID3D11Buffer_Release(buffer2);
16239 ID3D11Buffer_Release(staging_buffer);
16240 ID3D11ComputeShader_Release(cs_producer);
16241 ID3D11ComputeShader_Release(cs_consumer);
16242 ID3D11UnorderedAccessView_Release(uav);
16243 ID3D11UnorderedAccessView_Release(uav2);
16244 release_test_context(&test_context);
16247 static void test_compute_shader_registers(void)
16249 struct data
16251 unsigned int group_id[3];
16252 unsigned int group_index;
16253 unsigned int dispatch_id[3];
16254 unsigned int thread_id[3];
16257 struct d3d11_test_context test_context;
16258 unsigned int i, x, y, group_x, group_y;
16259 ID3D11UnorderedAccessView *uav;
16260 D3D11_BUFFER_DESC buffer_desc;
16261 ID3D11DeviceContext *context;
16262 struct resource_readback rb;
16263 ID3D11Buffer *cb, *buffer;
16264 struct uvec4 dimensions;
16265 ID3D11ComputeShader *cs;
16266 const struct data *data;
16267 ID3D11Device *device;
16268 HRESULT hr;
16270 static const DWORD cs_code[] =
16272 #if 0
16273 struct data
16275 uint3 group_id;
16276 uint group_index;
16277 uint3 dispatch_id;
16278 uint3 group_thread_id;
16281 RWStructuredBuffer<data> u;
16283 uint2 dim;
16285 [numthreads(3, 2, 1)]
16286 void main(uint3 group_id : SV_GroupID,
16287 uint group_index : SV_GroupIndex,
16288 uint3 dispatch_id : SV_DispatchThreadID,
16289 uint3 group_thread_id : SV_GroupThreadID)
16291 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
16292 u[i].group_id = group_id;
16293 u[i].group_index = group_index;
16294 u[i].dispatch_id = dispatch_id;
16295 u[i].group_thread_id = group_thread_id;
16297 #endif
16298 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
16299 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16300 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
16301 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
16302 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
16303 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
16304 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
16305 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
16306 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
16307 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
16308 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
16309 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
16310 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
16311 0x0100003e,
16313 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16315 if (!init_test_context(&test_context, &feature_level))
16316 return;
16318 device = test_context.device;
16319 context = test_context.immediate_context;
16321 buffer_desc.ByteWidth = 10240;
16322 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
16323 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16324 buffer_desc.CPUAccessFlags = 0;
16325 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
16326 buffer_desc.StructureByteStride = 40;
16327 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
16328 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16329 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
16330 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
16331 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16333 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
16335 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
16336 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16338 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16339 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
16340 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16342 dimensions.x = 2;
16343 dimensions.y = 3;
16344 dimensions.z = 1;
16345 dimensions.w = 0;
16346 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
16347 NULL, &dimensions, 0, 0);
16348 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
16350 get_buffer_readback(buffer, &rb);
16351 i = 0;
16352 data = rb.map_desc.pData;
16353 for (y = 0; y < dimensions.y; ++y)
16355 for (group_y = 0; group_y < 2; ++group_y)
16357 for (x = 0; x < dimensions.x; ++x)
16359 for (group_x = 0; group_x < 3; ++group_x)
16361 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
16362 const unsigned int group_index = group_y * 3 + group_x;
16363 const struct data *d = &data[i];
16365 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
16366 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
16367 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
16368 i, x, y, group_x, group_y);
16369 ok(d->group_index == group_index,
16370 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
16371 d->group_index, group_index, i, x, y, group_x, group_y);
16372 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
16373 && !d->dispatch_id[2],
16374 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
16375 "at %u (%u, %u, %u, %u).\n",
16376 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
16377 dispatch_id[0], dispatch_id[1], 0,
16378 i, x, y, group_x, group_y);
16379 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
16380 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
16381 "at %u (%u, %u, %u, %u).\n",
16382 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
16383 i, x, y, group_x, group_y);
16384 ++i;
16389 release_resource_readback(&rb);
16391 ID3D11Buffer_Release(cb);
16392 ID3D11Buffer_Release(buffer);
16393 ID3D11ComputeShader_Release(cs);
16394 ID3D11UnorderedAccessView_Release(uav);
16395 release_test_context(&test_context);
16398 static void test_tgsm(void)
16400 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16401 struct d3d11_test_context test_context;
16402 ID3D11UnorderedAccessView *uav, *uav2;
16403 struct resource_readback rb, rb2;
16404 unsigned int i, data, expected;
16405 ID3D11Buffer *buffer, *buffer2;
16406 D3D11_BUFFER_DESC buffer_desc;
16407 ID3D11DeviceContext *context;
16408 ID3D11ComputeShader *cs;
16409 ID3D11Device *device;
16410 float float_data;
16411 HRESULT hr;
16413 static const DWORD raw_tgsm_code[] =
16415 #if 0
16416 RWByteAddressBuffer u;
16417 groupshared uint m;
16419 [numthreads(32, 1, 1)]
16420 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
16422 if (!local_idx)
16423 m = group_id.x;
16424 GroupMemoryBarrierWithGroupSync();
16425 InterlockedAdd(m, group_id.x);
16426 GroupMemoryBarrierWithGroupSync();
16427 if (!local_idx)
16428 u.Store(4 * group_id.x, m);
16430 #endif
16431 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
16432 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16433 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
16434 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
16435 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
16436 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
16437 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
16438 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
16439 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
16440 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
16441 0x01000015, 0x0100003e,
16443 static const DWORD structured_tgsm_code[] =
16445 #if 0
16446 #define GROUP_SIZE 32
16448 RWByteAddressBuffer u;
16449 RWByteAddressBuffer u2;
16450 groupshared uint m[GROUP_SIZE];
16452 [numthreads(GROUP_SIZE, 1, 1)]
16453 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
16455 uint sum, original, i;
16457 if (!local_idx)
16459 for (i = 0; i < GROUP_SIZE; ++i)
16460 m[i] = 2 * group_id.x;
16462 GroupMemoryBarrierWithGroupSync();
16463 InterlockedAdd(m[local_idx], 1);
16464 GroupMemoryBarrierWithGroupSync();
16465 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
16466 u.InterlockedExchange(4 * group_id.x, sum, original);
16467 u2.Store(4 * group_id.x, original);
16469 #endif
16470 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
16471 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16472 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
16473 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
16474 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
16475 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
16476 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
16477 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
16478 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
16479 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
16480 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
16481 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
16482 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
16483 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
16484 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
16485 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
16486 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
16487 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
16488 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
16489 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
16490 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
16491 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
16493 static const DWORD structured_tgsm_float_code[] =
16495 #if 0
16496 #define GROUP_SIZE 32
16498 struct data
16500 float f;
16501 uint u;
16504 RWBuffer<float> u;
16505 RWBuffer<uint> u2;
16506 groupshared data m[GROUP_SIZE];
16508 [numthreads(GROUP_SIZE, 1, 1)]
16509 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
16510 uint thread_id : SV_DispatchThreadID)
16512 uint i;
16513 if (!local_idx)
16515 for (i = 0; i < GROUP_SIZE; ++i)
16517 m[i].f = group_id.x;
16518 m[i].u = group_id.x;
16521 GroupMemoryBarrierWithGroupSync();
16522 for (i = 0; i < local_idx; ++i)
16524 m[local_idx].f += group_id.x;
16525 m[local_idx].u += group_id.x;
16527 u[thread_id.x] = m[local_idx].f;
16528 u2[thread_id.x] = m[local_idx].u;
16530 #endif
16531 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
16532 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16533 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
16534 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
16535 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
16536 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
16537 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
16538 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
16539 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
16540 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
16541 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
16542 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
16543 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
16544 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
16545 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
16546 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
16547 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
16548 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
16549 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
16550 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
16551 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
16552 0x00100556, 0x00000000, 0x0100003e,
16554 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16555 static const unsigned int zero[4] = {0};
16557 if (!init_test_context(&test_context, &feature_level))
16558 return;
16560 device = test_context.device;
16561 context = test_context.immediate_context;
16563 buffer_desc.ByteWidth = 1024;
16564 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
16565 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16566 buffer_desc.CPUAccessFlags = 0;
16567 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
16568 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16569 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
16571 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
16572 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16573 U(uav_desc).Buffer.FirstElement = 0;
16574 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
16575 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
16576 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16577 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16579 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
16580 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16582 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16583 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16585 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
16586 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
16587 get_buffer_readback(buffer, &rb);
16588 for (i = 0; i < 64; ++i)
16590 data = get_readback_color(&rb, i, 0);
16591 expected = 33 * i;
16592 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
16594 release_resource_readback(&rb);
16596 ID3D11Buffer_Release(buffer);
16597 ID3D11ComputeShader_Release(cs);
16598 ID3D11UnorderedAccessView_Release(uav);
16600 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16601 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
16602 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16603 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16604 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
16605 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
16606 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
16607 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16608 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
16609 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16611 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16612 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16613 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
16615 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
16616 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
16617 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
16618 get_buffer_readback(buffer, &rb);
16619 get_buffer_readback(buffer2, &rb2);
16620 for (i = 0; i < 32; ++i)
16622 expected = 64 * i + 32;
16623 data = get_readback_color(&rb, i, 0);
16624 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
16625 data = get_readback_color(&rb2, i, 0);
16626 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
16628 release_resource_readback(&rb);
16629 release_resource_readback(&rb2);
16631 ID3D11Buffer_Release(buffer);
16632 ID3D11Buffer_Release(buffer2);
16633 ID3D11ComputeShader_Release(cs);
16634 ID3D11UnorderedAccessView_Release(uav);
16635 ID3D11UnorderedAccessView_Release(uav2);
16637 buffer_desc.MiscFlags = 0;
16638 U(uav_desc).Buffer.Flags = 0;
16639 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16640 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
16641 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
16642 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16643 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16644 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
16645 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
16646 uav_desc.Format = DXGI_FORMAT_R32_UINT;
16647 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
16648 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16649 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
16650 sizeof(structured_tgsm_float_code), NULL, &cs);
16651 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16653 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16654 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16655 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
16657 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
16658 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
16659 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
16660 get_buffer_readback(buffer, &rb);
16661 get_buffer_readback(buffer2, &rb2);
16662 for (i = 0; i < 96; ++i)
16664 expected = (i % 32 + 1) * (i / 32);
16665 float_data = get_readback_float(&rb, i, 0);
16666 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
16667 data = get_readback_color(&rb2, i, 0);
16668 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
16670 release_resource_readback(&rb);
16671 release_resource_readback(&rb2);
16673 ID3D11Buffer_Release(buffer);
16674 ID3D11Buffer_Release(buffer2);
16675 ID3D11ComputeShader_Release(cs);
16676 ID3D11UnorderedAccessView_Release(uav);
16677 ID3D11UnorderedAccessView_Release(uav2);
16678 release_test_context(&test_context);
16681 static void test_geometry_shader(void)
16683 static const struct
16685 struct vec4 position;
16686 unsigned int color;
16688 vertex[] =
16690 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
16692 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
16694 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
16695 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
16697 #if 0
16698 struct vs_data
16700 float4 pos : SV_POSITION;
16701 float4 color : COLOR;
16704 void main(in struct vs_data vs_input, out struct vs_data vs_output)
16706 vs_output.pos = vs_input.pos;
16707 vs_output.color = vs_input.color;
16709 #endif
16710 static const DWORD vs_code[] =
16712 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
16713 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16714 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
16715 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
16716 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
16717 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
16718 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
16719 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
16720 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
16721 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
16722 0x0100003e,
16724 #if 0
16725 struct gs_data
16727 float4 pos : SV_POSITION;
16728 float4 color : COLOR;
16731 [maxvertexcount(4)]
16732 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
16734 float offset = 0.2 * vin[0].pos.w;
16735 gs_data v;
16737 v.color = vin[0].color;
16739 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
16740 vout.Append(v);
16741 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
16742 vout.Append(v);
16743 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
16744 vout.Append(v);
16745 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
16746 vout.Append(v);
16748 #endif
16749 static const DWORD gs_code[] =
16751 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
16752 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16753 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
16754 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
16755 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
16756 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
16757 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
16758 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
16759 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
16760 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
16761 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
16762 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
16763 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
16764 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
16765 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
16766 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
16767 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
16768 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
16769 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
16770 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
16771 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
16772 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
16773 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
16774 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
16775 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
16776 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
16777 0x00000001, 0x01000013, 0x0100003e,
16779 static const DWORD gs_5_0_code[] =
16781 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
16782 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16783 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
16784 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
16785 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
16786 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
16787 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
16788 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
16789 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
16790 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
16791 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
16792 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
16793 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
16794 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
16795 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
16796 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
16797 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
16798 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
16799 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
16800 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
16801 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
16802 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
16803 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
16804 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
16805 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
16806 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
16807 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
16808 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
16809 0x0100003e,
16811 #if 0
16812 struct ps_data
16814 float4 pos : SV_POSITION;
16815 float4 color : COLOR;
16818 float4 main(struct ps_data ps_input) : SV_Target
16820 return ps_input.color;
16822 #endif
16823 static const DWORD ps_code[] =
16825 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
16826 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16827 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
16828 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
16829 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16830 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
16831 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
16832 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
16834 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
16835 struct d3d11_test_context test_context;
16836 ID3D11InputLayout *input_layout;
16837 ID3D11DeviceContext *context;
16838 unsigned int stride, offset;
16839 struct resource_readback rb;
16840 ID3D11GeometryShader *gs;
16841 ID3D11VertexShader *vs;
16842 ID3D11PixelShader *ps;
16843 ID3D11Device *device;
16844 ID3D11Buffer *vb;
16845 DWORD color;
16846 HRESULT hr;
16848 if (!init_test_context(&test_context, NULL))
16849 return;
16851 device = test_context.device;
16852 context = test_context.immediate_context;
16854 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
16855 vs_code, sizeof(vs_code), &input_layout);
16856 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
16858 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
16860 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
16861 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
16862 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
16863 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
16864 else
16865 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
16866 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
16867 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16868 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16870 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
16871 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
16872 stride = sizeof(*vertex);
16873 offset = 0;
16874 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
16875 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
16876 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
16877 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16879 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
16880 ID3D11DeviceContext_Draw(context, 1, 0);
16882 get_texture_readback(test_context.backbuffer, 0, &rb);
16883 color = get_readback_color(&rb, 320, 190);
16884 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
16885 color = get_readback_color(&rb, 255, 240);
16886 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
16887 color = get_readback_color(&rb, 320, 240);
16888 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
16889 color = get_readback_color(&rb, 385, 240);
16890 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
16891 color = get_readback_color(&rb, 320, 290);
16892 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
16893 release_resource_readback(&rb);
16895 ID3D11PixelShader_Release(ps);
16896 ID3D11GeometryShader_Release(gs);
16897 ID3D11VertexShader_Release(vs);
16898 ID3D11Buffer_Release(vb);
16899 ID3D11InputLayout_Release(input_layout);
16900 release_test_context(&test_context);
16903 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
16904 static void check_so_desc_(unsigned int line, ID3D11Device *device,
16905 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
16906 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
16907 unsigned int rasterizer_stream)
16909 ID3D11GeometryShader *gs;
16910 HRESULT hr;
16912 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
16913 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
16914 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
16915 if (SUCCEEDED(hr))
16916 ID3D11GeometryShader_Release(gs);
16919 #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)
16920 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
16921 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
16922 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
16923 unsigned int rasterizer_stream)
16925 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
16926 HRESULT hr;
16928 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
16929 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
16930 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16931 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
16932 if (SUCCEEDED(hr))
16933 ID3D11GeometryShader_Release(gs);
16936 static void test_stream_output(void)
16938 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
16939 struct d3d11_test_context test_context;
16940 unsigned int i, count;
16941 ID3D11Device *device;
16943 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16944 static const DWORD vs_code[] =
16946 #if 0
16947 struct data
16949 float4 position : SV_Position;
16950 float4 attrib1 : ATTRIB1;
16951 float3 attrib2 : attrib2;
16952 float2 attrib3 : ATTriB3;
16953 float attrib4 : ATTRIB4;
16956 void main(in data i, out data o)
16958 o = i;
16960 #endif
16961 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
16962 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
16963 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
16964 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
16965 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
16966 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
16967 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
16968 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
16969 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
16970 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
16971 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
16972 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
16973 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
16974 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
16975 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
16976 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
16977 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
16978 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
16979 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
16980 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
16982 static const DWORD gs_code[] =
16984 #if 0
16985 struct data
16987 float4 position : SV_Position;
16988 float4 attrib1 : ATTRIB1;
16989 float3 attrib2 : attrib2;
16990 float2 attrib3 : ATTriB3;
16991 float attrib4 : ATTRIB4;
16994 [maxvertexcount(1)]
16995 void main(point data i[1], inout PointStream<data> o)
16997 o.Append(i[0]);
16999 #endif
17000 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
17001 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
17002 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
17003 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
17004 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
17005 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
17006 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
17007 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
17008 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
17009 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
17010 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
17011 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
17012 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
17013 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
17014 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
17015 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
17016 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
17017 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
17018 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
17019 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
17020 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
17022 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
17024 {0, "SV_Position", 0, 0, 4, 0},
17026 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
17028 {0, "SV_Position", 0, 0, 4, 0},
17029 {0, NULL, 0, 0, 0, 0},
17031 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
17033 /* SemanticName and SemanticIndex */
17035 {0, "sv_position", 0, 0, 4, 0},
17036 {0, "attrib", 1, 0, 4, 0},
17039 {0, "sv_position", 0, 0, 4, 0},
17040 {0, "ATTRIB", 1, 0, 4, 0},
17042 /* Gaps */
17044 {0, "SV_POSITION", 0, 0, 4, 0},
17045 {0, NULL, 0, 0, 8, 0},
17046 {0, "ATTRIB", 1, 0, 4, 0},
17049 {0, "SV_POSITION", 0, 0, 4, 0},
17050 {0, NULL, 0, 0, 4, 0},
17051 {0, NULL, 0, 0, 4, 0},
17052 {0, "ATTRIB", 1, 0, 4, 0},
17054 /* ComponentCount */
17056 {0, "ATTRIB", 1, 0, 4, 0},
17059 {0, "ATTRIB", 2, 0, 3, 0},
17062 {0, "ATTRIB", 3, 0, 2, 0},
17065 {0, "ATTRIB", 4, 0, 1, 0},
17067 /* ComponentIndex */
17069 {0, "ATTRIB", 1, 1, 3, 0},
17072 {0, "ATTRIB", 1, 2, 2, 0},
17075 {0, "ATTRIB", 1, 3, 1, 0},
17078 {0, "ATTRIB", 3, 1, 1, 0},
17080 /* OutputSlot */
17082 {0, "attrib", 1, 0, 4, 0},
17085 {0, "attrib", 1, 0, 4, 1},
17088 {0, "attrib", 1, 0, 4, 2},
17091 {0, "attrib", 1, 0, 4, 3},
17094 {0, "attrib", 1, 0, 4, 0},
17095 {0, "attrib", 2, 0, 3, 1},
17096 {0, NULL, 0, 0, 1, 1},
17097 {0, "attrib", 3, 0, 2, 2},
17098 {0, NULL, 0, 0, 2, 2},
17099 {0, "attrib", 4, 0, 1, 3},
17100 {0, NULL, 0, 0, 7, 3},
17103 {0, "attrib", 1, 0, 4, 0},
17104 {0, "attrib", 2, 0, 3, 1},
17105 {0, NULL, 0, 0, 1, 1},
17106 {0, "attrib", 3, 0, 2, 2},
17107 {0, NULL, 0, 0, 1, 2},
17108 {0, NULL, 0, 0, 1, 2},
17109 {0, "attrib", 4, 0, 1, 3},
17110 {0, NULL, 0, 0, 3, 3},
17111 {0, NULL, 0, 0, 1, 3},
17112 {0, NULL, 0, 0, 1, 3},
17113 {0, NULL, 0, 0, 1, 3},
17114 {0, NULL, 0, 0, 1, 3},
17117 {0, "attrib", 1, 0, 4, 0},
17118 {0, "attrib", 2, 0, 3, 0},
17119 {0, "attrib", 3, 0, 2, 0},
17120 {0, NULL, 0, 0, 1, 0},
17121 {0, "attrib", 4, 0, 1, 0},
17124 {0, "attrib", 1, 0, 4, 0},
17125 {0, "attrib", 2, 0, 3, 0},
17126 {0, "attrib", 3, 0, 2, 3},
17127 {0, NULL, 0, 0, 1, 3},
17128 {0, "attrib", 4, 0, 1, 3},
17130 /* Multiple occurrences of the same output */
17132 {0, "ATTRIB", 1, 0, 2, 0},
17133 {0, "ATTRIB", 1, 2, 2, 1},
17136 {0, "ATTRIB", 1, 0, 1, 0},
17137 {0, "ATTRIB", 1, 1, 3, 0},
17140 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
17142 /* SemanticName and SemanticIndex */
17144 {0, "SV_Position", 0, 0, 4, 0},
17145 {0, "ATTRIB", 0, 0, 4, 0},
17148 {0, "sv_position", 0, 0, 4, 0},
17149 {0, "ATTRIB_", 1, 0, 4, 0},
17151 /* Gaps */
17153 {0, "SV_POSITION", 0, 0, 4, 0},
17154 {0, NULL, 0, 1, 8, 0},
17155 {0, "ATTRIB", 1, 0, 4, 0},
17158 {0, "SV_POSITION", 0, 0, 4, 0},
17159 {0, NULL, 1, 0, 8, 0},
17160 {0, "ATTRIB", 1, 0, 4, 0},
17162 /* Buffer stride */
17164 {0, "SV_POSITION", 0, 0, 4, 0},
17165 {0, NULL, 0, 0, 8, 0},
17166 {0, NULL, 0, 0, 8, 0},
17167 {0, "ATTRIB", 1, 0, 4, 0},
17169 /* ComponentCount */
17171 {0, "ATTRIB", 2, 0, 5, 0},
17174 {0, "ATTRIB", 2, 0, 4, 0},
17177 {0, "ATTRIB", 3, 0, 3, 0},
17180 {0, "ATTRIB", 4, 0, 2, 0},
17182 /* ComponentIndex */
17184 {0, "ATTRIB", 1, 1, 4, 0},
17187 {0, "ATTRIB", 1, 2, 3, 0},
17190 {0, "ATTRIB", 1, 3, 2, 0},
17193 {0, "ATTRIB", 1, 4, 0, 0},
17196 {0, "ATTRIB", 1, 4, 1, 0},
17199 {0, "ATTRIB", 3, 2, 1, 0},
17202 {0, "ATTRIB", 3, 2, 0, 0},
17204 /* OutputSlot */
17206 {0, "attrib", 1, 0, 4, 4},
17209 {0, "attrib", 1, 0, 4, 4},
17212 {0, "attrib", 1, 0, 4, 4},
17215 {0, "attrib", 1, 0, 4, 4},
17218 {0, "attrib", 1, 0, 4, 0},
17219 {0, "attrib", 2, 0, 3, 1},
17220 {0, NULL, 0, 0, 1, 1},
17221 {0, "attrib", 3, 0, 2, 2},
17222 {0, NULL, 0, 0, 2, 2},
17223 {0, "attrib", 4, 0, 1, 3},
17224 {0, NULL, 0, 0, 3, 4},
17227 {0, "attrib", 1, 0, 4, 0},
17228 {0, "attrib", 2, 0, 3, 0},
17229 {0, "attrib", 3, 0, 2, 0},
17230 {0, NULL, 0, 0, 1, 0},
17231 {0, "attrib", 4, 0, 1, 0},
17232 {0, NULL, 0, 0, 3, 3},
17233 {0, NULL, 0, 0, 1, 3},
17234 {0, NULL, 0, 0, 1, 3},
17235 {0, NULL, 0, 0, 1, 3},
17236 {0, NULL, 0, 0, 1, 3},
17239 {0, "attrib", 1, 0, 4, 0},
17240 {0, NULL, 0, 0, 3, 1},
17241 {0, NULL, 0, 0, 1, 1},
17242 {0, NULL, 0, 0, 1, 2},
17243 {0, "attrib", 2, 0, 3, 3},
17244 {0, NULL, 0, 0, 1, 3},
17247 {0, "attrib", 2, 0, 3, 3},
17248 {0, NULL, 0, 0, 3, 1},
17249 {0, NULL, 0, 0, 1, 3},
17250 {0, "attrib", 1, 0, 4, 0},
17251 {0, NULL, 0, 0, 1, 2},
17252 {0, NULL, 0, 0, 1, 1},
17254 /* Stream */
17256 {1, "attrib", 1, 0, 4, 0},
17259 {4, "attrib", 1, 0, 4, 0},
17261 /* Multiple occurrences of the same output */
17263 {0, "ATTRIB", 1, 0, 4, 0},
17264 {0, "ATTRIB", 1, 0, 4, 1},
17267 {0, "ATTRIB", 1, 0, 4, 0},
17268 {0, "ATTRIB", 1, 0, 3, 0},
17272 if (!init_test_context(&test_context, &feature_level))
17273 return;
17275 device = test_context.device;
17277 for (i = 0; i < ARRAY_SIZE(stride); ++i)
17278 stride[i] = 64;
17280 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
17281 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
17282 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
17283 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
17284 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
17285 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
17287 todo_wine
17288 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
17289 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
17290 todo_wine
17291 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
17292 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
17294 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
17295 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
17296 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
17297 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
17298 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
17300 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
17301 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
17302 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
17303 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
17305 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
17307 unsigned int max_output_slot = 0;
17308 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
17310 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
17311 max_output_slot = max(max_output_slot, e->OutputSlot);
17312 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
17313 break;
17316 /* Buffer strides are required for all buffers. */
17317 if (!max_output_slot)
17319 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
17320 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
17321 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
17322 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
17323 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
17324 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
17325 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
17326 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
17327 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
17328 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
17330 else
17332 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
17333 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
17334 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
17335 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
17339 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
17341 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
17343 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
17344 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
17345 break;
17348 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
17349 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
17350 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
17351 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
17352 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
17353 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
17354 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
17355 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
17358 /* Buffer strides */
17359 stride[1] = 63;
17360 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
17361 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
17362 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
17363 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
17364 stride[1] = 1;
17365 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
17366 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
17367 stride[0] = 0;
17368 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
17369 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
17371 /* Rasterizer stream */
17372 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
17373 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
17374 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
17375 NULL, 0, D3D11_SO_STREAM_COUNT);
17377 release_test_context(&test_context);
17380 static void test_fl10_stream_output_desc(void)
17382 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
17383 struct d3d11_test_context test_context;
17384 unsigned int i, count;
17385 ID3D11Device *device;
17387 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
17388 static const DWORD vs_code[] =
17390 #if 0
17391 struct data
17393 float4 position : SV_Position;
17394 float4 attrib1 : ATTRIB1;
17395 float3 attrib2 : attrib2;
17396 float2 attrib3 : ATTriB3;
17397 float attrib4 : ATTRIB4;
17400 void main(in data i, out data o)
17402 o = i;
17404 #endif
17405 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
17406 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
17407 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
17408 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
17409 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
17410 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
17411 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
17412 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
17413 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
17414 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
17415 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
17416 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
17417 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
17418 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
17419 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
17420 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
17421 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
17422 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
17423 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
17424 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
17426 static const DWORD gs_code[] =
17428 #if 0
17429 struct data
17431 float4 position : SV_Position;
17432 float4 attrib1 : ATTRIB1;
17433 float3 attrib2 : attrib2;
17434 float2 attrib3 : ATTriB3;
17435 float attrib4 : ATTRIB4;
17438 [maxvertexcount(1)]
17439 void main(point data i[1], inout PointStream<data> o)
17441 o.Append(i[0]);
17443 #endif
17444 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
17445 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
17446 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
17447 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
17448 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
17449 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
17450 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
17451 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
17452 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
17453 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
17454 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
17455 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
17456 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
17457 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
17458 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
17459 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
17460 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
17461 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
17462 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
17463 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
17464 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
17466 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
17468 {0, "SV_Position", 0, 0, 4, 0},
17470 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
17472 {0, "SV_Position", 0, 0, 4, 0},
17473 {0, NULL, 0, 0, 0, 0},
17475 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
17477 /* Gaps */
17479 {0, "SV_POSITION", 0, 0, 4, 0},
17480 {0, NULL, 0, 0, 8, 0},
17481 {0, "ATTRIB", 1, 0, 4, 0},
17484 {0, "SV_POSITION", 0, 0, 4, 0},
17485 {0, NULL, 0, 0, 4, 0},
17486 {0, NULL, 0, 0, 4, 0},
17487 {0, "ATTRIB", 1, 0, 4, 0},
17489 /* OutputSlot */
17491 {0, "attrib", 1, 0, 4, 0},
17492 {0, "attrib", 2, 0, 3, 0},
17493 {0, "attrib", 3, 0, 2, 0},
17494 {0, "attrib", 4, 0, 1, 0},
17497 {0, "attrib", 1, 0, 4, 0},
17498 {0, "attrib", 2, 0, 3, 1},
17499 {0, "attrib", 3, 0, 2, 2},
17500 {0, "attrib", 4, 0, 1, 3},
17503 {0, "attrib", 1, 0, 4, 0},
17504 {0, "attrib", 2, 0, 3, 3},
17507 {0, "attrib", 1, 0, 4, 0},
17508 {0, "attrib", 2, 0, 3, 0},
17509 {0, "attrib", 3, 0, 2, 0},
17510 {0, NULL, 0, 0, 1, 0},
17511 {0, "attrib", 4, 0, 1, 0},
17513 /* Multiple occurrences of the same output */
17515 {0, "ATTRIB", 1, 0, 2, 0},
17516 {0, "ATTRIB", 1, 2, 2, 1},
17519 {0, "ATTRIB", 1, 0, 1, 0},
17520 {0, "ATTRIB", 1, 1, 3, 0},
17523 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
17525 /* OutputSlot */
17527 {0, "attrib", 1, 0, 4, 0},
17528 {0, NULL, 0, 0, 4, 0},
17529 {0, "attrib", 4, 0, 1, 3},
17532 {0, "attrib", 1, 0, 4, 0},
17533 {0, NULL, 0, 0, 4, 0},
17534 {0, NULL, 0, 0, 4, 0},
17535 {0, "attrib", 4, 0, 1, 3},
17538 {0, "attrib", 1, 0, 4, 0},
17539 {0, "attrib", 2, 0, 3, 0},
17540 {0, "attrib", 3, 0, 2, 0},
17541 {0, "attrib", 4, 0, 1, 1},
17544 {0, "attrib", 1, 0, 4, 0},
17545 {0, "attrib", 2, 0, 3, 0},
17546 {0, "attrib", 3, 0, 2, 3},
17547 {0, NULL, 0, 0, 1, 3},
17548 {0, "attrib", 4, 0, 1, 3},
17551 {0, "attrib", 1, 0, 4, 0},
17552 {0, "attrib", 1, 0, 3, 1},
17553 {0, "attrib", 1, 0, 2, 2},
17554 {0, "attrib", 1, 0, 1, 3},
17555 {0, NULL, 0, 0, 3, 3},
17559 if (!init_test_context(&test_context, &feature_level))
17560 return;
17562 device = test_context.device;
17564 for (i = 0; i < ARRAY_SIZE(stride); ++i)
17565 stride[i] = 64;
17567 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
17568 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
17569 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
17570 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
17572 todo_wine
17573 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
17574 todo_wine
17575 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
17577 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
17578 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
17579 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
17580 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
17581 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
17583 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
17584 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
17586 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
17588 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
17590 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
17591 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
17592 break;
17595 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
17598 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
17600 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
17602 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
17603 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
17604 break;
17607 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
17608 stride, 1, 0);
17609 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
17610 stride, 2, 0);
17611 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
17612 stride, 3, 0);
17613 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
17614 stride, 4, 0);
17617 /* Buffer strides */
17618 stride[1] = 63;
17619 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
17620 &stride[1], 1, 0);
17621 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
17622 stride, 2, 0);
17623 stride[0] = 0;
17624 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
17625 stride, 1, 0);
17627 /* Rasterizer stream */
17628 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
17629 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
17630 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
17631 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
17632 NULL, 0, i);
17633 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
17635 release_test_context(&test_context);
17638 static void test_stream_output_resume(void)
17640 struct d3d11_test_context test_context;
17641 ID3D11Buffer *cb, *so_buffer, *buffer;
17642 unsigned int i, j, idx, offset;
17643 ID3D11DeviceContext *context;
17644 struct resource_readback rb;
17645 ID3D11GeometryShader *gs;
17646 const struct vec4 *data;
17647 ID3D11Device *device;
17648 HRESULT hr;
17650 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17651 static const DWORD gs_code[] =
17653 #if 0
17654 float4 constant;
17656 struct vertex
17658 float4 position : SV_POSITION;
17661 struct element
17663 float4 position : SV_POSITION;
17664 float4 so_output : so_output;
17667 [maxvertexcount(3)]
17668 void main(triangle vertex input[3], inout PointStream<element> output)
17670 element o;
17671 o.so_output = constant;
17672 o.position = input[0].position;
17673 output.Append(o);
17674 o.position = input[1].position;
17675 output.Append(o);
17676 o.position = input[2].position;
17677 output.Append(o);
17679 #endif
17680 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
17681 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17682 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
17683 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
17684 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
17685 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
17686 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
17687 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
17688 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
17689 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
17690 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
17691 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
17692 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
17693 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
17695 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
17697 {0, "so_output", 0, 0, 4, 0},
17699 static const struct vec4 constants[] =
17701 {0.5f, 0.250f, 0.0f, 0.0f},
17702 {0.0f, 0.125f, 0.0f, 1.0f},
17703 {1.0f, 1.000f, 1.0f, 0.0f}
17705 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
17706 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
17707 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
17709 if (!init_test_context(&test_context, &feature_level))
17710 return;
17712 device = test_context.device;
17713 context = test_context.immediate_context;
17715 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
17716 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
17717 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
17719 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
17720 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
17722 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
17723 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
17725 offset = 0;
17726 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
17728 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
17729 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
17731 draw_color_quad(&test_context, &red);
17732 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
17734 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
17735 draw_color_quad(&test_context, &green);
17736 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17738 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
17739 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
17740 draw_color_quad(&test_context, &red);
17741 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17743 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
17744 draw_color_quad(&test_context, &red);
17745 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
17747 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
17748 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
17749 draw_color_quad(&test_context, &white);
17750 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
17752 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
17753 draw_color_quad(&test_context, &green);
17754 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17756 buffer = NULL;
17757 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
17758 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
17759 draw_color_quad(&test_context, &white);
17760 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
17762 idx = 0;
17763 get_buffer_readback(so_buffer, &rb);
17764 for (i = 0; i < ARRAY_SIZE(constants); ++i)
17766 for (j = 0; j < 6; ++j) /* 2 triangles */
17768 data = get_readback_vec4(&rb, idx++, 0);
17769 ok(compare_vec4(data, &constants[i], 0),
17770 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
17771 data->x, data->y, data->z, data->w, idx, i, j);
17774 release_resource_readback(&rb);
17776 ID3D11Buffer_Release(cb);
17777 ID3D11Buffer_Release(so_buffer);
17778 ID3D11GeometryShader_Release(gs);
17779 release_test_context(&test_context);
17782 static void test_gather(void)
17784 struct
17786 int width, height;
17787 int offset_x, offset_y;
17788 } constant;
17789 struct d3d11_test_context test_context;
17790 D3D11_TEXTURE2D_DESC texture_desc;
17791 ID3D11ShaderResourceView *srv;
17792 ID3D11Texture2D *texture, *rt;
17793 ID3D11DeviceContext *context;
17794 ID3D11RenderTargetView *rtv;
17795 struct resource_readback rb;
17796 ID3D11PixelShader *ps;
17797 ID3D11Device *device;
17798 unsigned int x, y;
17799 ID3D11Buffer *cb;
17800 HRESULT hr;
17802 static const DWORD gather4_code[] =
17804 #if 0
17805 SamplerState s;
17806 Texture2D<float4> t;
17808 int2 size;
17810 float4 main(float4 position : SV_Position) : SV_Target
17812 return t.Gather(s, position.xy / size);
17814 #endif
17815 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
17816 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17817 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
17818 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17819 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
17820 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
17821 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
17822 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
17823 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
17824 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
17825 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
17827 static const DWORD gather4_offset_code[] =
17829 #if 0
17830 SamplerState s;
17831 Texture2D<float4> t;
17833 int2 size;
17835 float4 main(float4 position : SV_Position) : SV_Target
17837 return t.Gather(s, position.xy / size, int2(1, 1));
17839 #endif
17840 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
17841 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17842 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
17843 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17844 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
17845 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
17846 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
17847 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
17848 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
17849 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
17850 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
17852 static const DWORD gather4_green_code[] =
17854 #if 0
17855 SamplerState s;
17856 Texture2D<float4> t;
17858 int2 size;
17860 float4 main(float4 position : SV_Position) : SV_Target
17862 return t.GatherGreen(s, position.xy / size);
17864 #endif
17865 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
17866 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17867 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
17868 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17869 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
17870 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
17871 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
17872 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
17873 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
17874 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
17875 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
17877 static const DWORD gather4_po_code[] =
17879 #if 0
17880 SamplerState s;
17881 Texture2D<float4> t;
17883 int2 size;
17884 int2 offset;
17886 float4 main(float4 position : SV_Position) : SV_Target
17888 return t.Gather(s, position.xy / size, offset);
17890 #endif
17891 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
17892 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17893 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
17894 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17895 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
17896 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
17897 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
17898 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
17899 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
17900 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
17901 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
17902 0x00000000, 0x0100003e,
17904 static const struct vec4 texture_data[] =
17906 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
17907 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
17908 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
17909 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
17911 static const struct vec4 expected_gather4[] =
17913 {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},
17914 {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},
17915 {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},
17916 {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},
17918 static const struct vec4 expected_gather4_offset[] =
17920 {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},
17921 {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},
17922 {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},
17923 {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},
17925 static const struct vec4 expected_gather4_green[] =
17927 {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},
17928 {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},
17929 {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},
17930 {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},
17932 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
17933 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
17935 if (!init_test_context(&test_context, NULL))
17936 return;
17938 device = test_context.device;
17939 context = test_context.immediate_context;
17941 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
17943 skip("Shader model 4.1 required for gather4 instruction.\n");
17944 release_test_context(&test_context);
17945 return;
17948 texture_desc.Width = 4;
17949 texture_desc.Height = 4;
17950 texture_desc.MipLevels = 1;
17951 texture_desc.ArraySize = 1;
17952 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17953 texture_desc.SampleDesc.Count = 1;
17954 texture_desc.SampleDesc.Quality = 0;
17955 texture_desc.Usage = D3D11_USAGE_DEFAULT;
17956 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
17957 texture_desc.CPUAccessFlags = 0;
17958 texture_desc.MiscFlags = 0;
17959 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
17960 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17961 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
17962 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17963 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17965 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
17966 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
17967 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17968 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
17969 ok(SUCCEEDED(hr), "Fialed to create shader resource view, hr %#x.\n", hr);
17970 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
17972 constant.width = texture_desc.Width;
17973 constant.height = texture_desc.Height;
17974 constant.offset_x = 1;
17975 constant.offset_y = 1;
17976 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
17977 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17979 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
17980 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17981 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17983 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
17984 draw_quad(&test_context);
17985 get_texture_readback(rt, 0, &rb);
17986 for (y = 0; y < texture_desc.Height; ++y)
17988 for (x = 0; x < texture_desc.Width; ++x)
17990 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
17991 const struct vec4 *got = get_readback_vec4(&rb, x, y);
17992 ok(compare_vec4(got, expected, 0),
17993 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
17994 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
17997 release_resource_readback(&rb);
17999 ID3D11PixelShader_Release(ps);
18000 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
18001 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18002 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18004 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
18005 draw_quad(&test_context);
18006 get_texture_readback(rt, 0, &rb);
18007 for (y = 0; y < texture_desc.Height; ++y)
18009 for (x = 0; x < texture_desc.Width; ++x)
18011 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
18012 const struct vec4 *got = get_readback_vec4(&rb, x, y);
18013 ok(compare_vec4(got, expected, 0),
18014 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
18015 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
18018 release_resource_readback(&rb);
18020 ID3D11PixelShader_Release(ps);
18022 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
18024 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
18025 goto done;
18028 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
18029 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18030 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18032 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
18033 draw_quad(&test_context);
18034 get_texture_readback(rt, 0, &rb);
18035 for (y = 0; y < texture_desc.Height; ++y)
18037 for (x = 0; x < texture_desc.Width; ++x)
18039 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
18040 const struct vec4 *got = get_readback_vec4(&rb, x, y);
18041 ok(compare_vec4(got, expected, 0),
18042 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
18043 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
18046 release_resource_readback(&rb);
18048 ID3D11PixelShader_Release(ps);
18049 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
18050 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18051 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18053 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
18054 draw_quad(&test_context);
18055 get_texture_readback(rt, 0, &rb);
18056 for (y = 0; y < texture_desc.Height; ++y)
18058 for (x = 0; x < texture_desc.Width; ++x)
18060 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
18061 const struct vec4 *got = get_readback_vec4(&rb, x, y);
18062 ok(compare_vec4(got, expected, 0),
18063 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
18064 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
18067 release_resource_readback(&rb);
18069 constant.offset_x = 0;
18070 constant.offset_y = 0;
18071 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
18072 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
18073 draw_quad(&test_context);
18074 get_texture_readback(rt, 0, &rb);
18075 for (y = 0; y < texture_desc.Height; ++y)
18077 for (x = 0; x < texture_desc.Width; ++x)
18079 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
18080 const struct vec4 *got = get_readback_vec4(&rb, x, y);
18081 ok(compare_vec4(got, expected, 0),
18082 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
18083 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
18086 release_resource_readback(&rb);
18088 ID3D11PixelShader_Release(ps);
18090 done:
18091 ID3D11Buffer_Release(cb);
18092 ID3D11Texture2D_Release(rt);
18093 ID3D11Texture2D_Release(texture);
18094 ID3D11RenderTargetView_Release(rtv);
18095 ID3D11ShaderResourceView_Release(srv);
18096 release_test_context(&test_context);
18099 static void test_fractional_viewports(void)
18101 struct d3d11_test_context test_context;
18102 D3D11_TEXTURE2D_DESC texture_desc;
18103 ID3D11InputLayout *input_layout;
18104 ID3D11DeviceContext *context;
18105 struct resource_readback rb;
18106 ID3D11RenderTargetView *rtv;
18107 ID3D11VertexShader *vs;
18108 ID3D11PixelShader *ps;
18109 unsigned int i, x, y;
18110 ID3D11Device *device;
18111 ID3D11Texture2D *rt;
18112 UINT offset, stride;
18113 D3D11_VIEWPORT vp;
18114 ID3D11Buffer *vb;
18115 HRESULT hr;
18117 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18118 static const DWORD vs_code[] =
18120 #if 0
18121 void main(in float4 in_position : POSITION,
18122 in float2 in_texcoord : TEXCOORD,
18123 out float4 position : SV_Position,
18124 out float2 texcoord : TEXCOORD)
18126 position = in_position;
18127 texcoord = in_texcoord;
18129 #endif
18130 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
18131 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18132 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18133 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
18134 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18135 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
18136 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
18137 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
18138 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
18139 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
18140 0x00000001, 0x0100003e,
18142 static const DWORD ps_code[] =
18144 #if 0
18145 float4 main(float4 position : SV_Position,
18146 float2 texcoord : TEXCOORD) : SV_Target
18148 return float4(position.xy, texcoord);
18150 #endif
18151 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
18152 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
18153 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
18154 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
18155 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
18156 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
18157 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
18158 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
18159 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
18161 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
18163 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18164 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
18166 static const struct
18168 struct vec2 position;
18169 struct vec2 texcoord;
18171 quad[] =
18173 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
18174 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
18175 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
18176 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
18178 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
18179 static const float viewport_offsets[] =
18181 0.0f, 0.5f, 0.25f, 0.125f, 0.0625f, 0.03125f, 0.015625f, 0.0078125f, 0.00390625f,
18182 1.0f / 128.0f, 63.0f / 128.0f,
18185 if (!init_test_context(&test_context, &feature_level))
18186 return;
18187 device = test_context.device;
18188 context = test_context.immediate_context;
18190 texture_desc.Width = 4;
18191 texture_desc.Height = 4;
18192 texture_desc.MipLevels = 1;
18193 texture_desc.ArraySize = 1;
18194 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
18195 texture_desc.SampleDesc.Count = 1;
18196 texture_desc.SampleDesc.Quality = 0;
18197 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18198 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
18199 texture_desc.CPUAccessFlags = 0;
18200 texture_desc.MiscFlags = 0;
18201 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
18202 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18203 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
18204 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
18205 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18207 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
18208 vs_code, sizeof(vs_code), &input_layout);
18209 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
18210 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
18212 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
18213 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
18214 stride = sizeof(*quad);
18215 offset = 0;
18216 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
18218 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
18219 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
18220 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
18222 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18223 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18224 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18226 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
18228 vp.TopLeftX = viewport_offsets[i];
18229 vp.TopLeftY = viewport_offsets[i];
18230 vp.Width = texture_desc.Width;
18231 vp.Height = texture_desc.Height;
18232 vp.MinDepth = 0.0f;
18233 vp.MaxDepth = 1.0f;
18234 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
18235 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
18236 ID3D11DeviceContext_Draw(context, 4, 0);
18237 get_texture_readback(rt, 0, &rb);
18238 for (y = 0; y < texture_desc.Height; ++y)
18240 for (x = 0; x < texture_desc.Width; ++x)
18242 const struct vec4 *v = get_readback_vec4(&rb, x, y);
18243 struct vec4 expected = {x + 0.5f, y + 0.5f,
18244 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
18245 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
18246 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
18247 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
18248 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
18249 todo_wine
18250 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
18251 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
18252 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
18255 release_resource_readback(&rb);
18258 ID3D11InputLayout_Release(input_layout);
18259 ID3D11Buffer_Release(vb);
18260 ID3D11VertexShader_Release(vs);
18261 ID3D11PixelShader_Release(ps);
18262 ID3D11RenderTargetView_Release(rtv);
18263 ID3D11Texture2D_Release(rt);
18264 release_test_context(&test_context);
18267 START_TEST(d3d11)
18269 test_create_device();
18270 run_for_each_feature_level(test_device_interfaces);
18271 test_get_immediate_context();
18272 test_create_texture2d();
18273 test_texture2d_interfaces();
18274 test_create_texture3d();
18275 test_texture3d_interfaces();
18276 test_create_buffer();
18277 test_create_depthstencil_view();
18278 test_depthstencil_view_interfaces();
18279 test_create_rendertarget_view();
18280 test_create_shader_resource_view();
18281 run_for_each_feature_level(test_create_shader);
18282 test_create_sampler_state();
18283 test_create_blend_state();
18284 test_create_depthstencil_state();
18285 test_create_rasterizer_state();
18286 test_create_query();
18287 test_occlusion_query();
18288 test_timestamp_query();
18289 test_device_removed_reason();
18290 test_private_data();
18291 run_for_each_feature_level(test_state_refcounting);
18292 test_device_context_state();
18293 test_blend();
18294 test_texture();
18295 test_cube_maps();
18296 test_depth_stencil_sampling();
18297 test_multiple_render_targets();
18298 test_render_target_views();
18299 test_layered_rendering();
18300 test_scissor();
18301 test_il_append_aligned();
18302 test_fragment_coords();
18303 test_update_subresource();
18304 test_copy_subresource_region();
18305 test_resource_map();
18306 test_check_multisample_quality_levels();
18307 run_for_each_feature_level(test_swapchain_formats);
18308 test_swapchain_views();
18309 test_swapchain_flip();
18310 test_clear_render_target_view();
18311 test_clear_depth_stencil_view();
18312 test_clear_buffer_unordered_access_view();
18313 test_draw_depth_only();
18314 test_draw_uav_only();
18315 test_cb_relative_addressing();
18316 test_getdc();
18317 test_shader_stage_input_output_matching();
18318 test_sm4_if_instruction();
18319 test_sm4_breakc_instruction();
18320 test_create_input_layout();
18321 test_input_assembler();
18322 test_null_sampler();
18323 test_check_feature_support();
18324 test_create_unordered_access_view();
18325 test_immediate_constant_buffer();
18326 test_fp_specials();
18327 test_uint_shader_instructions();
18328 test_index_buffer_offset();
18329 test_face_culling();
18330 test_line_antialiasing_blending();
18331 run_for_each_feature_level(test_required_format_support);
18332 run_for_each_9_x_feature_level(test_fl9_draw);
18333 test_ddy();
18334 test_shader_input_registers_limits();
18335 test_unbind_shader_resource_view();
18336 test_stencil_separate();
18337 test_uav_load();
18338 test_cs_uav_store();
18339 test_ps_cs_uav_binding();
18340 test_atomic_instructions();
18341 test_sm4_ret_instruction();
18342 test_primitive_restart();
18343 test_resinfo_instruction();
18344 test_sm5_bufinfo_instruction();
18345 test_render_target_device_mismatch();
18346 test_buffer_srv();
18347 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
18348 test_unaligned_raw_buffer_access);
18349 test_uav_counters();
18350 test_compute_shader_registers();
18351 test_tgsm();
18352 test_geometry_shader();
18353 test_stream_output();
18354 test_fl10_stream_output_desc();
18355 test_stream_output_resume();
18356 test_gather();
18357 test_fractional_viewports();