wined3d: Fix relative addressing for SM4+ vertex shader inputs.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob7d317dc1817c192d258661722ef6d95469e69be8
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, 0, c, d)
630 #define create_buffer_misc(a, b, c, d, e) create_buffer_(__LINE__, a, b, c, d, e)
631 static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
632 unsigned int bind_flags, unsigned int misc_flags, unsigned int size, const void *data)
634 D3D11_SUBRESOURCE_DATA resource_data;
635 D3D11_BUFFER_DESC buffer_desc;
636 ID3D11Buffer *buffer;
637 HRESULT hr;
639 buffer_desc.ByteWidth = size;
640 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
641 buffer_desc.BindFlags = bind_flags;
642 buffer_desc.CPUAccessFlags = 0;
643 buffer_desc.MiscFlags = misc_flags;
644 buffer_desc.StructureByteStride = 0;
646 resource_data.pSysMem = data;
647 resource_data.SysMemPitch = 0;
648 resource_data.SysMemSlicePitch = 0;
650 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
651 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
652 return buffer;
655 struct resource_readback
657 ID3D11Resource *resource;
658 D3D11_MAPPED_SUBRESOURCE map_desc;
659 ID3D11DeviceContext *immediate_context;
660 unsigned int width, height, sub_resource_idx;
663 static void get_buffer_readback(ID3D11Buffer *buffer, struct resource_readback *rb)
665 D3D11_BUFFER_DESC buffer_desc;
666 ID3D11Device *device;
667 HRESULT hr;
669 memset(rb, 0, sizeof(*rb));
671 ID3D11Buffer_GetDevice(buffer, &device);
673 ID3D11Buffer_GetDesc(buffer, &buffer_desc);
674 buffer_desc.Usage = D3D11_USAGE_STAGING;
675 buffer_desc.BindFlags = 0;
676 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
677 buffer_desc.MiscFlags = 0;
678 buffer_desc.StructureByteStride = 0;
679 if (FAILED(hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D11Buffer **)&rb->resource)))
681 trace("Failed to create staging buffer, hr %#x.\n", hr);
682 ID3D11Device_Release(device);
683 return;
686 rb->width = buffer_desc.ByteWidth;
687 rb->height = 1;
688 rb->sub_resource_idx = 0;
690 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
692 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)buffer);
693 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, 0,
694 D3D11_MAP_READ, 0, &rb->map_desc)))
696 trace("Failed to map buffer, hr %#x.\n", hr);
697 ID3D11Resource_Release(rb->resource);
698 rb->resource = NULL;
699 ID3D11DeviceContext_Release(rb->immediate_context);
700 rb->immediate_context = NULL;
703 ID3D11Device_Release(device);
706 static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
707 struct resource_readback *rb)
709 D3D11_TEXTURE2D_DESC texture_desc;
710 unsigned int miplevel;
711 ID3D11Device *device;
712 HRESULT hr;
714 memset(rb, 0, sizeof(*rb));
716 ID3D11Texture2D_GetDevice(texture, &device);
718 ID3D11Texture2D_GetDesc(texture, &texture_desc);
719 texture_desc.Usage = D3D11_USAGE_STAGING;
720 texture_desc.BindFlags = 0;
721 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
722 texture_desc.MiscFlags = 0;
723 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->resource)))
725 trace("Failed to create texture, hr %#x.\n", hr);
726 ID3D11Device_Release(device);
727 return;
730 miplevel = sub_resource_idx % texture_desc.MipLevels;
731 rb->width = max(1, texture_desc.Width >> miplevel);
732 rb->height = max(1, texture_desc.Height >> miplevel);
733 rb->sub_resource_idx = sub_resource_idx;
735 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
737 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)texture);
738 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, sub_resource_idx,
739 D3D11_MAP_READ, 0, &rb->map_desc)))
741 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
742 ID3D11Resource_Release(rb->resource);
743 rb->resource = NULL;
744 ID3D11DeviceContext_Release(rb->immediate_context);
745 rb->immediate_context = NULL;
748 ID3D11Device_Release(device);
751 static void *get_readback_data(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned byte_width)
753 return (BYTE *)rb->map_desc.pData + y * rb->map_desc.RowPitch + x * byte_width;
756 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y)
758 return *(DWORD *)get_readback_data(rb, x, y, sizeof(DWORD));
761 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
763 return *(float *)get_readback_data(rb, x, y, sizeof(float));
766 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
768 return get_readback_data(rb, x, y, sizeof(struct vec4));
771 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
773 return get_readback_data(rb, x, y, sizeof(struct uvec4));
776 static void release_resource_readback(struct resource_readback *rb)
778 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
779 ID3D11Resource_Release(rb->resource);
780 ID3D11DeviceContext_Release(rb->immediate_context);
783 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
785 struct resource_readback rb;
786 DWORD color;
788 get_texture_readback(texture, 0, &rb);
789 color = get_readback_color(&rb, x, y);
790 release_resource_readback(&rb);
792 return color;
795 #define check_readback_data_color(a, b, c, d) check_readback_data_color_(__LINE__, a, b, c, d)
796 static void check_readback_data_color_(unsigned int line, struct resource_readback *rb,
797 const RECT *rect, DWORD expected_color, BYTE max_diff)
799 unsigned int x = 0, y = 0;
800 BOOL all_match = TRUE;
801 RECT default_rect;
802 DWORD color = 0;
804 if (!rect)
806 SetRect(&default_rect, 0, 0, rb->width, rb->height);
807 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 ok_(__FILE__, line)(all_match,
825 "Got 0x%08x, expected 0x%08x at (%u, %u), sub-resource %u.\n",
826 color, expected_color, x, y, rb->sub_resource_idx);
829 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
830 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
831 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
833 struct resource_readback rb;
835 get_texture_readback(texture, sub_resource_idx, &rb);
836 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
837 release_resource_readback(&rb);
840 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
841 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
842 DWORD expected_color, BYTE max_diff)
844 unsigned int sub_resource_idx, sub_resource_count;
845 D3D11_TEXTURE2D_DESC texture_desc;
847 ID3D11Texture2D_GetDesc(texture, &texture_desc);
848 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
849 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
850 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
853 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
854 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
855 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
857 struct resource_readback rb;
858 unsigned int x = 0, y = 0;
859 BOOL all_match = TRUE;
860 float value = 0.0f;
861 RECT default_rect;
863 get_texture_readback(texture, sub_resource_idx, &rb);
864 if (!rect)
866 SetRect(&default_rect, 0, 0, rb.width, rb.height);
867 rect = &default_rect;
869 for (y = rect->top; y < rect->bottom; ++y)
871 for (x = rect->left; x < rect->right; ++x)
873 value = get_readback_float(&rb, x, y);
874 if (!compare_float(value, expected_value, max_diff))
876 all_match = FALSE;
877 break;
880 if (!all_match)
881 break;
883 release_resource_readback(&rb);
884 ok_(__FILE__, line)(all_match,
885 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
886 value, expected_value, x, y, sub_resource_idx);
889 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
890 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
891 float expected_value, BYTE max_diff)
893 unsigned int sub_resource_idx, sub_resource_count;
894 D3D11_TEXTURE2D_DESC texture_desc;
896 ID3D11Texture2D_GetDesc(texture, &texture_desc);
897 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
898 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
899 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
902 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
903 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
904 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
906 struct resource_readback rb;
907 unsigned int x = 0, y = 0;
908 struct vec4 value = {0};
909 BOOL all_match = TRUE;
910 RECT default_rect;
912 get_texture_readback(texture, sub_resource_idx, &rb);
913 if (!rect)
915 SetRect(&default_rect, 0, 0, rb.width, rb.height);
916 rect = &default_rect;
918 for (y = rect->top; y < rect->bottom; ++y)
920 for (x = rect->left; x < rect->right; ++x)
922 value = *get_readback_vec4(&rb, x, y);
923 if (!compare_vec4(&value, expected_value, max_diff))
925 all_match = FALSE;
926 break;
929 if (!all_match)
930 break;
932 release_resource_readback(&rb);
933 ok_(__FILE__, line)(all_match,
934 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
935 value.x, value.y, value.z, value.w,
936 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
937 x, y, sub_resource_idx);
940 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
941 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
942 const struct vec4 *expected_value, BYTE max_diff)
944 unsigned int sub_resource_idx, sub_resource_count;
945 D3D11_TEXTURE2D_DESC texture_desc;
947 ID3D11Texture2D_GetDesc(texture, &texture_desc);
948 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
949 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
950 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
953 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
954 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
955 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
957 struct resource_readback rb;
958 unsigned int x = 0, y = 0;
959 struct uvec4 value = {0};
960 BOOL all_match = TRUE;
961 RECT default_rect;
963 get_texture_readback(texture, sub_resource_idx, &rb);
964 if (!rect)
966 SetRect(&default_rect, 0, 0, rb.width, rb.height);
967 rect = &default_rect;
969 for (y = rect->top; y < rect->bottom; ++y)
971 for (x = rect->left; x < rect->right; ++x)
973 value = *get_readback_uvec4(&rb, x, y);
974 if (!compare_uvec4(&value, expected_value))
976 all_match = FALSE;
977 break;
980 if (!all_match)
981 break;
983 release_resource_readback(&rb);
984 ok_(__FILE__, line)(all_match,
985 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
986 "at (%u, %u), sub-resource %u.\n",
987 value.x, value.y, value.z, value.w,
988 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
989 x, y, sub_resource_idx);
992 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
993 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
994 const struct uvec4 *expected_value)
996 unsigned int sub_resource_idx, sub_resource_count;
997 D3D11_TEXTURE2D_DESC texture_desc;
999 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1000 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1001 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1002 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
1005 static ID3D11Device *create_device(const struct device_desc *desc)
1007 static const D3D_FEATURE_LEVEL default_feature_level[] =
1009 D3D_FEATURE_LEVEL_11_0,
1010 D3D_FEATURE_LEVEL_10_1,
1011 D3D_FEATURE_LEVEL_10_0,
1013 const D3D_FEATURE_LEVEL *feature_level;
1014 UINT flags = desc ? desc->flags : 0;
1015 unsigned int feature_level_count;
1016 ID3D11Device *device;
1018 if (desc && desc->feature_level)
1020 feature_level = desc->feature_level;
1021 feature_level_count = 1;
1023 else
1025 feature_level = default_feature_level;
1026 feature_level_count = ARRAY_SIZE(default_feature_level);
1029 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, feature_level, feature_level_count,
1030 D3D11_SDK_VERSION, &device, NULL, NULL)))
1031 return device;
1032 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags, feature_level, feature_level_count,
1033 D3D11_SDK_VERSION, &device, NULL, NULL)))
1034 return device;
1035 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags, feature_level, feature_level_count,
1036 D3D11_SDK_VERSION, &device, NULL, NULL)))
1037 return device;
1039 return NULL;
1042 static void get_device_adapter_desc(ID3D11Device *device, DXGI_ADAPTER_DESC *adapter_desc)
1044 IDXGIDevice *dxgi_device;
1045 IDXGIAdapter *adapter;
1046 HRESULT hr;
1048 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1049 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1050 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1051 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1052 IDXGIDevice_Release(dxgi_device);
1053 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1054 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1055 IDXGIAdapter_Release(adapter);
1058 static BOOL is_warp_device(ID3D11Device *device)
1060 DXGI_ADAPTER_DESC adapter_desc;
1061 get_device_adapter_desc(device, &adapter_desc);
1062 return !adapter_desc.SubSysId && !adapter_desc.Revision
1063 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1064 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1067 static BOOL is_vendor_device(ID3D11Device *device, unsigned int vendor_id)
1069 DXGI_ADAPTER_DESC adapter_desc;
1071 if (!strcmp(winetest_platform, "wine"))
1072 return FALSE;
1074 get_device_adapter_desc(device, &adapter_desc);
1075 return adapter_desc.VendorId == vendor_id;
1078 static BOOL is_amd_device(ID3D11Device *device)
1080 return is_vendor_device(device, 0x1002);
1083 static BOOL is_intel_device(ID3D11Device *device)
1085 return is_vendor_device(device, 0x8086);
1088 static BOOL is_nvidia_device(ID3D11Device *device)
1090 return is_vendor_device(device, 0x10de);
1093 static BOOL check_compute_shaders_via_sm4_support(ID3D11Device *device)
1095 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
1097 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1098 D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(options))))
1099 return FALSE;
1100 return options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x;
1103 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, const struct swapchain_desc *swapchain_desc)
1105 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1106 IDXGISwapChain *swapchain;
1107 IDXGIDevice *dxgi_device;
1108 IDXGIAdapter *adapter;
1109 IDXGIFactory *factory;
1110 HRESULT hr;
1112 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1113 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1114 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1115 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1116 IDXGIDevice_Release(dxgi_device);
1117 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1118 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1119 IDXGIAdapter_Release(adapter);
1121 dxgi_desc.BufferDesc.Width = 640;
1122 dxgi_desc.BufferDesc.Height = 480;
1123 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1124 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1125 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1126 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1127 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1128 dxgi_desc.SampleDesc.Count = 1;
1129 dxgi_desc.SampleDesc.Quality = 0;
1130 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1131 dxgi_desc.BufferCount = 1;
1132 dxgi_desc.OutputWindow = window;
1133 dxgi_desc.Windowed = TRUE;
1134 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1135 dxgi_desc.Flags = 0;
1137 if (swapchain_desc)
1139 dxgi_desc.Windowed = swapchain_desc->windowed;
1140 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1141 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1143 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1144 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1147 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1148 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1149 IDXGIFactory_Release(factory);
1151 return swapchain;
1154 struct d3d11_test_context
1156 ID3D11Device *device;
1157 HWND window;
1158 IDXGISwapChain *swapchain;
1159 ID3D11Texture2D *backbuffer;
1160 ID3D11RenderTargetView *backbuffer_rtv;
1161 ID3D11DeviceContext *immediate_context;
1163 ID3D11InputLayout *input_layout;
1164 ID3D11VertexShader *vs;
1165 ID3D11Buffer *vs_cb;
1166 ID3D11Buffer *vb;
1168 ID3D11PixelShader *ps;
1169 ID3D11Buffer *ps_cb;
1172 #define init_test_context(c, l) init_test_context_(__LINE__, c, l)
1173 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1174 const D3D_FEATURE_LEVEL *feature_level)
1176 struct device_desc device_desc;
1177 D3D11_VIEWPORT vp;
1178 HRESULT hr;
1179 RECT rect;
1181 memset(context, 0, sizeof(*context));
1183 device_desc.feature_level = feature_level;
1184 device_desc.flags = 0;
1185 if (!(context->device = create_device(&device_desc)))
1187 skip_(__FILE__, line)("Failed to create device.\n");
1188 return FALSE;
1190 SetRect(&rect, 0, 0, 640, 480);
1191 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1192 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1193 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1194 context->swapchain = create_swapchain(context->device, context->window, NULL);
1195 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1196 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1198 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1199 NULL, &context->backbuffer_rtv);
1200 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1202 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1204 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1206 vp.TopLeftX = 0.0f;
1207 vp.TopLeftY = 0.0f;
1208 vp.Width = 640.0f;
1209 vp.Height = 480.0f;
1210 vp.MinDepth = 0.0f;
1211 vp.MaxDepth = 1.0f;
1212 ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp);
1214 return TRUE;
1217 #define release_test_context(context) release_test_context_(__LINE__, context)
1218 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1220 ULONG ref;
1222 if (context->input_layout)
1223 ID3D11InputLayout_Release(context->input_layout);
1224 if (context->vs)
1225 ID3D11VertexShader_Release(context->vs);
1226 if (context->vs_cb)
1227 ID3D11Buffer_Release(context->vs_cb);
1228 if (context->vb)
1229 ID3D11Buffer_Release(context->vb);
1230 if (context->ps)
1231 ID3D11PixelShader_Release(context->ps);
1232 if (context->ps_cb)
1233 ID3D11Buffer_Release(context->ps_cb);
1235 ID3D11DeviceContext_Release(context->immediate_context);
1236 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1237 ID3D11Texture2D_Release(context->backbuffer);
1238 IDXGISwapChain_Release(context->swapchain);
1239 DestroyWindow(context->window);
1241 ref = ID3D11Device_Release(context->device);
1242 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1245 static void draw_quad_vs(unsigned int line, struct d3d11_test_context *context,
1246 const DWORD *vs_code, size_t vs_code_size)
1248 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1250 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1252 static const struct vec2 quad[] =
1254 {-1.0f, -1.0f},
1255 {-1.0f, 1.0f},
1256 { 1.0f, -1.0f},
1257 { 1.0f, 1.0f},
1260 ID3D11Device *device = context->device;
1261 unsigned int stride, offset;
1262 HRESULT hr;
1264 if (!context->input_layout)
1266 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1267 vs_code, vs_code_size, &context->input_layout);
1268 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1270 hr = ID3D11Device_CreateVertexShader(device, vs_code, vs_code_size, NULL, &context->vs);
1271 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1274 if (!context->vb)
1275 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1277 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1278 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1279 stride = sizeof(*quad);
1280 offset = 0;
1281 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1282 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1284 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1287 #define draw_quad(context) draw_quad_(__LINE__, context)
1288 static void draw_quad_(unsigned int line, struct d3d11_test_context *context)
1290 static const DWORD vs_code[] =
1292 #if 0
1293 float4 main(float4 position : POSITION) : SV_POSITION
1295 return position;
1297 #endif
1298 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1299 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1300 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1301 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1302 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1303 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1304 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1305 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1306 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1307 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1308 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1309 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1310 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1311 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1312 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1315 draw_quad_vs(__LINE__, context, vs_code, sizeof(vs_code));
1318 #define draw_quad_z(context, z) draw_quad_z_(__LINE__, context, z)
1319 static void draw_quad_z_(unsigned int line, struct d3d11_test_context *context, float z)
1321 static const DWORD vs_code[] =
1323 #if 0
1324 float depth;
1326 void main(float4 in_position : POSITION, out float4 out_position : SV_Position)
1328 out_position = in_position;
1329 out_position.z = depth;
1331 #endif
1332 0x43425844, 0x22d7ff76, 0xd53b167c, 0x1b49ccf1, 0xbebfec39, 0x00000001, 0x00000100, 0x00000003,
1333 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1334 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000b0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1335 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1336 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x52444853, 0x00000064, 0x00010040,
1337 0x00000019, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010b2, 0x00000000,
1338 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x05000036, 0x001020b2, 0x00000000, 0x00101c46,
1339 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
1342 struct vec4 data = {z};
1344 if (!context->vs_cb)
1345 context->vs_cb = create_buffer(context->device, D3D11_BIND_CONSTANT_BUFFER, sizeof(data), NULL);
1347 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1348 (ID3D11Resource *)context->vs_cb, 0, NULL, &data, 0, 0);
1350 ID3D11DeviceContext_VSSetConstantBuffers(context->immediate_context, 0, 1, &context->vs_cb);
1351 draw_quad_vs(__LINE__, context, vs_code, sizeof(vs_code));
1354 static void set_quad_color(struct d3d11_test_context *context, const struct vec4 *color)
1356 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1357 (ID3D11Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1360 #define draw_color_quad(context, color) draw_color_quad_(__LINE__, context, color)
1361 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context, const struct vec4 *color)
1363 static const DWORD ps_color_code[] =
1365 #if 0
1366 float4 color;
1368 float4 main() : SV_TARGET
1370 return color;
1372 #endif
1373 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1374 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1375 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1376 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1377 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1378 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1379 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1380 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1381 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1382 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1383 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1386 ID3D11Device *device = context->device;
1387 HRESULT hr;
1389 if (!context->ps)
1391 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1392 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1395 if (!context->ps_cb)
1396 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1398 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1399 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1401 set_quad_color(context, color);
1403 draw_quad_(line, context);
1406 static void test_create_device(void)
1408 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1410 D3D_FEATURE_LEVEL_11_0,
1411 D3D_FEATURE_LEVEL_10_1,
1412 D3D_FEATURE_LEVEL_10_0,
1413 D3D_FEATURE_LEVEL_9_3,
1414 D3D_FEATURE_LEVEL_9_2,
1415 D3D_FEATURE_LEVEL_9_1,
1417 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1418 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1419 ID3D11DeviceContext *immediate_context;
1420 IDXGISwapChain *swapchain;
1421 ID3D11Device *device;
1422 ULONG refcount;
1423 HWND window;
1424 HRESULT hr;
1426 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1427 &device, NULL, NULL)))
1429 skip("Failed to create HAL device.\n");
1430 if ((device = create_device(NULL)))
1432 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
1433 ID3D11Device_Release(device);
1435 return;
1438 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
1439 trace("Feature level %#x.\n", supported_feature_level);
1440 ID3D11Device_Release(device);
1442 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
1443 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1445 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
1446 &feature_level, NULL);
1447 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1448 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1449 feature_level, supported_feature_level);
1451 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
1452 ARRAY_SIZE(default_feature_levels), D3D11_SDK_VERSION, NULL, &feature_level, NULL);
1453 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1454 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1455 feature_level, supported_feature_level);
1457 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
1458 &immediate_context);
1459 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1461 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
1462 refcount = get_refcount(immediate_context);
1463 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1465 ID3D11DeviceContext_GetDevice(immediate_context, &device);
1466 refcount = ID3D11Device_Release(device);
1467 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1469 refcount = ID3D11DeviceContext_Release(immediate_context);
1470 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
1472 device = (ID3D11Device *)0xdeadbeef;
1473 feature_level = 0xdeadbeef;
1474 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1475 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1476 &device, &feature_level, &immediate_context);
1477 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
1478 ok(!device, "Got unexpected device pointer %p.\n", device);
1479 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1480 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1482 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
1484 swapchain_desc.BufferDesc.Width = 800;
1485 swapchain_desc.BufferDesc.Height = 600;
1486 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
1487 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
1488 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1489 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1490 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1491 swapchain_desc.SampleDesc.Count = 1;
1492 swapchain_desc.SampleDesc.Quality = 0;
1493 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1494 swapchain_desc.BufferCount = 1;
1495 swapchain_desc.OutputWindow = window;
1496 swapchain_desc.Windowed = TRUE;
1497 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1498 swapchain_desc.Flags = 0;
1500 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1501 &swapchain_desc, NULL, NULL, NULL, NULL);
1502 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1504 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1505 &swapchain_desc, NULL, NULL, &feature_level, NULL);
1506 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1507 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1508 feature_level, supported_feature_level);
1510 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1511 &swapchain_desc, &swapchain, &device, NULL, NULL);
1512 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1514 memset(&obtained_desc, 0, sizeof(obtained_desc));
1515 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
1516 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
1517 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
1518 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
1519 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
1520 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
1521 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
1522 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
1523 obtained_desc.BufferDesc.RefreshRate.Numerator);
1524 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
1525 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
1526 obtained_desc.BufferDesc.RefreshRate.Denominator);
1527 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
1528 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
1529 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
1530 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
1531 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
1532 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
1533 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
1534 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
1535 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
1536 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
1537 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
1538 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
1539 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
1540 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
1541 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
1542 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
1543 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
1544 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
1545 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
1546 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
1547 ok(obtained_desc.Flags == swapchain_desc.Flags,
1548 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
1550 refcount = IDXGISwapChain_Release(swapchain);
1551 ok(!refcount, "Swapchain has %u references left.\n", refcount);
1553 feature_level = ID3D11Device_GetFeatureLevel(device);
1554 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1555 feature_level, supported_feature_level);
1557 refcount = ID3D11Device_Release(device);
1558 ok(!refcount, "Device has %u references left.\n", refcount);
1560 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1561 NULL, NULL, &device, NULL, NULL);
1562 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1563 ID3D11Device_Release(device);
1565 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1566 NULL, NULL, NULL, NULL, NULL);
1567 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1569 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1570 NULL, NULL, NULL, &feature_level, NULL);
1571 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1572 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1573 feature_level, supported_feature_level);
1575 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1576 NULL, NULL, NULL, NULL, &immediate_context);
1577 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1578 ID3D11DeviceContext_Release(immediate_context);
1580 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1581 &swapchain_desc, NULL, NULL, NULL, NULL);
1582 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1584 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1585 &swapchain_desc, &swapchain, NULL, NULL, NULL);
1586 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1587 IDXGISwapChain_Release(swapchain);
1589 swapchain_desc.OutputWindow = NULL;
1590 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1591 &swapchain_desc, NULL, NULL, NULL, NULL);
1592 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1593 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1594 &swapchain_desc, NULL, &device, NULL, NULL);
1595 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1596 ID3D11Device_Release(device);
1598 swapchain = (IDXGISwapChain *)0xdeadbeef;
1599 device = (ID3D11Device *)0xdeadbeef;
1600 feature_level = 0xdeadbeef;
1601 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1602 swapchain_desc.OutputWindow = NULL;
1603 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1604 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1605 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1606 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1607 ok(!device, "Got unexpected device pointer %p.\n", device);
1608 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1609 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1611 swapchain = (IDXGISwapChain *)0xdeadbeef;
1612 device = (ID3D11Device *)0xdeadbeef;
1613 feature_level = 0xdeadbeef;
1614 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1615 swapchain_desc.OutputWindow = window;
1616 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
1617 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1618 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1619 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1620 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1621 ok(!device, "Got unexpected device pointer %p.\n", device);
1622 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1623 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1625 DestroyWindow(window);
1628 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
1630 struct device_desc device_desc;
1631 IDXGIAdapter *dxgi_adapter;
1632 IDXGIDevice *dxgi_device;
1633 ID3D11Device *device;
1634 IUnknown *iface;
1635 ULONG refcount;
1636 HRESULT hr;
1638 device_desc.feature_level = &feature_level;
1639 device_desc.flags = 0;
1640 if (!(device = create_device(&device_desc)))
1642 skip("Failed to create device for feature level %#x.\n", feature_level);
1643 return;
1646 check_interface(device, &IID_IUnknown, TRUE, FALSE);
1647 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
1648 check_interface(device, &IID_IDXGIDevice, TRUE, FALSE);
1649 check_interface(device, &IID_IDXGIDevice1, TRUE, FALSE);
1650 check_interface(device, &IID_ID3D10Multithread, TRUE, TRUE); /* Not available on all Windows versions. */
1651 todo_wine check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
1652 todo_wine check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
1653 check_interface(device, &IID_ID3D11InfoQueue, FALSE, FALSE); /* Non-debug mode. */
1655 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1656 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1657 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1658 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1659 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1660 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1661 IUnknown_Release(iface);
1662 IDXGIAdapter_Release(dxgi_adapter);
1663 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1664 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1665 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1666 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
1667 IUnknown_Release(iface);
1668 IDXGIAdapter_Release(dxgi_adapter);
1669 IDXGIDevice_Release(dxgi_device);
1671 refcount = ID3D11Device_Release(device);
1672 ok(!refcount, "Device has %u references left.\n", refcount);
1674 device_desc.feature_level = &feature_level;
1675 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
1676 if (!(device = create_device(&device_desc)))
1678 skip("Failed to create debug device for feature level %#x.\n", feature_level);
1679 return;
1682 todo_wine check_interface(device, &IID_ID3D11InfoQueue, TRUE, FALSE);
1684 refcount = ID3D11Device_Release(device);
1685 ok(!refcount, "Device has %u references left.\n", refcount);
1688 static void test_get_immediate_context(void)
1690 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
1691 ULONG expected_refcount, refcount;
1692 ID3D11Device *device;
1694 if (!(device = create_device(NULL)))
1696 skip("Failed to create device.\n");
1697 return;
1700 expected_refcount = get_refcount(device) + 1;
1701 ID3D11Device_GetImmediateContext(device, &immediate_context);
1702 refcount = get_refcount(device);
1703 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1704 previous_immediate_context = immediate_context;
1706 ID3D11Device_GetImmediateContext(device, &immediate_context);
1707 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1708 refcount = get_refcount(device);
1709 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1711 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
1712 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1713 refcount = ID3D11DeviceContext_Release(immediate_context);
1714 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1716 ID3D11Device_GetImmediateContext(device, &immediate_context);
1717 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1718 refcount = ID3D11DeviceContext_Release(immediate_context);
1719 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1721 refcount = ID3D11Device_Release(device);
1722 ok(!refcount, "Device has %u references left.\n", refcount);
1725 static void test_create_texture2d(void)
1727 ULONG refcount, expected_refcount;
1728 D3D11_SUBRESOURCE_DATA data = {0};
1729 D3D_FEATURE_LEVEL feature_level;
1730 ID3D11Device *device, *tmp;
1731 D3D11_TEXTURE2D_DESC desc;
1732 ID3D11Texture2D *texture;
1733 UINT quality_level_count;
1734 unsigned int i;
1735 HRESULT hr;
1737 static const struct
1739 DXGI_FORMAT format;
1740 UINT array_size;
1741 D3D11_BIND_FLAG bind_flags;
1742 UINT misc_flags;
1743 BOOL succeeds;
1744 BOOL todo;
1746 tests[] =
1748 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1749 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1750 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1751 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1752 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1753 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1754 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1755 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1756 FALSE, FALSE},
1757 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1758 FALSE, FALSE},
1759 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1760 FALSE, FALSE},
1761 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1762 TRUE, FALSE},
1763 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1764 TRUE, FALSE},
1765 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1766 TRUE, FALSE},
1767 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1768 TRUE, FALSE},
1769 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1770 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1771 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1772 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1773 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1774 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1775 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1776 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1777 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1778 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1779 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1780 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1781 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1782 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1783 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1784 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1785 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1786 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1787 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1788 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1789 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1790 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1791 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1792 TRUE, FALSE},
1793 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1794 TRUE, FALSE},
1795 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1796 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
1797 FALSE, TRUE},
1798 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1799 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
1800 FALSE, TRUE},
1801 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1802 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1803 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1804 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1805 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1806 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1807 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1808 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1809 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1810 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1811 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1812 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1813 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1814 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1815 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1816 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1817 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1818 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1819 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1820 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1821 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1822 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1823 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1824 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1825 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1826 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1827 FALSE, TRUE},
1828 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1829 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1830 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1831 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1832 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1835 if (!(device = create_device(NULL)))
1837 skip("Failed to create device.\n");
1838 return;
1841 feature_level = ID3D11Device_GetFeatureLevel(device);
1843 desc.Width = 512;
1844 desc.Height = 512;
1845 desc.MipLevels = 1;
1846 desc.ArraySize = 1;
1847 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1848 desc.SampleDesc.Count = 1;
1849 desc.SampleDesc.Quality = 0;
1850 desc.Usage = D3D11_USAGE_DEFAULT;
1851 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1852 desc.CPUAccessFlags = 0;
1853 desc.MiscFlags = 0;
1855 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
1856 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1858 expected_refcount = get_refcount(device) + 1;
1859 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1860 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1861 refcount = get_refcount(device);
1862 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1863 tmp = NULL;
1864 expected_refcount = refcount + 1;
1865 ID3D11Texture2D_GetDevice(texture, &tmp);
1866 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1867 refcount = get_refcount(device);
1868 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1869 ID3D11Device_Release(tmp);
1871 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1872 ID3D11Texture2D_Release(texture);
1874 desc.MipLevels = 0;
1875 expected_refcount = get_refcount(device) + 1;
1876 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1877 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1878 refcount = get_refcount(device);
1879 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1880 tmp = NULL;
1881 expected_refcount = refcount + 1;
1882 ID3D11Texture2D_GetDevice(texture, &tmp);
1883 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1884 refcount = get_refcount(device);
1885 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1886 ID3D11Device_Release(tmp);
1888 ID3D11Texture2D_GetDesc(texture, &desc);
1889 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1890 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1891 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1892 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1893 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1894 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1895 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1896 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1897 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1898 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1899 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1901 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1902 ID3D11Texture2D_Release(texture);
1904 desc.MipLevels = 1;
1905 desc.ArraySize = 2;
1906 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1907 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1909 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1910 ID3D11Texture2D_Release(texture);
1912 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1913 desc.ArraySize = 1;
1914 desc.SampleDesc.Count = 2;
1915 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1916 if (quality_level_count)
1918 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1919 ID3D11Texture2D_Release(texture);
1920 desc.SampleDesc.Quality = quality_level_count;
1921 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1923 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1925 /* We assume 15 samples multisampling is never supported in practice. */
1926 desc.SampleDesc.Count = 15;
1927 desc.SampleDesc.Quality = 0;
1928 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1929 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1931 desc.SampleDesc.Count = 1;
1932 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1934 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
1935 BOOL todo = tests[i].todo;
1937 if (feature_level < D3D_FEATURE_LEVEL_10_1
1938 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
1939 && tests[i].array_size > 6)
1941 expected_hr = E_INVALIDARG;
1942 todo = TRUE;
1945 desc.ArraySize = tests[i].array_size;
1946 desc.Format = tests[i].format;
1947 desc.BindFlags = tests[i].bind_flags;
1948 desc.MiscFlags = tests[i].misc_flags;
1949 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, (ID3D11Texture2D **)&texture);
1951 todo_wine_if(todo)
1952 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
1953 i, hr, desc.Format);
1955 if (SUCCEEDED(hr))
1956 ID3D11Texture2D_Release(texture);
1959 refcount = ID3D11Device_Release(device);
1960 ok(!refcount, "Device has %u references left.\n", refcount);
1963 static void test_texture2d_interfaces(void)
1965 ID3D10Texture2D *d3d10_texture;
1966 D3D11_TEXTURE2D_DESC desc;
1967 ID3D11Texture2D *texture;
1968 ID3D11Device *device;
1969 unsigned int i;
1970 ULONG refcount;
1971 HRESULT hr;
1973 static const struct test
1975 BOOL implements_d3d10_interfaces;
1976 UINT bind_flags;
1977 UINT misc_flags;
1978 UINT expected_bind_flags;
1979 UINT expected_misc_flags;
1981 desc_conversion_tests[] =
1984 TRUE,
1985 D3D11_BIND_SHADER_RESOURCE, 0,
1986 D3D10_BIND_SHADER_RESOURCE, 0
1989 TRUE,
1990 D3D11_BIND_UNORDERED_ACCESS, 0,
1991 D3D11_BIND_UNORDERED_ACCESS, 0
1994 FALSE,
1995 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1996 0, 0
1999 TRUE,
2000 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2001 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2004 TRUE,
2005 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
2006 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2010 if (!(device = create_device(NULL)))
2012 skip("Failed to create ID3D11Device, skipping tests.\n");
2013 return;
2016 desc.Width = 512;
2017 desc.Height = 512;
2018 desc.MipLevels = 0;
2019 desc.ArraySize = 1;
2020 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2021 desc.SampleDesc.Count = 1;
2022 desc.SampleDesc.Quality = 0;
2023 desc.Usage = D3D11_USAGE_DEFAULT;
2024 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2025 desc.CPUAccessFlags = 0;
2026 desc.MiscFlags = 0;
2028 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2029 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2030 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2031 hr = check_interface(texture, &IID_ID3D10Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
2032 ID3D11Texture2D_Release(texture);
2033 if (FAILED(hr))
2035 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
2036 ID3D11Device_Release(device);
2037 return;
2040 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2042 const struct test *current = &desc_conversion_tests[i];
2043 D3D10_TEXTURE2D_DESC d3d10_desc;
2044 ID3D10Device *d3d10_device;
2046 desc.Width = 512;
2047 desc.Height = 512;
2048 desc.MipLevels = 1;
2049 desc.ArraySize = 1;
2050 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2051 desc.SampleDesc.Count = 1;
2052 desc.SampleDesc.Quality = 0;
2053 desc.Usage = D3D11_USAGE_DEFAULT;
2054 desc.BindFlags = current->bind_flags;
2055 desc.CPUAccessFlags = 0;
2056 desc.MiscFlags = current->misc_flags;
2058 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2059 /* Shared resources are not supported by REF and WARP devices. */
2060 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2061 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2062 if (FAILED(hr))
2064 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
2065 continue;
2068 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2070 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2071 ID3D11Texture2D_Release(texture);
2073 if (current->implements_d3d10_interfaces)
2075 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2077 else
2079 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2080 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
2081 continue;
2084 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
2086 ok(d3d10_desc.Width == desc.Width,
2087 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2088 ok(d3d10_desc.Height == desc.Height,
2089 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2090 ok(d3d10_desc.MipLevels == desc.MipLevels,
2091 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2092 ok(d3d10_desc.ArraySize == desc.ArraySize,
2093 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2094 ok(d3d10_desc.Format == desc.Format,
2095 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2096 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
2097 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
2098 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2099 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
2100 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2101 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2102 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2103 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2104 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2105 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2106 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2107 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2109 d3d10_device = (ID3D10Device *)0xdeadbeef;
2110 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
2111 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2112 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2114 ID3D10Texture2D_Release(d3d10_texture);
2117 refcount = ID3D11Device_Release(device);
2118 ok(!refcount, "Device has %u references left.\n", refcount);
2121 static void test_create_texture3d(void)
2123 ULONG refcount, expected_refcount;
2124 D3D11_SUBRESOURCE_DATA data = {0};
2125 ID3D11Device *device, *tmp;
2126 D3D11_TEXTURE3D_DESC desc;
2127 ID3D11Texture3D *texture;
2128 unsigned int i;
2129 HRESULT hr;
2131 static const struct
2133 DXGI_FORMAT format;
2134 D3D11_BIND_FLAG bind_flags;
2135 BOOL succeeds;
2136 BOOL todo;
2138 tests[] =
2140 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
2141 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
2142 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2143 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2144 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2145 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2146 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2147 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2148 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2149 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2150 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2151 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2154 if (!(device = create_device(NULL)))
2156 skip("Failed to create ID3D11Device, skipping tests.\n");
2157 return;
2160 desc.Width = 64;
2161 desc.Height = 64;
2162 desc.Depth = 64;
2163 desc.MipLevels = 1;
2164 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2165 desc.Usage = D3D11_USAGE_DEFAULT;
2166 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2167 desc.CPUAccessFlags = 0;
2168 desc.MiscFlags = 0;
2170 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2171 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2173 expected_refcount = get_refcount(device) + 1;
2174 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2175 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2176 refcount = get_refcount(device);
2177 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2178 tmp = NULL;
2179 expected_refcount = refcount + 1;
2180 ID3D11Texture3D_GetDevice(texture, &tmp);
2181 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2182 refcount = get_refcount(device);
2183 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2184 ID3D11Device_Release(tmp);
2186 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2187 ID3D11Texture3D_Release(texture);
2189 desc.MipLevels = 0;
2190 expected_refcount = get_refcount(device) + 1;
2191 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2192 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2193 refcount = get_refcount(device);
2194 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2195 tmp = NULL;
2196 expected_refcount = refcount + 1;
2197 ID3D11Texture3D_GetDevice(texture, &tmp);
2198 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2199 refcount = get_refcount(device);
2200 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2201 ID3D11Device_Release(tmp);
2203 ID3D11Texture3D_GetDesc(texture, &desc);
2204 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2205 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2206 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2207 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2208 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2209 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2210 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2211 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2212 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2214 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2215 ID3D11Texture3D_Release(texture);
2217 desc.MipLevels = 1;
2218 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2220 desc.Format = tests[i].format;
2221 desc.BindFlags = tests[i].bind_flags;
2222 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, (ID3D11Texture3D **)&texture);
2224 todo_wine_if(tests[i].todo)
2225 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2227 if (SUCCEEDED(hr))
2228 ID3D11Texture3D_Release(texture);
2231 refcount = ID3D11Device_Release(device);
2232 ok(!refcount, "Device has %u references left.\n", refcount);
2235 static void test_texture3d_interfaces(void)
2237 ID3D10Texture3D *d3d10_texture;
2238 D3D11_TEXTURE3D_DESC desc;
2239 ID3D11Texture3D *texture;
2240 ID3D11Device *device;
2241 unsigned int i;
2242 ULONG refcount;
2243 HRESULT hr;
2245 static const struct test
2247 BOOL implements_d3d10_interfaces;
2248 UINT bind_flags;
2249 UINT misc_flags;
2250 UINT expected_bind_flags;
2251 UINT expected_misc_flags;
2253 desc_conversion_tests[] =
2256 TRUE,
2257 D3D11_BIND_SHADER_RESOURCE, 0,
2258 D3D10_BIND_SHADER_RESOURCE, 0
2261 TRUE,
2262 D3D11_BIND_UNORDERED_ACCESS, 0,
2263 D3D11_BIND_UNORDERED_ACCESS, 0
2266 FALSE,
2267 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2268 0, 0
2271 TRUE,
2272 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2273 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2277 if (!(device = create_device(NULL)))
2279 skip("Failed to create ID3D11Device.\n");
2280 return;
2283 desc.Width = 64;
2284 desc.Height = 64;
2285 desc.Depth = 64;
2286 desc.MipLevels = 0;
2287 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2288 desc.Usage = D3D11_USAGE_DEFAULT;
2289 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2290 desc.CPUAccessFlags = 0;
2291 desc.MiscFlags = 0;
2293 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2294 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2295 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2296 hr = check_interface(texture, &IID_ID3D10Texture3D, TRUE, TRUE); /* Not available on all Windows versions. */
2297 ID3D11Texture3D_Release(texture);
2298 if (FAILED(hr))
2300 win_skip("3D textures do not implement ID3D10Texture3D.\n");
2301 ID3D11Device_Release(device);
2302 return;
2305 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2307 const struct test *current = &desc_conversion_tests[i];
2308 D3D10_TEXTURE3D_DESC d3d10_desc;
2309 ID3D10Device *d3d10_device;
2311 desc.Width = 64;
2312 desc.Height = 64;
2313 desc.Depth = 64;
2314 desc.MipLevels = 1;
2315 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2316 desc.Usage = D3D11_USAGE_DEFAULT;
2317 desc.BindFlags = current->bind_flags;
2318 desc.CPUAccessFlags = 0;
2319 desc.MiscFlags = current->misc_flags;
2321 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2322 /* Shared resources are not supported by REF and WARP devices. */
2323 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2324 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
2325 if (FAILED(hr))
2327 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
2328 continue;
2331 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2333 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2334 ID3D11Texture3D_Release(texture);
2336 if (current->implements_d3d10_interfaces)
2338 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
2340 else
2342 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
2343 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2344 continue;
2347 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
2349 ok(d3d10_desc.Width == desc.Width,
2350 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2351 ok(d3d10_desc.Height == desc.Height,
2352 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2353 ok(d3d10_desc.Depth == desc.Depth,
2354 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
2355 ok(d3d10_desc.MipLevels == desc.MipLevels,
2356 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2357 ok(d3d10_desc.Format == desc.Format,
2358 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2359 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2360 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2361 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2362 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2363 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2364 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2365 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2366 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2368 d3d10_device = (ID3D10Device *)0xdeadbeef;
2369 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
2370 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2371 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2373 ID3D10Texture3D_Release(d3d10_texture);
2376 refcount = ID3D11Device_Release(device);
2377 ok(!refcount, "Device has %u references left.\n", refcount);
2380 static void test_create_buffer(void)
2382 ID3D10Buffer *d3d10_buffer;
2383 HRESULT expected_hr, hr;
2384 D3D11_BUFFER_DESC desc;
2385 ID3D11Buffer *buffer;
2386 ID3D11Device *device;
2387 unsigned int i;
2388 ULONG refcount;
2390 static const struct test
2392 BOOL succeeds;
2393 BOOL implements_d3d10_interfaces;
2394 UINT bind_flags;
2395 UINT misc_flags;
2396 UINT structure_stride;
2397 UINT expected_bind_flags;
2398 UINT expected_misc_flags;
2400 tests[] =
2403 TRUE, TRUE,
2404 D3D11_BIND_VERTEX_BUFFER, 0, 0,
2405 D3D10_BIND_VERTEX_BUFFER, 0
2408 TRUE, TRUE,
2409 D3D11_BIND_INDEX_BUFFER, 0, 0,
2410 D3D10_BIND_INDEX_BUFFER, 0
2413 TRUE, TRUE,
2414 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
2415 D3D10_BIND_CONSTANT_BUFFER, 0
2418 TRUE, TRUE,
2419 D3D11_BIND_SHADER_RESOURCE, 0, 0,
2420 D3D10_BIND_SHADER_RESOURCE, 0
2423 TRUE, TRUE,
2424 D3D11_BIND_STREAM_OUTPUT, 0, 0,
2425 D3D10_BIND_STREAM_OUTPUT, 0
2428 TRUE, TRUE,
2429 D3D11_BIND_RENDER_TARGET, 0, 0,
2430 D3D10_BIND_RENDER_TARGET, 0
2433 TRUE, TRUE,
2434 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
2435 D3D11_BIND_UNORDERED_ACCESS, 0
2438 TRUE, TRUE,
2439 0, D3D11_RESOURCE_MISC_SHARED, 0,
2440 0, D3D10_RESOURCE_MISC_SHARED
2443 TRUE, TRUE,
2444 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
2445 0, 0
2448 FALSE, FALSE,
2449 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2452 FALSE, FALSE,
2453 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2456 FALSE, FALSE,
2457 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2460 TRUE, TRUE,
2461 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2462 D3D10_BIND_SHADER_RESOURCE, 0
2465 FALSE, FALSE,
2466 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2469 FALSE, FALSE,
2470 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2473 TRUE, TRUE,
2474 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2475 D3D11_BIND_UNORDERED_ACCESS, 0
2478 FALSE, FALSE,
2479 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2481 /* Structured buffers do not implement ID3D10Buffer. */
2483 TRUE, FALSE,
2484 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2487 TRUE, FALSE,
2488 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2491 FALSE, FALSE,
2492 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
2495 FALSE, FALSE,
2496 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
2499 FALSE, FALSE,
2500 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
2503 FALSE, FALSE,
2504 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
2507 FALSE, FALSE,
2508 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
2511 TRUE, FALSE,
2512 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
2515 FALSE, FALSE,
2516 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
2519 TRUE, FALSE,
2520 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
2523 TRUE, FALSE,
2524 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
2527 FALSE, FALSE,
2528 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
2531 TRUE, FALSE,
2532 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
2535 TRUE, TRUE,
2536 0, 0, 513,
2537 0, 0
2540 TRUE, TRUE,
2541 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
2542 D3D10_BIND_CONSTANT_BUFFER, 0
2545 TRUE, TRUE,
2546 D3D11_BIND_SHADER_RESOURCE, 0, 513,
2547 D3D10_BIND_SHADER_RESOURCE, 0
2550 TRUE, TRUE,
2551 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
2552 D3D11_BIND_UNORDERED_ACCESS, 0
2555 FALSE, FALSE,
2556 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2559 FALSE, FALSE,
2560 D3D11_BIND_SHADER_RESOURCE,
2561 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2564 TRUE, TRUE,
2565 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
2566 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2570 if (!(device = create_device(NULL)))
2572 skip("Failed to create ID3D11Device.\n");
2573 return;
2576 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
2577 hr = check_interface(buffer, &IID_ID3D10Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
2578 ID3D11Buffer_Release(buffer);
2579 if (FAILED(hr))
2581 win_skip("Buffers do not implement ID3D10Buffer.\n");
2582 ID3D11Device_Release(device);
2583 return;
2586 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2588 const struct test *current = &tests[i];
2589 D3D11_BUFFER_DESC obtained_desc;
2590 D3D10_BUFFER_DESC d3d10_desc;
2591 ID3D10Device *d3d10_device;
2593 desc.ByteWidth = 1024;
2594 desc.Usage = D3D11_USAGE_DEFAULT;
2595 desc.BindFlags = current->bind_flags;
2596 desc.CPUAccessFlags = 0;
2597 desc.MiscFlags = current->misc_flags;
2598 desc.StructureByteStride = current->structure_stride;
2600 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2601 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
2602 /* Shared resources are not supported by REF and WARP devices. */
2603 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
2604 i, hr, expected_hr);
2605 if (FAILED(hr))
2607 if (hr == E_OUTOFMEMORY)
2608 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2609 continue;
2612 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
2613 desc.StructureByteStride = 0;
2615 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
2617 ok(obtained_desc.ByteWidth == desc.ByteWidth,
2618 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
2619 ok(obtained_desc.Usage == desc.Usage,
2620 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
2621 ok(obtained_desc.BindFlags == desc.BindFlags,
2622 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
2623 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
2624 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
2625 ok(obtained_desc.MiscFlags == desc.MiscFlags,
2626 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
2627 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
2628 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
2630 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2631 ID3D11Buffer_Release(buffer);
2633 if (current->implements_d3d10_interfaces)
2635 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
2637 else
2639 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
2640 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2641 continue;
2644 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
2646 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
2647 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
2648 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2649 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2650 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2651 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2652 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2653 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2654 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2655 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2657 d3d10_device = (ID3D10Device *)0xdeadbeef;
2658 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
2659 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2660 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2662 ID3D10Buffer_Release(d3d10_buffer);
2665 memset(&desc, 0, sizeof(desc));
2666 desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
2667 for (i = 0; i <= 32; ++i)
2669 desc.ByteWidth = i;
2670 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
2671 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2672 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
2673 if (SUCCEEDED(hr))
2674 ID3D11Buffer_Release(buffer);
2677 refcount = ID3D11Device_Release(device);
2678 ok(!refcount, "Device has %u references left.\n", refcount);
2681 static void test_create_depthstencil_view(void)
2683 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2684 D3D11_TEXTURE2D_DESC texture_desc;
2685 ULONG refcount, expected_refcount;
2686 ID3D11DepthStencilView *dsview;
2687 ID3D11Device *device, *tmp;
2688 ID3D11Texture2D *texture;
2689 unsigned int i;
2690 HRESULT hr;
2692 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2693 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2694 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2695 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
2696 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
2697 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
2698 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
2699 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
2700 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
2701 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
2702 static const struct
2704 struct
2706 unsigned int miplevel_count;
2707 unsigned int array_size;
2708 DXGI_FORMAT format;
2709 } texture;
2710 struct dsv_desc dsv_desc;
2711 struct dsv_desc expected_dsv_desc;
2713 tests[] =
2715 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2716 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2717 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2718 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2719 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2720 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2721 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2722 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2723 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2724 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2725 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2726 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2727 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2728 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2729 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2730 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2731 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2732 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2733 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2734 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2735 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2736 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2737 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2738 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2739 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2740 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2741 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2743 static const struct
2745 struct
2747 unsigned int miplevel_count;
2748 unsigned int array_size;
2749 DXGI_FORMAT format;
2750 } texture;
2751 struct dsv_desc dsv_desc;
2753 invalid_desc_tests[] =
2755 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2756 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2757 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2758 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2759 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2760 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2761 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2762 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2763 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2764 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2765 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2766 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2767 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2769 #undef FMT_UNKNOWN
2770 #undef D24S8
2771 #undef R24S8_TL
2772 #undef DIM_UNKNOWN
2773 #undef TEX_1D
2774 #undef TEX_1D_ARRAY
2775 #undef TEX_2D
2776 #undef TEX_2D_ARRAY
2777 #undef TEX_2DMS
2778 #undef TEX_2DMS_ARR
2780 if (!(device = create_device(NULL)))
2782 skip("Failed to create device.\n");
2783 return;
2786 texture_desc.Width = 512;
2787 texture_desc.Height = 512;
2788 texture_desc.MipLevels = 1;
2789 texture_desc.ArraySize = 1;
2790 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2791 texture_desc.SampleDesc.Count = 1;
2792 texture_desc.SampleDesc.Quality = 0;
2793 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2794 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2795 texture_desc.CPUAccessFlags = 0;
2796 texture_desc.MiscFlags = 0;
2798 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2799 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2801 expected_refcount = get_refcount(device) + 1;
2802 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
2803 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2804 refcount = get_refcount(device);
2805 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2806 tmp = NULL;
2807 expected_refcount = refcount + 1;
2808 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
2809 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2810 refcount = get_refcount(device);
2811 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2812 ID3D11Device_Release(tmp);
2814 memset(&dsv_desc, 0, sizeof(dsv_desc));
2815 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2816 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2817 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
2818 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2819 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
2820 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2822 ID3D11DepthStencilView_Release(dsview);
2823 ID3D11Texture2D_Release(texture);
2825 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2827 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
2829 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2830 texture_desc.ArraySize = tests[i].texture.array_size;
2831 texture_desc.Format = tests[i].texture.format;
2833 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2834 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2836 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
2838 current_desc = NULL;
2840 else
2842 current_desc = &dsv_desc;
2843 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2846 expected_refcount = get_refcount(texture);
2847 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
2848 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2849 refcount = get_refcount(texture);
2850 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2852 /* Not available on all Windows versions. */
2853 check_interface(dsview, &IID_ID3D10DepthStencilView, TRUE, TRUE);
2855 memset(&dsv_desc, 0, sizeof(dsv_desc));
2856 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2857 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2859 ID3D11DepthStencilView_Release(dsview);
2860 ID3D11Texture2D_Release(texture);
2863 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2865 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2866 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2867 texture_desc.Format = invalid_desc_tests[i].texture.format;
2869 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2870 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2872 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2873 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2874 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2876 ID3D11Texture2D_Release(texture);
2879 refcount = ID3D11Device_Release(device);
2880 ok(!refcount, "Device has %u references left.\n", refcount);
2883 static void test_depthstencil_view_interfaces(void)
2885 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
2886 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2887 ID3D10DepthStencilView *d3d10_dsview;
2888 D3D11_TEXTURE2D_DESC texture_desc;
2889 ID3D11DepthStencilView *dsview;
2890 ID3D11Texture2D *texture;
2891 ID3D11Device *device;
2892 ULONG refcount;
2893 HRESULT hr;
2895 if (!(device = create_device(NULL)))
2897 skip("Failed to create device.\n");
2898 return;
2901 texture_desc.Width = 512;
2902 texture_desc.Height = 512;
2903 texture_desc.MipLevels = 1;
2904 texture_desc.ArraySize = 1;
2905 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2906 texture_desc.SampleDesc.Count = 1;
2907 texture_desc.SampleDesc.Quality = 0;
2908 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2909 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2910 texture_desc.CPUAccessFlags = 0;
2911 texture_desc.MiscFlags = 0;
2913 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2914 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2916 dsv_desc.Format = texture_desc.Format;
2917 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
2918 dsv_desc.Flags = 0;
2919 U(dsv_desc).Texture2D.MipSlice = 0;
2921 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2922 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2924 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
2925 ID3D11DepthStencilView_Release(dsview);
2926 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2927 "Depth stencil view should implement ID3D10DepthStencilView.\n");
2929 if (FAILED(hr))
2931 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
2932 goto done;
2935 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
2936 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
2937 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
2938 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
2939 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2940 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
2942 ID3D10DepthStencilView_Release(d3d10_dsview);
2944 done:
2945 ID3D11Texture2D_Release(texture);
2947 refcount = ID3D11Device_Release(device);
2948 ok(!refcount, "Device has %u references left.\n", refcount);
2951 static void test_create_rendertarget_view(void)
2953 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
2954 D3D11_TEXTURE3D_DESC texture3d_desc;
2955 D3D11_TEXTURE2D_DESC texture2d_desc;
2956 D3D11_SUBRESOURCE_DATA data = {0};
2957 ULONG refcount, expected_refcount;
2958 D3D11_BUFFER_DESC buffer_desc;
2959 ID3D11RenderTargetView *rtview;
2960 ID3D11Device *device, *tmp;
2961 ID3D11Texture3D *texture3d;
2962 ID3D11Texture2D *texture2d;
2963 ID3D11Resource *texture;
2964 ID3D11Buffer *buffer;
2965 unsigned int i;
2966 HRESULT hr;
2968 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2969 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2970 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2971 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
2972 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
2973 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
2974 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
2975 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
2976 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
2977 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
2978 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
2979 static const struct
2981 struct
2983 unsigned int miplevel_count;
2984 unsigned int depth_or_array_size;
2985 DXGI_FORMAT format;
2986 } texture;
2987 struct rtv_desc rtv_desc;
2988 struct rtv_desc expected_rtv_desc;
2990 tests[] =
2992 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2993 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2994 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2995 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2996 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2997 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2998 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2999 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3000 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3001 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3002 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
3003 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
3004 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
3005 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
3006 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
3007 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
3008 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
3009 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3010 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3011 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3012 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3013 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3014 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3015 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3016 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3017 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3018 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3019 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3020 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3021 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3022 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3023 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3024 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
3025 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
3026 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
3027 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
3028 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3029 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3030 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
3031 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
3032 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
3033 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
3034 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
3035 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
3037 static const struct
3039 struct
3041 D3D11_RTV_DIMENSION dimension;
3042 unsigned int miplevel_count;
3043 unsigned int depth_or_array_size;
3044 DXGI_FORMAT format;
3045 } texture;
3046 struct rtv_desc rtv_desc;
3048 invalid_desc_tests[] =
3050 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3051 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3052 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3053 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3054 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
3055 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
3056 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
3057 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3058 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
3059 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
3060 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
3061 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
3062 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
3063 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
3064 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
3065 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3066 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3067 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3068 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3069 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3070 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3071 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3072 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3073 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
3074 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
3075 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3076 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3077 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
3078 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3079 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3080 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
3081 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
3082 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
3083 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
3084 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
3086 #undef FMT_UNKNOWN
3087 #undef RGBA8_UNORM
3088 #undef RGBA8_TL
3089 #undef DIM_UNKNOWN
3090 #undef TEX_1D
3091 #undef TEX_1D_ARRAY
3092 #undef TEX_2D
3093 #undef TEX_2D_ARRAY
3094 #undef TEX_2DMS
3095 #undef TEX_2DMS_ARR
3096 #undef TEX_3D
3098 if (!(device = create_device(NULL)))
3100 skip("Failed to create device.\n");
3101 return;
3104 buffer_desc.ByteWidth = 1024;
3105 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3106 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3107 buffer_desc.CPUAccessFlags = 0;
3108 buffer_desc.MiscFlags = 0;
3109 buffer_desc.StructureByteStride = 0;
3111 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
3112 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3114 expected_refcount = get_refcount(device) + 1;
3115 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3116 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3117 refcount = get_refcount(device);
3118 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3119 tmp = NULL;
3120 expected_refcount = refcount + 1;
3121 ID3D11Buffer_GetDevice(buffer, &tmp);
3122 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3123 refcount = get_refcount(device);
3124 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3125 ID3D11Device_Release(tmp);
3127 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3128 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
3129 U1(U(rtv_desc).Buffer).ElementOffset = 0;
3130 U2(U(rtv_desc).Buffer).ElementWidth = 64;
3132 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
3133 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3135 expected_refcount = get_refcount(device) + 1;
3136 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
3137 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
3138 refcount = get_refcount(device);
3139 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3140 tmp = NULL;
3141 expected_refcount = refcount + 1;
3142 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
3143 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3144 refcount = get_refcount(device);
3145 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3146 ID3D11Device_Release(tmp);
3148 /* Not available on all Windows versions. */
3149 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3151 ID3D11RenderTargetView_Release(rtview);
3152 ID3D11Buffer_Release(buffer);
3154 texture2d_desc.Width = 512;
3155 texture2d_desc.Height = 512;
3156 texture2d_desc.SampleDesc.Count = 1;
3157 texture2d_desc.SampleDesc.Quality = 0;
3158 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3159 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3160 texture2d_desc.CPUAccessFlags = 0;
3161 texture2d_desc.MiscFlags = 0;
3163 texture3d_desc.Width = 64;
3164 texture3d_desc.Height = 64;
3165 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3166 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3167 texture3d_desc.CPUAccessFlags = 0;
3168 texture3d_desc.MiscFlags = 0;
3170 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3172 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3174 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3176 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3177 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3178 texture2d_desc.Format = tests[i].texture.format;
3180 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3181 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3182 texture = (ID3D11Resource *)texture2d;
3184 else
3186 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3187 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3188 texture3d_desc.Format = tests[i].texture.format;
3190 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3191 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3192 texture = (ID3D11Resource *)texture3d;
3195 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
3197 current_desc = NULL;
3199 else
3201 current_desc = &rtv_desc;
3202 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3205 expected_refcount = get_refcount(texture);
3206 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3207 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3208 refcount = get_refcount(texture);
3209 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3211 /* Not available on all Windows versions. */
3212 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3214 memset(&rtv_desc, 0, sizeof(rtv_desc));
3215 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
3216 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3218 ID3D11RenderTargetView_Release(rtview);
3219 ID3D11Resource_Release(texture);
3222 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3224 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
3225 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
3227 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3229 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3230 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3231 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3233 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3234 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3235 texture = (ID3D11Resource *)texture2d;
3237 else
3239 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3240 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3241 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3243 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3244 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3245 texture = (ID3D11Resource *)texture3d;
3248 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3249 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3250 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3252 ID3D11Resource_Release(texture);
3255 refcount = ID3D11Device_Release(device);
3256 ok(!refcount, "Device has %u references left.\n", refcount);
3259 static void test_create_shader_resource_view(void)
3261 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
3262 D3D11_TEXTURE3D_DESC texture3d_desc;
3263 D3D11_TEXTURE2D_DESC texture2d_desc;
3264 ULONG refcount, expected_refcount;
3265 ID3D11ShaderResourceView *srview;
3266 D3D_FEATURE_LEVEL feature_level;
3267 D3D11_BUFFER_DESC buffer_desc;
3268 ID3D11Device *device, *tmp;
3269 ID3D11Texture3D *texture3d;
3270 ID3D11Texture2D *texture2d;
3271 ID3D11Resource *texture;
3272 ID3D11Buffer *buffer;
3273 unsigned int i;
3274 HRESULT hr;
3276 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3277 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3278 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
3279 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3280 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
3281 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
3282 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
3283 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
3284 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
3285 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
3286 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
3287 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
3288 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
3289 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3290 static const struct
3292 struct
3294 unsigned int miplevel_count;
3295 unsigned int depth_or_array_size;
3296 DXGI_FORMAT format;
3297 } texture;
3298 struct srv_desc srv_desc;
3299 struct srv_desc expected_srv_desc;
3301 tests[] =
3303 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3304 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3305 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3306 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3307 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3308 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3309 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3310 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3311 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3312 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3313 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3314 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3315 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3316 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3317 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3318 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3319 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3320 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3321 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3322 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3323 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3324 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3325 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3326 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3327 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3328 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3329 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3330 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3331 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3332 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3333 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3334 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3335 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3336 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3337 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3338 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3339 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3340 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3341 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3342 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3343 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3344 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3345 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3346 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3347 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3348 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
3349 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
3350 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
3352 static const struct
3354 struct
3356 D3D11_SRV_DIMENSION dimension;
3357 unsigned int miplevel_count;
3358 unsigned int depth_or_array_size;
3359 DXGI_FORMAT format;
3360 } texture;
3361 struct srv_desc srv_desc;
3363 invalid_desc_tests[] =
3365 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3366 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3367 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3368 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3369 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3370 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3371 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3372 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3373 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3374 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3375 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3376 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3377 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3378 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3379 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3380 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3381 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3382 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3383 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3384 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3385 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3386 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3387 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3388 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3389 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
3390 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
3391 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3392 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3393 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3394 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
3395 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
3396 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
3397 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
3398 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
3399 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3400 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3401 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 1}},
3402 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3403 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3404 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3405 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3406 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3407 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3408 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3409 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3410 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3411 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3412 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3413 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3414 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3415 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3416 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3417 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3418 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3420 #undef FMT_UNKNOWN
3421 #undef RGBA8_UNORM
3422 #undef DIM_UNKNOWN
3423 #undef TEX_1D
3424 #undef TEX_1D_ARRAY
3425 #undef TEX_2D
3426 #undef TEX_2D_ARRAY
3427 #undef TEX_2DMS
3428 #undef TEX_2DMS_ARR
3429 #undef TEX_3D
3430 #undef TEX_CUBE
3431 #undef CUBE_ARRAY
3433 if (!(device = create_device(NULL)))
3435 skip("Failed to create device.\n");
3436 return;
3438 feature_level = ID3D11Device_GetFeatureLevel(device);
3440 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
3442 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3443 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3445 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3446 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
3447 U1(U(srv_desc).Buffer).ElementOffset = 0;
3448 U2(U(srv_desc).Buffer).ElementWidth = 64;
3450 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
3451 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3453 expected_refcount = get_refcount(device) + 1;
3454 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
3455 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
3456 refcount = get_refcount(device);
3457 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3458 tmp = NULL;
3459 expected_refcount = refcount + 1;
3460 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
3461 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3462 refcount = get_refcount(device);
3463 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3464 ID3D11Device_Release(tmp);
3466 /* Not available on all Windows versions. */
3467 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
3468 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3470 ID3D11ShaderResourceView_Release(srview);
3471 ID3D11Buffer_Release(buffer);
3473 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
3475 buffer_desc.ByteWidth = 1024;
3476 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3477 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3478 buffer_desc.CPUAccessFlags = 0;
3479 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
3480 buffer_desc.StructureByteStride = 4;
3482 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3483 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3485 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3486 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
3488 memset(&srv_desc, 0, sizeof(srv_desc));
3489 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3491 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
3492 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
3493 srv_desc.ViewDimension);
3494 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
3495 U1(U(srv_desc).Buffer).FirstElement);
3496 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
3497 U2(U(srv_desc).Buffer).NumElements);
3499 ID3D11ShaderResourceView_Release(srview);
3500 ID3D11Buffer_Release(buffer);
3502 else
3504 skip("Structured buffers require feature level 11_0.\n");
3507 texture2d_desc.Width = 512;
3508 texture2d_desc.Height = 512;
3509 texture2d_desc.SampleDesc.Count = 1;
3510 texture2d_desc.SampleDesc.Quality = 0;
3511 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3512 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3513 texture2d_desc.CPUAccessFlags = 0;
3515 texture3d_desc.Width = 64;
3516 texture3d_desc.Height = 64;
3517 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3518 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3519 texture3d_desc.CPUAccessFlags = 0;
3520 texture3d_desc.MiscFlags = 0;
3522 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3524 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
3526 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
3528 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3529 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3530 texture2d_desc.Format = tests[i].texture.format;
3531 texture2d_desc.MiscFlags = 0;
3533 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3534 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3535 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3537 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
3538 && (texture2d_desc.ArraySize != 6
3539 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3540 && feature_level < D3D_FEATURE_LEVEL_10_1)
3542 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3543 continue;
3546 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3547 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3548 texture = (ID3D11Resource *)texture2d;
3550 else
3552 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3553 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3554 texture3d_desc.Format = tests[i].texture.format;
3556 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3557 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3558 texture = (ID3D11Resource *)texture3d;
3561 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
3563 current_desc = NULL;
3565 else
3567 current_desc = &srv_desc;
3568 get_srv_desc(current_desc, &tests[i].srv_desc);
3571 expected_refcount = get_refcount(texture);
3572 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3573 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3574 refcount = get_refcount(texture);
3575 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3577 /* Not available on all Windows versions. */
3578 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
3579 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3581 memset(&srv_desc, 0, sizeof(srv_desc));
3582 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3583 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3585 ID3D11ShaderResourceView_Release(srview);
3586 ID3D11Resource_Release(texture);
3589 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3591 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
3592 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
3594 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
3596 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3597 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3598 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3599 texture2d_desc.MiscFlags = 0;
3601 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3602 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3603 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3605 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3606 && feature_level < D3D_FEATURE_LEVEL_10_1)
3608 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3609 continue;
3612 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3613 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3614 texture = (ID3D11Resource *)texture2d;
3616 else
3618 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3619 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3620 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3622 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3623 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3624 texture = (ID3D11Resource *)texture3d;
3627 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3628 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3629 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3631 ID3D11Resource_Release(texture);
3634 refcount = ID3D11Device_Release(device);
3635 ok(!refcount, "Device has %u references left.\n", refcount);
3638 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
3640 #if 0
3641 float4 light;
3642 float4x4 mat;
3644 struct input
3646 float4 position : POSITION;
3647 float3 normal : NORMAL;
3650 struct output
3652 float4 position : POSITION;
3653 float4 diffuse : COLOR;
3656 output main(const input v)
3658 output o;
3660 o.position = mul(v.position, mat);
3661 o.diffuse = dot((float3)light, v.normal);
3663 return o;
3665 #endif
3666 static const DWORD vs_4_1[] =
3668 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
3669 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
3670 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
3671 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
3672 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3673 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
3674 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
3675 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3676 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
3677 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
3678 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
3679 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
3680 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
3681 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
3682 0x0100003e,
3684 static const DWORD vs_4_0[] =
3686 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3687 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3688 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3689 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3690 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3691 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3692 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3693 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3694 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3695 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3696 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3697 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3698 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3699 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3700 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3701 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3703 static const DWORD vs_3_0[] =
3705 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3706 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3707 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3708 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3709 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3710 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3711 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3712 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3713 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3714 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3715 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3716 0x0000ffff,
3718 static const DWORD vs_2_0[] =
3720 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3721 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3722 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3723 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3724 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3725 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3726 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3727 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3728 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3729 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3730 0x90e40001, 0x0000ffff,
3733 #if 0
3734 float4 main(const float4 color : COLOR) : SV_TARGET
3736 float4 o;
3738 o = color;
3740 return o;
3742 #endif
3743 static const DWORD ps_4_1[] =
3745 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
3746 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3747 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3748 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3749 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
3750 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3751 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3753 static const DWORD ps_4_0[] =
3755 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
3756 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3757 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3758 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3759 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3760 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3761 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3763 static const DWORD ps_4_0_level_9_0[] =
3765 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
3766 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
3767 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
3768 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
3769 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
3770 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
3771 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
3772 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
3773 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3774 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
3775 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3776 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3777 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
3778 0xabab0054,
3780 static const DWORD ps_4_0_level_9_1[] =
3782 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
3783 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3784 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3785 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3786 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3787 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3788 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3789 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3790 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3791 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3792 0x45475241, 0xabab0054,
3794 static const DWORD ps_4_0_level_9_3[] =
3796 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
3797 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3798 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3799 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3800 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3801 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3802 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3803 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3804 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3805 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3806 0x45475241, 0xabab0054,
3809 #if 0
3810 struct gs_out
3812 float4 pos : SV_POSITION;
3815 [maxvertexcount(4)]
3816 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3818 float offset = 0.1 * vin[0].w;
3819 gs_out v;
3821 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3822 vout.Append(v);
3823 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3824 vout.Append(v);
3825 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3826 vout.Append(v);
3827 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3828 vout.Append(v);
3830 #endif
3831 static const DWORD gs_4_1[] =
3833 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
3834 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3835 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3836 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3837 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
3838 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
3839 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
3840 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
3841 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
3842 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3843 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
3844 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3845 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
3846 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3847 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
3848 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3849 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
3850 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3852 static const DWORD gs_4_0[] =
3854 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3855 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3856 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3857 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3858 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3859 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3860 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3861 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3862 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3863 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3864 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3865 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3866 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3867 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3868 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3869 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3870 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3871 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3874 ULONG refcount, expected_refcount;
3875 struct device_desc device_desc;
3876 ID3D11Device *device, *tmp;
3877 ID3D11GeometryShader *gs;
3878 ID3D11VertexShader *vs;
3879 ID3D11PixelShader *ps;
3880 HRESULT hr;
3882 device_desc.feature_level = &feature_level;
3883 device_desc.flags = 0;
3884 if (!(device = create_device(&device_desc)))
3886 skip("Failed to create device for feature level %#x.\n", feature_level);
3887 return;
3890 /* level_9 shaders */
3891 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
3892 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3893 ID3D11PixelShader_Release(ps);
3895 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
3896 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3897 ID3D11PixelShader_Release(ps);
3899 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
3900 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3901 ID3D11PixelShader_Release(ps);
3903 /* vertex shader */
3904 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
3905 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3907 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
3908 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3910 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
3911 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
3912 hr, feature_level);
3914 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3915 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
3916 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3917 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3918 else
3919 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3921 refcount = get_refcount(device);
3922 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3923 refcount, expected_refcount);
3924 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3926 tmp = NULL;
3927 expected_refcount = refcount + 1;
3928 ID3D11VertexShader_GetDevice(vs, &tmp);
3929 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3930 refcount = get_refcount(device);
3931 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3932 refcount, expected_refcount);
3933 ID3D11Device_Release(tmp);
3935 /* Not available on all Windows versions. */
3936 check_interface(vs, &IID_ID3D10VertexShader, TRUE, TRUE);
3938 refcount = ID3D11VertexShader_Release(vs);
3939 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3942 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
3943 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3945 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3946 hr, feature_level);
3947 refcount = ID3D11VertexShader_Release(vs);
3948 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3950 else
3952 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3953 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3954 hr, feature_level);
3955 if (SUCCEEDED(hr))
3956 ID3D11VertexShader_Release(vs);
3959 /* pixel shader */
3960 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3961 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
3962 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3963 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3964 else
3965 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3967 refcount = get_refcount(device);
3968 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3969 refcount, expected_refcount);
3970 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3972 tmp = NULL;
3973 expected_refcount = refcount + 1;
3974 ID3D11PixelShader_GetDevice(ps, &tmp);
3975 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3976 refcount = get_refcount(device);
3977 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3978 refcount, expected_refcount);
3979 ID3D11Device_Release(tmp);
3981 /* Not available on all Windows versions. */
3982 check_interface(ps, &IID_ID3D10PixelShader, TRUE, TRUE);
3984 refcount = ID3D11PixelShader_Release(ps);
3985 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3988 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
3989 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3991 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
3992 hr, feature_level);
3993 refcount = ID3D11PixelShader_Release(ps);
3994 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3996 else
3998 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3999 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4000 if (SUCCEEDED(hr))
4001 ID3D11PixelShader_Release(ps);
4004 /* geometry shader */
4005 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4006 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
4007 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4008 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4009 else
4010 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4012 refcount = get_refcount(device);
4013 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4014 refcount, expected_refcount);
4015 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4017 tmp = NULL;
4018 expected_refcount = refcount + 1;
4019 ID3D11GeometryShader_GetDevice(gs, &tmp);
4020 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4021 refcount = get_refcount(device);
4022 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4023 refcount, expected_refcount);
4024 ID3D11Device_Release(tmp);
4026 /* Not available on all Windows versions. */
4027 check_interface(gs, &IID_ID3D10GeometryShader, TRUE, TRUE);
4029 refcount = ID3D11GeometryShader_Release(gs);
4030 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4033 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
4034 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4036 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4037 hr, feature_level);
4038 refcount = ID3D11GeometryShader_Release(gs);
4039 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4041 else
4043 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4044 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4045 hr, feature_level);
4046 if (SUCCEEDED(hr))
4047 ID3D11GeometryShader_Release(gs);
4050 refcount = ID3D11Device_Release(device);
4051 ok(!refcount, "Device has %u references left.\n", refcount);
4054 static void test_create_sampler_state(void)
4056 static const struct test
4058 D3D11_FILTER filter;
4059 D3D10_FILTER expected_filter;
4061 desc_conversion_tests[] =
4063 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
4064 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
4065 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
4066 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
4067 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
4068 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
4069 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
4070 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
4071 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
4072 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
4073 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
4075 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
4076 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
4078 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
4079 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
4081 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
4082 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
4084 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
4085 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
4086 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
4089 ID3D11SamplerState *sampler_state1, *sampler_state2;
4090 ID3D10SamplerState *d3d10_sampler_state;
4091 ULONG refcount, expected_refcount;
4092 ID3D11Device *device, *tmp;
4093 D3D11_SAMPLER_DESC desc;
4094 unsigned int i;
4095 HRESULT hr;
4097 if (!(device = create_device(NULL)))
4099 skip("Failed to create device.\n");
4100 return;
4103 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
4104 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4106 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
4107 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4108 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4109 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
4110 desc.MipLODBias = 0.0f;
4111 desc.MaxAnisotropy = 16;
4112 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4113 desc.BorderColor[0] = 0.0f;
4114 desc.BorderColor[1] = 1.0f;
4115 desc.BorderColor[2] = 0.0f;
4116 desc.BorderColor[3] = 1.0f;
4117 desc.MinLOD = 0.0f;
4118 desc.MaxLOD = 16.0f;
4120 expected_refcount = get_refcount(device) + 1;
4121 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4122 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4123 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
4124 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4125 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4126 refcount = get_refcount(device);
4127 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4128 tmp = NULL;
4129 expected_refcount = refcount + 1;
4130 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
4131 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4132 refcount = get_refcount(device);
4133 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4134 ID3D11Device_Release(tmp);
4136 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
4137 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4138 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4139 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4140 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4141 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4142 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4143 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4144 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4145 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4146 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4147 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4148 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4150 refcount = ID3D11SamplerState_Release(sampler_state2);
4151 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4152 refcount = ID3D11SamplerState_Release(sampler_state1);
4153 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4155 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4157 const struct test *current = &desc_conversion_tests[i];
4158 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4160 desc.Filter = current->filter;
4161 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4162 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4163 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4164 desc.MipLODBias = 0.0f;
4165 desc.MaxAnisotropy = 16;
4166 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4167 desc.BorderColor[0] = 0.0f;
4168 desc.BorderColor[1] = 1.0f;
4169 desc.BorderColor[2] = 0.0f;
4170 desc.BorderColor[3] = 1.0f;
4171 desc.MinLOD = 0.0f;
4172 desc.MaxLOD = 16.0f;
4174 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4175 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4177 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
4178 (void **)&d3d10_sampler_state);
4179 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4180 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4181 if (FAILED(hr))
4183 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
4184 ID3D11SamplerState_Release(sampler_state1);
4185 break;
4188 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4189 expected_desc.Filter = current->expected_filter;
4190 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4191 expected_desc.MaxAnisotropy = 0;
4192 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4193 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4195 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
4196 ok(d3d10_desc.Filter == expected_desc.Filter,
4197 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
4198 ok(d3d10_desc.AddressU == expected_desc.AddressU,
4199 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
4200 ok(d3d10_desc.AddressV == expected_desc.AddressV,
4201 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
4202 ok(d3d10_desc.AddressW == expected_desc.AddressW,
4203 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
4204 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
4205 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
4206 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4207 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
4208 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4209 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
4210 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
4211 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
4212 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
4213 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
4214 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4215 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
4216 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
4217 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
4218 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
4219 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
4220 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
4222 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
4223 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4224 refcount = ID3D11SamplerState_Release(sampler_state1);
4225 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4228 refcount = ID3D11Device_Release(device);
4229 ok(!refcount, "Device has %u references left.\n", refcount);
4232 static void test_create_blend_state(void)
4234 static const D3D11_BLEND_DESC desc_conversion_tests[] =
4237 FALSE, FALSE,
4240 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4241 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
4246 FALSE, TRUE,
4249 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4250 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4253 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4254 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
4257 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4258 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4261 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4262 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
4265 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4266 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4269 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4270 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4273 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4274 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4277 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4278 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4283 FALSE, TRUE,
4286 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4287 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4290 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
4291 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4294 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
4295 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4298 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4299 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4302 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
4303 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4306 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
4307 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4310 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4311 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4314 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4315 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4321 ID3D11BlendState *blend_state1, *blend_state2;
4322 D3D11_BLEND_DESC desc, obtained_desc;
4323 ID3D10BlendState *d3d10_blend_state;
4324 D3D10_BLEND_DESC d3d10_blend_desc;
4325 ULONG refcount, expected_refcount;
4326 ID3D11Device *device, *tmp;
4327 unsigned int i, j;
4328 HRESULT hr;
4330 if (!(device = create_device(NULL)))
4332 skip("Failed to create device.\n");
4333 return;
4336 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
4337 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4339 memset(&desc, 0, sizeof(desc));
4340 desc.AlphaToCoverageEnable = FALSE;
4341 desc.IndependentBlendEnable = FALSE;
4342 desc.RenderTarget[0].BlendEnable = FALSE;
4343 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
4344 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
4345 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
4346 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
4347 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
4348 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
4349 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
4351 expected_refcount = get_refcount(device) + 1;
4352 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
4353 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4354 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
4355 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4356 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4357 refcount = get_refcount(device);
4358 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4359 tmp = NULL;
4360 expected_refcount = refcount + 1;
4361 ID3D11BlendState_GetDevice(blend_state1, &tmp);
4362 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4363 refcount = get_refcount(device);
4364 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4365 ID3D11Device_Release(tmp);
4367 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
4368 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
4369 obtained_desc.AlphaToCoverageEnable);
4370 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
4371 obtained_desc.IndependentBlendEnable);
4372 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4374 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
4375 "Got unexpected blend enable %#x for render target %u.\n",
4376 obtained_desc.RenderTarget[i].BlendEnable, i);
4377 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
4378 "Got unexpected src blend %u for render target %u.\n",
4379 obtained_desc.RenderTarget[i].SrcBlend, i);
4380 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
4381 "Got unexpected dest blend %u for render target %u.\n",
4382 obtained_desc.RenderTarget[i].DestBlend, i);
4383 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
4384 "Got unexpected blend op %u for render target %u.\n",
4385 obtained_desc.RenderTarget[i].BlendOp, i);
4386 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
4387 "Got unexpected src blend alpha %u for render target %u.\n",
4388 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
4389 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
4390 "Got unexpected dest blend alpha %u for render target %u.\n",
4391 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
4392 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
4393 "Got unexpected blend op alpha %u for render target %u.\n",
4394 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
4395 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
4396 "Got unexpected render target write mask %#x for render target %u.\n",
4397 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
4400 /* Not available on all Windows versions. */
4401 check_interface(blend_state1, &IID_ID3D10BlendState, TRUE, TRUE);
4402 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
4404 refcount = ID3D11BlendState_Release(blend_state1);
4405 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4406 refcount = ID3D11BlendState_Release(blend_state2);
4407 ok(!refcount, "Blend state has %u references left.\n", refcount);
4409 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4411 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
4413 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
4414 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4416 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
4417 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4418 "Blend state should implement ID3D10BlendState.\n");
4419 if (FAILED(hr))
4421 win_skip("Blend state does not implement ID3D10BlendState.\n");
4422 ID3D11BlendState_Release(blend_state1);
4423 break;
4426 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
4427 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
4428 "Got unexpected alpha to coverage enable %#x for test %u.\n",
4429 d3d10_blend_desc.AlphaToCoverageEnable, i);
4430 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
4431 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
4432 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
4433 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
4434 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
4435 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
4436 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
4437 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
4438 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
4439 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
4440 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
4441 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
4442 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
4444 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
4445 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
4446 "Got unexpected blend enable %#x for test %u, render target %u.\n",
4447 d3d10_blend_desc.BlendEnable[j], i, j);
4448 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
4449 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
4450 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
4453 ID3D10BlendState_Release(d3d10_blend_state);
4455 refcount = ID3D11BlendState_Release(blend_state1);
4456 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4459 refcount = ID3D11Device_Release(device);
4460 ok(!refcount, "Device has %u references left.\n", refcount);
4463 static void test_create_depthstencil_state(void)
4465 ID3D11DepthStencilState *ds_state1, *ds_state2;
4466 ULONG refcount, expected_refcount;
4467 D3D11_DEPTH_STENCIL_DESC ds_desc;
4468 ID3D11Device *device, *tmp;
4469 HRESULT hr;
4471 if (!(device = create_device(NULL)))
4473 skip("Failed to create device.\n");
4474 return;
4477 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
4478 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4480 ds_desc.DepthEnable = TRUE;
4481 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
4482 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
4483 ds_desc.StencilEnable = FALSE;
4484 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
4485 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
4486 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4487 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4488 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4489 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4490 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4491 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4492 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4493 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4495 expected_refcount = get_refcount(device) + 1;
4496 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4497 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4498 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4499 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4500 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4501 refcount = get_refcount(device);
4502 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4503 tmp = NULL;
4504 expected_refcount = refcount + 1;
4505 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
4506 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4507 refcount = get_refcount(device);
4508 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4509 ID3D11Device_Release(tmp);
4511 /* Not available on all Windows versions. */
4512 check_interface(ds_state1, &IID_ID3D10DepthStencilState, TRUE, TRUE);
4514 refcount = ID3D11DepthStencilState_Release(ds_state2);
4515 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4516 refcount = ID3D11DepthStencilState_Release(ds_state1);
4517 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4519 ds_desc.DepthEnable = FALSE;
4520 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
4521 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
4522 ds_desc.StencilEnable = FALSE;
4523 ds_desc.StencilReadMask = 0;
4524 ds_desc.StencilWriteMask = 0;
4525 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
4526 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
4527 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
4528 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
4529 ds_desc.BackFace = ds_desc.FrontFace;
4531 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4532 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4534 memset(&ds_desc, 0, sizeof(ds_desc));
4535 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
4536 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4537 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
4538 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4539 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4540 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4541 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
4542 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4543 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
4544 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4545 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4546 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4547 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4548 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4549 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4550 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4551 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4552 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4553 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4554 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4555 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4556 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4557 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4558 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4559 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4560 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4562 ID3D11DepthStencilState_Release(ds_state1);
4564 refcount = ID3D11Device_Release(device);
4565 ok(!refcount, "Device has %u references left.\n", refcount);
4568 static void test_create_rasterizer_state(void)
4570 ID3D11RasterizerState *rast_state1, *rast_state2;
4571 ID3D10RasterizerState *d3d10_rast_state;
4572 ULONG refcount, expected_refcount;
4573 D3D10_RASTERIZER_DESC d3d10_desc;
4574 D3D11_RASTERIZER_DESC desc;
4575 ID3D11Device *device, *tmp;
4576 HRESULT hr;
4578 if (!(device = create_device(NULL)))
4580 skip("Failed to create device.\n");
4581 return;
4584 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
4585 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4587 desc.FillMode = D3D11_FILL_SOLID;
4588 desc.CullMode = D3D11_CULL_BACK;
4589 desc.FrontCounterClockwise = FALSE;
4590 desc.DepthBias = 0;
4591 desc.DepthBiasClamp = 0.0f;
4592 desc.SlopeScaledDepthBias = 0.0f;
4593 desc.DepthClipEnable = TRUE;
4594 desc.ScissorEnable = FALSE;
4595 desc.MultisampleEnable = FALSE;
4596 desc.AntialiasedLineEnable = FALSE;
4598 expected_refcount = get_refcount(device) + 1;
4599 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
4600 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4601 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
4602 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4603 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4604 refcount = get_refcount(device);
4605 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4606 tmp = NULL;
4607 expected_refcount = refcount + 1;
4608 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
4609 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4610 refcount = get_refcount(device);
4611 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4612 ID3D11Device_Release(tmp);
4614 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
4615 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4616 "Rasterizer state should implement ID3D10RasterizerState.\n");
4617 if (SUCCEEDED(hr))
4619 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
4620 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
4621 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
4622 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
4623 d3d10_desc.FrontCounterClockwise);
4624 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
4625 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
4626 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
4627 d3d10_desc.SlopeScaledDepthBias);
4628 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
4629 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
4630 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
4631 d3d10_desc.MultisampleEnable);
4632 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
4633 d3d10_desc.AntialiasedLineEnable);
4635 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
4636 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4639 refcount = ID3D11RasterizerState_Release(rast_state2);
4640 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4641 refcount = ID3D11RasterizerState_Release(rast_state1);
4642 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4644 refcount = ID3D11Device_Release(device);
4645 ok(!refcount, "Device has %u references left.\n", refcount);
4648 static void test_create_query(void)
4650 static const struct
4652 D3D11_QUERY query;
4653 D3D_FEATURE_LEVEL required_feature_level;
4654 BOOL is_predicate;
4655 BOOL can_use_create_predicate;
4656 BOOL todo;
4658 tests[] =
4660 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4661 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4662 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4663 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4664 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4665 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
4666 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4667 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
4668 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
4669 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4670 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
4671 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4672 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
4673 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4674 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
4675 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4678 ULONG refcount, expected_refcount;
4679 D3D_FEATURE_LEVEL feature_level;
4680 D3D11_QUERY_DESC query_desc;
4681 ID3D11Predicate *predicate;
4682 ID3D11Device *device, *tmp;
4683 HRESULT hr, expected_hr;
4684 ID3D11Query *query;
4685 unsigned int i;
4687 if (!(device = create_device(NULL)))
4689 skip("Failed to create device.\n");
4690 return;
4692 feature_level = ID3D11Device_GetFeatureLevel(device);
4694 hr = ID3D11Device_CreateQuery(device, NULL, &query);
4695 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4696 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
4697 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4699 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4701 if (tests[i].required_feature_level > feature_level)
4703 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
4704 continue;
4707 query_desc.Query = tests[i].query;
4708 query_desc.MiscFlags = 0;
4710 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
4711 todo_wine_if(tests[i].todo)
4712 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4714 query_desc.Query = tests[i].query;
4715 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
4716 todo_wine_if(tests[i].todo)
4717 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4718 if (FAILED(hr))
4719 continue;
4721 check_interface(query, &IID_ID3D11Predicate, tests[i].is_predicate, FALSE);
4722 ID3D11Query_Release(query);
4724 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
4725 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
4726 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4728 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
4729 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4730 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4731 if (SUCCEEDED(hr))
4732 ID3D11Predicate_Release(predicate);
4735 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
4736 expected_refcount = get_refcount(device) + 1;
4737 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4738 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4739 refcount = get_refcount(device);
4740 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4741 tmp = NULL;
4742 expected_refcount = refcount + 1;
4743 ID3D11Predicate_GetDevice(predicate, &tmp);
4744 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4745 refcount = get_refcount(device);
4746 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4747 ID3D11Device_Release(tmp);
4748 /* Not available on all Windows versions. */
4749 check_interface(predicate, &IID_ID3D10Predicate, TRUE, TRUE);
4750 ID3D11Predicate_Release(predicate);
4752 refcount = ID3D11Device_Release(device);
4753 ok(!refcount, "Device has %u references left.\n", refcount);
4756 #define get_query_data(a, b, c, d) get_query_data_(__LINE__, a, b, c, d)
4757 static void get_query_data_(unsigned int line, ID3D11DeviceContext *context,
4758 ID3D11Asynchronous *query, void *data, unsigned int data_size)
4760 unsigned int i;
4761 HRESULT hr;
4763 for (i = 0; i < 500; ++i)
4765 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4766 break;
4767 Sleep(10);
4769 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4770 memset(data, 0xff, data_size);
4771 hr = ID3D11DeviceContext_GetData(context, query, data, data_size, 0);
4772 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4775 static void test_occlusion_query(void)
4777 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4778 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4780 struct d3d11_test_context test_context;
4781 D3D11_TEXTURE2D_DESC texture_desc;
4782 ID3D11DeviceContext *context;
4783 ID3D11RenderTargetView *rtv;
4784 D3D11_QUERY_DESC query_desc;
4785 ID3D11Asynchronous *query;
4786 unsigned int data_size, i;
4787 ID3D11Texture2D *texture;
4788 ID3D11Device *device;
4789 D3D11_VIEWPORT vp;
4790 union
4792 UINT64 uint;
4793 DWORD dword[2];
4794 } data;
4795 HRESULT hr;
4797 if (!init_test_context(&test_context, NULL))
4798 return;
4800 device = test_context.device;
4801 context = test_context.immediate_context;
4803 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4805 query_desc.Query = D3D11_QUERY_OCCLUSION;
4806 query_desc.MiscFlags = 0;
4807 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4808 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4809 data_size = ID3D11Asynchronous_GetDataSize(query);
4810 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4812 memset(&data, 0xff, sizeof(data));
4813 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4814 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4815 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4816 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4817 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4818 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4820 ID3D11DeviceContext_End(context, query);
4821 ID3D11DeviceContext_Begin(context, query);
4822 ID3D11DeviceContext_Begin(context, query);
4824 memset(&data, 0xff, sizeof(data));
4825 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4826 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4827 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4828 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4829 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4830 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4832 draw_color_quad(&test_context, &red);
4834 ID3D11DeviceContext_End(context, query);
4835 get_query_data(context, query, &data, sizeof(data));
4836 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4838 memset(&data, 0xff, sizeof(data));
4839 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
4840 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4841 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
4842 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4843 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
4844 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4845 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
4846 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4847 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4848 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4850 memset(&data, 0xff, sizeof(data));
4851 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
4852 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4853 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4854 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4856 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
4857 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4858 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
4859 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4861 ID3D11DeviceContext_Begin(context, query);
4862 ID3D11DeviceContext_End(context, query);
4863 ID3D11DeviceContext_End(context, query);
4865 get_query_data(context, query, &data, sizeof(data));
4866 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4867 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4868 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4870 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4871 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4872 texture_desc.MipLevels = 1;
4873 texture_desc.ArraySize = 1;
4874 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4875 texture_desc.SampleDesc.Count = 1;
4876 texture_desc.SampleDesc.Quality = 0;
4877 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4878 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4879 texture_desc.CPUAccessFlags = 0;
4880 texture_desc.MiscFlags = 0;
4881 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4882 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4883 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
4884 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4886 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
4887 vp.TopLeftX = 0.0f;
4888 vp.TopLeftY = 0.0f;
4889 vp.Width = texture_desc.Width;
4890 vp.Height = texture_desc.Height;
4891 vp.MinDepth = 0.0f;
4892 vp.MaxDepth = 1.0f;
4893 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4895 ID3D11DeviceContext_Begin(context, query);
4896 for (i = 0; i < 100; i++)
4897 draw_color_quad(&test_context, &red);
4898 ID3D11DeviceContext_End(context, query);
4900 get_query_data(context, query, &data, sizeof(data));
4901 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4902 || (data.dword[0] == 0xffffffff && !data.dword[1])
4903 || broken(!data.uint),
4904 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4905 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4906 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4908 ID3D11Asynchronous_Release(query);
4910 /* The following test exercises a code path in wined3d. A wined3d context
4911 * associated with the query is destroyed when the swapchain is released. */
4912 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4913 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4915 vp.Width = 64.0f;
4916 vp.Height = 64.0f;
4917 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4918 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4919 ID3D11DeviceContext_Begin(context, query);
4920 draw_color_quad(&test_context, &red);
4921 ID3D11DeviceContext_End(context, query);
4923 ID3D11RenderTargetView_Release(test_context.backbuffer_rtv);
4924 ID3D11Texture2D_Release(test_context.backbuffer);
4925 IDXGISwapChain_Release(test_context.swapchain);
4926 test_context.swapchain = create_swapchain(device, test_context.window, NULL);
4927 hr = IDXGISwapChain_GetBuffer(test_context.swapchain, 0, &IID_ID3D11Texture2D,
4928 (void **)&test_context.backbuffer);
4929 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
4930 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer,
4931 NULL, &test_context.backbuffer_rtv);
4932 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4933 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
4934 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4936 get_query_data(context, query, &data, sizeof(data));
4937 /* This test occasionally succeeds with CSMT enabled because of a race condition. */
4938 if (0)
4939 todo_wine ok(data.dword[0] == 0x1000 && !data.dword[1],
4940 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4942 ID3D11Asynchronous_Release(query);
4943 ID3D11RenderTargetView_Release(rtv);
4944 ID3D11Texture2D_Release(texture);
4945 release_test_context(&test_context);
4948 static void test_pipeline_statistics_query(void)
4950 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4951 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4953 D3D11_QUERY_DATA_PIPELINE_STATISTICS data;
4954 struct d3d11_test_context test_context;
4955 ID3D11DeviceContext *context;
4956 D3D11_QUERY_DESC query_desc;
4957 ID3D11Asynchronous *query;
4958 unsigned int data_size;
4959 ID3D11Device *device;
4960 HRESULT hr;
4962 if (!init_test_context(&test_context, NULL))
4963 return;
4965 device = test_context.device;
4966 context = test_context.immediate_context;
4968 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4970 query_desc.Query = D3D11_QUERY_PIPELINE_STATISTICS;
4971 query_desc.MiscFlags = 0;
4972 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4973 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4974 data_size = ID3D11Asynchronous_GetDataSize(query);
4975 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4977 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4978 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4979 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4980 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4982 ID3D11DeviceContext_End(context, query);
4983 ID3D11DeviceContext_Begin(context, query);
4984 ID3D11DeviceContext_Begin(context, query);
4986 memset(&data, 0xff, sizeof(data));
4987 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4988 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4989 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4990 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4991 ok(data.IAVertices == ~(UINT64)0, "Data was modified.\n");
4993 draw_quad(&test_context);
4995 ID3D11DeviceContext_End(context, query);
4996 get_query_data(context, query, &data, sizeof(data));
4997 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
4998 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
4999 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5000 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5001 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5002 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5003 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5004 todo_wine
5005 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5006 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5007 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5008 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5010 ID3D11DeviceContext_Begin(context, query);
5011 draw_color_quad(&test_context, &red);
5012 ID3D11DeviceContext_End(context, query);
5013 get_query_data(context, query, &data, sizeof(data));
5014 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5015 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5016 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5017 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5018 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5019 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5020 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5021 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5022 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5023 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5024 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5026 ID3D11Asynchronous_Release(query);
5027 release_test_context(&test_context);
5030 static void test_timestamp_query(void)
5032 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5034 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
5035 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
5036 struct d3d11_test_context test_context;
5037 ID3D11DeviceContext *context;
5038 D3D11_QUERY_DESC query_desc;
5039 unsigned int data_size;
5040 ID3D11Device *device;
5041 UINT64 timestamp;
5042 HRESULT hr;
5044 if (!init_test_context(&test_context, NULL))
5045 return;
5047 device = test_context.device;
5048 context = test_context.immediate_context;
5050 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5051 query_desc.MiscFlags = 0;
5052 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5053 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5054 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
5055 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
5057 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
5058 query_desc.MiscFlags = 0;
5059 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
5060 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5061 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
5062 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
5064 disjoint.Frequency = 0xdeadbeef;
5065 disjoint.Disjoint = 0xdeadbeef;
5066 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5067 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5068 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5069 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5070 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5071 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5073 /* Test a TIMESTAMP_DISJOINT query. */
5074 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5076 disjoint.Frequency = 0xdeadbeef;
5077 disjoint.Disjoint = 0xdeadbeef;
5078 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5079 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5080 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5081 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5082 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5083 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5085 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5086 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5087 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
5088 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5090 prev_disjoint = disjoint;
5092 disjoint.Frequency = 0xdeadbeef;
5093 disjoint.Disjoint = 0xff;
5094 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
5095 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5096 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
5097 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5098 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
5099 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5100 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
5101 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5102 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5103 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
5105 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5106 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5107 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
5108 D3D11_ASYNC_GETDATA_DONOTFLUSH);
5109 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5110 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
5111 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
5113 memset(&timestamp, 0xff, sizeof(timestamp));
5114 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
5115 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5116 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5117 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5118 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5120 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
5121 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5123 memset(&timestamp, 0xff, sizeof(timestamp));
5124 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5125 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5126 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5128 draw_color_quad(&test_context, &red);
5130 ID3D11DeviceContext_End(context, timestamp_query);
5131 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5133 timestamp = 0xdeadbeef;
5134 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5135 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5136 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5138 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5139 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5140 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
5142 timestamp = 0xdeadbeef;
5143 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
5144 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5145 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
5146 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5147 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5148 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5149 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
5150 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5151 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5153 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5154 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5155 disjoint.Frequency = 0xdeadbeef;
5156 disjoint.Disjoint = 0xff;
5157 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5158 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5159 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
5160 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5162 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
5163 ID3D11Asynchronous_Release(timestamp_query);
5164 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5165 query_desc.MiscFlags = 0;
5166 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5167 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5169 draw_color_quad(&test_context, &red);
5171 ID3D11DeviceContext_End(context, timestamp_query);
5172 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5174 ID3D11Asynchronous_Release(timestamp_query);
5175 ID3D11Asynchronous_Release(timestamp_disjoint_query);
5176 release_test_context(&test_context);
5179 static void test_device_removed_reason(void)
5181 ID3D11Device *device;
5182 ULONG refcount;
5183 HRESULT hr;
5185 if (!(device = create_device(NULL)))
5187 skip("Failed to create device.\n");
5188 return;
5191 hr = ID3D11Device_GetDeviceRemovedReason(device);
5192 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5193 hr = ID3D11Device_GetDeviceRemovedReason(device);
5194 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5196 refcount = ID3D11Device_Release(device);
5197 ok(!refcount, "Device has %u references left.\n", refcount);
5200 static void test_private_data(void)
5202 ULONG refcount, expected_refcount;
5203 D3D11_TEXTURE2D_DESC texture_desc;
5204 ID3D10Texture2D *d3d10_texture;
5205 ID3D11Device *test_object;
5206 ID3D11Texture2D *texture;
5207 IDXGIDevice *dxgi_device;
5208 IDXGISurface *surface;
5209 ID3D11Device *device;
5210 IUnknown *ptr;
5211 HRESULT hr;
5212 UINT size;
5214 static const GUID test_guid =
5215 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
5216 static const GUID test_guid2 =
5217 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
5218 static const DWORD data[] = {1, 2, 3, 4};
5220 if (!(device = create_device(NULL)))
5222 skip("Failed to create device.\n");
5223 return;
5226 test_object = create_device(NULL);
5228 texture_desc.Width = 512;
5229 texture_desc.Height = 512;
5230 texture_desc.MipLevels = 1;
5231 texture_desc.ArraySize = 1;
5232 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5233 texture_desc.SampleDesc.Count = 1;
5234 texture_desc.SampleDesc.Quality = 0;
5235 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5236 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5237 texture_desc.CPUAccessFlags = 0;
5238 texture_desc.MiscFlags = 0;
5240 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5241 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5242 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
5243 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
5245 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
5246 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5247 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5248 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5249 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5250 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5251 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5252 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5254 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5255 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5256 size = sizeof(ptr) * 2;
5257 ptr = (IUnknown *)0xdeadbeef;
5258 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5259 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5260 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5261 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5263 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
5264 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
5265 size = sizeof(ptr) * 2;
5266 ptr = (IUnknown *)0xdeadbeef;
5267 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
5268 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5269 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5270 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5271 IDXGIDevice_Release(dxgi_device);
5273 refcount = get_refcount(test_object);
5274 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5275 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5276 expected_refcount = refcount + 1;
5277 refcount = get_refcount(test_object);
5278 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5279 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5280 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5281 refcount = get_refcount(test_object);
5282 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5284 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5285 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5286 --expected_refcount;
5287 refcount = get_refcount(test_object);
5288 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5290 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5291 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5292 size = sizeof(data);
5293 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
5294 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5295 refcount = get_refcount(test_object);
5296 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5297 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5298 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5299 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5300 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5302 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5303 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5304 ++expected_refcount;
5305 size = 2 * sizeof(ptr);
5306 ptr = NULL;
5307 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5308 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5309 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
5310 ++expected_refcount;
5311 refcount = get_refcount(test_object);
5312 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5313 IUnknown_Release(ptr);
5314 --expected_refcount;
5316 ptr = (IUnknown *)0xdeadbeef;
5317 size = 1;
5318 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5319 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5320 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5321 size = 2 * sizeof(ptr);
5322 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5323 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5324 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5325 refcount = get_refcount(test_object);
5326 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5328 size = 1;
5329 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5330 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
5331 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5332 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5333 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
5334 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5335 size = 0xdeadbabe;
5336 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
5337 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
5338 ok(size == 0, "Got unexpected size %u.\n", size);
5339 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5340 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
5341 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5342 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5344 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
5345 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5346 ptr = NULL;
5347 size = sizeof(ptr);
5348 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
5349 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5350 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5351 IUnknown_Release(ptr);
5353 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
5354 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5355 "Texture should implement ID3D10Texture2D.\n");
5356 if (SUCCEEDED(hr))
5358 ptr = NULL;
5359 size = sizeof(ptr);
5360 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
5361 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5362 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5363 IUnknown_Release(ptr);
5364 ID3D10Texture2D_Release(d3d10_texture);
5367 IDXGISurface_Release(surface);
5368 ID3D11Texture2D_Release(texture);
5369 refcount = ID3D11Device_Release(device);
5370 ok(!refcount, "Device has %u references left.\n", refcount);
5371 refcount = ID3D11Device_Release(test_object);
5372 ok(!refcount, "Test object has %u references left.\n", refcount);
5375 static void test_state_refcounting(const D3D_FEATURE_LEVEL feature_level)
5377 ID3D11RasterizerState *rasterizer_state, *tmp_rasterizer_state;
5378 ID3D11Predicate *predicate, *tmp_predicate;
5379 ID3D11SamplerState *sampler, *tmp_sampler;
5380 ID3D11ShaderResourceView *srv, *tmp_srv;
5381 ID3D11RenderTargetView *rtv, *tmp_rtv;
5382 D3D11_RASTERIZER_DESC rasterizer_desc;
5383 D3D11_TEXTURE2D_DESC texture_desc;
5384 D3D11_QUERY_DESC predicate_desc;
5385 D3D11_SAMPLER_DESC sampler_desc;
5386 struct device_desc device_desc;
5387 ID3D11DeviceContext *context;
5388 ID3D11Texture2D *texture;
5389 ID3D11Device *device;
5390 ULONG refcount;
5391 HRESULT hr;
5393 device_desc.feature_level = &feature_level;
5394 device_desc.flags = 0;
5395 if (!(device = create_device(&device_desc)))
5397 skip("Failed to create device for feature level %#x.\n", feature_level);
5398 return;
5401 ID3D11Device_GetImmediateContext(device, &context);
5403 /* ID3D11SamplerState */
5404 memset(&sampler_desc, 0, sizeof(sampler_desc));
5405 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5406 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5407 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5408 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5409 sampler_desc.MaxLOD = FLT_MAX;
5410 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
5411 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5413 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
5414 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5415 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5416 ID3D11SamplerState_Release(tmp_sampler);
5418 tmp_sampler = sampler;
5419 refcount = get_refcount(sampler);
5420 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
5421 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
5422 refcount = ID3D11SamplerState_Release(sampler);
5423 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5424 sampler = NULL;
5425 ID3D11DeviceContext_PSGetSamplers(context, 0, 1, &sampler);
5426 ok(sampler == tmp_sampler, "Got sampler %p, expected %p.\n", sampler, tmp_sampler);
5427 refcount = ID3D11SamplerState_Release(sampler);
5428 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5430 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
5431 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5432 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5433 refcount = ID3D11SamplerState_Release(tmp_sampler);
5434 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5436 /* ID3D11RasterizerState */
5437 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
5438 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
5439 rasterizer_desc.CullMode = D3D11_CULL_BACK;
5440 rasterizer_desc.DepthClipEnable = TRUE;
5441 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
5442 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5444 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
5445 refcount = ID3D11RasterizerState_Release(rasterizer_state);
5446 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5447 ID3D11DeviceContext_RSGetState(context, &tmp_rasterizer_state);
5448 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
5449 tmp_rasterizer_state, rasterizer_state);
5450 refcount = ID3D11RasterizerState_Release(tmp_rasterizer_state);
5451 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5453 /* ID3D11ShaderResourceView */
5454 memset(&texture_desc, 0, sizeof(texture_desc));
5455 texture_desc.Width = 32;
5456 texture_desc.Height = 32;
5457 texture_desc.MipLevels = 1;
5458 texture_desc.ArraySize = 1;
5459 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5460 texture_desc.SampleDesc.Count = 1;
5461 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5462 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
5463 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5464 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5465 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
5466 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
5467 ID3D11Texture2D_Release(texture);
5469 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
5470 refcount = ID3D11ShaderResourceView_Release(srv);
5471 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5472 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &tmp_srv);
5473 ok(tmp_srv == srv, "Got SRV %p, expected %p.\n", tmp_srv, srv);
5474 refcount = ID3D11ShaderResourceView_Release(tmp_srv);
5475 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5477 /* ID3D11RenderTargetView */
5478 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5479 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5480 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5481 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
5482 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5483 ID3D11Texture2D_Release(texture);
5485 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
5486 refcount = ID3D11RenderTargetView_Release(rtv);
5487 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5488 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &tmp_rtv, NULL);
5489 ok(tmp_rtv == rtv, "Got RTV %p, expected %p.\n", tmp_rtv, rtv);
5490 refcount = ID3D11RenderTargetView_Release(tmp_rtv);
5491 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5493 /* ID3D11Predicate */
5494 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
5496 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
5497 predicate_desc.MiscFlags = 0;
5498 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
5499 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5501 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
5502 refcount = ID3D11Predicate_Release(predicate);
5503 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5504 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, NULL);
5505 ok(tmp_predicate == predicate, "Got predicate %p, expected %p.\n", tmp_predicate, predicate);
5506 refcount = ID3D11Predicate_Release(tmp_predicate);
5507 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5510 ID3D11DeviceContext_Release(context);
5511 refcount = ID3D11Device_Release(device);
5512 ok(!refcount, "Device has %u references left.\n", refcount);
5515 static void test_device_context_state(void)
5517 ID3DDeviceContextState *context_state, *previous_context_state;
5518 ID3D11SamplerState *sampler, *tmp_sampler;
5519 D3D11_SAMPLER_DESC sampler_desc;
5520 D3D_FEATURE_LEVEL feature_level;
5521 ID3D11DeviceContext1 *context;
5522 ID3D11Device *d3d11_device;
5523 ID3D11Device1 *device;
5524 ULONG refcount;
5525 HRESULT hr;
5527 if (!(d3d11_device = create_device(NULL)))
5529 skip("Failed to create device.\n");
5530 return;
5533 hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11Device1, (void **)&device);
5534 ID3D11Device_Release(d3d11_device);
5535 if (FAILED(hr))
5537 skip("ID3D11Device1 is not available.\n");
5538 return;
5541 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
5542 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
5544 feature_level = ID3D11Device1_GetFeatureLevel(device);
5545 ID3D11Device1_GetImmediateContext1(device, &context);
5547 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5548 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5549 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5550 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5551 sampler_desc.MipLODBias = 0.0f;
5552 sampler_desc.MaxAnisotropy = 0;
5553 sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
5554 sampler_desc.BorderColor[0] = 0.0f;
5555 sampler_desc.BorderColor[1] = 1.0f;
5556 sampler_desc.BorderColor[2] = 0.0f;
5557 sampler_desc.BorderColor[3] = 1.0f;
5558 sampler_desc.MinLOD = 0.0f;
5559 sampler_desc.MaxLOD = 16.0f;
5560 hr = ID3D11Device1_CreateSamplerState(device, &sampler_desc, &sampler);
5561 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5563 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5564 tmp_sampler = NULL;
5565 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5566 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5567 ID3D11SamplerState_Release(tmp_sampler);
5569 feature_level = min(feature_level, D3D_FEATURE_LEVEL_10_1);
5570 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
5571 &IID_ID3D10Device, NULL, &context_state);
5572 ok(SUCCEEDED(hr), "Failed to create device context state, hr %#x.\n", hr);
5573 refcount = get_refcount(context_state);
5574 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
5576 /* Enable ID3D10Device behavior. */
5577 previous_context_state = NULL;
5578 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
5579 refcount = ID3DDeviceContextState_Release(context_state);
5580 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5582 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5583 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
5584 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5585 ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler);
5586 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
5588 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
5589 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
5591 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
5592 refcount = ID3DDeviceContextState_Release(context_state);
5593 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5594 refcount = ID3DDeviceContextState_Release(previous_context_state);
5595 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5597 /* ID3DDeviceContextState retains the previous state. */
5598 tmp_sampler = NULL;
5599 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5600 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5601 ID3D11SamplerState_Release(tmp_sampler);
5603 tmp_sampler = NULL;
5604 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
5605 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
5606 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5607 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
5608 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5609 tmp_sampler = NULL;
5610 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5611 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5612 ID3D11SamplerState_Release(tmp_sampler);
5614 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
5615 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
5617 ID3D11SamplerState_Release(sampler);
5618 ID3D11DeviceContext1_Release(context);
5619 refcount = ID3D11Device1_Release(device);
5620 ok(!refcount, "Device has %u references left.\n", refcount);
5623 static void test_blend(void)
5625 ID3D11BlendState *src_blend, *dst_blend;
5626 struct d3d11_test_context test_context;
5627 ID3D11RenderTargetView *offscreen_rtv;
5628 D3D11_TEXTURE2D_DESC texture_desc;
5629 ID3D11InputLayout *input_layout;
5630 ID3D11DeviceContext *context;
5631 D3D11_BLEND_DESC blend_desc;
5632 unsigned int stride, offset;
5633 ID3D11Texture2D *offscreen;
5634 ID3D11VertexShader *vs;
5635 ID3D11PixelShader *ps;
5636 ID3D11Device *device;
5637 D3D11_VIEWPORT vp;
5638 ID3D11Buffer *vb;
5639 DWORD color;
5640 HRESULT hr;
5642 static const DWORD vs_code[] =
5644 #if 0
5645 struct vs_out
5647 float4 position : SV_POSITION;
5648 float4 color : COLOR;
5651 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5653 struct vs_out o;
5655 o.position = position;
5656 o.color = color;
5658 return o;
5660 #endif
5661 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5662 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5663 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5664 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5665 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5666 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5667 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5668 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5669 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5670 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5672 static const DWORD ps_code[] =
5674 #if 0
5675 struct vs_out
5677 float4 position : SV_POSITION;
5678 float4 color : COLOR;
5681 float4 main(struct vs_out i) : SV_TARGET
5683 return i.color;
5685 #endif
5686 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5687 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5688 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5689 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5690 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5691 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5692 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5693 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5695 static const struct
5697 struct vec3 position;
5698 DWORD diffuse;
5700 quads[] =
5702 /* quad1 */
5703 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5704 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5705 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5706 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5707 /* quad2 */
5708 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5709 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5710 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5711 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5713 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
5715 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
5716 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
5718 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5719 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5721 if (!init_test_context(&test_context, NULL))
5722 return;
5724 device = test_context.device;
5725 context = test_context.immediate_context;
5727 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
5728 vs_code, sizeof(vs_code), &input_layout);
5729 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5731 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5733 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
5734 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5735 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5736 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5738 memset(&blend_desc, 0, sizeof(blend_desc));
5739 blend_desc.RenderTarget[0].BlendEnable = TRUE;
5740 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
5741 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
5742 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
5743 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
5744 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
5745 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
5746 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5748 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
5749 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5751 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
5752 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
5753 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
5754 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
5756 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
5757 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5759 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
5760 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5761 stride = sizeof(*quads);
5762 offset = 0;
5763 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
5764 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
5765 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5767 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
5769 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5770 ID3D11DeviceContext_Draw(context, 4, 0);
5771 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5772 ID3D11DeviceContext_Draw(context, 4, 4);
5774 color = get_texture_color(test_context.backbuffer, 320, 360);
5775 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5776 color = get_texture_color(test_context.backbuffer, 320, 120);
5777 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5779 texture_desc.Width = 128;
5780 texture_desc.Height = 128;
5781 texture_desc.MipLevels = 1;
5782 texture_desc.ArraySize = 1;
5783 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5784 texture_desc.SampleDesc.Count = 1;
5785 texture_desc.SampleDesc.Quality = 0;
5786 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5787 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
5788 texture_desc.CPUAccessFlags = 0;
5789 texture_desc.MiscFlags = 0;
5791 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5792 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5794 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
5795 goto done;
5798 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
5799 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5801 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
5803 vp.TopLeftX = 0.0f;
5804 vp.TopLeftY = 0.0f;
5805 vp.Width = 128.0f;
5806 vp.Height = 128.0f;
5807 vp.MinDepth = 0.0f;
5808 vp.MaxDepth = 1.0f;
5809 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
5811 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
5813 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5814 ID3D11DeviceContext_Draw(context, 4, 0);
5815 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5816 ID3D11DeviceContext_Draw(context, 4, 4);
5818 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5819 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5820 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5821 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5823 ID3D11RenderTargetView_Release(offscreen_rtv);
5824 ID3D11Texture2D_Release(offscreen);
5825 done:
5826 ID3D11BlendState_Release(dst_blend);
5827 ID3D11BlendState_Release(src_blend);
5828 ID3D11PixelShader_Release(ps);
5829 ID3D11VertexShader_Release(vs);
5830 ID3D11Buffer_Release(vb);
5831 ID3D11InputLayout_Release(input_layout);
5832 release_test_context(&test_context);
5835 static void test_texture(void)
5837 struct shader
5839 const DWORD *code;
5840 size_t size;
5842 struct texture
5844 UINT width;
5845 UINT height;
5846 UINT miplevel_count;
5847 UINT array_size;
5848 DXGI_FORMAT format;
5849 D3D11_SUBRESOURCE_DATA data[3];
5852 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
5853 struct d3d11_test_context test_context;
5854 const struct texture *current_texture;
5855 D3D11_TEXTURE2D_DESC texture_desc;
5856 D3D11_SAMPLER_DESC sampler_desc;
5857 const struct shader *current_ps;
5858 D3D_FEATURE_LEVEL feature_level;
5859 ID3D11ShaderResourceView *srv;
5860 ID3D11DeviceContext *context;
5861 ID3D11SamplerState *sampler;
5862 struct resource_readback rb;
5863 ID3D11Texture2D *texture;
5864 struct vec4 ps_constant;
5865 ID3D11PixelShader *ps;
5866 ID3D11Device *device;
5867 unsigned int i, x, y;
5868 ID3D11Buffer *cb;
5869 DWORD color;
5870 HRESULT hr;
5872 static const DWORD ps_ld_code[] =
5874 #if 0
5875 Texture2D t;
5877 float miplevel;
5879 float4 main(float4 position : SV_POSITION) : SV_TARGET
5881 float3 p;
5882 t.GetDimensions(miplevel, p.x, p.y, p.z);
5883 p.z = miplevel;
5884 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5885 return t.Load(int3(p));
5887 #endif
5888 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5889 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5890 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5891 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5892 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5893 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5894 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5895 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5896 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5897 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5898 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5899 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5900 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5901 0x00107e46, 0x00000000, 0x0100003e,
5903 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5904 static const DWORD ps_ld_sint8_code[] =
5906 #if 0
5907 Texture2D<int4> t;
5909 float4 main(float4 position : SV_POSITION) : SV_TARGET
5911 float3 p, s;
5912 int4 c;
5914 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5915 t.GetDimensions(0, s.x, s.y, s.z);
5916 p *= s;
5918 c = t.Load(int3(p));
5919 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5921 #endif
5922 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
5923 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5924 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5925 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5926 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5927 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5928 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5929 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5930 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5931 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5932 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5933 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5934 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5935 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5936 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5937 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5938 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5939 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5941 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5942 static const DWORD ps_ld_uint8_code[] =
5944 #if 0
5945 Texture2D<uint4> t;
5947 float4 main(float4 position : SV_POSITION) : SV_TARGET
5949 float3 p, s;
5951 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5952 t.GetDimensions(0, s.x, s.y, s.z);
5953 p *= s;
5955 return t.Load(int3(p)) / (float4)255;
5957 #endif
5958 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5959 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5960 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5961 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5962 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5963 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5964 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5965 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5966 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5967 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5968 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5969 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5970 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5971 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5972 0x3b808081, 0x0100003e,
5974 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5975 static const DWORD ps_sample_code[] =
5977 #if 0
5978 Texture2D t;
5979 SamplerState s;
5981 float4 main(float4 position : SV_POSITION) : SV_Target
5983 float2 p;
5985 p.x = position.x / 640.0f;
5986 p.y = position.y / 480.0f;
5987 return t.Sample(s, p);
5989 #endif
5990 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5991 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5992 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5993 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5994 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5995 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5996 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5997 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5998 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5999 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6001 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
6002 static const DWORD ps_sample_b_code[] =
6004 #if 0
6005 Texture2D t;
6006 SamplerState s;
6008 float bias;
6010 float4 main(float4 position : SV_POSITION) : SV_Target
6012 float2 p;
6014 p.x = position.x / 640.0f;
6015 p.y = position.y / 480.0f;
6016 return t.SampleBias(s, p, bias);
6018 #endif
6019 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
6020 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6021 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6022 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6023 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6024 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6025 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6026 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6027 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
6028 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6029 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6031 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
6032 static const DWORD ps_sample_l_code[] =
6034 #if 0
6035 Texture2D t;
6036 SamplerState s;
6038 float level;
6040 float4 main(float4 position : SV_POSITION) : SV_Target
6042 float2 p;
6044 p.x = position.x / 640.0f;
6045 p.y = position.y / 480.0f;
6046 return t.SampleLevel(s, p, level);
6048 #endif
6049 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
6050 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6051 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6052 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6053 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6054 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6055 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6056 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6057 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
6058 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6059 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6061 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
6062 static const DWORD ps_sample_2d_array_code[] =
6064 #if 0
6065 Texture2DArray t;
6066 SamplerState s;
6068 float layer;
6070 float4 main(float4 position : SV_POSITION) : SV_TARGET
6072 float3 d;
6073 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
6074 t.GetDimensions(d.x, d.y, d.z);
6075 d.z = layer;
6076 return t.Sample(s, p * d);
6078 #endif
6079 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
6080 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6081 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6082 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6083 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
6084 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6085 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6086 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
6087 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
6088 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
6089 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
6090 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
6091 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6093 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
6094 static const DWORD red_data[] =
6096 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6097 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6098 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6099 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6101 static const DWORD green_data[] =
6103 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6104 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6105 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6106 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6108 static const DWORD blue_data[] =
6110 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6111 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6112 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6113 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6115 static const DWORD rgba_level_0[] =
6117 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6118 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6119 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6120 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6122 static const DWORD rgba_level_1[] =
6124 0xffffffff, 0xff0000ff,
6125 0xff000000, 0xff00ff00,
6127 static const DWORD rgba_level_2[] =
6129 0xffff0000,
6131 static const DWORD srgb_data[] =
6133 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
6134 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
6135 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
6136 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
6138 static const BYTE a8_data[] =
6140 0x00, 0x10, 0x20, 0x30,
6141 0x40, 0x50, 0x60, 0x70,
6142 0x80, 0x90, 0xa0, 0xb0,
6143 0xc0, 0xd0, 0xe0, 0xf0,
6145 static const BYTE bc1_data[] =
6147 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6148 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6149 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6150 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6152 static const BYTE bc2_data[] =
6154 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6155 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6156 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6157 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6159 static const BYTE bc3_data[] =
6161 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6162 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6163 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6164 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6166 static const BYTE bc4_data[] =
6168 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6169 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6170 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6171 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6173 static const BYTE bc5_data[] =
6175 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6176 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6177 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6178 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6180 static const BYTE bc6h_u_data[] =
6182 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6183 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6184 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6185 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6187 static const BYTE bc6h_s_data[] =
6189 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6190 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6191 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6192 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6194 static const BYTE bc7_data[] =
6196 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6197 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6198 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6199 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
6201 static const float r32_float[] =
6203 0.0f, 1.0f, 0.5f, 0.50f,
6204 1.0f, 0.0f, 0.0f, 0.75f,
6205 0.0f, 1.0f, 0.5f, 0.25f,
6206 1.0f, 0.0f, 0.0f, 0.75f,
6208 static const DWORD r32_uint[] =
6210 0, 1, 2, 3,
6211 100, 200, 255, 128,
6212 40, 30, 20, 10,
6213 250, 210, 155, 190,
6215 static const DWORD r9g9b9e5_data[] =
6217 0x80000100, 0x80020000, 0x84000000, 0x84000100,
6218 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
6219 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
6220 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
6222 static const struct texture rgba_texture =
6224 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
6226 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
6227 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
6228 {rgba_level_2, sizeof(*rgba_level_2), 0},
6231 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6232 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6233 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
6234 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6235 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
6236 {{a8_data, 4 * sizeof(*a8_data)}}};
6237 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
6238 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
6239 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
6240 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
6241 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
6242 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
6243 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
6244 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
6245 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
6246 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
6247 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
6248 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
6249 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
6250 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
6251 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
6252 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
6253 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6254 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
6255 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6256 static const struct texture array_2d_texture =
6258 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
6260 {red_data, 6 * sizeof(*red_data)},
6261 {green_data, 4 * sizeof(*green_data)},
6262 {blue_data, 5 * sizeof(*blue_data)},
6265 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6266 {{r32_float, 4 * sizeof(*r32_float)}}};
6267 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6268 {{r32_uint, 4 * sizeof(*r32_uint)}}};
6269 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
6270 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
6271 static const DWORD red_colors[] =
6273 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6274 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6275 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6276 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6278 static const DWORD blue_colors[] =
6280 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6281 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6282 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6283 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6285 static const DWORD level_1_colors[] =
6287 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6288 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6289 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6290 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6292 static const DWORD lerp_1_2_colors[] =
6294 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6295 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6296 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6297 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6299 static const DWORD level_2_colors[] =
6301 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6302 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6303 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6304 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6306 static const DWORD srgb_colors[] =
6308 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
6309 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
6310 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
6311 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
6313 static const DWORD a8_colors[] =
6315 0x00000000, 0x10000000, 0x20000000, 0x30000000,
6316 0x40000000, 0x50000000, 0x60000000, 0x70000000,
6317 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
6318 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
6320 static const DWORD bc_colors[] =
6322 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6323 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6324 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6325 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6327 static const DWORD bc4_colors[] =
6329 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
6330 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
6331 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6332 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6334 static const DWORD bc5_colors[] =
6336 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
6337 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
6338 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6339 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6341 static const DWORD bc7_colors[] =
6343 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6344 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6345 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6346 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6348 static const DWORD sint8_colors[] =
6350 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
6351 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
6352 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
6353 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
6355 static const DWORD r32f_colors[] =
6357 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
6358 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6359 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
6360 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6362 static const DWORD r32u_colors[16] =
6364 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6365 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
6366 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
6367 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
6369 static const DWORD r9g9b9e5_colors[16] =
6371 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
6372 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
6373 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
6374 0xff000033, 0xff003300, 0xff330000, 0xff333333,
6376 static const DWORD zero_colors[4 * 4] = {0};
6377 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6379 static const struct texture_test
6381 const struct shader *ps;
6382 const struct texture *texture;
6383 D3D11_FILTER filter;
6384 float lod_bias;
6385 float min_lod;
6386 float max_lod;
6387 float ps_constant;
6388 const DWORD *expected_colors;
6390 texture_tests[] =
6392 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
6393 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
6394 #define MIP_MAX D3D11_FLOAT32_MAX
6395 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6396 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6397 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6398 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6399 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6400 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6401 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6402 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6403 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6404 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6405 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6406 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6407 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6408 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6409 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6410 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6411 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6412 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6413 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6414 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6415 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6416 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6417 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6418 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6419 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6420 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6421 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6422 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6423 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6424 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6425 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6426 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6427 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6428 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6429 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6430 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6431 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6432 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6433 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6434 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
6435 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6436 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6437 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6438 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6439 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6440 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
6441 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
6442 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
6443 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
6444 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
6445 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
6446 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
6447 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
6448 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6449 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6450 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6451 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6452 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
6453 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6454 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
6455 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
6456 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
6457 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
6458 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6459 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
6460 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
6461 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
6462 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
6463 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
6464 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
6465 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
6466 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
6467 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6468 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6469 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6470 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6471 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6472 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6473 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6474 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6475 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6476 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6477 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6478 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
6479 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
6480 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
6481 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
6482 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
6483 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
6484 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
6485 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
6486 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
6487 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
6488 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
6489 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
6490 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
6491 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
6492 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
6493 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
6494 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6495 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6496 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
6497 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6498 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6499 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
6500 #undef POINT
6501 #undef POINT_LINEAR
6502 #undef MIP_MAX
6504 static const struct srv_test
6506 const struct shader *ps;
6507 const struct texture *texture;
6508 struct srv_desc srv_desc;
6509 float ps_constant;
6510 const DWORD *expected_colors;
6512 srv_tests[] =
6514 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
6515 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
6516 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
6517 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
6518 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
6519 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
6520 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
6521 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
6522 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
6523 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
6524 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
6525 #define R32_UINT DXGI_FORMAT_R32_UINT
6526 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
6527 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6528 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6529 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6530 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6531 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6532 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6533 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
6534 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
6535 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
6536 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
6537 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
6538 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
6539 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
6540 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
6541 #undef TEX_2D
6542 #undef TEX_2D_ARRAY
6543 #undef BC1_UNORM
6544 #undef BC1_UNORM_SRGB
6545 #undef BC2_UNORM
6546 #undef BC2_UNORM_SRGB
6547 #undef BC3_UNORM
6548 #undef BC3_UNORM_SRGB
6549 #undef R8G8B8A8_UNORM_SRGB
6550 #undef R8G8B8A8_UNORM
6551 #undef R32_FLOAT
6552 #undef R32_UINT
6553 #undef FMT_UNKNOWN
6556 if (!init_test_context(&test_context, NULL))
6557 return;
6559 device = test_context.device;
6560 context = test_context.immediate_context;
6561 feature_level = ID3D11Device_GetFeatureLevel(device);
6563 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6565 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6567 texture_desc.SampleDesc.Count = 1;
6568 texture_desc.SampleDesc.Quality = 0;
6569 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6570 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6571 texture_desc.CPUAccessFlags = 0;
6572 texture_desc.MiscFlags = 0;
6574 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6575 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
6576 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
6577 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
6578 sampler_desc.MipLODBias = 0.0f;
6579 sampler_desc.MaxAnisotropy = 0;
6580 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
6581 sampler_desc.BorderColor[0] = 0.0f;
6582 sampler_desc.BorderColor[1] = 0.0f;
6583 sampler_desc.BorderColor[2] = 0.0f;
6584 sampler_desc.BorderColor[3] = 0.0f;
6585 sampler_desc.MinLOD = 0.0f;
6586 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6588 ps = NULL;
6589 srv = NULL;
6590 sampler = NULL;
6591 texture = NULL;
6592 current_ps = NULL;
6593 current_texture = NULL;
6594 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6596 const struct texture_test *test = &texture_tests[i];
6598 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
6599 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
6600 && feature_level < D3D_FEATURE_LEVEL_11_0)
6602 skip("Feature level >= 11.0 is required for BC7 tests.\n");
6603 continue;
6606 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
6607 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
6608 && feature_level < D3D_FEATURE_LEVEL_11_0)
6610 skip("Feature level >= 11.0 is required for BC6H tests.\n");
6611 continue;
6614 if (current_ps != test->ps)
6616 if (ps)
6617 ID3D11PixelShader_Release(ps);
6619 current_ps = test->ps;
6621 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6622 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6624 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6627 if (current_texture != test->texture)
6629 if (texture)
6630 ID3D11Texture2D_Release(texture);
6631 if (srv)
6632 ID3D11ShaderResourceView_Release(srv);
6634 current_texture = test->texture;
6636 if (current_texture)
6638 texture_desc.Width = current_texture->width;
6639 texture_desc.Height = current_texture->height;
6640 texture_desc.MipLevels = current_texture->miplevel_count;
6641 texture_desc.ArraySize = current_texture->array_size;
6642 texture_desc.Format = current_texture->format;
6644 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6645 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6647 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6648 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6650 else
6652 texture = NULL;
6653 srv = NULL;
6656 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6659 if (!sampler || (sampler_desc.Filter != test->filter
6660 || sampler_desc.MipLODBias != test->lod_bias
6661 || sampler_desc.MinLOD != test->min_lod
6662 || sampler_desc.MaxLOD != test->max_lod))
6664 if (sampler)
6665 ID3D11SamplerState_Release(sampler);
6667 sampler_desc.Filter = test->filter;
6668 sampler_desc.MipLODBias = test->lod_bias;
6669 sampler_desc.MinLOD = test->min_lod;
6670 sampler_desc.MaxLOD = test->max_lod;
6672 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6673 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6675 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6678 ps_constant.x = test->ps_constant;
6679 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6681 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6683 draw_quad(&test_context);
6685 get_texture_readback(test_context.backbuffer, 0, &rb);
6686 for (y = 0; y < 4; ++y)
6688 for (x = 0; x < 4; ++x)
6690 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6691 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
6692 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6695 release_resource_readback(&rb);
6697 if (srv)
6698 ID3D11ShaderResourceView_Release(srv);
6699 ID3D11SamplerState_Release(sampler);
6700 if (texture)
6701 ID3D11Texture2D_Release(texture);
6702 ID3D11PixelShader_Release(ps);
6704 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
6706 win_skip("SRV tests are broken on WARP.\n");
6707 ID3D11Buffer_Release(cb);
6708 release_test_context(&test_context);
6709 return;
6712 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6713 sampler_desc.MipLODBias = 0.0f;
6714 sampler_desc.MinLOD = 0.0f;
6715 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6717 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6718 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6720 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6722 ps = NULL;
6723 srv = NULL;
6724 texture = NULL;
6725 current_ps = NULL;
6726 current_texture = NULL;
6727 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
6729 const struct srv_test *test = &srv_tests[i];
6731 if (current_ps != test->ps)
6733 if (ps)
6734 ID3D11PixelShader_Release(ps);
6736 current_ps = test->ps;
6738 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6739 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6741 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6744 if (current_texture != test->texture)
6746 if (texture)
6747 ID3D11Texture2D_Release(texture);
6749 current_texture = test->texture;
6751 texture_desc.Width = current_texture->width;
6752 texture_desc.Height = current_texture->height;
6753 texture_desc.MipLevels = current_texture->miplevel_count;
6754 texture_desc.ArraySize = current_texture->array_size;
6755 texture_desc.Format = current_texture->format;
6757 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6758 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6761 if (srv)
6762 ID3D11ShaderResourceView_Release(srv);
6764 get_srv_desc(&srv_desc, &test->srv_desc);
6765 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
6766 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6768 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6770 ps_constant.x = test->ps_constant;
6771 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6773 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6775 draw_quad(&test_context);
6777 get_texture_readback(test_context.backbuffer, 0, &rb);
6778 for (y = 0; y < 4; ++y)
6780 for (x = 0; x < 4; ++x)
6782 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6783 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
6784 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6787 release_resource_readback(&rb);
6789 ID3D11PixelShader_Release(ps);
6790 ID3D11Texture2D_Release(texture);
6791 ID3D11ShaderResourceView_Release(srv);
6792 ID3D11SamplerState_Release(sampler);
6794 ID3D11Buffer_Release(cb);
6795 release_test_context(&test_context);
6798 static void test_cube_maps(void)
6800 struct shader
6802 const DWORD *code;
6803 size_t size;
6806 unsigned int i, j, sub_resource_idx, sub_resource_count;
6807 struct d3d11_test_context test_context;
6808 D3D11_TEXTURE2D_DESC texture_desc;
6809 const struct shader *current_ps;
6810 D3D_FEATURE_LEVEL feature_level;
6811 ID3D11ShaderResourceView *srv;
6812 ID3D11DeviceContext *context;
6813 ID3D11Texture2D *rtv_texture;
6814 ID3D11RenderTargetView *rtv;
6815 struct vec4 expected_result;
6816 ID3D11Resource *texture;
6817 ID3D11PixelShader *ps;
6818 ID3D11Device *device;
6819 float data[64 * 64];
6820 ID3D11Buffer *cb;
6821 HRESULT hr;
6822 RECT rect;
6823 struct
6825 unsigned int face;
6826 unsigned int level;
6827 unsigned int cube;
6828 unsigned int padding;
6829 } constant;
6831 static const DWORD ps_cube_code[] =
6833 #if 0
6834 TextureCube t;
6835 SamplerState s;
6837 uint face;
6838 uint level;
6840 float4 main(float4 position : SV_POSITION) : SV_Target
6842 float2 p;
6843 p.x = position.x / 640.0f;
6844 p.y = position.y / 480.0f;
6846 float3 coord;
6847 switch (face)
6849 case 0:
6850 coord = float3(1.0f, p.x, p.y);
6851 break;
6852 case 1:
6853 coord = float3(-1.0f, p.x, p.y);
6854 break;
6855 case 2:
6856 coord = float3(p.x, 1.0f, p.y);
6857 break;
6858 case 3:
6859 coord = float3(p.x, -1.0f, p.y);
6860 break;
6861 case 4:
6862 coord = float3(p.x, p.y, 1.0f);
6863 break;
6864 case 5:
6865 default:
6866 coord = float3(p.x, p.y, -1.0f);
6867 break;
6869 return t.SampleLevel(s, coord, level);
6871 #endif
6872 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
6873 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6874 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6875 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6876 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
6877 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6878 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6879 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
6880 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
6881 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
6882 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
6883 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
6884 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
6885 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6886 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
6887 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
6888 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
6889 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
6890 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
6891 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
6892 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6893 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
6894 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
6895 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
6896 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
6898 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
6899 static const DWORD ps_cube_array_code[] =
6901 #if 0
6902 TextureCubeArray t;
6903 SamplerState s;
6905 uint face;
6906 uint level;
6907 uint cube;
6909 float4 main(float4 position : SV_POSITION) : SV_Target
6911 float2 p;
6912 p.x = position.x / 640.0f;
6913 p.y = position.y / 480.0f;
6915 float3 coord;
6916 switch (face)
6918 case 0:
6919 coord = float3(1.0f, p.x, p.y);
6920 break;
6921 case 1:
6922 coord = float3(-1.0f, p.x, p.y);
6923 break;
6924 case 2:
6925 coord = float3(p.x, 1.0f, p.y);
6926 break;
6927 case 3:
6928 coord = float3(p.x, -1.0f, p.y);
6929 break;
6930 case 4:
6931 coord = float3(p.x, p.y, 1.0f);
6932 break;
6933 case 5:
6934 default:
6935 coord = float3(p.x, p.y, -1.0f);
6936 break;
6938 return t.SampleLevel(s, float4(coord, cube), level);
6940 #endif
6941 0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
6942 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6943 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6944 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6945 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
6946 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
6947 0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
6948 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
6949 0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
6950 0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6951 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
6952 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
6953 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
6954 0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
6955 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
6956 0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
6957 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
6958 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
6959 0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6960 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
6961 0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
6962 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
6963 0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
6964 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
6965 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
6966 0x00000001, 0x0100003e,
6968 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
6969 static const struct ps_test
6971 const struct shader *ps;
6972 unsigned int miplevel_count;
6973 unsigned int array_size;
6975 ps_tests[] =
6977 {&ps_cube, 1, 6},
6978 {&ps_cube, 2, 6},
6979 {&ps_cube, 3, 6},
6980 {&ps_cube, 0, 6},
6982 {&ps_cube_array, 1, 12},
6983 {&ps_cube_array, 2, 12},
6984 {&ps_cube_array, 3, 12},
6985 {&ps_cube_array, 0, 12},
6988 if (!init_test_context(&test_context, NULL))
6989 return;
6991 device = test_context.device;
6992 context = test_context.immediate_context;
6993 feature_level = ID3D11Device_GetFeatureLevel(device);
6995 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
6996 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
6997 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
6998 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6999 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
7000 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7002 memset(&constant, 0, sizeof(constant));
7003 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
7005 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7006 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7008 ps = NULL;
7009 current_ps = NULL;
7010 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
7012 const struct ps_test *test = &ps_tests[i];
7014 if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
7016 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
7017 continue;
7020 if (current_ps != test->ps)
7022 if (ps)
7023 ID3D11PixelShader_Release(ps);
7025 current_ps = test->ps;
7027 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
7028 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7029 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7032 if (!test->miplevel_count)
7034 srv = NULL;
7035 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7037 memset(&expected_result, 0, sizeof(expected_result));
7039 memset(&constant, 0, sizeof(constant));
7040 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7041 draw_quad(&test_context);
7042 check_texture_vec4(rtv_texture, &expected_result, 0);
7043 constant.level = 1;
7044 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7045 draw_quad(&test_context);
7046 check_texture_vec4(rtv_texture, &expected_result, 0);
7047 continue;
7050 texture_desc.Width = 64;
7051 texture_desc.Height = 64;
7052 texture_desc.MipLevels = test->miplevel_count;
7053 texture_desc.ArraySize = test->array_size;
7054 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7055 texture_desc.SampleDesc.Count = 1;
7056 texture_desc.SampleDesc.Quality = 0;
7057 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7058 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
7059 texture_desc.CPUAccessFlags = 0;
7060 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
7061 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
7062 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7064 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
7065 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7066 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7068 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7069 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7071 for (j = 0; j < ARRAY_SIZE(data); ++j)
7072 data[j] = sub_resource_idx;
7073 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, sub_resource_idx, NULL,
7074 data, texture_desc.Width * sizeof(*data), 0);
7077 expected_result.y = expected_result.z = 0.0f;
7078 expected_result.w = 1.0f;
7079 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7081 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
7082 constant.level = sub_resource_idx % texture_desc.MipLevels;
7083 constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
7084 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7086 draw_quad(&test_context);
7087 expected_result.x = sub_resource_idx;
7088 /* Avoid testing values affected by seamless cube map filtering. */
7089 SetRect(&rect, 100, 100, 540, 380);
7090 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
7093 ID3D11Resource_Release(texture);
7094 ID3D11ShaderResourceView_Release(srv);
7096 ID3D11PixelShader_Release(ps);
7098 ID3D11Buffer_Release(cb);
7099 ID3D11RenderTargetView_Release(rtv);
7100 ID3D11Texture2D_Release(rtv_texture);
7101 release_test_context(&test_context);
7104 static void test_depth_stencil_sampling(void)
7106 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
7107 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
7108 ID3D11SamplerState *cmp_sampler, *sampler;
7109 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
7110 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
7111 struct d3d11_test_context test_context;
7112 ID3D11Texture2D *texture, *rt_texture;
7113 D3D11_TEXTURE2D_DESC texture_desc;
7114 D3D11_SAMPLER_DESC sampler_desc;
7115 ID3D11DeviceContext *context;
7116 ID3D11DepthStencilView *dsv;
7117 ID3D11RenderTargetView *rtv;
7118 struct vec4 ps_constant;
7119 ID3D11Device *device;
7120 ID3D11Buffer *cb;
7121 unsigned int i;
7122 HRESULT hr;
7124 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
7125 static const DWORD ps_compare_code[] =
7127 #if 0
7128 Texture2D t;
7129 SamplerComparisonState s;
7131 float ref;
7133 float4 main(float4 position : SV_Position) : SV_Target
7135 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
7137 #endif
7138 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
7139 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7140 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7141 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7142 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
7143 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
7144 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7145 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
7146 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
7147 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
7148 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
7149 0x0100003e,
7151 static const DWORD ps_sample_code[] =
7153 #if 0
7154 Texture2D t;
7155 SamplerState s;
7157 float4 main(float4 position : SV_Position) : SV_Target
7159 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
7161 #endif
7162 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
7163 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7164 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7165 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7166 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7167 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7168 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7169 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7170 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7171 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7173 static const DWORD ps_stencil_code[] =
7175 #if 0
7176 Texture2D<uint4> t;
7178 float4 main(float4 position : SV_Position) : SV_Target
7180 float2 s;
7181 t.GetDimensions(s.x, s.y);
7182 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
7184 #endif
7185 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
7186 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7187 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7188 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7189 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
7190 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
7191 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
7192 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
7193 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
7194 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
7195 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
7196 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7197 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
7199 static const DWORD ps_depth_stencil_code[] =
7201 #if 0
7202 SamplerState samp;
7203 Texture2D depth_tex;
7204 Texture2D<uint4> stencil_tex;
7206 float main(float4 position: SV_Position) : SV_Target
7208 float2 s, p;
7209 float depth, stencil;
7210 depth_tex.GetDimensions(s.x, s.y);
7211 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
7212 depth = depth_tex.Sample(samp, p).r;
7213 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
7214 return depth + stencil;
7216 #endif
7217 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
7218 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7219 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7220 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7221 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
7222 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7223 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7224 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
7225 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
7226 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
7227 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
7228 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
7229 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
7230 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
7231 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
7232 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
7234 static const struct test
7236 DXGI_FORMAT typeless_format;
7237 DXGI_FORMAT dsv_format;
7238 DXGI_FORMAT depth_view_format;
7239 DXGI_FORMAT stencil_view_format;
7241 tests[] =
7243 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
7244 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
7245 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
7246 DXGI_FORMAT_R32_FLOAT},
7247 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
7248 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
7249 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
7250 DXGI_FORMAT_R16_UNORM},
7253 if (!init_test_context(&test_context, NULL))
7254 return;
7256 device = test_context.device;
7257 context = test_context.immediate_context;
7259 if (is_amd_device(device))
7261 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
7262 win_skip("Some AMD drivers have a bug affecting the test.\n");
7263 release_test_context(&test_context);
7264 return;
7267 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
7268 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7269 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7270 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7271 sampler_desc.MipLODBias = 0.0f;
7272 sampler_desc.MaxAnisotropy = 0;
7273 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
7274 sampler_desc.BorderColor[0] = 0.0f;
7275 sampler_desc.BorderColor[1] = 0.0f;
7276 sampler_desc.BorderColor[2] = 0.0f;
7277 sampler_desc.BorderColor[3] = 0.0f;
7278 sampler_desc.MinLOD = 0.0f;
7279 sampler_desc.MaxLOD = 0.0f;
7280 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
7281 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7283 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7284 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7285 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
7286 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7288 texture_desc.Width = 640;
7289 texture_desc.Height = 480;
7290 texture_desc.MipLevels = 1;
7291 texture_desc.ArraySize = 1;
7292 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7293 texture_desc.SampleDesc.Count = 1;
7294 texture_desc.SampleDesc.Quality = 0;
7295 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7296 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7297 texture_desc.CPUAccessFlags = 0;
7298 texture_desc.MiscFlags = 0;
7299 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
7300 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7301 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
7302 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
7303 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7305 memset(&ps_constant, 0, sizeof(ps_constant));
7306 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
7307 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7309 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
7310 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7311 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
7312 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7313 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
7314 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7315 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
7316 &ps_depth_stencil);
7317 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7319 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7321 texture_desc.Format = tests[i].typeless_format;
7322 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
7323 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7324 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
7325 texture_desc.Format, hr);
7327 dsv_desc.Format = tests[i].dsv_format;
7328 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
7329 dsv_desc.Flags = 0;
7330 U(dsv_desc).Texture2D.MipSlice = 0;
7331 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7332 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
7333 dsv_desc.Format, hr);
7335 srv_desc.Format = tests[i].depth_view_format;
7336 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
7337 U(srv_desc).Texture2D.MostDetailedMip = 0;
7338 U(srv_desc).Texture2D.MipLevels = 1;
7339 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
7340 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
7341 srv_desc.Format, hr);
7343 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
7344 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
7345 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
7347 ps_constant.x = 0.5f;
7348 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7349 NULL, &ps_constant, 0, 0);
7351 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7352 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7353 draw_quad(&test_context);
7354 check_texture_float(rt_texture, 0.0f, 2);
7356 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
7357 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7358 draw_quad(&test_context);
7359 check_texture_float(rt_texture, 1.0f, 2);
7361 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
7362 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7363 draw_quad(&test_context);
7364 check_texture_float(rt_texture, 0.0f, 2);
7366 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
7367 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7368 draw_quad(&test_context);
7369 check_texture_float(rt_texture, 0.0f, 2);
7371 ps_constant.x = 0.7f;
7372 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7373 NULL, &ps_constant, 0, 0);
7375 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7376 draw_quad(&test_context);
7377 check_texture_float(rt_texture, 1.0f, 2);
7379 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
7380 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7382 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7383 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7384 draw_quad(&test_context);
7385 check_texture_float(rt_texture, 1.0f, 2);
7387 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
7388 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7389 draw_quad(&test_context);
7390 check_texture_float(rt_texture, 0.2f, 2);
7392 if (!tests[i].stencil_view_format)
7394 ID3D11DepthStencilView_Release(dsv);
7395 ID3D11ShaderResourceView_Release(depth_srv);
7396 ID3D11Texture2D_Release(texture);
7397 continue;
7400 srv_desc.Format = tests[i].stencil_view_format;
7401 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
7402 if (hr == E_OUTOFMEMORY)
7404 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
7405 ID3D11DepthStencilView_Release(dsv);
7406 ID3D11ShaderResourceView_Release(depth_srv);
7407 ID3D11Texture2D_Release(texture);
7408 continue;
7410 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
7411 srv_desc.Format, hr);
7413 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
7414 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
7416 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
7417 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7418 draw_quad(&test_context);
7419 check_texture_float(rt_texture, 0.0f, 0);
7421 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
7422 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7423 draw_quad(&test_context);
7424 check_texture_float(rt_texture, 100.0f, 0);
7426 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
7427 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7428 draw_quad(&test_context);
7429 check_texture_float(rt_texture, 255.0f, 0);
7431 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
7432 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
7433 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
7435 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
7436 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7437 draw_quad(&test_context);
7438 check_texture_float(rt_texture, 3.3f, 2);
7440 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
7441 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7442 draw_quad(&test_context);
7443 check_texture_float(rt_texture, 4.0f, 2);
7445 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
7446 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7447 draw_quad(&test_context);
7448 check_texture_float(rt_texture, 0.0f, 2);
7450 ID3D11DepthStencilView_Release(dsv);
7451 ID3D11ShaderResourceView_Release(depth_srv);
7452 ID3D11ShaderResourceView_Release(stencil_srv);
7453 ID3D11Texture2D_Release(texture);
7456 ID3D11Buffer_Release(cb);
7457 ID3D11PixelShader_Release(ps_cmp);
7458 ID3D11PixelShader_Release(ps_depth);
7459 ID3D11PixelShader_Release(ps_depth_stencil);
7460 ID3D11PixelShader_Release(ps_stencil);
7461 ID3D11RenderTargetView_Release(rtv);
7462 ID3D11SamplerState_Release(cmp_sampler);
7463 ID3D11SamplerState_Release(sampler);
7464 ID3D11Texture2D_Release(rt_texture);
7465 release_test_context(&test_context);
7468 static void test_sample_c_lz(void)
7470 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
7471 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
7472 struct d3d11_test_context test_context;
7473 ID3D11Texture2D *texture, *rt_texture;
7474 D3D11_TEXTURE2D_DESC texture_desc;
7475 D3D11_SAMPLER_DESC sampler_desc;
7476 ID3D11ShaderResourceView *srv;
7477 ID3D11DeviceContext *context;
7478 ID3D11DepthStencilView *dsv;
7479 ID3D11RenderTargetView *rtv;
7480 ID3D11SamplerState *sampler;
7481 struct vec4 ps_constant;
7482 ID3D11PixelShader *ps;
7483 ID3D11Device *device;
7484 ID3D11Buffer *cb;
7485 unsigned int i;
7486 HRESULT hr;
7487 RECT rect;
7489 static const float clear_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
7490 static const DWORD ps_array_code[] =
7492 #if 0
7493 Texture2DArray t;
7494 SamplerComparisonState s;
7496 float ref;
7497 float layer;
7499 float4 main(float4 position : SV_Position) : SV_Target
7501 return t.SampleCmpLevelZero(s, float3(position.x / 640.0f, position.y / 480.0f, layer), ref);
7503 #endif
7504 0x43425844, 0xfe28b3c3, 0xdd7ef404, 0x8d5874a1, 0x984ff182, 0x00000001, 0x00000180, 0x00000003,
7505 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7506 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7507 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7508 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000e4, 0x00000041,
7509 0x00000039, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
7510 0x00000000, 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
7511 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
7512 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
7513 0x06000036, 0x00100042, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0c000047, 0x00100012,
7514 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000, 0x0020800a,
7515 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
7517 static const DWORD ps_cube_code[] =
7519 #if 0
7520 TextureCube t;
7521 SamplerComparisonState s;
7523 float ref;
7524 float face;
7526 float4 main(float4 position : SV_Position) : SV_Target
7528 float2 p;
7529 p.x = position.x / 640.0f;
7530 p.y = position.y / 480.0f;
7532 float3 coord;
7533 switch ((uint)face)
7535 case 0:
7536 coord = float3(1.0f, p.x, p.y);
7537 break;
7538 case 1:
7539 coord = float3(-1.0f, p.x, p.y);
7540 break;
7541 case 2:
7542 coord = float3(p.x, 1.0f, p.y);
7543 break;
7544 case 3:
7545 coord = float3(p.x, -1.0f, p.y);
7546 break;
7547 case 4:
7548 coord = float3(p.x, p.y, 1.0f);
7549 break;
7550 case 5:
7551 default:
7552 coord = float3(p.x, p.y, -1.0f);
7553 break;
7556 return t.SampleCmpLevelZero(s, coord, ref);
7558 #endif
7559 0x43425844, 0xde5655e5, 0x1b116fa1, 0xfce9e757, 0x41c28aac, 0x00000001, 0x00000328, 0x00000003,
7560 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7561 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7562 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7563 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
7564 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
7565 0x00000000, 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
7566 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600001c, 0x00100012,
7567 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0300004c, 0x0010000a, 0x00000000, 0x03000006,
7568 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x3f800000, 0x0a000038,
7569 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889,
7570 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, 0x00100012, 0x00000000,
7571 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
7572 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000002,
7573 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000,
7574 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
7575 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
7576 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
7577 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, 0x0a000038, 0x00100032,
7578 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
7579 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x0100000a, 0x0a000038,
7580 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000,
7581 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x01000017,
7582 0x0c000047, 0x00100012, 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000,
7583 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006,
7584 0x00000000, 0x0100003e,
7586 static const float depth_values[] = {1.0f, 0.0f, 0.5f, 0.6f, 0.4f, 0.1f};
7587 static const struct
7589 unsigned int layer;
7590 float d_ref;
7591 float expected;
7593 tests[] =
7595 {0, 0.5f, 0.0f},
7596 {1, 0.5f, 1.0f},
7597 {2, 0.5f, 0.0f},
7598 {3, 0.5f, 0.0f},
7599 {4, 0.5f, 1.0f},
7600 {5, 0.5f, 1.0f},
7602 {0, 0.0f, 0.0f},
7603 {1, 0.0f, 0.0f},
7604 {2, 0.0f, 0.0f},
7605 {3, 0.0f, 0.0f},
7606 {4, 0.0f, 0.0f},
7607 {5, 0.0f, 0.0f},
7609 {0, 1.0f, 0.0f},
7610 {1, 1.0f, 1.0f},
7611 {2, 1.0f, 1.0f},
7612 {3, 1.0f, 1.0f},
7613 {4, 1.0f, 1.0f},
7614 {5, 1.0f, 1.0f},
7617 if (!init_test_context(&test_context, NULL))
7618 return;
7620 device = test_context.device;
7621 context = test_context.immediate_context;
7623 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
7624 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7625 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7626 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7627 sampler_desc.MipLODBias = 0.0f;
7628 sampler_desc.MaxAnisotropy = 0;
7629 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
7630 sampler_desc.BorderColor[0] = 0.0f;
7631 sampler_desc.BorderColor[1] = 0.0f;
7632 sampler_desc.BorderColor[2] = 0.0f;
7633 sampler_desc.BorderColor[3] = 0.0f;
7634 sampler_desc.MinLOD = 0.0f;
7635 sampler_desc.MaxLOD = 10.0f;
7636 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
7637 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7639 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
7640 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7641 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
7642 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7643 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
7644 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7645 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7647 memset(&ps_constant, 0, sizeof(ps_constant));
7648 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
7650 /* 2D array texture */
7651 texture_desc.Width = 32;
7652 texture_desc.Height = 32;
7653 texture_desc.MipLevels = 2;
7654 texture_desc.ArraySize = ARRAY_SIZE(depth_values);
7655 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
7656 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
7657 texture_desc.MiscFlags = 0;
7658 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7659 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7661 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
7663 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
7664 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
7665 dsv_desc.Flags = 0;
7666 U(dsv_desc).Texture2DArray.MipSlice = 0;
7667 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
7668 U(dsv_desc).Texture2DArray.ArraySize = 1;
7670 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7671 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7672 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
7673 ID3D11DepthStencilView_Release(dsv);
7675 U(dsv_desc).Texture2DArray.MipSlice = 1;
7676 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7677 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7678 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7679 ID3D11DepthStencilView_Release(dsv);
7682 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
7683 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
7684 U(srv_desc).Texture2DArray.MostDetailedMip = 0;
7685 U(srv_desc).Texture2DArray.MipLevels = ~0u;
7686 U(srv_desc).Texture2DArray.FirstArraySlice = 0;
7687 U(srv_desc).Texture2DArray.ArraySize = ~0u;
7688 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
7689 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7691 hr = ID3D11Device_CreatePixelShader(device, ps_array_code, sizeof(ps_array_code), NULL, &ps);
7692 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7694 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7695 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7696 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7697 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7699 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7701 ps_constant.x = tests[i].d_ref;
7702 ps_constant.y = tests[i].layer;
7703 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7704 NULL, &ps_constant, 0, 0);
7705 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
7706 draw_quad(&test_context);
7707 check_texture_float(rt_texture, tests[i].expected, 2);
7710 ID3D11Texture2D_Release(texture);
7711 ID3D11ShaderResourceView_Release(srv);
7712 ID3D11PixelShader_Release(ps);
7714 /* cube texture */
7715 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
7716 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7717 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7719 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
7721 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
7722 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
7723 dsv_desc.Flags = 0;
7724 U(dsv_desc).Texture2DArray.MipSlice = 0;
7725 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
7726 U(dsv_desc).Texture2DArray.ArraySize = 1;
7728 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7729 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7730 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
7731 ID3D11DepthStencilView_Release(dsv);
7733 U(dsv_desc).Texture2DArray.MipSlice = 1;
7734 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7735 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7736 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7737 ID3D11DepthStencilView_Release(dsv);
7740 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
7741 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
7742 U(srv_desc).TextureCube.MostDetailedMip = 0;
7743 U(srv_desc).TextureCube.MipLevels = ~0u;
7744 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
7745 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7747 hr = ID3D11Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), NULL, &ps);
7748 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7750 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7751 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7752 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7753 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7755 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7757 ps_constant.x = tests[i].d_ref;
7758 ps_constant.y = tests[i].layer;
7759 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7760 NULL, &ps_constant, 0, 0);
7761 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
7762 draw_quad(&test_context);
7763 /* Avoid testing values affected by seamless cube map filtering. */
7764 SetRect(&rect, 100, 100, 540, 380);
7765 check_texture_sub_resource_float(rt_texture, 0, &rect, tests[i].expected, 2);
7768 ID3D11Texture2D_Release(texture);
7769 ID3D11ShaderResourceView_Release(srv);
7771 ID3D11Buffer_Release(cb);
7772 ID3D11PixelShader_Release(ps);
7773 ID3D11RenderTargetView_Release(rtv);
7774 ID3D11SamplerState_Release(sampler);
7775 ID3D11Texture2D_Release(rt_texture);
7776 release_test_context(&test_context);
7779 static void test_multiple_render_targets(void)
7781 D3D11_TEXTURE2D_DESC texture_desc;
7782 ID3D11InputLayout *input_layout;
7783 unsigned int stride, offset, i;
7784 ID3D11RenderTargetView *rtv[4];
7785 ID3D11DeviceContext *context;
7786 ID3D11Texture2D *rt[4];
7787 ID3D11VertexShader *vs;
7788 ID3D11PixelShader *ps;
7789 ID3D11Device *device;
7790 D3D11_VIEWPORT vp;
7791 ID3D11Buffer *vb;
7792 ULONG refcount;
7793 HRESULT hr;
7795 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
7797 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
7799 static const DWORD vs_code[] =
7801 #if 0
7802 float4 main(float4 position : POSITION) : SV_POSITION
7804 return position;
7806 #endif
7807 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
7808 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7809 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7810 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
7811 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
7812 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7813 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
7815 static const DWORD ps_code[] =
7817 #if 0
7818 struct output
7820 float4 t1 : SV_TARGET0;
7821 float4 t2 : SV_Target1;
7822 float4 t3 : SV_TARGET2;
7823 float4 t4 : SV_Target3;
7826 output main(float4 position : SV_POSITION)
7828 struct output o;
7829 o.t1 = (float4)1.0f;
7830 o.t2 = (float4)0.5f;
7831 o.t3 = (float4)0.2f;
7832 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
7833 return o;
7835 #endif
7836 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
7837 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7838 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7839 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
7840 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
7841 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
7842 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
7843 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
7844 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
7845 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
7846 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
7847 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
7848 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
7849 0x3f800000, 0x0100003e,
7851 static const struct vec2 quad[] =
7853 {-1.0f, -1.0f},
7854 {-1.0f, 1.0f},
7855 { 1.0f, -1.0f},
7856 { 1.0f, 1.0f},
7858 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
7860 if (!(device = create_device(NULL)))
7862 skip("Failed to create device.\n");
7863 return;
7866 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
7867 vs_code, sizeof(vs_code), &input_layout);
7868 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7870 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7872 texture_desc.Width = 640;
7873 texture_desc.Height = 480;
7874 texture_desc.MipLevels = 1;
7875 texture_desc.ArraySize = 1;
7876 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7877 texture_desc.SampleDesc.Count = 1;
7878 texture_desc.SampleDesc.Quality = 0;
7879 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7880 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7881 texture_desc.CPUAccessFlags = 0;
7882 texture_desc.MiscFlags = 0;
7884 for (i = 0; i < ARRAY_SIZE(rt); ++i)
7886 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
7887 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
7889 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
7890 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
7893 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
7894 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7895 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7896 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7898 ID3D11Device_GetImmediateContext(device, &context);
7900 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
7901 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
7902 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7903 stride = sizeof(*quad);
7904 offset = 0;
7905 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
7906 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
7907 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7909 vp.TopLeftX = 0.0f;
7910 vp.TopLeftY = 0.0f;
7911 vp.Width = 640.0f;
7912 vp.Height = 480.0f;
7913 vp.MinDepth = 0.0f;
7914 vp.MaxDepth = 1.0f;
7915 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
7917 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7918 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
7920 ID3D11DeviceContext_Draw(context, 4, 0);
7922 check_texture_color(rt[0], 0xffffffff, 2);
7923 check_texture_color(rt[1], 0x7f7f7f7f, 2);
7924 check_texture_color(rt[2], 0x33333333, 2);
7925 check_texture_color(rt[3], 0xff7f3300, 2);
7927 ID3D11Buffer_Release(vb);
7928 ID3D11PixelShader_Release(ps);
7929 ID3D11VertexShader_Release(vs);
7930 ID3D11InputLayout_Release(input_layout);
7931 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7933 ID3D11RenderTargetView_Release(rtv[i]);
7934 ID3D11Texture2D_Release(rt[i]);
7936 ID3D11DeviceContext_Release(context);
7937 refcount = ID3D11Device_Release(device);
7938 ok(!refcount, "Device has %u references left.\n", refcount);
7941 static void test_render_target_views(void)
7943 struct texture
7945 UINT miplevel_count;
7946 UINT array_size;
7949 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
7950 static struct test
7952 struct texture texture;
7953 struct rtv_desc rtv;
7954 DWORD expected_colors[4];
7956 tests[] =
7958 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7959 {0xff0000ff, 0x00000000}},
7960 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
7961 {0x00000000, 0xff0000ff}},
7962 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7963 {0xff0000ff, 0x00000000}},
7964 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7965 {0x00000000, 0xff0000ff}},
7966 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7967 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7968 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7969 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7970 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7971 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7972 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
7973 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7974 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
7975 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7976 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
7977 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7978 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7979 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7980 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7981 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7982 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7983 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7984 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7985 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7986 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
7987 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7990 struct d3d11_test_context test_context;
7991 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7992 D3D11_TEXTURE2D_DESC texture_desc;
7993 ID3D11DeviceContext *context;
7994 ID3D11RenderTargetView *rtv;
7995 ID3D11Texture2D *texture;
7996 ID3D11Device *device;
7997 unsigned int i, j, k;
7998 void *data;
7999 HRESULT hr;
8001 if (!init_test_context(&test_context, NULL))
8002 return;
8004 device = test_context.device;
8005 context = test_context.immediate_context;
8007 texture_desc.Width = 32;
8008 texture_desc.Height = 32;
8009 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8010 texture_desc.SampleDesc.Count = 1;
8011 texture_desc.SampleDesc.Quality = 0;
8012 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8013 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8014 texture_desc.CPUAccessFlags = 0;
8015 texture_desc.MiscFlags = 0;
8017 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, texture_desc.Width * texture_desc.Height * 4);
8018 ok(!!data, "Failed to allocate memory.\n");
8020 for (i = 0; i < ARRAY_SIZE(tests); ++i)
8022 const struct test *test = &tests[i];
8023 unsigned int sub_resource_count;
8025 texture_desc.MipLevels = test->texture.miplevel_count;
8026 texture_desc.ArraySize = test->texture.array_size;
8028 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8029 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
8031 get_rtv_desc(&rtv_desc, &test->rtv);
8032 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8033 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
8035 for (j = 0; j < texture_desc.ArraySize; ++j)
8037 for (k = 0; k < texture_desc.MipLevels; ++k)
8039 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
8040 ID3D11DeviceContext_UpdateSubresource(context,
8041 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
8044 check_texture_color(texture, 0, 0);
8046 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8047 draw_color_quad(&test_context, &red);
8049 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
8050 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
8051 for (j = 0; j < sub_resource_count; ++j)
8052 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
8054 ID3D11RenderTargetView_Release(rtv);
8055 ID3D11Texture2D_Release(texture);
8058 HeapFree(GetProcessHeap(), 0, data);
8059 release_test_context(&test_context);
8062 static void test_layered_rendering(void)
8064 struct
8066 unsigned int layer_offset;
8067 unsigned int draw_id;
8068 unsigned int padding[2];
8069 } constant;
8070 struct d3d11_test_context test_context;
8071 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
8072 unsigned int i, sub_resource_count;
8073 D3D11_TEXTURE2D_DESC texture_desc;
8074 ID3D11DeviceContext *context;
8075 ID3D11RenderTargetView *rtv;
8076 ID3D11Texture2D *texture;
8077 ID3D11GeometryShader *gs;
8078 ID3D11PixelShader *ps;
8079 ID3D11Device *device;
8080 ID3D11Buffer *cb;
8081 HRESULT hr;
8082 BOOL warp;
8084 static const DWORD gs_5_code[] =
8086 #if 0
8087 uint layer_offset;
8089 struct gs_in
8091 float4 pos : SV_Position;
8094 struct gs_out
8096 float4 pos : SV_Position;
8097 uint layer : SV_RenderTargetArrayIndex;
8100 [instance(4)]
8101 [maxvertexcount(3)]
8102 void main(triangle gs_in vin[3], in uint instance_id : SV_GSInstanceID,
8103 inout TriangleStream<gs_out> vout)
8105 gs_out o;
8106 o.layer = layer_offset + instance_id;
8107 for (uint i = 0; i < 3; ++i)
8109 o.pos = vin[i].pos;
8110 vout.Append(o);
8113 #endif
8114 0x43425844, 0xb52da162, 0x9a13d8ee, 0xf7c30b50, 0xe80bc2e7, 0x00000001, 0x00000218, 0x00000003,
8115 0x0000002c, 0x00000060, 0x000000d0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8116 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
8117 0x3547534f, 0x00000068, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
8118 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000004, 0x00000001,
8119 0x00000001, 0x00000e01, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472,
8120 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x58454853, 0x00000140, 0x00020050, 0x00000050,
8121 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
8122 0x00000000, 0x00000001, 0x0200005f, 0x00025000, 0x02000068, 0x00000001, 0x020000ce, 0x00000004,
8123 0x0100185d, 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
8124 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x00000003, 0x0700001e,
8125 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0002500a, 0x05000036, 0x00100022,
8126 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a,
8127 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000, 0x07000036, 0x001020f2,
8128 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001,
8129 0x0010000a, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x0700001e, 0x00100022, 0x00000000,
8130 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
8132 static const DWORD gs_4_code[] =
8134 #if 0
8135 uint layer_offset;
8137 struct gs_in
8139 float4 pos : SV_Position;
8142 struct gs_out
8144 float4 pos : SV_Position;
8145 uint layer : SV_RenderTargetArrayIndex;
8148 [maxvertexcount(12)]
8149 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
8151 gs_out o;
8152 for (uint instance_id = 0; instance_id < 4; ++instance_id)
8154 o.layer = layer_offset + instance_id;
8155 for (uint i = 0; i < 3; ++i)
8157 o.pos = vin[i].pos;
8158 vout.Append(o);
8160 vout.RestartStrip();
8163 #endif
8164 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
8165 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8166 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
8167 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8168 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
8169 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
8170 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
8171 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
8172 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
8173 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
8174 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
8175 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
8176 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
8177 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
8178 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
8179 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
8180 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
8181 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
8182 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
8184 static const DWORD ps_code[] =
8186 #if 0
8187 uint layer_offset;
8188 uint draw_id;
8190 float4 main(in float4 pos : SV_Position,
8191 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
8193 return float4(layer, draw_id, 0, 0);
8195 #endif
8196 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
8197 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
8198 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
8199 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
8200 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
8201 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
8202 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
8203 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
8204 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
8205 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
8206 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
8208 static const struct vec4 expected_values[] =
8210 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
8211 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
8212 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
8213 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
8216 if (!init_test_context(&test_context, NULL))
8217 return;
8219 device = test_context.device;
8220 context = test_context.immediate_context;
8222 warp = is_warp_device(device);
8224 memset(&constant, 0, sizeof(constant));
8225 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
8226 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
8227 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8229 /* Geometry shader instancing seems broken on WARP. */
8230 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0 || warp)
8232 hr = ID3D11Device_CreateGeometryShader(device, gs_4_code, sizeof(gs_4_code), NULL, &gs);
8233 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
8235 else
8237 hr = ID3D11Device_CreateGeometryShader(device, gs_5_code, sizeof(gs_5_code), NULL, &gs);
8238 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
8240 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
8242 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8243 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8244 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8246 texture_desc.Width = 32;
8247 texture_desc.Height = 32;
8248 texture_desc.MipLevels = 3;
8249 texture_desc.ArraySize = 8;
8250 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8251 texture_desc.SampleDesc.Count = 1;
8252 texture_desc.SampleDesc.Quality = 0;
8253 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8254 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8255 texture_desc.CPUAccessFlags = 0;
8256 texture_desc.MiscFlags = 0;
8257 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8258 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8260 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
8261 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8262 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8263 constant.layer_offset = 0;
8264 constant.draw_id = 0;
8265 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8266 draw_quad(&test_context);
8267 constant.layer_offset = 4;
8268 constant.draw_id = 1;
8269 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8270 draw_quad(&test_context);
8271 ID3D11RenderTargetView_Release(rtv);
8273 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
8274 rtv_desc.Format = texture_desc.Format;
8275 U(rtv_desc).Texture2DArray.MipSlice = 0;
8276 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
8277 U(rtv_desc).Texture2DArray.ArraySize = 1;
8278 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8279 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8280 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8281 constant.layer_offset = 1;
8282 constant.draw_id = 2;
8283 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8284 draw_quad(&test_context);
8285 ID3D11RenderTargetView_Release(rtv);
8287 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
8288 U(rtv_desc).Texture2DArray.MipSlice = 1;
8289 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
8290 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
8291 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8292 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8293 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8294 constant.layer_offset = 0;
8295 constant.draw_id = 3;
8296 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8297 draw_quad(&test_context);
8298 constant.layer_offset = 4;
8299 constant.draw_id = 3;
8300 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8301 draw_quad(&test_context);
8302 ID3D11RenderTargetView_Release(rtv);
8304 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
8305 U(rtv_desc).Texture2DArray.MipSlice = 2;
8306 U(rtv_desc).Texture2DArray.ArraySize = 1;
8307 for (i = 0; i < texture_desc.ArraySize; ++i)
8309 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
8310 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8311 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8312 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8313 constant.layer_offset = 0;
8314 constant.draw_id = 4 + i;
8315 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8316 draw_quad(&test_context);
8317 ID3D11RenderTargetView_Release(rtv);
8320 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
8321 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
8322 for (i = 0; i < sub_resource_count; ++i)
8324 if (warp && (i == 3 || i == 4)) /* Broken on WARP. */
8325 continue;
8326 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
8329 ID3D11Texture2D_Release(texture);
8331 ID3D11Buffer_Release(cb);
8332 ID3D11GeometryShader_Release(gs);
8333 ID3D11PixelShader_Release(ps);
8334 release_test_context(&test_context);
8337 static void test_scissor(void)
8339 struct d3d11_test_context test_context;
8340 ID3D11DeviceContext *immediate_context;
8341 D3D11_RASTERIZER_DESC rs_desc;
8342 ID3D11RasterizerState *rs;
8343 D3D11_RECT scissor_rect;
8344 ID3D11Device *device;
8345 DWORD color;
8346 HRESULT hr;
8348 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
8349 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
8351 if (!init_test_context(&test_context, NULL))
8352 return;
8354 device = test_context.device;
8355 immediate_context = test_context.immediate_context;
8357 rs_desc.FillMode = D3D11_FILL_SOLID;
8358 rs_desc.CullMode = D3D11_CULL_BACK;
8359 rs_desc.FrontCounterClockwise = FALSE;
8360 rs_desc.DepthBias = 0;
8361 rs_desc.DepthBiasClamp = 0.0f;
8362 rs_desc.SlopeScaledDepthBias = 0.0f;
8363 rs_desc.DepthClipEnable = TRUE;
8364 rs_desc.ScissorEnable = TRUE;
8365 rs_desc.MultisampleEnable = FALSE;
8366 rs_desc.AntialiasedLineEnable = FALSE;
8367 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
8368 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
8370 scissor_rect.left = 160;
8371 scissor_rect.top = 120;
8372 scissor_rect.right = 480;
8373 scissor_rect.bottom = 360;
8374 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
8376 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
8377 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
8379 draw_color_quad(&test_context, &green);
8380 color = get_texture_color(test_context.backbuffer, 320, 60);
8381 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8382 color = get_texture_color(test_context.backbuffer, 80, 240);
8383 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8384 color = get_texture_color(test_context.backbuffer, 320, 240);
8385 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8386 color = get_texture_color(test_context.backbuffer, 560, 240);
8387 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8388 color = get_texture_color(test_context.backbuffer, 320, 420);
8389 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8391 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
8392 ID3D11DeviceContext_RSSetState(immediate_context, rs);
8393 draw_color_quad(&test_context, &green);
8394 color = get_texture_color(test_context.backbuffer, 320, 60);
8395 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8396 color = get_texture_color(test_context.backbuffer, 80, 240);
8397 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8398 color = get_texture_color(test_context.backbuffer, 320, 240);
8399 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8400 color = get_texture_color(test_context.backbuffer, 560, 240);
8401 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8402 color = get_texture_color(test_context.backbuffer, 320, 420);
8403 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8405 ID3D11RasterizerState_Release(rs);
8406 release_test_context(&test_context);
8409 static void test_clear_state(void)
8411 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
8412 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8414 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8416 #if 0
8417 float4 main(float4 pos : POSITION) : POSITION
8419 return pos;
8421 #endif
8422 static const DWORD simple_vs[] =
8424 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
8425 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8426 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8427 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8428 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
8429 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
8430 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8432 #if 0
8433 struct data
8435 float4 position : SV_Position;
8438 struct patch_constant_data
8440 float edges[3] : SV_TessFactor;
8441 float inside : SV_InsideTessFactor;
8444 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
8446 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
8447 output.inside = 1.0f;
8450 [domain("tri")]
8451 [outputcontrolpoints(3)]
8452 [partitioning("integer")]
8453 [outputtopology("triangle_ccw")]
8454 [patchconstantfunc("patch_constant")]
8455 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
8457 return input[i];
8460 [domain("tri")]
8461 void ds_main(patch_constant_data input,
8462 float3 tess_coord : SV_DomainLocation,
8463 const OutputPatch<data, 3> patch,
8464 out data output)
8466 output.position = tess_coord.x * patch[0].position
8467 + tess_coord.y * patch[1].position
8468 + tess_coord.z * patch[2].position;
8470 #endif
8471 static const DWORD simple_hs[] =
8473 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
8474 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
8475 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
8476 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
8477 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
8478 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
8479 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
8480 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
8481 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
8482 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
8483 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
8484 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
8485 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
8486 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
8487 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
8488 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
8489 0x00004001, 0x3f800000, 0x0100003e,
8491 static const DWORD simple_ds[] =
8493 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
8494 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
8495 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
8496 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
8497 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
8498 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
8499 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
8500 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
8501 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
8502 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
8503 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
8504 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
8505 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
8506 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
8507 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
8509 #if 0
8510 struct gs_out
8512 float4 pos : SV_POSITION;
8515 [maxvertexcount(4)]
8516 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
8518 float offset = 0.1 * vin[0].w;
8519 gs_out v;
8521 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
8522 vout.Append(v);
8523 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
8524 vout.Append(v);
8525 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
8526 vout.Append(v);
8527 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
8528 vout.Append(v);
8530 #endif
8531 static const DWORD simple_gs[] =
8533 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
8534 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8535 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8536 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8537 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
8538 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
8539 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
8540 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
8541 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
8542 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
8543 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
8544 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
8545 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
8546 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
8547 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
8548 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
8549 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
8550 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
8552 #if 0
8553 float4 main(float4 color : COLOR) : SV_TARGET
8555 return color;
8557 #endif
8558 static const DWORD simple_ps[] =
8560 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
8561 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
8562 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
8563 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8564 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8565 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
8566 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8568 #if 0
8569 [numthreads(1, 1, 1)]
8570 void main() { }
8571 #endif
8572 static const DWORD simple_cs[] =
8574 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
8575 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8576 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
8577 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
8580 D3D11_VIEWPORT tmp_viewport[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
8581 ID3D11ShaderResourceView *tmp_srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
8582 ID3D11ShaderResourceView *srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
8583 ID3D11RenderTargetView *tmp_rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8584 RECT tmp_rect[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
8585 ID3D11SamplerState *tmp_sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
8586 ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8587 ID3D11Texture2D *rt_texture[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8588 ID3D11Buffer *cb[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
8589 ID3D11Buffer *tmp_buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8590 ID3D11SamplerState *sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
8591 ID3D11UnorderedAccessView *tmp_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
8592 ID3D11UnorderedAccessView *cs_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
8593 ID3D11Buffer *buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8594 ID3D11Buffer *cs_uav_buffer[D3D11_PS_CS_UAV_REGISTER_COUNT];
8595 UINT offset[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8596 UINT stride[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8597 ID3D11Buffer *so_buffer[D3D11_SO_BUFFER_SLOT_COUNT];
8598 ID3D11InputLayout *tmp_input_layout, *input_layout;
8599 ID3D11DepthStencilState *tmp_ds_state, *ds_state;
8600 ID3D11BlendState *tmp_blend_state, *blend_state;
8601 ID3D11RasterizerState *tmp_rs_state, *rs_state;
8602 ID3D11Predicate *tmp_predicate, *predicate;
8603 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
8604 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8605 ID3D11DepthStencilView *tmp_dsv, *dsv;
8606 ID3D11UnorderedAccessView *ps_uav;
8607 D3D11_PRIMITIVE_TOPOLOGY topology;
8608 D3D11_TEXTURE2D_DESC texture_desc;
8609 ID3D11GeometryShader *tmp_gs, *gs;
8610 ID3D11ComputeShader *tmp_cs, *cs;
8611 D3D11_DEPTH_STENCIL_DESC ds_desc;
8612 ID3D11VertexShader *tmp_vs, *vs;
8613 ID3D11DomainShader *tmp_ds, *ds;
8614 D3D11_SAMPLER_DESC sampler_desc;
8615 D3D11_QUERY_DESC predicate_desc;
8616 struct device_desc device_desc;
8617 ID3D11PixelShader *tmp_ps, *ps;
8618 ID3D11HullShader *tmp_hs, *hs;
8619 D3D11_RASTERIZER_DESC rs_desc;
8620 ID3D11DeviceContext *context;
8621 D3D11_BLEND_DESC blend_desc;
8622 ID3D11Texture2D *ds_texture;
8623 ID3D11Buffer *ps_uav_buffer;
8624 float blend_factor[4];
8625 ID3D11Device *device;
8626 BOOL predicate_value;
8627 DXGI_FORMAT format;
8628 UINT sample_mask;
8629 UINT stencil_ref;
8630 ULONG refcount;
8631 UINT count, i;
8632 HRESULT hr;
8634 device_desc.feature_level = &feature_level;
8635 device_desc.flags = 0;
8636 if (!(device = create_device(&device_desc)))
8638 skip("Failed to create device.\n");
8639 return;
8642 ID3D11Device_GetImmediateContext(device, &context);
8644 /* Verify the initial state after device creation. */
8646 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8647 tmp_buffer);
8648 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8650 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8652 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8653 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8655 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8657 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8658 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8660 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8662 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
8663 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
8665 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8666 tmp_buffer);
8667 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8669 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8671 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8672 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8674 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8676 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8677 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8679 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8681 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
8682 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
8684 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8685 tmp_buffer);
8686 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8688 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8690 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8691 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8693 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8695 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8696 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8698 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8700 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
8701 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
8703 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8704 tmp_buffer);
8705 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8707 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8709 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8710 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8712 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8714 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8715 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8717 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8719 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
8720 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
8722 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8723 tmp_buffer);
8724 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8726 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8728 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
8729 tmp_srv);
8730 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8732 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8734 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8735 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8737 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8739 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
8740 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
8742 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8743 tmp_buffer);
8744 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8746 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8748 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
8749 tmp_srv);
8750 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8752 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8754 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8755 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8757 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8759 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
8760 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
8761 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8762 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8764 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
8767 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
8768 tmp_buffer, stride, offset);
8769 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
8771 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
8772 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
8773 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
8775 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
8776 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
8777 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
8778 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
8779 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
8780 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
8781 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
8782 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
8784 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
8785 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
8786 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
8787 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
8788 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
8789 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
8790 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
8791 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
8792 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
8793 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
8794 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
8795 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8797 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8799 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
8800 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
8801 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
8802 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8803 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8805 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8807 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
8808 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8810 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
8813 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
8814 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
8815 memset(tmp_rect, 0x55, sizeof(tmp_rect));
8816 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
8817 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
8818 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
8820 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
8821 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
8823 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
8824 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
8825 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
8826 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
8827 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
8828 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
8830 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
8831 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
8832 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
8833 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
8834 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
8836 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
8837 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
8839 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
8840 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
8842 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
8845 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
8846 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
8847 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
8849 /* Create resources. */
8851 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8852 cb[i] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 1024, NULL);
8854 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
8856 buffer[i] = create_buffer(device,
8857 D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_SHADER_RESOURCE,
8858 1024, NULL);
8860 stride[i] = (i + 1) * 4;
8861 offset[i] = (i + 1) * 16;
8864 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
8865 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
8867 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8868 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
8869 U(srv_desc).Buffer.ElementOffset = 0;
8870 U(srv_desc).Buffer.ElementWidth = 64;
8872 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8874 hr = ID3D11Device_CreateShaderResourceView(device,
8875 (ID3D11Resource *)buffer[i % D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
8876 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8879 uav_desc.Format = DXGI_FORMAT_R32_UINT;
8880 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
8881 U(uav_desc).Buffer.FirstElement = 0;
8882 U(uav_desc).Buffer.NumElements = 8;
8883 U(uav_desc).Buffer.Flags = 0;
8885 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8887 cs_uav_buffer[i] = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
8888 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_uav_buffer[i],
8889 &uav_desc, &cs_uav[i]);
8890 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
8893 ps_uav_buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
8894 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_uav_buffer,
8895 &uav_desc, &ps_uav);
8896 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
8898 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
8899 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8900 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8901 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8902 sampler_desc.MipLODBias = 0.0f;
8903 sampler_desc.MaxAnisotropy = 16;
8904 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8905 sampler_desc.BorderColor[0] = 0.0f;
8906 sampler_desc.BorderColor[1] = 0.0f;
8907 sampler_desc.BorderColor[2] = 0.0f;
8908 sampler_desc.BorderColor[3] = 0.0f;
8909 sampler_desc.MinLOD = 0.0f;
8910 sampler_desc.MaxLOD = 16.0f;
8912 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8914 sampler_desc.MinLOD = (float)i;
8916 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
8917 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8920 hr = ID3D11Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
8921 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8923 hr = ID3D11Device_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
8924 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
8926 hr = ID3D11Device_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
8927 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
8929 hr = ID3D11Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
8930 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
8932 hr = ID3D11Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
8933 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8935 hr = ID3D11Device_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
8936 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
8938 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8939 simple_vs, sizeof(simple_vs), &input_layout);
8940 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8942 memset(&blend_desc, 0, sizeof(blend_desc));
8943 blend_desc.AlphaToCoverageEnable = FALSE;
8944 blend_desc.IndependentBlendEnable = FALSE;
8945 blend_desc.RenderTarget[0].BlendEnable = TRUE;
8946 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
8947 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
8948 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
8949 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
8950 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
8951 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
8952 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
8954 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
8955 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8957 ds_desc.DepthEnable = TRUE;
8958 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
8959 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
8960 ds_desc.StencilEnable = FALSE;
8961 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
8962 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
8963 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
8964 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
8965 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
8966 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
8967 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
8968 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
8969 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
8970 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
8972 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
8973 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
8975 texture_desc.Width = 512;
8976 texture_desc.Height = 512;
8977 texture_desc.MipLevels = 1;
8978 texture_desc.ArraySize = 1;
8979 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8980 texture_desc.SampleDesc.Count = 1;
8981 texture_desc.SampleDesc.Quality = 0;
8982 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8983 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8984 texture_desc.CPUAccessFlags = 0;
8985 texture_desc.MiscFlags = 0;
8987 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8989 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
8990 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8993 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
8994 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
8996 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
8997 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8999 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9001 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture[i], NULL, &rtv[i]);
9002 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9005 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)ds_texture, NULL, &dsv);
9006 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
9008 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
9010 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
9012 tmp_viewport[i].TopLeftX = i * 3;
9013 tmp_viewport[i].TopLeftY = i * 4;
9014 tmp_viewport[i].Width = 3;
9015 tmp_viewport[i].Height = 4;
9016 tmp_viewport[i].MinDepth = i * 0.01f;
9017 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
9020 rs_desc.FillMode = D3D11_FILL_SOLID;
9021 rs_desc.CullMode = D3D11_CULL_BACK;
9022 rs_desc.FrontCounterClockwise = FALSE;
9023 rs_desc.DepthBias = 0;
9024 rs_desc.DepthBiasClamp = 0.0f;
9025 rs_desc.SlopeScaledDepthBias = 0.0f;
9026 rs_desc.DepthClipEnable = TRUE;
9027 rs_desc.ScissorEnable = FALSE;
9028 rs_desc.MultisampleEnable = FALSE;
9029 rs_desc.AntialiasedLineEnable = FALSE;
9031 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs_state);
9032 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
9034 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
9035 predicate_desc.MiscFlags = 0;
9037 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
9038 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
9040 /* Setup state. */
9042 /* Some versions of Windows AMD drivers hang while the device is being
9043 * released, if the total number of used resource slots exceeds some limit.
9044 * Do not use all constant buffers slots in order to not trigger this
9045 * driver bug. */
9046 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb[0]);
9047 ID3D11DeviceContext_VSSetConstantBuffers(context, 7, 1, &cb[7]);
9048 ID3D11DeviceContext_VSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9049 ID3D11DeviceContext_VSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9050 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
9052 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb[0]);
9053 ID3D11DeviceContext_HSSetConstantBuffers(context, 7, 1, &cb[7]);
9054 ID3D11DeviceContext_HSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9055 ID3D11DeviceContext_HSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9056 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
9058 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
9059 ID3D11DeviceContext_DSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9060 ID3D11DeviceContext_DSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9061 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
9063 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
9064 ID3D11DeviceContext_GSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9065 ID3D11DeviceContext_GSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9066 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
9068 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
9069 ID3D11DeviceContext_PSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9070 ID3D11DeviceContext_PSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9071 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9073 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
9074 ID3D11DeviceContext_CSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9075 ID3D11DeviceContext_CSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9076 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
9077 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, cs_uav, NULL);
9079 ID3D11DeviceContext_IASetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
9080 buffer, stride, offset);
9081 ID3D11DeviceContext_IASetIndexBuffer(context, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
9082 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
9083 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9085 blend_factor[0] = 0.1f;
9086 blend_factor[1] = 0.2f;
9087 blend_factor[2] = 0.3f;
9088 blend_factor[3] = 0.4f;
9089 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, 0xff00ff00);
9090 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 3);
9091 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
9092 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, rtv, dsv,
9093 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, 1, &ps_uav, NULL);
9095 ID3D11DeviceContext_RSSetScissorRects(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
9096 tmp_rect);
9097 ID3D11DeviceContext_RSSetViewports(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
9098 tmp_viewport);
9099 ID3D11DeviceContext_RSSetState(context, rs_state);
9101 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
9103 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
9105 /* Verify the set state. */
9107 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9108 tmp_buffer);
9109 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9111 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
9112 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9113 tmp_buffer[i], i, expected_cb);
9114 if (tmp_buffer[i])
9115 ID3D11Buffer_Release(tmp_buffer[i]);
9117 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9118 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9120 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9121 tmp_srv[i], i, srv[i]);
9122 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9124 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9125 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9127 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9128 tmp_sampler[i], i, sampler[i]);
9129 ID3D11SamplerState_Release(tmp_sampler[i]);
9131 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
9132 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
9133 ID3D11VertexShader_Release(tmp_vs);
9135 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9136 tmp_buffer);
9137 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9139 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
9140 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9141 tmp_buffer[i], i, expected_cb);
9142 if (tmp_buffer[i])
9143 ID3D11Buffer_Release(tmp_buffer[i]);
9145 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9146 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9148 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9149 tmp_srv[i], i, srv[i]);
9150 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9152 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9153 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9155 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9156 tmp_sampler[i], i, sampler[i]);
9157 ID3D11SamplerState_Release(tmp_sampler[i]);
9159 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
9160 ok(tmp_hs == hs, "Got unexpected hull shader %p, expected %p.\n", tmp_hs, hs);
9161 ID3D11HullShader_Release(tmp_hs);
9163 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9164 tmp_buffer);
9165 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9167 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9168 tmp_buffer[i], i, cb[i]);
9169 ID3D11Buffer_Release(tmp_buffer[i]);
9171 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9172 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9174 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9175 tmp_srv[i], i, srv[i]);
9176 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9178 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9179 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9181 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9182 tmp_sampler[i], i, sampler[i]);
9183 ID3D11SamplerState_Release(tmp_sampler[i]);
9185 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
9186 ok(tmp_ds == ds, "Got unexpected domain shader %p, expected %p.\n", tmp_ds, ds);
9187 ID3D11DomainShader_Release(tmp_ds);
9189 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9190 tmp_buffer);
9191 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9193 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9194 tmp_buffer[i], i, cb[i]);
9195 ID3D11Buffer_Release(tmp_buffer[i]);
9197 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9198 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9200 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9201 tmp_srv[i], i, srv[i]);
9202 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9204 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9205 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9207 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9208 tmp_sampler[i], i, sampler[i]);
9209 ID3D11SamplerState_Release(tmp_sampler[i]);
9211 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
9212 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
9213 ID3D11GeometryShader_Release(tmp_gs);
9215 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9216 tmp_buffer);
9217 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9219 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9220 tmp_buffer[i], i, cb[i]);
9221 ID3D11Buffer_Release(tmp_buffer[i]);
9223 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9224 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9226 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9227 tmp_srv[i], i, srv[i]);
9228 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9230 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9231 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9233 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9234 tmp_sampler[i], i, sampler[i]);
9235 ID3D11SamplerState_Release(tmp_sampler[i]);
9237 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
9238 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
9239 ID3D11PixelShader_Release(tmp_ps);
9241 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9242 tmp_buffer);
9243 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9245 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9246 tmp_buffer[i], i, cb[i]);
9247 ID3D11Buffer_Release(tmp_buffer[i]);
9249 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9250 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9252 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9253 tmp_srv[i], i, srv[i]);
9254 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9256 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9257 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9259 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9260 tmp_sampler[i], i, sampler[i]);
9261 ID3D11SamplerState_Release(tmp_sampler[i]);
9263 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
9264 ok(tmp_cs == cs, "Got unexpected compute shader %p, expected %p.\n", tmp_cs, cs);
9265 ID3D11ComputeShader_Release(tmp_cs);
9266 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9267 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9269 ok(tmp_uav[i] == cs_uav[i], "Got unexpected unordered access view %p in slot %u, expected %p.\n",
9270 tmp_uav[i], i, cs_uav[i]);
9271 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
9274 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
9275 tmp_buffer, stride, offset);
9276 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9278 todo_wine_if(i >= D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
9280 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
9281 tmp_buffer[i], i, buffer[i]);
9282 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
9283 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
9285 if (tmp_buffer[i])
9286 ID3D11Buffer_Release(tmp_buffer[i]);
9288 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
9289 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
9290 ID3D11Buffer_Release(tmp_buffer[0]);
9291 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
9292 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
9293 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
9294 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
9295 tmp_input_layout, input_layout);
9296 ID3D11InputLayout_Release(tmp_input_layout);
9297 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
9298 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
9300 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
9301 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
9302 ID3D11BlendState_Release(tmp_blend_state);
9303 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
9304 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
9305 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
9306 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
9307 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
9308 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
9309 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
9310 ID3D11DepthStencilState_Release(tmp_ds_state);
9311 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
9312 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
9313 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
9315 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
9316 tmp_rtv[i], i, rtv[i]);
9317 ID3D11RenderTargetView_Release(tmp_rtv[i]);
9319 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9320 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
9321 ID3D11DepthStencilView_Release(tmp_dsv);
9322 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
9323 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
9324 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9325 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
9327 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
9328 tmp_rtv[i], i, rtv[i]);
9329 ID3D11RenderTargetView_Release(tmp_rtv[i]);
9331 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9332 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
9333 ID3D11DepthStencilView_Release(tmp_dsv);
9334 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT - 1; ++i)
9336 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9338 ok(tmp_uav[i] == ps_uav, "Got unexpected unordered access view %p in slot %u, expected %p.\n",
9339 tmp_uav[i], i, ps_uav);
9340 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
9342 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
9343 todo_wine ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
9344 "Got unexpected scissor rect count %u.\n", count);
9345 memset(tmp_rect, 0x55, sizeof(tmp_rect));
9346 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
9347 for (i = 0; i < count; ++i)
9349 ok(tmp_rect[i].left == i
9350 && tmp_rect[i].top == i * 2
9351 && tmp_rect[i].right == i + 1
9352 && tmp_rect[i].bottom == (i + 1) * 2,
9353 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
9355 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
9356 todo_wine ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
9357 "Got unexpected viewport count %u.\n", count);
9358 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
9359 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
9360 for (i = 0; i < count; ++i)
9362 ok(tmp_viewport[i].TopLeftX == i * 3
9363 && tmp_viewport[i].TopLeftY == i * 4
9364 && tmp_viewport[i].Width == 3
9365 && tmp_viewport[i].Height == 4
9366 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
9367 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
9368 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
9369 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
9370 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
9372 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
9373 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
9374 ID3D11RasterizerState_Release(tmp_rs_state);
9376 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
9377 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
9379 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
9380 tmp_buffer[i], i, so_buffer[i]);
9381 ID3D11Buffer_Release(tmp_buffer[i]);
9384 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
9385 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
9386 ID3D11Predicate_Release(tmp_predicate);
9387 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
9389 /* Verify ClearState(). */
9391 ID3D11DeviceContext_ClearState(context);
9393 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9394 tmp_buffer);
9395 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9397 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9399 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9400 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9402 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9404 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9405 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9407 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9409 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
9410 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
9412 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9413 tmp_buffer);
9414 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9416 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9418 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9419 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9421 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9423 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9424 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9426 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9428 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
9429 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
9431 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9432 tmp_buffer);
9433 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9435 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9437 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9438 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9440 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9442 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9443 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9445 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9447 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
9448 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
9450 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9451 tmp_buffer);
9452 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9454 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9456 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9457 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9459 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9461 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9462 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9464 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9466 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
9467 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
9469 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9470 tmp_buffer);
9471 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9473 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9475 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9476 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9478 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9480 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9481 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9483 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9485 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
9486 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
9488 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9489 tmp_buffer);
9490 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9492 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9494 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
9495 tmp_srv);
9496 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9498 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9500 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9501 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9503 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9505 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
9506 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
9507 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9508 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9510 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9513 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
9514 tmp_buffer, stride, offset);
9515 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9517 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
9518 todo_wine_if(i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
9520 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
9521 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
9524 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
9525 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
9526 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
9527 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
9528 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
9529 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
9530 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
9531 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
9533 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
9534 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
9535 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
9536 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
9537 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
9538 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
9539 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
9540 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
9541 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
9542 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
9543 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
9544 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9546 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9548 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
9549 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
9550 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
9551 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9552 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9554 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9556 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
9557 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9559 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9562 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
9563 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
9564 memset(tmp_rect, 0x55, sizeof(tmp_rect));
9565 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
9566 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
9567 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
9569 todo_wine_if(!i)
9570 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
9571 "Got unexpected scissor rect %s in slot %u.\n",
9572 wine_dbgstr_rect(&tmp_rect[i]), i);
9574 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
9575 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
9576 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
9577 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
9578 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
9579 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
9581 todo_wine_if(!i)
9582 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
9583 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
9584 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
9585 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
9586 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
9588 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
9589 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
9591 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
9592 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
9594 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
9597 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
9598 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
9599 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
9601 /* Cleanup. */
9603 ID3D11Predicate_Release(predicate);
9604 ID3D11RasterizerState_Release(rs_state);
9605 ID3D11DepthStencilView_Release(dsv);
9606 ID3D11Texture2D_Release(ds_texture);
9608 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9610 ID3D11RenderTargetView_Release(rtv[i]);
9611 ID3D11Texture2D_Release(rt_texture[i]);
9614 ID3D11DepthStencilState_Release(ds_state);
9615 ID3D11BlendState_Release(blend_state);
9616 ID3D11InputLayout_Release(input_layout);
9617 ID3D11VertexShader_Release(vs);
9618 ID3D11HullShader_Release(hs);
9619 ID3D11DomainShader_Release(ds);
9620 ID3D11GeometryShader_Release(gs);
9621 ID3D11PixelShader_Release(ps);
9622 ID3D11ComputeShader_Release(cs);
9624 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9626 ID3D11SamplerState_Release(sampler[i]);
9629 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9631 ID3D11ShaderResourceView_Release(srv[i]);
9634 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9636 ID3D11UnorderedAccessView_Release(cs_uav[i]);
9637 ID3D11Buffer_Release(cs_uav_buffer[i]);
9639 ID3D11UnorderedAccessView_Release(ps_uav);
9640 ID3D11Buffer_Release(ps_uav_buffer);
9642 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
9644 ID3D11Buffer_Release(so_buffer[i]);
9647 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9649 ID3D11Buffer_Release(buffer[i]);
9652 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9654 ID3D11Buffer_Release(cb[i]);
9657 ID3D11DeviceContext_Release(context);
9658 refcount = ID3D11Device_Release(device);
9659 ok(!refcount, "Device has %u references left.\n", refcount);
9662 static void test_il_append_aligned(void)
9664 struct d3d11_test_context test_context;
9665 ID3D11InputLayout *input_layout;
9666 ID3D11DeviceContext *context;
9667 unsigned int stride, offset;
9668 ID3D11VertexShader *vs;
9669 ID3D11PixelShader *ps;
9670 ID3D11Device *device;
9671 ID3D11Buffer *vb[3];
9672 DWORD color;
9673 HRESULT hr;
9675 /* Semantic names are case-insensitive. */
9676 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9678 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9679 D3D11_INPUT_PER_INSTANCE_DATA, 2},
9680 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
9681 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9682 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
9683 D3D11_INPUT_PER_VERTEX_DATA, 0},
9684 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
9685 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9686 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9687 D3D11_INPUT_PER_INSTANCE_DATA, 2},
9689 static const DWORD vs_code[] =
9691 #if 0
9692 struct vs_in
9694 float4 position : POSITION;
9695 float2 color_xy : COLOR0;
9696 float2 color_zw : COLOR1;
9697 unsigned int instance_id : SV_INSTANCEID;
9700 struct vs_out
9702 float4 position : SV_POSITION;
9703 float2 color_xy : COLOR0;
9704 float2 color_zw : COLOR1;
9707 struct vs_out main(struct vs_in i)
9709 struct vs_out o;
9711 o.position = i.position;
9712 o.position.x += i.instance_id * 0.5;
9713 o.color_xy = i.color_xy;
9714 o.color_zw = i.color_zw;
9716 return o;
9718 #endif
9719 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
9720 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
9721 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
9722 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
9723 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
9724 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
9725 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
9726 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
9727 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
9728 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
9729 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
9730 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
9731 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
9732 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
9733 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
9734 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
9735 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
9737 static const DWORD ps_code[] =
9739 #if 0
9740 struct vs_out
9742 float4 position : SV_POSITION;
9743 float2 color_xy : COLOR0;
9744 float2 color_zw : COLOR1;
9747 float4 main(struct vs_out i) : SV_TARGET
9749 return float4(i.color_xy.xy, i.color_zw.xy);
9751 #endif
9752 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
9753 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
9754 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
9755 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
9756 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
9757 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
9758 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
9759 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9760 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9762 static const struct
9764 struct vec4 position;
9766 stream0[] =
9768 {{-1.0f, -1.0f, 0.0f, 1.0f}},
9769 {{-1.0f, 1.0f, 0.0f, 1.0f}},
9770 {{-0.5f, -1.0f, 0.0f, 1.0f}},
9771 {{-0.5f, 1.0f, 0.0f, 1.0f}},
9773 static const struct
9775 struct vec2 color2;
9776 struct vec2 color1;
9778 stream1[] =
9780 {{0.5f, 0.5f}, {0.0f, 1.0f}},
9781 {{0.5f, 0.5f}, {1.0f, 1.0f}},
9783 static const struct
9785 struct vec2 color3;
9786 struct vec2 color0;
9788 stream2[] =
9790 {{0.5f, 0.5f}, {1.0f, 0.0f}},
9791 {{0.5f, 0.5f}, {0.0f, 1.0f}},
9792 {{0.5f, 0.5f}, {0.0f, 0.0f}},
9793 {{0.5f, 0.5f}, {1.0f, 0.0f}},
9795 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9797 if (!init_test_context(&test_context, NULL))
9798 return;
9800 device = test_context.device;
9801 context = test_context.immediate_context;
9803 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9804 vs_code, sizeof(vs_code), &input_layout);
9805 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9807 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
9808 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
9809 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
9811 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
9812 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9813 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9814 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9816 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
9817 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9818 offset = 0;
9819 stride = sizeof(*stream0);
9820 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
9821 stride = sizeof(*stream1);
9822 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
9823 stride = sizeof(*stream2);
9824 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
9825 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
9826 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9828 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9830 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
9832 color = get_texture_color(test_context.backbuffer, 80, 240);
9833 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9834 color = get_texture_color(test_context.backbuffer, 240, 240);
9835 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9836 color = get_texture_color(test_context.backbuffer, 400, 240);
9837 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9838 color = get_texture_color(test_context.backbuffer, 560, 240);
9839 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
9841 ID3D11PixelShader_Release(ps);
9842 ID3D11VertexShader_Release(vs);
9843 ID3D11Buffer_Release(vb[2]);
9844 ID3D11Buffer_Release(vb[1]);
9845 ID3D11Buffer_Release(vb[0]);
9846 ID3D11InputLayout_Release(input_layout);
9847 release_test_context(&test_context);
9850 static void test_instance_id(void)
9852 struct d3d11_test_context test_context;
9853 D3D11_TEXTURE2D_DESC texture_desc;
9854 ID3D11InputLayout *input_layout;
9855 ID3D11RenderTargetView *rtvs[2];
9856 ID3D11Texture2D *render_target;
9857 ID3D11DeviceContext *context;
9858 struct resource_readback rb;
9859 unsigned int stride, offset;
9860 ID3D11Buffer *args_buffer;
9861 ID3D11VertexShader *vs;
9862 ID3D11PixelShader *ps;
9863 ID3D11Device *device;
9864 ID3D11Buffer *vb[2];
9865 unsigned int i;
9866 HRESULT hr;
9868 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9870 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
9871 D3D11_INPUT_PER_VERTEX_DATA, 0},
9872 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9873 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9874 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9875 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9877 static const DWORD vs_code[] =
9879 #if 0
9880 struct vs_in
9882 float4 position : Position;
9883 float color : Color;
9884 float v_offset : V_Offset;
9885 uint instance_id : SV_InstanceId;
9888 struct vs_out
9890 float4 position : SV_Position;
9891 float color : Color;
9892 uint instance_id : InstanceId;
9895 void main(vs_in i, out vs_out o)
9897 o.position = i.position;
9898 o.position.x += i.v_offset;
9899 o.color = i.color;
9900 o.instance_id = i.instance_id;
9902 #endif
9903 0x43425844, 0xcde3cfbf, 0xe2e3d090, 0xe2eb1038, 0x7e5ad1cf, 0x00000001, 0x00000204, 0x00000003,
9904 0x0000002c, 0x000000c4, 0x0000013c, 0x4e475349, 0x00000090, 0x00000004, 0x00000008, 0x00000068,
9905 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
9906 0x00000003, 0x00000001, 0x00000101, 0x00000077, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
9907 0x00000101, 0x00000080, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x69736f50,
9908 0x6e6f6974, 0x6c6f4300, 0x5600726f, 0x66664f5f, 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e,
9909 0xabab0064, 0x4e47534f, 0x00000070, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
9910 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
9911 0x00000e01, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
9912 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
9913 0x000000c0, 0x00010040, 0x00000030, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
9914 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x04000060, 0x00101012, 0x00000003, 0x00000008,
9915 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
9916 0x00102012, 0x00000002, 0x07000000, 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x0010100a,
9917 0x00000002, 0x05000036, 0x001020e2, 0x00000000, 0x00101e56, 0x00000000, 0x05000036, 0x00102012,
9918 0x00000001, 0x0010100a, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000003,
9919 0x0100003e,
9921 static const DWORD ps_code[] =
9923 #if 0
9924 struct vs_out
9926 float4 position : SV_Position;
9927 float color : Color;
9928 uint instance_id : InstanceId;
9931 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
9933 o0 = float4(i.color, i.color, i.color, 1.0f);
9934 o1 = i.instance_id;
9936 #endif
9937 0x43425844, 0xda0ad0bb, 0x4743f5f5, 0xfbc6d0b1, 0x7c8e7df5, 0x00000001, 0x00000170, 0x00000003,
9938 0x0000002c, 0x000000a4, 0x000000f0, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
9939 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
9940 0x00000003, 0x00000001, 0x00000101, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002,
9941 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563,
9942 0xababab00, 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000,
9943 0x00000003, 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
9944 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000078, 0x00000040, 0x0000001e,
9945 0x03001062, 0x00101012, 0x00000001, 0x03000862, 0x00101012, 0x00000002, 0x03000065, 0x001020f2,
9946 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072, 0x00000000, 0x00101006,
9947 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x05000036, 0x001020f2,
9948 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
9950 static const struct vec4 stream0[] =
9952 {-1.00f, 0.0f, 0.0f, 1.0f},
9953 {-1.00f, 1.0f, 0.0f, 1.0f},
9954 {-0.75f, 0.0f, 0.0f, 1.0f},
9955 {-0.75f, 1.0f, 0.0f, 1.0f},
9956 /* indirect draws data */
9957 {-1.00f, -1.0f, 0.0f, 1.0f},
9958 {-1.00f, 0.0f, 0.0f, 1.0f},
9959 {-0.75f, -1.0f, 0.0f, 1.0f},
9960 {-0.75f, 0.0f, 0.0f, 1.0f},
9962 static const struct
9964 BYTE color;
9965 float v_offset;
9967 stream1[] =
9969 {0xf0, 0.00f},
9970 {0x80, 0.25f},
9971 {0x10, 0.50f},
9972 {0x40, 0.75f},
9974 {0xaa, 1.00f},
9975 {0xbb, 1.25f},
9976 {0xcc, 1.50f},
9977 {0x90, 1.75f},
9979 static const D3D11_DRAW_INSTANCED_INDIRECT_ARGS argument_data[] =
9981 {4, 4, 4, 0},
9982 {4, 4, 4, 4},
9984 static const struct
9986 RECT rect;
9987 unsigned int color;
9988 unsigned int instance_id;
9990 expected_results[] =
9992 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
9993 {{ 80, 0, 160, 240}, 0xff808080, 1},
9994 {{160, 0, 240, 240}, 0xff101010, 2},
9995 {{240, 0, 320, 240}, 0xff404040, 3},
9996 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
9997 {{400, 0, 480, 240}, 0xffbbbbbb, 1},
9998 {{480, 0, 560, 240}, 0xffcccccc, 2},
9999 {{560, 0, 640, 240}, 0xff909090, 3},
10000 /* indirect draws results */
10001 {{ 0, 240, 80, 480}, 0xfff0f0f0, 0},
10002 {{ 80, 240, 160, 480}, 0xff808080, 1},
10003 {{160, 240, 240, 480}, 0xff101010, 2},
10004 {{240, 240, 320, 480}, 0xff404040, 3},
10005 {{320, 240, 400, 480}, 0xffaaaaaa, 0},
10006 {{400, 240, 480, 480}, 0xffbbbbbb, 1},
10007 {{480, 240, 560, 480}, 0xffcccccc, 2},
10008 {{560, 240, 640, 480}, 0xff909090, 3},
10010 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
10011 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
10013 if (!init_test_context(&test_context, &feature_level))
10014 return;
10015 device = test_context.device;
10016 context = test_context.immediate_context;
10018 rtvs[0] = test_context.backbuffer_rtv;
10020 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10021 texture_desc.Format = DXGI_FORMAT_R32_UINT;
10022 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
10023 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10024 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtvs[1]);
10025 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10027 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10028 vs_code, sizeof(vs_code), &input_layout);
10029 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10031 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
10032 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10033 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10034 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10036 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
10037 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
10039 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
10040 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10041 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
10042 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10043 offset = 0;
10044 stride = sizeof(*stream0);
10045 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
10046 stride = sizeof(*stream1);
10047 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
10049 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
10050 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[1], white);
10052 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
10053 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
10054 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 4);
10056 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
10057 sizeof(argument_data), argument_data);
10059 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, 0);
10060 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, sizeof(*argument_data));
10062 get_texture_readback(test_context.backbuffer, 0, &rb);
10063 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
10064 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
10065 release_resource_readback(&rb);
10067 get_texture_readback(render_target, 0, &rb);
10068 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
10069 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
10070 release_resource_readback(&rb);
10072 ID3D11Buffer_Release(vb[0]);
10073 ID3D11Buffer_Release(vb[1]);
10074 ID3D11Buffer_Release(args_buffer);
10075 ID3D11RenderTargetView_Release(rtvs[1]);
10076 ID3D11Texture2D_Release(render_target);
10077 ID3D11VertexShader_Release(vs);
10078 ID3D11PixelShader_Release(ps);
10079 ID3D11InputLayout_Release(input_layout);
10080 release_test_context(&test_context);
10083 static void test_fragment_coords(void)
10085 struct d3d11_test_context test_context;
10086 ID3D11PixelShader *ps, *ps_frac;
10087 ID3D11DeviceContext *context;
10088 ID3D11Device *device;
10089 ID3D11Buffer *ps_cb;
10090 DWORD color;
10091 HRESULT hr;
10093 static const DWORD ps_code[] =
10095 #if 0
10096 float2 cutoff;
10098 float4 main(float4 position : SV_POSITION) : SV_TARGET
10100 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
10102 if (position.x > cutoff.x)
10103 ret.y = 1.0;
10104 if (position.y > cutoff.y)
10105 ret.z = 1.0;
10107 return ret;
10109 #endif
10110 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
10111 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10112 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10113 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10114 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
10115 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
10116 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
10117 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
10118 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
10119 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
10120 0x0100003e,
10122 static const DWORD ps_frac_code[] =
10124 #if 0
10125 float4 main(float4 position : SV_POSITION) : SV_TARGET
10127 return float4(frac(position.xy), 0.0, 1.0);
10129 #endif
10130 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
10131 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10132 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10133 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10134 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
10135 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10136 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
10137 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
10139 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10140 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
10142 if (!init_test_context(&test_context, NULL))
10143 return;
10145 device = test_context.device;
10146 context = test_context.immediate_context;
10148 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
10150 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10151 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10152 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
10153 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10155 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
10156 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10158 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
10160 draw_quad(&test_context);
10162 color = get_texture_color(test_context.backbuffer, 319, 239);
10163 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
10164 color = get_texture_color(test_context.backbuffer, 320, 239);
10165 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10166 color = get_texture_color(test_context.backbuffer, 319, 240);
10167 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
10168 color = get_texture_color(test_context.backbuffer, 320, 240);
10169 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
10171 ID3D11Buffer_Release(ps_cb);
10172 cutoff.x = 16.0f;
10173 cutoff.y = 16.0f;
10174 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
10175 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
10177 draw_quad(&test_context);
10179 color = get_texture_color(test_context.backbuffer, 14, 14);
10180 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
10181 color = get_texture_color(test_context.backbuffer, 18, 14);
10182 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10183 color = get_texture_color(test_context.backbuffer, 14, 18);
10184 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
10185 color = get_texture_color(test_context.backbuffer, 18, 18);
10186 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
10188 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
10189 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
10191 ID3D11DeviceContext_Draw(context, 4, 0);
10193 color = get_texture_color(test_context.backbuffer, 14, 14);
10194 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
10196 ID3D11Buffer_Release(ps_cb);
10197 ID3D11PixelShader_Release(ps_frac);
10198 ID3D11PixelShader_Release(ps);
10199 release_test_context(&test_context);
10202 static void test_update_subresource(void)
10204 struct d3d11_test_context test_context;
10205 D3D11_SUBRESOURCE_DATA resource_data;
10206 D3D11_TEXTURE2D_DESC texture_desc;
10207 ID3D11SamplerState *sampler_state;
10208 ID3D11ShaderResourceView *ps_srv;
10209 D3D11_SAMPLER_DESC sampler_desc;
10210 ID3D11DeviceContext *context;
10211 struct resource_readback rb;
10212 ID3D11Texture2D *texture;
10213 ID3D11PixelShader *ps;
10214 ID3D11Device *device;
10215 unsigned int i, j;
10216 D3D11_BOX box;
10217 DWORD color;
10218 HRESULT hr;
10220 static const DWORD ps_code[] =
10222 #if 0
10223 Texture2D t;
10224 SamplerState s;
10226 float4 main(float4 position : SV_POSITION) : SV_Target
10228 float2 p;
10230 p.x = position.x / 640.0f;
10231 p.y = position.y / 480.0f;
10232 return t.Sample(s, p);
10234 #endif
10235 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
10236 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10237 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10238 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10239 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
10240 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10241 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10242 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10243 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
10244 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
10246 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10247 static const DWORD initial_data[16] = {0};
10248 static const DWORD bitmap_data[] =
10250 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
10251 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
10252 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
10253 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
10255 static const DWORD expected_colors[] =
10257 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
10258 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
10259 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
10260 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
10263 if (!init_test_context(&test_context, NULL))
10264 return;
10266 device = test_context.device;
10267 context = test_context.immediate_context;
10269 texture_desc.Width = 4;
10270 texture_desc.Height = 4;
10271 texture_desc.MipLevels = 1;
10272 texture_desc.ArraySize = 1;
10273 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10274 texture_desc.SampleDesc.Count = 1;
10275 texture_desc.SampleDesc.Quality = 0;
10276 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10277 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
10278 texture_desc.CPUAccessFlags = 0;
10279 texture_desc.MiscFlags = 0;
10281 resource_data.pSysMem = initial_data;
10282 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
10283 resource_data.SysMemSlicePitch = 0;
10285 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
10286 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10288 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
10289 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10291 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
10292 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10293 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10294 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10295 sampler_desc.MipLODBias = 0.0f;
10296 sampler_desc.MaxAnisotropy = 0;
10297 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
10298 sampler_desc.BorderColor[0] = 0.0f;
10299 sampler_desc.BorderColor[1] = 0.0f;
10300 sampler_desc.BorderColor[2] = 0.0f;
10301 sampler_desc.BorderColor[3] = 0.0f;
10302 sampler_desc.MinLOD = 0.0f;
10303 sampler_desc.MaxLOD = 0.0f;
10305 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
10306 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10308 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10309 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10311 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
10312 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
10313 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10315 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
10316 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
10318 draw_quad(&test_context);
10319 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10321 set_box(&box, 1, 1, 0, 3, 3, 1);
10322 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10323 bitmap_data, 4 * sizeof(*bitmap_data), 0);
10324 set_box(&box, 0, 3, 0, 3, 4, 1);
10325 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10326 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
10327 set_box(&box, 0, 0, 0, 4, 1, 1);
10328 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10329 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
10330 set_box(&box, 0, 1, 0, 1, 3, 1);
10331 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10332 &bitmap_data[2], sizeof(*bitmap_data), 0);
10333 set_box(&box, 4, 4, 0, 3, 1, 1);
10334 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10335 bitmap_data, sizeof(*bitmap_data), 0);
10336 set_box(&box, 0, 0, 0, 4, 4, 0);
10337 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10338 bitmap_data, 4 * sizeof(*bitmap_data), 0);
10339 draw_quad(&test_context);
10340 get_texture_readback(test_context.backbuffer, 0, &rb);
10341 for (i = 0; i < 4; ++i)
10343 for (j = 0; j < 4; ++j)
10345 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10346 ok(compare_color(color, expected_colors[j + i * 4], 1),
10347 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10348 color, j, i, expected_colors[j + i * 4]);
10351 release_resource_readback(&rb);
10353 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
10354 bitmap_data, 4 * sizeof(*bitmap_data), 0);
10355 draw_quad(&test_context);
10356 get_texture_readback(test_context.backbuffer, 0, &rb);
10357 for (i = 0; i < 4; ++i)
10359 for (j = 0; j < 4; ++j)
10361 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10362 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10363 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10364 color, j, i, bitmap_data[j + i * 4]);
10367 release_resource_readback(&rb);
10369 ID3D11PixelShader_Release(ps);
10370 ID3D11SamplerState_Release(sampler_state);
10371 ID3D11ShaderResourceView_Release(ps_srv);
10372 ID3D11Texture2D_Release(texture);
10373 release_test_context(&test_context);
10376 static void test_copy_subresource_region(void)
10378 ID3D11Texture2D *dst_texture, *src_texture;
10379 struct d3d11_test_context test_context;
10380 ID3D11Buffer *dst_buffer, *src_buffer;
10381 D3D11_SUBRESOURCE_DATA resource_data;
10382 D3D11_TEXTURE2D_DESC texture_desc;
10383 ID3D11SamplerState *sampler_state;
10384 ID3D11ShaderResourceView *ps_srv;
10385 D3D11_SAMPLER_DESC sampler_desc;
10386 ID3D11DeviceContext *context;
10387 struct vec4 float_colors[16];
10388 struct resource_readback rb;
10389 ID3D11PixelShader *ps;
10390 ID3D11Device *device;
10391 unsigned int i, j;
10392 D3D11_BOX box;
10393 DWORD color;
10394 HRESULT hr;
10396 static const DWORD ps_code[] =
10398 #if 0
10399 Texture2D t;
10400 SamplerState s;
10402 float4 main(float4 position : SV_POSITION) : SV_Target
10404 float2 p;
10406 p.x = position.x / 640.0f;
10407 p.y = position.y / 480.0f;
10408 return t.Sample(s, p);
10410 #endif
10411 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
10412 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10413 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10414 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10415 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
10416 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10417 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10418 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10419 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
10420 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
10422 static const DWORD ps_buffer_code[] =
10424 #if 0
10425 float4 buffer[16];
10427 float4 main(float4 position : SV_POSITION) : SV_TARGET
10429 float2 p = (float2)4;
10430 p *= float2(position.x / 640.0f, position.y / 480.0f);
10431 return buffer[(int)p.y * 4 + (int)p.x];
10433 #endif
10434 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
10435 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10436 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10437 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10438 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
10439 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
10440 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
10441 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
10442 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
10443 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
10444 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
10445 0x0010000a, 0x00000000, 0x0100003e,
10447 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10448 static const DWORD initial_data[16] = {0};
10449 static const DWORD bitmap_data[] =
10451 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
10452 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
10453 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
10454 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
10456 static const DWORD expected_colors[] =
10458 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
10459 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
10460 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
10461 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
10464 if (!init_test_context(&test_context, NULL))
10465 return;
10467 device = test_context.device;
10468 context = test_context.immediate_context;
10470 texture_desc.Width = 4;
10471 texture_desc.Height = 4;
10472 texture_desc.MipLevels = 1;
10473 texture_desc.ArraySize = 1;
10474 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10475 texture_desc.SampleDesc.Count = 1;
10476 texture_desc.SampleDesc.Quality = 0;
10477 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10478 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
10479 texture_desc.CPUAccessFlags = 0;
10480 texture_desc.MiscFlags = 0;
10482 resource_data.pSysMem = initial_data;
10483 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
10484 resource_data.SysMemSlicePitch = 0;
10486 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
10487 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10489 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
10491 resource_data.pSysMem = bitmap_data;
10492 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
10493 resource_data.SysMemSlicePitch = 0;
10495 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
10496 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10498 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
10499 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10501 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
10502 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10503 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10504 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10505 sampler_desc.MipLODBias = 0.0f;
10506 sampler_desc.MaxAnisotropy = 0;
10507 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
10508 sampler_desc.BorderColor[0] = 0.0f;
10509 sampler_desc.BorderColor[1] = 0.0f;
10510 sampler_desc.BorderColor[2] = 0.0f;
10511 sampler_desc.BorderColor[3] = 0.0f;
10512 sampler_desc.MinLOD = 0.0f;
10513 sampler_desc.MaxLOD = 0.0f;
10515 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
10516 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10518 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10519 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10521 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
10522 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
10523 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10525 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
10527 set_box(&box, 0, 0, 0, 2, 2, 1);
10528 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10529 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
10530 set_box(&box, 1, 2, 0, 4, 3, 1);
10531 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10532 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
10533 set_box(&box, 0, 3, 0, 4, 4, 1);
10534 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10535 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
10536 set_box(&box, 3, 0, 0, 4, 2, 1);
10537 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10538 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
10539 set_box(&box, 3, 1, 0, 4, 2, 1);
10540 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10541 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
10542 set_box(&box, 0, 0, 0, 4, 4, 0);
10543 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10544 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
10545 draw_quad(&test_context);
10546 get_texture_readback(test_context.backbuffer, 0, &rb);
10547 for (i = 0; i < 4; ++i)
10549 for (j = 0; j < 4; ++j)
10551 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10552 ok(compare_color(color, expected_colors[j + i * 4], 1),
10553 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10554 color, j, i, expected_colors[j + i * 4]);
10557 release_resource_readback(&rb);
10559 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10560 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
10561 draw_quad(&test_context);
10562 get_texture_readback(test_context.backbuffer, 0, &rb);
10563 for (i = 0; i < 4; ++i)
10565 for (j = 0; j < 4; ++j)
10567 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10568 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10569 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10570 color, j, i, bitmap_data[j + i * 4]);
10573 release_resource_readback(&rb);
10575 ID3D11PixelShader_Release(ps);
10576 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
10577 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10579 ID3D11ShaderResourceView_Release(ps_srv);
10580 ps_srv = NULL;
10582 ID3D11SamplerState_Release(sampler_state);
10583 sampler_state = NULL;
10585 ID3D11Texture2D_Release(dst_texture);
10586 ID3D11Texture2D_Release(src_texture);
10588 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
10589 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
10590 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10592 memset(float_colors, 0, sizeof(float_colors));
10593 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
10594 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
10596 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
10598 for (i = 0; i < 4; ++i)
10600 for (j = 0; j < 4; ++j)
10602 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
10603 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
10604 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
10605 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
10608 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
10609 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
10611 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
10612 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
10613 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
10614 draw_quad(&test_context);
10615 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10617 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
10618 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
10619 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
10620 draw_quad(&test_context);
10621 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10623 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
10624 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
10625 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
10626 draw_quad(&test_context);
10627 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10629 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
10630 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
10631 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
10632 draw_quad(&test_context);
10633 get_texture_readback(test_context.backbuffer, 0, &rb);
10634 for (i = 0; i < 4; ++i)
10636 for (j = 0; j < 4; ++j)
10638 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10639 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10640 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10641 color, j, i, bitmap_data[j + i * 4]);
10644 release_resource_readback(&rb);
10646 ID3D11Buffer_Release(dst_buffer);
10647 ID3D11Buffer_Release(src_buffer);
10648 ID3D11PixelShader_Release(ps);
10649 release_test_context(&test_context);
10652 static void test_resource_map(void)
10654 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
10655 D3D11_TEXTURE3D_DESC texture3d_desc;
10656 D3D11_TEXTURE2D_DESC texture2d_desc;
10657 D3D11_BUFFER_DESC buffer_desc;
10658 ID3D11DeviceContext *context;
10659 ID3D11Texture3D *texture3d;
10660 ID3D11Texture2D *texture2d;
10661 ID3D11Buffer *buffer;
10662 ID3D11Device *device;
10663 ULONG refcount;
10664 HRESULT hr;
10665 DWORD data;
10667 if (!(device = create_device(NULL)))
10669 skip("Failed to create device.\n");
10670 return;
10673 ID3D11Device_GetImmediateContext(device, &context);
10675 buffer_desc.ByteWidth = 1024;
10676 buffer_desc.Usage = D3D11_USAGE_STAGING;
10677 buffer_desc.BindFlags = 0;
10678 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10679 buffer_desc.MiscFlags = 0;
10680 buffer_desc.StructureByteStride = 0;
10682 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
10683 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
10685 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10686 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10688 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10689 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10690 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
10691 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10692 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
10693 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10694 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
10696 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10697 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10698 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
10699 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10700 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
10701 data = *((DWORD *)mapped_subresource.pData);
10702 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10703 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
10705 refcount = ID3D11Buffer_Release(buffer);
10706 ok(!refcount, "Buffer has %u references left.\n", refcount);
10708 texture2d_desc.Width = 512;
10709 texture2d_desc.Height = 512;
10710 texture2d_desc.MipLevels = 1;
10711 texture2d_desc.ArraySize = 1;
10712 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10713 texture2d_desc.SampleDesc.Count = 1;
10714 texture2d_desc.SampleDesc.Quality = 0;
10715 texture2d_desc.Usage = D3D11_USAGE_STAGING;
10716 texture2d_desc.BindFlags = 0;
10717 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10718 texture2d_desc.MiscFlags = 0;
10720 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
10721 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10723 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10724 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10726 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10727 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10728 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10729 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10730 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
10731 mapped_subresource.DepthPitch);
10732 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10733 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
10735 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10736 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10737 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10738 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10739 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
10740 mapped_subresource.DepthPitch);
10741 data = *((DWORD *)mapped_subresource.pData);
10742 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10743 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
10745 refcount = ID3D11Texture2D_Release(texture2d);
10746 ok(!refcount, "2D texture has %u references left.\n", refcount);
10748 texture3d_desc.Width = 64;
10749 texture3d_desc.Height = 64;
10750 texture3d_desc.Depth = 64;
10751 texture3d_desc.MipLevels = 1;
10752 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10753 texture3d_desc.Usage = D3D11_USAGE_STAGING;
10754 texture3d_desc.BindFlags = 0;
10755 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10756 texture3d_desc.MiscFlags = 0;
10758 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
10759 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
10761 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10762 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10764 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10765 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10766 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10767 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10768 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
10769 mapped_subresource.DepthPitch);
10770 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10771 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
10773 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10774 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10775 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10776 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10777 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
10778 mapped_subresource.DepthPitch);
10779 data = *((DWORD *)mapped_subresource.pData);
10780 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10781 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
10783 refcount = ID3D11Texture3D_Release(texture3d);
10784 ok(!refcount, "3D texture has %u references left.\n", refcount);
10786 ID3D11DeviceContext_Release(context);
10788 refcount = ID3D11Device_Release(device);
10789 ok(!refcount, "Device has %u references left.\n", refcount);
10792 static void test_check_multisample_quality_levels(void)
10794 ID3D11Device *device;
10795 UINT quality_levels;
10796 ULONG refcount;
10797 HRESULT hr;
10799 if (!(device = create_device(NULL)))
10801 skip("Failed to create device.\n");
10802 return;
10805 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10806 if (!quality_levels)
10808 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
10809 goto done;
10812 quality_levels = 0xdeadbeef;
10813 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
10814 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10815 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10816 quality_levels = 0xdeadbeef;
10817 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
10818 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10819 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
10821 quality_levels = 0xdeadbeef;
10822 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
10823 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10824 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
10825 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10826 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10828 quality_levels = 0xdeadbeef;
10829 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
10830 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10831 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
10832 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10833 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
10835 quality_levels = 0xdeadbeef;
10836 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
10837 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10838 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10839 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10840 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10842 /* We assume 15 samples multisampling is never supported in practice. */
10843 quality_levels = 0xdeadbeef;
10844 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
10845 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10846 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10847 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
10848 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10849 quality_levels = 0xdeadbeef;
10850 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
10851 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10852 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10853 quality_levels = 0xdeadbeef;
10854 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
10855 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10856 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10858 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
10859 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10860 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10862 done:
10863 refcount = ID3D11Device_Release(device);
10864 ok(!refcount, "Device has %u references left.\n", refcount);
10867 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
10869 DXGI_SWAP_CHAIN_DESC swapchain_desc;
10870 struct device_desc device_desc;
10871 IDXGISwapChain *swapchain;
10872 IDXGIDevice *dxgi_device;
10873 HRESULT hr, expected_hr;
10874 IDXGIAdapter *adapter;
10875 IDXGIFactory *factory;
10876 ID3D11Device *device;
10877 unsigned int i;
10878 ULONG refcount;
10880 swapchain_desc.BufferDesc.Width = 800;
10881 swapchain_desc.BufferDesc.Height = 600;
10882 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
10883 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
10884 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
10885 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
10886 swapchain_desc.SampleDesc.Count = 1;
10887 swapchain_desc.SampleDesc.Quality = 0;
10888 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
10889 swapchain_desc.BufferCount = 1;
10890 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
10891 swapchain_desc.Windowed = TRUE;
10892 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
10893 swapchain_desc.Flags = 0;
10895 device_desc.feature_level = &feature_level;
10896 device_desc.flags = 0;
10897 if (!(device = create_device(&device_desc)))
10899 skip("Failed to create device for feature level %#x.\n", feature_level);
10900 return;
10903 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
10904 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
10905 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
10906 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
10907 IDXGIDevice_Release(dxgi_device);
10908 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
10909 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
10910 IDXGIAdapter_Release(adapter);
10912 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
10913 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10914 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
10915 hr, feature_level);
10916 if (SUCCEEDED(hr))
10917 IDXGISwapChain_Release(swapchain);
10919 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
10921 DXGI_FORMAT format = display_format_support[i].format;
10922 BOOL todo = FALSE;
10924 if (display_format_support[i].fl_required <= feature_level)
10926 expected_hr = S_OK;
10927 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
10928 todo = TRUE;
10930 else if (!display_format_support[i].fl_optional
10931 || display_format_support[i].fl_optional > feature_level)
10933 expected_hr = E_INVALIDARG;
10934 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
10935 todo = TRUE;
10937 else
10939 continue;
10942 swapchain_desc.BufferDesc.Format = format;
10943 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10944 todo_wine_if(todo)
10945 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
10946 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
10947 hr, expected_hr, feature_level, format);
10948 if (FAILED(hr))
10949 continue;
10950 refcount = IDXGISwapChain_Release(swapchain);
10951 ok(!refcount, "Swapchain has %u references left.\n", refcount);
10954 refcount = ID3D11Device_Release(device);
10955 ok(!refcount, "Device has %u references left.\n", refcount);
10956 refcount = IDXGIFactory_Release(factory);
10957 ok(!refcount, "Factory has %u references left.\n", refcount);
10958 DestroyWindow(swapchain_desc.OutputWindow);
10961 static void test_swapchain_views(void)
10963 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10964 struct d3d11_test_context test_context;
10965 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
10966 ID3D11ShaderResourceView *srv;
10967 ID3D11DeviceContext *context;
10968 ID3D11RenderTargetView *rtv;
10969 ID3D11Device *device;
10970 ULONG refcount;
10971 HRESULT hr;
10973 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
10975 if (!init_test_context(&test_context, NULL))
10976 return;
10978 device = test_context.device;
10979 context = test_context.immediate_context;
10981 refcount = get_refcount(test_context.backbuffer);
10982 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
10984 draw_color_quad(&test_context, &color);
10985 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
10987 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10988 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
10989 U(rtv_desc).Texture2D.MipSlice = 0;
10990 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
10991 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10992 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10994 refcount = get_refcount(test_context.backbuffer);
10995 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
10997 draw_color_quad(&test_context, &color);
10998 todo_wine check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
11000 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11001 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
11002 U(srv_desc).Texture2D.MostDetailedMip = 0;
11003 U(srv_desc).Texture2D.MipLevels = 1;
11004 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
11005 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11006 if (SUCCEEDED(hr))
11007 ID3D11ShaderResourceView_Release(srv);
11009 ID3D11RenderTargetView_Release(rtv);
11010 release_test_context(&test_context);
11013 static void test_swapchain_flip(void)
11015 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
11016 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
11017 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
11018 D3D11_TEXTURE2D_DESC texture_desc;
11019 ID3D11InputLayout *input_layout;
11020 ID3D11DeviceContext *context;
11021 unsigned int stride, offset;
11022 struct swapchain_desc desc;
11023 IDXGISwapChain *swapchain;
11024 ID3D11VertexShader *vs;
11025 ID3D11PixelShader *ps;
11026 ID3D11Device *device;
11027 D3D11_VIEWPORT vp;
11028 ID3D11Buffer *vb;
11029 ULONG refcount;
11030 DWORD color;
11031 HWND window;
11032 HRESULT hr;
11033 RECT rect;
11035 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11037 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11039 static const DWORD vs_code[] =
11041 #if 0
11042 float4 main(float4 position : POSITION) : SV_POSITION
11044 return position;
11046 #endif
11047 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
11048 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11049 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11050 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
11051 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
11052 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
11053 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11056 static const DWORD ps_code[] =
11058 #if 0
11059 Texture2D t0, t1;
11060 SamplerState s;
11062 float4 main(float4 position : SV_POSITION) : SV_Target
11064 float2 p;
11066 p.x = 0.5;
11067 p.y = 0.5;
11068 if (position.x < 320)
11069 return t0.Sample(s, p);
11070 return t1.Sample(s, p);
11072 #endif
11073 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
11074 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11075 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
11076 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11077 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
11078 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
11079 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
11080 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
11081 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
11082 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
11083 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
11084 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
11085 0x00000000, 0x0100003e,
11087 static const struct vec2 quad[] =
11089 {-1.0f, -1.0f},
11090 {-1.0f, 1.0f},
11091 { 1.0f, -1.0f},
11092 { 1.0f, 1.0f},
11094 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
11095 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
11096 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
11098 if (!(device = create_device(NULL)))
11100 skip("Failed to create device, skipping tests.\n");
11101 return;
11103 SetRect(&rect, 0, 0, 640, 480);
11104 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
11105 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11106 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
11107 desc.buffer_count = 3;
11108 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
11109 desc.windowed = TRUE;
11110 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
11111 swapchain = create_swapchain(device, window, &desc);
11113 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
11114 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
11115 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
11116 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
11117 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
11118 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
11120 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
11121 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11122 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
11123 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11124 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
11125 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11127 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
11128 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
11129 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
11130 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
11131 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
11133 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
11134 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
11135 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
11136 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
11137 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
11139 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
11140 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11141 if (SUCCEEDED(hr))
11142 ID3D11RenderTargetView_Release(offscreen_rtv);
11144 ID3D11Device_GetImmediateContext(device, &context);
11146 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
11147 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
11149 texture_desc.Width = 640;
11150 texture_desc.Height = 480;
11151 texture_desc.MipLevels = 1;
11152 texture_desc.ArraySize = 1;
11153 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11154 texture_desc.SampleDesc.Count = 1;
11155 texture_desc.SampleDesc.Quality = 0;
11156 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11157 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11158 texture_desc.CPUAccessFlags = 0;
11159 texture_desc.MiscFlags = 0;
11160 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
11161 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
11162 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
11163 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11164 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
11165 vp.TopLeftX = 0;
11166 vp.TopLeftY = 0;
11167 vp.Width = 640;
11168 vp.Height = 480;
11169 vp.MinDepth = 0.0f;
11170 vp.MaxDepth = 1.0f;
11171 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11173 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11175 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11176 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11177 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11178 vs_code, sizeof(vs_code), &input_layout);
11179 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11180 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
11181 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11182 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11183 stride = sizeof(*quad);
11184 offset = 0;
11185 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
11187 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11188 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11189 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11191 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
11193 ID3D11DeviceContext_Draw(context, 4, 0);
11194 color = get_texture_color(offscreen, 120, 240);
11195 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11197 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
11198 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
11199 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
11201 * What is this good for? I don't know. Ad-hoc tests suggest that
11202 * Present() always waits for the next V-sync interval, even if there are
11203 * still untouched buffers. Buffer 0 is the buffer that is shown on the
11204 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
11205 * rendering finishes before the V-sync interval is over. I haven't found
11206 * any productive use for more than one buffer. */
11207 IDXGISwapChain_Present(swapchain, 0, 0);
11209 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
11211 ID3D11DeviceContext_Draw(context, 4, 0);
11212 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
11213 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11214 /* Buffer 1 is still untouched. */
11216 color = get_texture_color(backbuffer_0, 320, 240); /* green */
11217 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11218 color = get_texture_color(backbuffer_2, 320, 240); /* red */
11219 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11221 IDXGISwapChain_Present(swapchain, 0, 0);
11223 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
11225 ID3D11DeviceContext_Draw(context, 4, 0);
11226 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
11227 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
11228 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
11229 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11231 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
11232 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
11233 color = get_texture_color(backbuffer_1, 320, 240); /* red */
11234 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11235 color = get_texture_color(backbuffer_2, 320, 240); /* green */
11236 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11238 ID3D11VertexShader_Release(vs);
11239 ID3D11PixelShader_Release(ps);
11240 ID3D11Buffer_Release(vb);
11241 ID3D11InputLayout_Release(input_layout);
11242 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
11243 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
11244 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
11245 ID3D11RenderTargetView_Release(offscreen_rtv);
11246 ID3D11Texture2D_Release(offscreen);
11247 ID3D11Texture2D_Release(backbuffer_0);
11248 ID3D11Texture2D_Release(backbuffer_1);
11249 ID3D11Texture2D_Release(backbuffer_2);
11250 IDXGISwapChain_Release(swapchain);
11252 ID3D11DeviceContext_Release(context);
11253 refcount = ID3D11Device_Release(device);
11254 ok(!refcount, "Device has %u references left.\n", refcount);
11255 DestroyWindow(window);
11258 static void test_clear_render_target_view(void)
11260 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
11261 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
11262 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
11264 ID3D11Texture2D *texture, *srgb_texture;
11265 struct d3d11_test_context test_context;
11266 ID3D11RenderTargetView *rtv, *srgb_rtv;
11267 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
11268 D3D11_TEXTURE2D_DESC texture_desc;
11269 ID3D11DeviceContext *context;
11270 struct resource_readback rb;
11271 ID3D11Device *device;
11272 unsigned int i, j;
11273 HRESULT hr;
11275 if (!init_test_context(&test_context, NULL))
11276 return;
11278 device = test_context.device;
11279 context = test_context.immediate_context;
11281 texture_desc.Width = 640;
11282 texture_desc.Height = 480;
11283 texture_desc.MipLevels = 1;
11284 texture_desc.ArraySize = 1;
11285 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11286 texture_desc.SampleDesc.Count = 1;
11287 texture_desc.SampleDesc.Quality = 0;
11288 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11289 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11290 texture_desc.CPUAccessFlags = 0;
11291 texture_desc.MiscFlags = 0;
11292 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11293 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11295 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11296 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
11297 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11299 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11300 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11302 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
11303 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11305 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
11306 check_texture_color(test_context.backbuffer, expected_color, 1);
11308 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
11309 check_texture_color(texture, expected_color, 1);
11311 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
11312 check_texture_color(texture, expected_color, 1);
11314 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
11315 check_texture_color(srgb_texture, expected_srgb_color, 1);
11317 ID3D11RenderTargetView_Release(srgb_rtv);
11318 ID3D11RenderTargetView_Release(rtv);
11319 ID3D11Texture2D_Release(srgb_texture);
11320 ID3D11Texture2D_Release(texture);
11322 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
11323 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11324 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11326 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11327 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
11328 U(rtv_desc).Texture2D.MipSlice = 0;
11329 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
11330 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11332 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11333 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
11334 U(rtv_desc).Texture2D.MipSlice = 0;
11335 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11336 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11338 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
11339 check_texture_color(texture, expected_color, 1);
11341 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
11342 get_texture_readback(texture, 0, &rb);
11343 for (i = 0; i < 4; ++i)
11345 for (j = 0; j < 4; ++j)
11347 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
11348 DWORD color = get_readback_color(&rb, 80 + i * 160, 60 + j * 120);
11349 ok(compare_color(color, expected_srgb_color, 1)
11350 || broken(compare_color(color, expected_color, 1) && broken_device),
11351 "Got unexpected color 0x%08x.\n", color);
11354 release_resource_readback(&rb);
11356 ID3D11RenderTargetView_Release(srgb_rtv);
11357 ID3D11RenderTargetView_Release(rtv);
11358 ID3D11Texture2D_Release(texture);
11359 release_test_context(&test_context);
11362 static void test_clear_depth_stencil_view(void)
11364 D3D11_TEXTURE2D_DESC texture_desc;
11365 ID3D11Texture2D *depth_texture;
11366 ID3D11DeviceContext *context;
11367 ID3D11DepthStencilView *dsv;
11368 ID3D11Device *device;
11369 ULONG refcount;
11370 HRESULT hr;
11372 if (!(device = create_device(NULL)))
11374 skip("Failed to create device.\n");
11375 return;
11378 ID3D11Device_GetImmediateContext(device, &context);
11380 texture_desc.Width = 640;
11381 texture_desc.Height = 480;
11382 texture_desc.MipLevels = 1;
11383 texture_desc.ArraySize = 1;
11384 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11385 texture_desc.SampleDesc.Count = 1;
11386 texture_desc.SampleDesc.Quality = 0;
11387 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11388 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
11389 texture_desc.CPUAccessFlags = 0;
11390 texture_desc.MiscFlags = 0;
11391 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
11392 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11394 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
11395 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11397 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11398 check_texture_float(depth_texture, 1.0f, 0);
11400 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
11401 check_texture_float(depth_texture, 0.25f, 0);
11403 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
11404 check_texture_float(depth_texture, 0.25f, 0);
11406 ID3D11Texture2D_Release(depth_texture);
11407 ID3D11DepthStencilView_Release(dsv);
11409 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
11410 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
11411 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11413 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
11414 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11416 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
11417 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
11419 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
11420 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
11422 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
11423 check_texture_color(depth_texture, 0xffffffff, 0);
11425 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
11426 check_texture_color(depth_texture, 0x00000000, 0);
11428 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
11429 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
11431 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
11432 check_texture_color(depth_texture, 0xffffffff, 0);
11434 ID3D11Texture2D_Release(depth_texture);
11435 ID3D11DepthStencilView_Release(dsv);
11437 ID3D11DeviceContext_Release(context);
11439 refcount = ID3D11Device_Release(device);
11440 ok(!refcount, "Device has %u references left.\n", refcount);
11443 static unsigned int to_sint8(unsigned int x)
11445 union
11447 signed int s;
11448 unsigned int u;
11449 } bits;
11450 bits.u = x;
11451 return min(max(bits.s, -128), 127) & 0xff;
11454 #define check_rgba_sint8(data, uvec) check_rgba_sint8_(__LINE__, data, uvec)
11455 static void check_rgba_sint8_(unsigned int line, DWORD data, const struct uvec4 *v)
11457 unsigned int x = to_sint8(v->x);
11458 unsigned int y = to_sint8(v->y);
11459 unsigned int z = to_sint8(v->z);
11460 unsigned int w = to_sint8(v->w);
11461 DWORD expected[] =
11463 /* Windows 7 - Nvidia, WARP */
11464 (v->x & 0xff) | (v->y & 0xff) << 8 | (v->z & 0xff) << 16 | (v->w & 0xff) << 24,
11465 /* Windows 10 - AMD */
11466 x | y << 8 | z << 16 | w << 24,
11467 /* Windows 10 - Intel */
11468 x | x << 8 | x << 16 | x << 24,
11471 ok_(__FILE__, line)(data == expected[0] || data == expected[1] || broken(data == expected[2]),
11472 "Got %#x, expected %#x or %#x at %u, uvec4 %#x, %#x, %#x, %#x.\n",
11473 data, expected[0], expected[1], x, v->x, v->y, v->z, v->w);
11476 static void test_clear_buffer_unordered_access_view(void)
11478 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
11479 ID3D11UnorderedAccessView *uav, *uav2;
11480 struct device_desc device_desc;
11481 D3D11_BUFFER_DESC buffer_desc;
11482 ID3D11DeviceContext *context;
11483 struct resource_readback rb;
11484 ID3D11Buffer *buffer;
11485 ID3D11Device *device;
11486 struct uvec4 uvec4;
11487 unsigned int i, x;
11488 ULONG refcount;
11489 HRESULT hr;
11491 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11492 static const struct uvec4 fe_uvec4 = {0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe};
11493 static const struct uvec4 uvec4_data[] =
11495 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
11497 {0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
11498 {0xffffffff, 0x00000000, 0x00000000, 0x00000000},
11499 {0x00000000, 0xffffffff, 0x00000000, 0x00000000},
11500 {0x00000000, 0x00000000, 0xffffffff, 0x00000000},
11501 {0x00000000, 0x00000000, 0x00000000, 0xffffffff},
11503 {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff},
11504 {0x80000000, 0x80000000, 0x80000000, 0x80000000},
11505 {0x000000ff, 0x00000080, 0x80000080, 0x00000080},
11506 {0x000000ff, 0x0000007f, 0x000000ef, 0x000000fe},
11507 {0x800000ff, 0x8000007f, 0x800000ef, 0x800000fe},
11508 {0xfefefefe, 0xf0f0f0f0, 0xefefefef, 0x0f0f0f0f},
11509 {0xaaaaaaaa, 0xdeadbeef, 0xdeadbabe, 0xdeadf00d},
11511 {0x00000001, 0x00000002, 0x00000003, 0x00000004},
11512 {0x000000ff, 0x000000fe, 0x000000fd, 0x000000fc},
11513 {0x000000f2, 0x000000f1, 0x000000f0, 0x000000ef},
11514 {0x0000000a, 0x0000000d, 0x0000000e, 0x0000000f},
11515 {0x0000001a, 0x0000002d, 0x0000003e, 0x0000004f},
11516 {0x00000050, 0x00000060, 0x00000070, 0x00000080},
11517 {0x00000090, 0x000000a0, 0x000000b0, 0x000000c0},
11518 {0x000000d0, 0x000000e0, 0x000000f0, 0x000000ff},
11519 {0x00000073, 0x00000077, 0x0000007a, 0x0000007b},
11520 {0x0000007c, 0x0000007d, 0x0000007e, 0x0000007f},
11522 {0x80000001, 0x80000002, 0x80000003, 0x80000004},
11523 {0x800000ff, 0x800000fe, 0x800000fd, 0x800000fc},
11524 {0x800000f2, 0x800000f1, 0x800000f0, 0x800000ef},
11525 {0x8000000a, 0x0000000d, 0x8000000e, 0x8000000f},
11526 {0x8000001a, 0x8000002d, 0x8000003e, 0x8000004f},
11527 {0x80000050, 0x80000060, 0x80000070, 0x00000080},
11528 {0x80000090, 0x800000a0, 0x800000b0, 0x800000c0},
11529 {0x800000d0, 0x800000e0, 0x800000f0, 0x800000ff},
11530 {0x80000073, 0x80000077, 0x8000007a, 0x8000007b},
11531 {0x8000007c, 0x8000007d, 0x8000007e, 0x8000007f},
11533 {0x7fffff01, 0x7fffff02, 0x7fffff03, 0x7fffff04},
11534 {0x7fffffff, 0x7ffffffe, 0x7ffffffd, 0x7ffffffc},
11535 {0x7ffffff2, 0x7ffffff1, 0x7ffffff0, 0x7fffffef},
11536 {0x7fffff0a, 0x7fffff0d, 0x7fffff0e, 0x7fffff0f},
11537 {0x7fffff1a, 0x7fffff2d, 0x7fffff3e, 0x7fffff4f},
11538 {0x7fffff50, 0x7fffff60, 0x7fffff70, 0x7fffff80},
11539 {0x8fffff90, 0x7fffffa0, 0x7fffffb0, 0x7fffffc0},
11540 {0x7fffffd0, 0x7fffffe0, 0x7ffffff0, 0x7fffffff},
11541 {0x7fffff73, 0x7fffff77, 0x7fffff7a, 0x7fffff7b},
11542 {0x7fffff7c, 0x7fffff7d, 0x7fffff7e, 0x7fffff7f},
11544 {0xffffff01, 0xffffff02, 0xffffff03, 0xffffff04},
11545 {0xffffffff, 0xfffffffe, 0xfffffffd, 0xfffffffc},
11546 {0xfffffff2, 0xfffffff1, 0xfffffff0, 0xffffffef},
11547 {0xffffff0a, 0xffffff0d, 0xffffff0e, 0xffffff0f},
11548 {0xffffff1a, 0xffffff2d, 0xffffff3e, 0xffffff4f},
11549 {0xffffff50, 0xffffff60, 0xffffff70, 0xffffff80},
11550 {0xffffff90, 0xffffffa0, 0xffffffb0, 0xffffffc0},
11551 {0xffffffd0, 0xffffffe0, 0xfffffff0, 0xffffffff},
11552 {0xffffff73, 0xffffff77, 0xffffff7a, 0xffffff7b},
11553 {0xffffff7c, 0xffffff7d, 0xffffff7e, 0xffffff7f},
11556 device_desc.feature_level = &feature_level;
11557 device_desc.flags = 0;
11558 if (!(device = create_device(&device_desc)))
11560 skip("Failed to create device for feature level %#x.\n", feature_level);
11561 return;
11564 ID3D11Device_GetImmediateContext(device, &context);
11566 /* Structured buffer views */
11567 buffer_desc.ByteWidth = 64;
11568 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
11569 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
11570 buffer_desc.CPUAccessFlags = 0;
11571 buffer_desc.MiscFlags = 0;
11572 buffer_desc.StructureByteStride = 0;
11573 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
11574 buffer_desc.StructureByteStride = 4;
11575 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11576 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11578 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
11579 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11581 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
11582 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11583 U(uav_desc).Buffer.FirstElement = 0;
11584 U(uav_desc).Buffer.NumElements = 4;
11585 U(uav_desc).Buffer.Flags = 0;
11586 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11587 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11589 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11591 uvec4 = uvec4_data[i];
11592 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11593 get_buffer_readback(buffer, &rb);
11594 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11596 DWORD data = get_readback_color(&rb, x, 0);
11597 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11599 release_resource_readback(&rb);
11601 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11602 get_buffer_readback(buffer, &rb);
11603 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11605 DWORD data = get_readback_color(&rb, x, 0);
11606 uvec4 = x < U(uav_desc).Buffer.NumElements ? fe_uvec4 : uvec4_data[i];
11607 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11609 release_resource_readback(&rb);
11612 ID3D11Buffer_Release(buffer);
11613 ID3D11UnorderedAccessView_Release(uav);
11614 ID3D11UnorderedAccessView_Release(uav2);
11616 /* Raw buffer views */
11617 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
11618 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11619 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11621 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
11622 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11623 U(uav_desc).Buffer.FirstElement = 0;
11624 U(uav_desc).Buffer.NumElements = 16;
11625 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
11626 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11627 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11628 U(uav_desc).Buffer.FirstElement = 8;
11629 U(uav_desc).Buffer.NumElements = 8;
11630 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11631 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11633 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11635 uvec4 = uvec4_data[i];
11636 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11637 get_buffer_readback(buffer, &rb);
11638 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11640 DWORD data = get_readback_color(&rb, x, 0);
11641 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11643 release_resource_readback(&rb);
11645 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11646 get_buffer_readback(buffer, &rb);
11647 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11649 DWORD data = get_readback_color(&rb, x, 0);
11650 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11651 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11653 release_resource_readback(&rb);
11656 ID3D11Buffer_Release(buffer);
11657 ID3D11UnorderedAccessView_Release(uav);
11658 ID3D11UnorderedAccessView_Release(uav2);
11660 /* Typed buffer views */
11661 buffer_desc.MiscFlags = 0;
11662 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11663 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11665 uav_desc.Format = DXGI_FORMAT_R32_SINT;
11666 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11667 U(uav_desc).Buffer.FirstElement = 0;
11668 U(uav_desc).Buffer.NumElements = 16;
11669 U(uav_desc).Buffer.Flags = 0;
11670 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11671 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11672 U(uav_desc).Buffer.FirstElement = 9;
11673 U(uav_desc).Buffer.NumElements = 7;
11674 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11675 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11677 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11679 uvec4 = uvec4_data[i];
11680 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11681 get_buffer_readback(buffer, &rb);
11682 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11684 DWORD data = get_readback_color(&rb, x, 0);
11685 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11687 release_resource_readback(&rb);
11689 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11690 get_buffer_readback(buffer, &rb);
11691 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11693 DWORD data = get_readback_color(&rb, x, 0);
11694 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11695 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11697 release_resource_readback(&rb);
11700 ID3D11UnorderedAccessView_Release(uav);
11701 ID3D11UnorderedAccessView_Release(uav2);
11703 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
11704 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11705 U(uav_desc).Buffer.FirstElement = 0;
11706 U(uav_desc).Buffer.NumElements = 4;
11707 U(uav_desc).Buffer.Flags = 0;
11708 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11709 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11710 U(uav_desc).Buffer.FirstElement = 2;
11711 U(uav_desc).Buffer.NumElements = 2;
11712 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11713 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11715 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11717 uvec4 = uvec4_data[i];
11718 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11719 get_buffer_readback(buffer, &rb);
11720 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
11722 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
11723 const struct uvec4 broken_result = {uvec4.x, uvec4.x, uvec4.x, uvec4.x}; /* Intel */
11724 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
11725 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
11726 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
11728 release_resource_readback(&rb);
11730 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11731 get_buffer_readback(buffer, &rb);
11732 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
11734 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
11735 struct uvec4 broken_result;
11736 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11737 broken_result.x = broken_result.y = broken_result.z = broken_result.w = uvec4.x;
11738 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
11739 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
11740 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
11742 release_resource_readback(&rb);
11745 uvec4.x = uvec4.y = uvec4.z = uvec4.w = 0xdeadbeef;
11746 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11747 ID3D11UnorderedAccessView_Release(uav);
11748 ID3D11UnorderedAccessView_Release(uav2);
11750 uav_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT;
11751 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11752 U(uav_desc).Buffer.FirstElement = 0;
11753 U(uav_desc).Buffer.NumElements = 16;
11754 U(uav_desc).Buffer.Flags = 0;
11755 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11756 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11757 U(uav_desc).Buffer.FirstElement = 8;
11758 U(uav_desc).Buffer.NumElements = 8;
11759 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11760 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11762 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11764 uvec4 = uvec4_data[i];
11765 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11766 get_buffer_readback(buffer, &rb);
11767 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11768 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0), &uvec4);
11769 release_resource_readback(&rb);
11771 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11772 get_buffer_readback(buffer, &rb);
11773 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11775 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11776 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0), &uvec4);
11778 release_resource_readback(&rb);
11781 ID3D11UnorderedAccessView_Release(uav);
11782 ID3D11UnorderedAccessView_Release(uav2);
11784 ID3D11Buffer_Release(buffer);
11786 ID3D11DeviceContext_Release(context);
11787 refcount = ID3D11Device_Release(device);
11788 ok(!refcount, "Device has %u references left.\n", refcount);
11791 static void test_initial_depth_stencil_state(void)
11793 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11794 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
11795 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11796 struct d3d11_test_context test_context;
11797 D3D11_TEXTURE2D_DESC texture_desc;
11798 ID3D11DeviceContext *context;
11799 ID3D11DepthStencilView *dsv;
11800 ID3D11Texture2D *texture;
11801 ID3D11Device *device;
11802 unsigned int count;
11803 D3D11_VIEWPORT vp;
11804 HRESULT hr;
11806 if (!init_test_context(&test_context, NULL))
11807 return;
11809 device = test_context.device;
11810 context = test_context.immediate_context;
11812 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11813 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11814 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
11815 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11816 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11818 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
11819 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11821 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
11823 count = 1;
11824 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
11826 /* check if depth function is D3D11_COMPARISON_LESS */
11827 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
11828 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
11829 vp.MinDepth = vp.MaxDepth = 0.4f;
11830 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11831 draw_color_quad(&test_context, &green);
11832 draw_color_quad(&test_context, &red);
11833 vp.MinDepth = vp.MaxDepth = 0.6f;
11834 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11835 draw_color_quad(&test_context, &red);
11836 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
11837 check_texture_float(texture, 0.4f, 1);
11839 ID3D11DepthStencilView_Release(dsv);
11840 ID3D11Texture2D_Release(texture);
11841 release_test_context(&test_context);
11844 static void test_draw_depth_only(void)
11846 struct d3d11_test_context test_context;
11847 ID3D11PixelShader *ps_color, *ps_depth;
11848 D3D11_TEXTURE2D_DESC texture_desc;
11849 ID3D11DeviceContext *context;
11850 ID3D11DepthStencilView *dsv;
11851 struct resource_readback rb;
11852 ID3D11Texture2D *texture;
11853 ID3D11Device *device;
11854 unsigned int i, j;
11855 D3D11_VIEWPORT vp;
11856 struct vec4 depth;
11857 ID3D11Buffer *cb;
11858 HRESULT hr;
11860 static const DWORD ps_color_code[] =
11862 #if 0
11863 float4 main(float4 position : SV_POSITION) : SV_Target
11865 return float4(0.0, 1.0, 0.0, 1.0);
11867 #endif
11868 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
11869 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11870 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
11871 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11872 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
11873 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
11874 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
11876 static const DWORD ps_depth_code[] =
11878 #if 0
11879 float depth;
11881 float main() : SV_Depth
11883 return depth;
11885 #endif
11886 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
11887 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11888 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
11889 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11890 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
11891 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
11894 if (!init_test_context(&test_context, NULL))
11895 return;
11897 device = test_context.device;
11898 context = test_context.immediate_context;
11900 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
11902 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11903 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11904 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
11905 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11906 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11908 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
11909 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11911 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
11912 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11913 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
11914 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11916 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11917 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
11918 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
11920 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11921 check_texture_float(texture, 1.0f, 1);
11922 draw_quad(&test_context);
11923 check_texture_float(texture, 0.0f, 1);
11925 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
11927 depth.x = 0.7f;
11928 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11929 draw_quad(&test_context);
11930 check_texture_float(texture, 0.0f, 1);
11931 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11932 check_texture_float(texture, 1.0f, 1);
11933 draw_quad(&test_context);
11934 check_texture_float(texture, 0.7f, 1);
11935 depth.x = 0.8f;
11936 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11937 draw_quad(&test_context);
11938 check_texture_float(texture, 0.7f, 1);
11939 depth.x = 0.5f;
11940 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11941 draw_quad(&test_context);
11942 check_texture_float(texture, 0.5f, 1);
11944 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11945 for (i = 0; i < 4; ++i)
11947 for (j = 0; j < 4; ++j)
11949 depth.x = 1.0f / 16.0f * (j + 4 * i);
11950 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11952 vp.TopLeftX = 160.0f * j;
11953 vp.TopLeftY = 120.0f * i;
11954 vp.Width = 160.0f;
11955 vp.Height = 120.0f;
11956 vp.MinDepth = 0.0f;
11957 vp.MaxDepth = 1.0f;
11958 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11960 draw_quad(&test_context);
11963 get_texture_readback(texture, 0, &rb);
11964 for (i = 0; i < 4; ++i)
11966 for (j = 0; j < 4; ++j)
11968 float obtained_depth, expected_depth;
11970 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
11971 expected_depth = 1.0f / 16.0f * (j + 4 * i);
11972 ok(compare_float(obtained_depth, expected_depth, 1),
11973 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
11974 obtained_depth, j, i, expected_depth);
11977 release_resource_readback(&rb);
11979 ID3D11Buffer_Release(cb);
11980 ID3D11PixelShader_Release(ps_color);
11981 ID3D11PixelShader_Release(ps_depth);
11982 ID3D11DepthStencilView_Release(dsv);
11983 ID3D11Texture2D_Release(texture);
11984 release_test_context(&test_context);
11987 static void test_draw_uav_only(void)
11989 struct d3d11_test_context test_context;
11990 D3D11_TEXTURE2D_DESC texture_desc;
11991 ID3D11UnorderedAccessView *uav;
11992 ID3D11DeviceContext *context;
11993 ID3D11Texture2D *texture;
11994 ID3D11PixelShader *ps;
11995 ID3D11Device *device;
11996 D3D11_VIEWPORT vp;
11997 HRESULT hr;
11999 static const DWORD ps_code[] =
12001 #if 0
12002 RWTexture2D<int> u;
12004 void main()
12006 InterlockedAdd(u[uint2(0, 0)], 1);
12008 #endif
12009 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
12010 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12011 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
12012 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
12013 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
12015 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12016 static const UINT values[4] = {0};
12018 if (!init_test_context(&test_context, &feature_level))
12019 return;
12021 device = test_context.device;
12022 context = test_context.immediate_context;
12024 texture_desc.Width = 1;
12025 texture_desc.Height = 1;
12026 texture_desc.MipLevels = 1;
12027 texture_desc.ArraySize = 1;
12028 texture_desc.Format = DXGI_FORMAT_R32_SINT;
12029 texture_desc.SampleDesc.Count = 1;
12030 texture_desc.SampleDesc.Quality = 0;
12031 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12032 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
12033 texture_desc.CPUAccessFlags = 0;
12034 texture_desc.MiscFlags = 0;
12036 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12037 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12039 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
12040 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12042 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12043 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12045 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12046 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
12047 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &test_context.backbuffer_rtv, NULL,
12048 0, 1, &uav, NULL);
12050 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
12051 memset(&vp, 0, sizeof(vp));
12052 vp.Width = 1.0f;
12053 vp.Height = 100.0f;
12054 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
12055 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
12056 draw_quad(&test_context);
12057 check_texture_color(texture, 100, 1);
12059 draw_quad(&test_context);
12060 draw_quad(&test_context);
12061 draw_quad(&test_context);
12062 draw_quad(&test_context);
12063 check_texture_color(texture, 500, 1);
12065 ID3D11PixelShader_Release(ps);
12066 ID3D11Texture2D_Release(texture);
12067 ID3D11UnorderedAccessView_Release(uav);
12068 release_test_context(&test_context);
12071 static void test_cb_relative_addressing(void)
12073 struct d3d11_test_context test_context;
12074 ID3D11Buffer *colors_cb, *index_cb;
12075 unsigned int i, index[4] = {0};
12076 ID3D11DeviceContext *context;
12077 ID3D11PixelShader *ps;
12078 ID3D11Device *device;
12079 HRESULT hr;
12081 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12083 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12085 static const DWORD vs_code[] =
12087 #if 0
12088 int color_index;
12090 cbuffer colors
12092 float4 colors[8];
12095 struct vs_in
12097 float4 position : POSITION;
12100 struct vs_out
12102 float4 position : SV_POSITION;
12103 float4 color : COLOR;
12106 vs_out main(const vs_in v)
12108 vs_out o;
12110 o.position = v.position;
12111 o.color = colors[color_index];
12113 return o;
12115 #endif
12116 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
12117 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12118 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
12119 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12120 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12121 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
12122 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
12123 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
12124 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
12125 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
12126 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
12127 0x0100003e,
12129 static const DWORD ps_code[] =
12131 #if 0
12132 struct ps_in
12134 float4 position : SV_POSITION;
12135 float4 color : COLOR;
12138 float4 main(const ps_in v) : SV_TARGET
12140 return v.color;
12142 #endif
12143 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
12144 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12145 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12146 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12147 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12148 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
12149 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
12150 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12152 static const struct
12154 float color[4];
12156 colors[10] =
12158 {{0.0f, 0.0f, 0.0f, 1.0f}},
12159 {{0.0f, 0.0f, 1.0f, 0.0f}},
12160 {{0.0f, 0.0f, 1.0f, 1.0f}},
12161 {{0.0f, 1.0f, 0.0f, 0.0f}},
12162 {{0.0f, 1.0f, 0.0f, 1.0f}},
12163 {{0.0f, 1.0f, 1.0f, 0.0f}},
12164 {{0.0f, 1.0f, 1.0f, 1.0f}},
12165 {{1.0f, 0.0f, 0.0f, 0.0f}},
12166 {{1.0f, 0.0f, 0.0f, 1.0f}},
12167 {{1.0f, 0.0f, 1.0f, 0.0f}},
12169 static const struct
12171 unsigned int index;
12172 DWORD expected;
12174 test_data[] =
12176 {0, 0xff000000},
12177 {1, 0x00ff0000},
12178 {2, 0xffff0000},
12179 {3, 0x0000ff00},
12180 {4, 0xff00ff00},
12181 {5, 0x00ffff00},
12182 {6, 0xffffff00},
12183 {7, 0x000000ff},
12185 {8, 0xff0000ff},
12186 {9, 0x00ff00ff},
12188 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
12189 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12191 if (!init_test_context(&test_context, &feature_level))
12192 return;
12194 device = test_context.device;
12195 context = test_context.immediate_context;
12197 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12198 vs_code, sizeof(vs_code), &test_context.input_layout);
12199 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12201 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
12202 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
12204 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
12205 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12206 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12207 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12209 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
12210 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
12211 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12213 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
12215 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
12217 index[0] = test_data[i].index;
12218 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
12220 draw_quad(&test_context);
12221 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
12224 ID3D11Buffer_Release(index_cb);
12225 ID3D11Buffer_Release(colors_cb);
12226 ID3D11PixelShader_Release(ps);
12228 release_test_context(&test_context);
12231 static void test_vs_input_relative_addressing(void)
12233 struct d3d11_test_context test_context;
12234 ID3D11DeviceContext *context;
12235 unsigned int offset, stride;
12236 unsigned int index[4] = {0};
12237 ID3D11PixelShader *ps;
12238 ID3D11Buffer *vb, *cb;
12239 ID3D11Device *device;
12240 unsigned int i;
12241 HRESULT hr;
12243 static const DWORD vs_code[] =
12245 #if 0
12246 struct vertex
12248 float4 position : POSITION;
12249 float4 colors[4] : COLOR;
12252 uint index;
12254 void main(vertex vin, out float4 position : SV_Position,
12255 out float4 color : COLOR)
12257 position = vin.position;
12258 color = vin.colors[index];
12260 #endif
12261 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003,
12262 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080,
12263 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000,
12264 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
12265 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089,
12266 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300,
12267 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
12268 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
12269 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4,
12270 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2,
12271 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f,
12272 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000,
12273 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2,
12274 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036,
12275 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001,
12276 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
12278 static const DWORD ps_code[] =
12280 #if 0
12281 struct vs_out
12283 float4 position : SV_POSITION;
12284 float4 color : COLOR;
12287 float4 main(struct vs_out i) : SV_TARGET
12289 return i.color;
12291 #endif
12292 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
12293 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12294 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12295 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12296 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12297 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
12298 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
12299 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12301 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12303 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12304 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1},
12305 {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D11_INPUT_PER_INSTANCE_DATA, 1},
12306 {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D11_INPUT_PER_INSTANCE_DATA, 1},
12307 {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D11_INPUT_PER_INSTANCE_DATA, 1},
12309 static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f};
12310 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12312 if (!init_test_context(&test_context, NULL))
12313 return;
12314 device = test_context.device;
12315 context = test_context.immediate_context;
12317 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12318 vs_code, sizeof(vs_code), &test_context.input_layout);
12319 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12321 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
12322 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
12324 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(colors), colors);
12325 stride = sizeof(colors);
12326 offset = 0;
12327 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
12329 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
12330 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12332 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12333 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12334 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12336 for (i = 0; i < ARRAY_SIZE(colors); ++i)
12338 *index = i;
12339 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
12340 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
12341 draw_quad(&test_context);
12342 check_texture_color(test_context.backbuffer, colors[i], 1);
12345 ID3D11Buffer_Release(cb);
12346 ID3D11Buffer_Release(vb);
12347 ID3D11PixelShader_Release(ps);
12348 release_test_context(&test_context);
12351 static void test_getdc(void)
12353 static const struct
12355 const char *name;
12356 DXGI_FORMAT format;
12357 BOOL getdc_supported;
12359 testdata[] =
12361 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
12362 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
12363 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
12364 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
12365 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
12366 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
12368 struct device_desc device_desc;
12369 D3D11_TEXTURE2D_DESC desc;
12370 ID3D11Texture2D *texture;
12371 IDXGISurface1 *surface;
12372 ID3D11Device *device;
12373 unsigned int i;
12374 ULONG refcount;
12375 HRESULT hr;
12376 HDC dc;
12378 device_desc.feature_level = NULL;
12379 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
12380 if (!(device = create_device(&device_desc)))
12382 skip("Failed to create device.\n");
12383 return;
12386 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
12387 desc.Width = 512;
12388 desc.Height = 512;
12389 desc.MipLevels = 1;
12390 desc.ArraySize = 1;
12391 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
12392 desc.SampleDesc.Count = 1;
12393 desc.SampleDesc.Quality = 0;
12394 desc.Usage = D3D11_USAGE_DEFAULT;
12395 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12396 desc.CPUAccessFlags = 0;
12397 desc.MiscFlags = 0;
12398 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12399 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12401 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
12402 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
12404 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
12405 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
12407 IDXGISurface1_Release(surface);
12408 ID3D11Texture2D_Release(texture);
12410 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
12411 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12412 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12414 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
12415 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
12417 hr = IDXGISurface1_ReleaseDC(surface, NULL);
12418 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
12420 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
12421 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
12423 hr = IDXGISurface1_ReleaseDC(surface, NULL);
12424 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
12426 IDXGISurface1_Release(surface);
12427 ID3D11Texture2D_Release(texture);
12429 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
12431 static const unsigned int bit_count = 32;
12432 unsigned int width_bytes;
12433 DIBSECTION dib;
12434 HBITMAP bitmap;
12435 DWORD type;
12436 int size;
12438 desc.Width = 64;
12439 desc.Height = 64;
12440 desc.MipLevels = 1;
12441 desc.ArraySize = 1;
12442 desc.Format = testdata[i].format;
12443 desc.SampleDesc.Count = 1;
12444 desc.SampleDesc.Quality = 0;
12445 desc.Usage = D3D11_USAGE_STAGING;
12446 desc.BindFlags = 0;
12447 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
12448 desc.MiscFlags = 0;
12450 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12451 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12452 ID3D11Texture2D_Release(texture);
12454 /* STAGING usage, requesting GDI compatibility mode. */
12455 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
12456 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12457 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
12459 desc.Usage = D3D11_USAGE_DEFAULT;
12460 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12461 desc.CPUAccessFlags = 0;
12462 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12463 if (testdata[i].getdc_supported)
12464 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
12465 else
12466 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
12468 if (FAILED(hr))
12469 continue;
12471 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
12472 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
12474 dc = (void *)0x1234;
12475 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
12476 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
12478 if (FAILED(hr))
12480 IDXGISurface1_Release(surface);
12481 ID3D11Texture2D_Release(texture);
12482 continue;
12485 type = GetObjectType(dc);
12486 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
12487 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
12488 type = GetObjectType(bitmap);
12489 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
12491 size = GetObjectA(bitmap, sizeof(dib), &dib);
12492 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
12493 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
12495 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
12496 dib.dsBm.bmType, testdata[i].name);
12497 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
12498 dib.dsBm.bmWidth, testdata[i].name);
12499 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
12500 dib.dsBm.bmHeight, testdata[i].name);
12501 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
12502 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
12503 dib.dsBm.bmWidthBytes, testdata[i].name);
12504 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
12505 dib.dsBm.bmPlanes, testdata[i].name);
12506 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
12507 dib.dsBm.bmBitsPixel, testdata[i].name);
12509 if (size == sizeof(dib))
12510 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
12511 dib.dsBm.bmBits, testdata[i].name);
12512 else
12513 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
12514 dib.dsBm.bmBits, testdata[i].name);
12516 if (size == sizeof(dib))
12518 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
12519 dib.dsBmih.biSize, testdata[i].name);
12520 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
12521 dib.dsBmih.biHeight, testdata[i].name);
12522 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
12523 dib.dsBmih.biHeight, testdata[i].name);
12524 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
12525 dib.dsBmih.biPlanes, testdata[i].name);
12526 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
12527 dib.dsBmih.biBitCount, testdata[i].name);
12528 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
12529 dib.dsBmih.biCompression, testdata[i].name);
12530 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
12531 dib.dsBmih.biSizeImage, testdata[i].name);
12532 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
12533 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
12534 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
12535 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
12536 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
12537 dib.dsBmih.biClrUsed, testdata[i].name);
12538 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
12539 dib.dsBmih.biClrImportant, testdata[i].name);
12540 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
12541 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
12542 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
12543 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
12544 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
12547 hr = IDXGISurface1_ReleaseDC(surface, NULL);
12548 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
12550 IDXGISurface1_Release(surface);
12551 ID3D11Texture2D_Release(texture);
12554 refcount = ID3D11Device_Release(device);
12555 ok(!refcount, "Device has %u references left.\n", refcount);
12558 static void test_shader_stage_input_output_matching(void)
12560 struct d3d11_test_context test_context;
12561 D3D11_TEXTURE2D_DESC texture_desc;
12562 ID3D11Texture2D *render_target;
12563 ID3D11RenderTargetView *rtv[2];
12564 ID3D11DeviceContext *context;
12565 ID3D11VertexShader *vs;
12566 ID3D11PixelShader *ps;
12567 ID3D11Device *device;
12568 HRESULT hr;
12570 static const DWORD vs_code[] =
12572 #if 0
12573 struct output
12575 float4 position : SV_PoSiTion;
12576 float4 color0 : COLOR0;
12577 float4 color1 : COLOR1;
12580 void main(uint id : SV_VertexID, out output o)
12582 float2 coords = float2((id << 1) & 2, id & 2);
12583 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
12584 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
12585 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
12587 #endif
12588 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
12589 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12590 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
12591 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
12592 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12593 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
12594 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
12595 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
12596 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
12597 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
12598 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
12599 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
12600 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
12601 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
12602 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
12603 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
12604 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
12605 0x0100003e,
12607 static const DWORD ps_code[] =
12609 #if 0
12610 struct input
12612 float4 position : SV_PoSiTiOn;
12613 float4 color1 : COLOR1;
12614 float4 color0 : COLOR0;
12617 struct output
12619 float4 target0 : SV_Target0;
12620 float4 target1 : SV_Target1;
12623 void main(const in input i, out output o)
12625 o.target0 = i.color0;
12626 o.target1 = i.color1;
12628 #endif
12629 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
12630 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
12631 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
12632 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
12633 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
12634 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
12635 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
12636 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
12637 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
12638 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
12639 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
12642 if (!init_test_context(&test_context, NULL))
12643 return;
12645 device = test_context.device;
12646 context = test_context.immediate_context;
12648 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12649 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12650 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12651 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12653 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12654 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
12655 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12657 rtv[0] = test_context.backbuffer_rtv;
12658 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
12659 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12661 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12662 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12663 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
12664 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
12665 ID3D11DeviceContext_Draw(context, 3, 0);
12667 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12668 check_texture_color(render_target, 0xff0000ff, 0);
12670 ID3D11RenderTargetView_Release(rtv[1]);
12671 ID3D11Texture2D_Release(render_target);
12672 ID3D11PixelShader_Release(ps);
12673 ID3D11VertexShader_Release(vs);
12674 release_test_context(&test_context);
12677 static void test_shader_interstage_interface(void)
12679 struct d3d11_test_context test_context;
12680 D3D11_TEXTURE2D_DESC texture_desc;
12681 ID3D11InputLayout *input_layout;
12682 ID3D11Texture2D *render_target;
12683 ID3D11DeviceContext *context;
12684 ID3D11RenderTargetView *rtv;
12685 ID3D11VertexShader *vs;
12686 ID3D11PixelShader *ps;
12687 ID3D11Device *device;
12688 UINT stride, offset;
12689 ID3D11Buffer *vb;
12690 HRESULT hr;
12692 static const DWORD vs_code[] =
12694 #if 0
12695 struct vertex
12697 float4 position : SV_Position;
12698 float2 t0 : TEXCOORD0;
12699 nointerpolation float t1 : TEXCOORD1;
12700 uint t2 : TEXCOORD2;
12701 uint t3 : TEXCOORD3;
12702 float t4 : TEXCOORD4;
12705 void main(in vertex vin, out vertex vout)
12707 vout = vin;
12709 #endif
12710 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
12711 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
12712 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
12713 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
12714 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
12715 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
12716 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
12717 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
12718 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
12719 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
12720 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
12721 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
12722 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
12723 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
12724 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
12725 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
12726 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
12727 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
12728 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
12729 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
12730 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
12731 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
12733 static const DWORD ps_code[] =
12735 #if 0
12736 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
12737 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
12738 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
12740 o.x = t0.y + t1;
12741 o.y = t2 + t3;
12742 o.z = t4;
12743 o.w = t0.x;
12745 #endif
12746 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
12747 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
12748 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
12749 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
12750 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
12751 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
12752 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
12753 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
12754 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
12755 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
12756 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
12757 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
12758 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
12759 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
12760 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
12762 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12764 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12765 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
12766 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
12767 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
12768 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
12769 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
12771 static const struct
12773 struct vec2 position;
12774 struct vec2 t0;
12775 float t1;
12776 unsigned int t2;
12777 unsigned int t3;
12778 float t4;
12780 quad[] =
12782 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12783 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12784 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12785 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12787 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12788 static const struct vec4 expected_result = {10.0f, 8.0f, 7.0f, 3.0f};
12790 if (!init_test_context(&test_context, NULL))
12791 return;
12793 device = test_context.device;
12794 context = test_context.immediate_context;
12796 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12797 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12798 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12799 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12801 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12802 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12803 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
12804 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12806 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
12807 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12809 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12810 vs_code, sizeof(vs_code), &input_layout);
12811 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12813 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
12815 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
12817 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
12819 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12820 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12821 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12822 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12823 offset = 0;
12824 stride = sizeof(*quad);
12825 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
12826 ID3D11DeviceContext_Draw(context, 4, 0);
12827 check_texture_vec4(render_target, &expected_result, 0);
12829 ID3D11InputLayout_Release(input_layout);
12830 ID3D11RenderTargetView_Release(rtv);
12831 ID3D11Texture2D_Release(render_target);
12832 ID3D11PixelShader_Release(ps);
12833 ID3D11VertexShader_Release(vs);
12834 ID3D11Buffer_Release(vb);
12835 release_test_context(&test_context);
12838 static void test_sm4_if_instruction(void)
12840 struct d3d11_test_context test_context;
12841 ID3D11PixelShader *ps_if_nz, *ps_if_z;
12842 ID3D11DeviceContext *context;
12843 ID3D11Device *device;
12844 unsigned int bits[4];
12845 DWORD expected_color;
12846 ID3D11Buffer *cb;
12847 unsigned int i;
12848 HRESULT hr;
12850 static const DWORD ps_if_nz_code[] =
12852 #if 0
12853 uint bits;
12855 float4 main() : SV_TARGET
12857 if (bits)
12858 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12859 else
12860 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12862 #endif
12863 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
12864 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12865 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12866 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
12867 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
12868 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12869 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12870 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12872 static const DWORD ps_if_z_code[] =
12874 #if 0
12875 uint bits;
12877 float4 main() : SV_TARGET
12879 if (!bits)
12880 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12881 else
12882 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12884 #endif
12885 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
12886 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12887 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12888 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
12889 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
12890 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12891 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12892 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12894 static unsigned int bit_patterns[] =
12896 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
12899 if (!init_test_context(&test_context, NULL))
12900 return;
12902 device = test_context.device;
12903 context = test_context.immediate_context;
12905 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
12906 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
12907 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
12908 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
12910 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
12911 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
12913 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
12915 *bits = bit_patterns[i];
12916 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
12918 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
12919 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
12920 draw_quad(&test_context);
12921 check_texture_color(test_context.backbuffer, expected_color, 0);
12923 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
12924 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
12925 draw_quad(&test_context);
12926 check_texture_color(test_context.backbuffer, expected_color, 0);
12929 ID3D11Buffer_Release(cb);
12930 ID3D11PixelShader_Release(ps_if_z);
12931 ID3D11PixelShader_Release(ps_if_nz);
12932 release_test_context(&test_context);
12935 static void test_sm4_breakc_instruction(void)
12937 struct d3d11_test_context test_context;
12938 ID3D11DeviceContext *context;
12939 ID3D11PixelShader *ps;
12940 ID3D11Device *device;
12941 HRESULT hr;
12943 static const DWORD ps_breakc_nz_code[] =
12945 #if 0
12946 float4 main() : SV_TARGET
12948 uint counter = 0;
12950 for (uint i = 0; i < 255; ++i)
12951 ++counter;
12953 if (counter == 255)
12954 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12955 else
12956 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12958 #endif
12959 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
12960 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12961 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12962 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
12963 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
12964 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
12965 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12966 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
12967 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
12968 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
12969 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
12970 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12971 0x01000015, 0x0100003e,
12973 static const DWORD ps_breakc_z_code[] =
12975 #if 0
12976 float4 main() : SV_TARGET
12978 uint counter = 0;
12980 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
12981 ++counter;
12983 if (counter == 255)
12984 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12985 else
12986 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12988 #endif
12989 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
12990 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12991 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12992 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
12993 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
12994 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
12995 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
12996 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
12997 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
12998 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
12999 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
13000 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
13001 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
13002 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
13005 if (!init_test_context(&test_context, NULL))
13006 return;
13008 device = test_context.device;
13009 context = test_context.immediate_context;
13011 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
13012 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
13013 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13014 draw_quad(&test_context);
13015 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13016 ID3D11PixelShader_Release(ps);
13018 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
13019 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
13020 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13021 draw_quad(&test_context);
13022 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13023 ID3D11PixelShader_Release(ps);
13025 release_test_context(&test_context);
13028 static void test_sm4_continuec_instruction(void)
13030 struct d3d11_test_context test_context;
13031 ID3D11DeviceContext *context;
13032 ID3D11PixelShader *ps;
13033 ID3D11Device *device;
13034 HRESULT hr;
13036 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
13037 * with a normal continue inside, the shaders have been compiled with
13038 * the /Gfa flag. */
13039 static const DWORD ps_continuec_nz_code[] =
13041 #if 0
13042 float4 main() : SV_TARGET
13044 uint counter = 0;
13045 int i = -1;
13047 while (i < 255) {
13048 ++i;
13050 if (i != 0)
13051 continue;
13053 ++counter;
13056 if (counter == 1)
13057 return float4(0.0f, 1.0f, 0.0f, 1.0f);
13058 else
13059 return float4(1.0f, 0.0f, 0.0f, 1.0f);
13061 #endif
13062 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
13063 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13064 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13065 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
13066 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
13067 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
13068 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
13069 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
13070 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
13071 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
13072 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
13073 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
13074 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
13075 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
13076 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
13077 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
13078 0x3f800000, 0x0100003e,
13081 static const DWORD ps_continuec_z_code[] =
13083 #if 0
13084 float4 main() : SV_TARGET
13086 uint counter = 0;
13087 int i = -1;
13089 while (i < 255) {
13090 ++i;
13092 if (i == 0)
13093 continue;
13095 ++counter;
13098 if (counter == 255)
13099 return float4(0.0f, 1.0f, 0.0f, 1.0f);
13100 else
13101 return float4(1.0f, 0.0f, 0.0f, 1.0f);
13103 #endif
13104 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
13105 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13106 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13107 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
13108 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
13109 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
13110 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
13111 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
13112 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
13113 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
13114 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
13115 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
13116 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
13117 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
13118 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
13121 if (!init_test_context(&test_context, NULL))
13122 return;
13124 device = test_context.device;
13125 context = test_context.immediate_context;
13127 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), NULL, &ps);
13128 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
13129 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13130 draw_quad(&test_context);
13131 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13132 ID3D11PixelShader_Release(ps);
13134 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), NULL, &ps);
13135 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
13136 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13137 draw_quad(&test_context);
13138 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13139 ID3D11PixelShader_Release(ps);
13141 release_test_context(&test_context);
13144 static void test_sm4_discard_instruction(void)
13146 ID3D11PixelShader *ps_discard_nz, *ps_discard_z;
13147 struct d3d11_test_context test_context;
13148 ID3D11DeviceContext *context;
13149 ID3D11Device *device;
13150 ID3D11Buffer *cb;
13151 unsigned int i;
13152 HRESULT hr;
13154 static const DWORD ps_discard_nz_code[] =
13156 #if 0
13157 uint data;
13159 float4 main() : SV_Target
13161 if (data)
13162 discard;
13163 return float4(0.0f, 0.5f, 0.0f, 1.0f);
13165 #endif
13166 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
13167 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13168 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13169 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
13170 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
13171 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
13172 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
13174 static const DWORD ps_discard_z_code[] =
13176 #if 0
13177 uint data;
13179 float4 main() : SV_Target
13181 if (!data)
13182 discard;
13183 return float4(0.0f, 1.0f, 0.0f, 1.0f);
13185 #endif
13186 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
13187 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13188 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13189 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
13190 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
13191 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
13192 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
13194 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13195 static const struct uvec4 values[] =
13197 {0x0000000},
13198 {0x0000001},
13199 {0x8000000},
13200 {0xfffffff},
13203 if (!init_test_context(&test_context, NULL))
13204 return;
13206 device = test_context.device;
13207 context = test_context.immediate_context;
13209 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
13210 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13212 hr = ID3D11Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code),
13213 NULL, &ps_discard_nz);
13214 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
13215 hr = ID3D11Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code),
13216 NULL, &ps_discard_z);
13217 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
13219 for (i = 0; i < ARRAY_SIZE(values); ++i)
13221 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &values[i], 0, 0);
13223 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
13224 ID3D11DeviceContext_PSSetShader(context, ps_discard_nz, NULL, 0);
13225 draw_quad(&test_context);
13226 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
13228 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
13229 ID3D11DeviceContext_PSSetShader(context, ps_discard_z, NULL, 0);
13230 draw_quad(&test_context);
13231 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
13234 ID3D11Buffer_Release(cb);
13235 ID3D11PixelShader_Release(ps_discard_nz);
13236 ID3D11PixelShader_Release(ps_discard_z);
13237 release_test_context(&test_context);
13240 static void test_sm5_swapc_instruction(void)
13242 struct input
13244 struct uvec4 src0;
13245 struct uvec4 src1;
13246 struct uvec4 src2;
13249 struct d3d11_test_context test_context;
13250 D3D11_TEXTURE2D_DESC texture_desc;
13251 ID3D11DeviceContext *context;
13252 ID3D11RenderTargetView *rtv;
13253 ID3D11Texture2D *texture;
13254 ID3D11PixelShader *ps[6];
13255 ID3D11Device *device;
13256 ID3D11Buffer *cb;
13257 unsigned int i;
13258 HRESULT hr;
13260 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13261 static const DWORD ps_swapc0_code[] =
13263 #if 0
13264 ps_5_0
13265 dcl_globalFlags refactoringAllowed
13266 dcl_constantbuffer cb0[3], immediateIndexed
13267 dcl_output o0.xyzw
13268 dcl_temps 2
13269 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
13270 mov o0.xyzw, r0.xyzw
13272 #endif
13273 0x43425844, 0x9e089246, 0x9f8b5cbe, 0xbac66faf, 0xaef23488, 0x00000001, 0x000000f8, 0x00000003,
13274 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13275 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13276 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
13277 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13278 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
13279 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
13280 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
13282 static const DWORD ps_swapc1_code[] =
13284 #if 0
13285 ps_5_0
13286 dcl_globalFlags refactoringAllowed
13287 dcl_constantbuffer cb0[3], immediateIndexed
13288 dcl_output o0.xyzw
13289 dcl_temps 2
13290 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
13291 mov o0.xyzw, r1.xyzw
13293 #endif
13294 0x43425844, 0xf2daed61, 0xede211f7, 0x7300dbea, 0x573ed49f, 0x00000001, 0x000000f8, 0x00000003,
13295 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13296 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13297 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
13298 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13299 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
13300 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
13301 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
13303 static const DWORD ps_swapc2_code[] =
13305 #if 0
13306 ps_5_0
13307 dcl_globalFlags refactoringAllowed
13308 dcl_constantbuffer cb0[3], immediateIndexed
13309 dcl_output o0.xyzw
13310 dcl_temps 2
13311 mov r0.xyzw, cb0[1].xyzw
13312 mov r1.xyzw, cb0[2].xyzw
13313 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
13314 mov o0.xyzw, r0.xyzw
13316 #endif
13317 0x43425844, 0x230fcb22, 0x70d99148, 0x65814d89, 0x97473498, 0x00000001, 0x00000120, 0x00000003,
13318 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13319 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13320 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
13321 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13322 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
13323 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
13324 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
13325 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
13327 static const DWORD ps_swapc3_code[] =
13329 #if 0
13330 ps_5_0
13331 dcl_globalFlags refactoringAllowed
13332 dcl_constantbuffer cb0[3], immediateIndexed
13333 dcl_output o0.xyzw
13334 dcl_temps 2
13335 mov r0.xyzw, cb0[1].xyzw
13336 mov r1.xyzw, cb0[2].xyzw
13337 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
13338 mov o0.xyzw, r1.xyzw
13340 #endif
13341 0x43425844, 0xce595d62, 0x98305541, 0xb04e74c8, 0xfc010f3a, 0x00000001, 0x00000120, 0x00000003,
13342 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13343 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13344 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
13345 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13346 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
13347 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
13348 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
13349 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
13351 static const DWORD ps_swapc4_code[] =
13353 #if 0
13354 ps_5_0
13355 dcl_globalFlags refactoringAllowed
13356 dcl_constantbuffer cb0[3], immediateIndexed
13357 dcl_output o0.xyzw
13358 dcl_temps 2
13359 mov r0.xyzw, cb0[0].xyzw
13360 swapc r0.xyzw, r1.xyzw, r0.xyzw, cb0[1].xyzw, cb0[2].xyzw
13361 mov o0.xyzw, r0.xyzw
13363 #endif
13364 0x43425844, 0x72067c48, 0xb53572a0, 0x9dd9e0fd, 0x903e37e3, 0x00000001, 0x0000010c, 0x00000003,
13365 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13366 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13367 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
13368 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13369 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
13370 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000000, 0x00208e46,
13371 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
13372 0x00100e46, 0x00000000, 0x0100003e,
13374 static const DWORD ps_swapc5_code[] =
13376 #if 0
13377 ps_5_0
13378 dcl_globalFlags refactoringAllowed
13379 dcl_constantbuffer cb0[3], immediateIndexed
13380 dcl_output o0.xyzw
13381 dcl_temps 2
13382 mov r1.xyzw, cb0[0].xyzw
13383 swapc r0.xyzw, r1.xyzw, r1.xyzw, cb0[1].xyzw, cb0[2].xyzw
13384 mov o0.xyzw, r1.xyzw
13386 #endif
13387 0x43425844, 0x7078fb08, 0xdd24cd44, 0x469d3258, 0x9e33a0bc, 0x00000001, 0x0000010c, 0x00000003,
13388 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13389 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13390 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
13391 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13392 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000,
13393 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001, 0x00208e46,
13394 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
13395 0x00100e46, 0x00000001, 0x0100003e,
13397 static const struct
13399 struct input input;
13400 struct uvec4 dst0;
13401 struct uvec4 dst1;
13403 tests[] =
13406 {{0, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13407 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}
13410 {{1, 1, 1, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13411 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
13414 {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
13415 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13416 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
13419 {{1, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13420 {0xaaaa, 0xc0de, 0xcccc, 0xeeee}, {0xdead, 0xbbbb, 0xffff, 0xdddd},
13423 {{1, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13424 {0xaaaa, 0xc0de, 0xffff, 0xdddd}, {0xdead, 0xbbbb, 0xcccc, 0xeeee},
13427 {{1, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13428 {0xaaaa, 0xc0de, 0xffff, 0xeeee}, {0xdead, 0xbbbb, 0xcccc, 0xdddd}
13431 {{0, 1, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13432 {0xdead, 0xbbbb, 0xffff, 0xeeee}, {0xaaaa, 0xc0de, 0xcccc, 0xdddd}
13435 {{0, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13436 {0xdead, 0xc0de, 0xcccc, 0xeeee}, {0xaaaa, 0xbbbb, 0xffff, 0xdddd}
13439 {{0, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13440 {0xdead, 0xc0de, 0xffff, 0xdddd}, {0xaaaa, 0xbbbb, 0xcccc, 0xeeee},
13444 if (!init_test_context(&test_context, &feature_level))
13445 return;
13447 device = test_context.device;
13448 context = test_context.immediate_context;
13450 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13451 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
13452 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13453 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13455 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13456 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13458 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13460 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct input), NULL);
13461 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13463 hr = ID3D11Device_CreatePixelShader(device, ps_swapc0_code, sizeof(ps_swapc0_code), NULL, &ps[0]);
13464 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13465 hr = ID3D11Device_CreatePixelShader(device, ps_swapc1_code, sizeof(ps_swapc1_code), NULL, &ps[1]);
13466 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13467 hr = ID3D11Device_CreatePixelShader(device, ps_swapc2_code, sizeof(ps_swapc2_code), NULL, &ps[2]);
13468 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13469 hr = ID3D11Device_CreatePixelShader(device, ps_swapc3_code, sizeof(ps_swapc3_code), NULL, &ps[3]);
13470 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13471 hr = ID3D11Device_CreatePixelShader(device, ps_swapc4_code, sizeof(ps_swapc4_code), NULL, &ps[4]);
13472 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13473 hr = ID3D11Device_CreatePixelShader(device, ps_swapc5_code, sizeof(ps_swapc5_code), NULL, &ps[5]);
13474 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13476 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13478 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &tests[i].input, 0, 0);
13480 ID3D11DeviceContext_PSSetShader(context, ps[0], NULL, 0);
13481 draw_quad(&test_context);
13482 check_texture_uvec4(texture, &tests[i].dst0);
13484 ID3D11DeviceContext_PSSetShader(context, ps[1], NULL, 0);
13485 draw_quad(&test_context);
13486 check_texture_uvec4(texture, &tests[i].dst1);
13488 ID3D11DeviceContext_PSSetShader(context, ps[2], NULL, 0);
13489 draw_quad(&test_context);
13490 check_texture_uvec4(texture, &tests[i].dst0);
13492 ID3D11DeviceContext_PSSetShader(context, ps[3], NULL, 0);
13493 draw_quad(&test_context);
13494 check_texture_uvec4(texture, &tests[i].dst1);
13496 ID3D11DeviceContext_PSSetShader(context, ps[4], NULL, 0);
13497 draw_quad(&test_context);
13498 check_texture_uvec4(texture, &tests[i].dst0);
13500 ID3D11DeviceContext_PSSetShader(context, ps[5], NULL, 0);
13501 draw_quad(&test_context);
13502 check_texture_uvec4(texture, &tests[i].dst1);
13505 for (i = 0; i < ARRAY_SIZE(ps); ++i)
13506 ID3D11PixelShader_Release(ps[i]);
13507 ID3D11RenderTargetView_Release(rtv);
13508 ID3D11Texture2D_Release(texture);
13509 ID3D11Buffer_Release(cb);
13510 release_test_context(&test_context);
13513 static void test_create_input_layout(void)
13515 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13517 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13519 ULONG refcount, expected_refcount;
13520 ID3D11InputLayout *input_layout;
13521 ID3D11Device *device;
13522 unsigned int i;
13523 HRESULT hr;
13525 static const DWORD vs_code[] =
13527 #if 0
13528 float4 main(float4 position : POSITION) : SV_POSITION
13530 return position;
13532 #endif
13533 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
13534 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13535 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
13536 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
13537 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
13538 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
13539 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
13541 static const DXGI_FORMAT vertex_formats[] =
13543 DXGI_FORMAT_R32G32_FLOAT,
13544 DXGI_FORMAT_R32G32_UINT,
13545 DXGI_FORMAT_R32G32_SINT,
13546 DXGI_FORMAT_R16G16_FLOAT,
13547 DXGI_FORMAT_R16G16_UINT,
13548 DXGI_FORMAT_R16G16_SINT,
13549 DXGI_FORMAT_R32_FLOAT,
13550 DXGI_FORMAT_R32_UINT,
13551 DXGI_FORMAT_R32_SINT,
13552 DXGI_FORMAT_R16_UINT,
13553 DXGI_FORMAT_R16_SINT,
13554 DXGI_FORMAT_R8_UINT,
13555 DXGI_FORMAT_R8_SINT,
13558 if (!(device = create_device(NULL)))
13560 skip("Failed to create device.\n");
13561 return;
13564 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
13566 expected_refcount = get_refcount(device) + 1;
13567 layout_desc->Format = vertex_formats[i];
13568 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13569 vs_code, sizeof(vs_code), &input_layout);
13570 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
13571 vertex_formats[i], hr);
13572 refcount = get_refcount(device);
13573 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
13574 refcount, expected_refcount);
13575 ID3D11InputLayout_Release(input_layout);
13578 refcount = ID3D11Device_Release(device);
13579 ok(!refcount, "Device has %u references left.\n", refcount);
13582 static void test_input_assembler(void)
13584 enum layout_id
13586 LAYOUT_FLOAT32,
13587 LAYOUT_UINT16,
13588 LAYOUT_SINT16,
13589 LAYOUT_UNORM16,
13590 LAYOUT_SNORM16,
13591 LAYOUT_UINT8,
13592 LAYOUT_SINT8,
13593 LAYOUT_UNORM8,
13594 LAYOUT_SNORM8,
13595 LAYOUT_UNORM10_2,
13596 LAYOUT_UINT10_2,
13598 LAYOUT_COUNT,
13601 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
13603 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13604 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13606 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
13607 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
13608 ID3D11Buffer *vb_position, *vb_attribute;
13609 struct d3d11_test_context test_context;
13610 D3D11_TEXTURE2D_DESC texture_desc;
13611 unsigned int i, j, stride, offset;
13612 ID3D11Texture2D *render_target;
13613 ID3D11DeviceContext *context;
13614 ID3D11RenderTargetView *rtv;
13615 ID3D11PixelShader *ps;
13616 ID3D11Device *device;
13617 HRESULT hr;
13619 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
13621 DXGI_FORMAT_R32G32B32A32_FLOAT,
13622 DXGI_FORMAT_R16G16B16A16_UINT,
13623 DXGI_FORMAT_R16G16B16A16_SINT,
13624 DXGI_FORMAT_R16G16B16A16_UNORM,
13625 DXGI_FORMAT_R16G16B16A16_SNORM,
13626 DXGI_FORMAT_R8G8B8A8_UINT,
13627 DXGI_FORMAT_R8G8B8A8_SINT,
13628 DXGI_FORMAT_R8G8B8A8_UNORM,
13629 DXGI_FORMAT_R8G8B8A8_SNORM,
13630 DXGI_FORMAT_R10G10B10A2_UNORM,
13631 DXGI_FORMAT_R10G10B10A2_UINT,
13633 static const struct vec2 quad[] =
13635 {-1.0f, -1.0f},
13636 {-1.0f, 1.0f},
13637 { 1.0f, -1.0f},
13638 { 1.0f, 1.0f},
13640 static const DWORD ps_code[] =
13642 #if 0
13643 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
13645 return color;
13647 #endif
13648 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
13649 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
13650 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
13651 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
13652 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13653 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
13654 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
13655 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
13657 static const DWORD vs_float_code[] =
13659 #if 0
13660 struct output
13662 float4 position : SV_Position;
13663 float4 color : COLOR;
13666 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
13668 o.position = position;
13669 o.color = color;
13671 #endif
13672 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
13673 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13674 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
13675 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
13676 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13677 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13678 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13679 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13680 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13681 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13682 0x0100003e,
13684 static const DWORD vs_uint_code[] =
13686 #if 0
13687 struct output
13689 float4 position : SV_Position;
13690 float4 color : COLOR;
13693 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
13695 o.position = position;
13696 o.color = color;
13698 #endif
13699 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
13700 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13701 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
13702 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
13703 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13704 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13705 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13706 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13707 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13708 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13709 0x0100003e,
13711 static const DWORD vs_sint_code[] =
13713 #if 0
13714 struct output
13716 float4 position : SV_Position;
13717 float4 color : COLOR;
13720 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
13722 o.position = position;
13723 o.color = color;
13725 #endif
13726 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
13727 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13728 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
13729 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
13730 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13731 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13732 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13733 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13734 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13735 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13736 0x0100003e,
13738 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
13739 static const unsigned short uint16_data[] = {6, 8, 55, 777};
13740 static const short sint16_data[] = {-1, 33, 8, -77};
13741 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
13742 static const short snorm16_data[] = {-32768, 0, 32767, 0};
13743 static const unsigned char uint8_data[] = {0, 64, 128, 255};
13744 static const signed char sint8_data[] = {-128, 0, 127, 64};
13745 static const unsigned int uint32_zero = 0;
13746 static const unsigned int uint32_max = 0xffffffff;
13747 static const unsigned int unorm10_2_data= 0xa00003ff;
13748 static const unsigned int g10_data = 0x000ffc00;
13749 static const unsigned int a2_data = 0xc0000000;
13750 static const struct
13752 enum layout_id layout_id;
13753 unsigned int stride;
13754 const void *data;
13755 struct vec4 expected_color;
13756 BOOL todo;
13758 tests[] =
13760 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
13761 {1.0f, 2.0f, 3.0f, 4.0f}},
13762 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
13763 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
13764 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
13765 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
13766 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
13767 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
13768 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
13769 {-1.0f, 0.0f, 1.0f, 0.0f}},
13770 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
13771 {0.0f, 0.0f, 0.0f, 0.0f}},
13772 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
13773 {255.0f, 255.0f, 255.0f, 255.0f}},
13774 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
13775 {0.0f, 64.0f, 128.0f, 255.0f}},
13776 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
13777 {0.0f, 0.0f, 0.0f, 0.0f}},
13778 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
13779 {-1.0f, -1.0f, -1.0f, -1.0f}},
13780 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
13781 {-128.0f, 0.0f, 127.0f, 64.0f}},
13782 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
13783 {0.0f, 0.0f, 0.0f, 0.0f}},
13784 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
13785 {1.0f, 1.0f, 1.0f, 1.0f}},
13786 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
13787 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
13788 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
13789 {0.0f, 0.0f, 0.0f, 0.0f}},
13790 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
13791 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
13792 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
13793 {0.0f, 0.0f, 0.0f, 0.0f}},
13794 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
13795 {1.0f, 1.0f, 1.0f, 1.0f}},
13796 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
13797 {0.0f, 1.0f, 0.0f, 0.0f}},
13798 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
13799 {0.0f, 0.0f, 0.0f, 1.0f}},
13800 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
13801 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
13802 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
13803 {0.0f, 0.0f, 0.0f, 0.0f}},
13804 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
13805 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
13806 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
13807 {0.0f, 1023.0f, 0.0f, 0.0f}},
13808 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
13809 {0.0f, 0.0f, 0.0f, 3.0f}},
13810 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
13811 {1023.0f, 0.0f, 512.0f, 2.0f}},
13814 if (!init_test_context(&test_context, NULL))
13815 return;
13817 device = test_context.device;
13818 context = test_context.immediate_context;
13820 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13821 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13823 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
13824 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
13825 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
13826 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
13827 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
13828 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
13830 for (i = 0; i < LAYOUT_COUNT; ++i)
13832 input_layout_desc[1].Format = layout_formats[i];
13833 input_layout[i] = NULL;
13834 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
13835 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
13836 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
13837 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
13840 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
13841 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
13843 texture_desc.Width = 640;
13844 texture_desc.Height = 480;
13845 texture_desc.MipLevels = 1;
13846 texture_desc.ArraySize = 1;
13847 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
13848 texture_desc.SampleDesc.Count = 1;
13849 texture_desc.SampleDesc.Quality = 0;
13850 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13851 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
13852 texture_desc.CPUAccessFlags = 0;
13853 texture_desc.MiscFlags = 0;
13855 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
13856 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
13858 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
13859 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13861 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13862 offset = 0;
13863 stride = sizeof(*quad);
13864 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
13865 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13866 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13868 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13870 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
13872 if (tests[i].layout_id == LAYOUT_UINT10_2)
13873 continue;
13875 assert(tests[i].layout_id < LAYOUT_COUNT);
13876 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
13878 assert(4 * tests[i].stride <= 1024);
13879 box.right = tests[i].stride;
13880 for (j = 0; j < 4; ++j)
13882 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
13883 &box, tests[i].data, 0, 0);
13884 box.left += tests[i].stride;
13885 box.right += tests[i].stride;
13888 stride = tests[i].stride;
13889 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
13891 switch (layout_formats[tests[i].layout_id])
13893 case DXGI_FORMAT_R16G16B16A16_UINT:
13894 case DXGI_FORMAT_R10G10B10A2_UINT:
13895 case DXGI_FORMAT_R8G8B8A8_UINT:
13896 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
13897 break;
13898 case DXGI_FORMAT_R16G16B16A16_SINT:
13899 case DXGI_FORMAT_R8G8B8A8_SINT:
13900 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
13901 break;
13903 default:
13904 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
13905 /* Fall through. */
13906 case DXGI_FORMAT_R32G32B32A32_FLOAT:
13907 case DXGI_FORMAT_R16G16B16A16_UNORM:
13908 case DXGI_FORMAT_R16G16B16A16_SNORM:
13909 case DXGI_FORMAT_R10G10B10A2_UNORM:
13910 case DXGI_FORMAT_R8G8B8A8_UNORM:
13911 case DXGI_FORMAT_R8G8B8A8_SNORM:
13912 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
13913 break;
13916 ID3D11DeviceContext_Draw(context, 4, 0);
13917 check_texture_vec4(render_target, &tests[i].expected_color, 2);
13920 ID3D11Texture2D_Release(render_target);
13921 ID3D11RenderTargetView_Release(rtv);
13922 ID3D11Buffer_Release(vb_attribute);
13923 ID3D11Buffer_Release(vb_position);
13924 for (i = 0; i < LAYOUT_COUNT; ++i)
13926 if (input_layout[i])
13927 ID3D11InputLayout_Release(input_layout[i]);
13929 ID3D11PixelShader_Release(ps);
13930 ID3D11VertexShader_Release(vs_float);
13931 ID3D11VertexShader_Release(vs_uint);
13932 ID3D11VertexShader_Release(vs_sint);
13933 release_test_context(&test_context);
13936 static void test_null_sampler(void)
13938 struct d3d11_test_context test_context;
13939 D3D11_TEXTURE2D_DESC texture_desc;
13940 ID3D11ShaderResourceView *srv;
13941 ID3D11DeviceContext *context;
13942 ID3D11RenderTargetView *rtv;
13943 ID3D11SamplerState *sampler;
13944 ID3D11Texture2D *texture;
13945 ID3D11PixelShader *ps;
13946 ID3D11Device *device;
13947 HRESULT hr;
13949 static const DWORD ps_code[] =
13951 #if 0
13952 Texture2D t;
13953 SamplerState s;
13955 float4 main(float4 position : SV_POSITION) : SV_Target
13957 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
13959 #endif
13960 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13961 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13962 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13963 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13964 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13965 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13966 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13967 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13968 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13969 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13971 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
13973 if (!init_test_context(&test_context, NULL))
13974 return;
13976 device = test_context.device;
13977 context = test_context.immediate_context;
13979 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13980 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13982 texture_desc.Width = 64;
13983 texture_desc.Height = 64;
13984 texture_desc.MipLevels = 1;
13985 texture_desc.ArraySize = 1;
13986 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13987 texture_desc.SampleDesc.Count = 1;
13988 texture_desc.SampleDesc.Quality = 0;
13989 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13990 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
13991 texture_desc.CPUAccessFlags = 0;
13992 texture_desc.MiscFlags = 0;
13994 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13995 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13997 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13998 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14000 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
14001 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14003 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
14005 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14006 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
14007 sampler = NULL;
14008 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
14009 draw_quad(&test_context);
14010 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
14012 ID3D11ShaderResourceView_Release(srv);
14013 ID3D11RenderTargetView_Release(rtv);
14014 ID3D11Texture2D_Release(texture);
14015 ID3D11PixelShader_Release(ps);
14016 release_test_context(&test_context);
14019 static void test_check_feature_support(void)
14021 D3D11_FEATURE_DATA_THREADING threading[2];
14022 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
14023 ID3D11Device *device;
14024 ULONG refcount;
14025 HRESULT hr;
14027 if (!(device = create_device(NULL)))
14029 skip("Failed to create device.\n");
14030 return;
14033 memset(threading, 0xef, sizeof(threading));
14035 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
14036 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14037 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
14038 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14039 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
14040 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14041 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
14042 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14043 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
14044 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14045 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
14046 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14048 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
14049 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
14050 ok(threading[0].DriverCommandLists == 0xefefefef,
14051 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
14052 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
14053 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
14054 ok(threading[1].DriverCommandLists == 0xefefefef,
14055 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
14057 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
14058 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
14059 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
14060 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
14061 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
14062 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
14064 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
14065 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14066 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
14067 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14068 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
14069 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14070 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
14071 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14072 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
14073 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14074 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
14075 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14077 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
14078 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
14079 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
14081 refcount = ID3D11Device_Release(device);
14082 ok(!refcount, "Device has %u references left.\n", refcount);
14085 static void test_create_unordered_access_view(void)
14087 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
14088 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
14089 D3D11_TEXTURE3D_DESC texture3d_desc;
14090 D3D11_TEXTURE2D_DESC texture2d_desc;
14091 ULONG refcount, expected_refcount;
14092 D3D11_SUBRESOURCE_DATA data = {0};
14093 ID3D11UnorderedAccessView *uav;
14094 struct device_desc device_desc;
14095 D3D11_BUFFER_DESC buffer_desc;
14096 ID3D11Device *device, *tmp;
14097 ID3D11Texture3D *texture3d;
14098 ID3D11Texture2D *texture2d;
14099 ID3D11Resource *texture;
14100 ID3D11Buffer *buffer;
14101 unsigned int i;
14102 HRESULT hr;
14104 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
14105 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
14106 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
14107 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
14108 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
14109 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
14110 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
14111 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
14112 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
14113 static const struct
14115 struct
14117 unsigned int miplevel_count;
14118 unsigned int depth_or_array_size;
14119 DXGI_FORMAT format;
14120 } texture;
14121 struct uav_desc uav_desc;
14122 struct uav_desc expected_uav_desc;
14124 tests[] =
14126 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
14127 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
14128 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
14129 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
14130 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
14131 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
14132 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
14133 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
14134 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
14135 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
14136 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
14137 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
14138 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
14139 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
14140 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
14141 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
14142 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
14143 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
14144 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
14145 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
14146 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
14147 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
14148 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
14149 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
14150 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
14151 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
14152 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
14153 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
14154 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
14155 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
14156 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
14157 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
14158 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
14159 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
14161 static const struct
14163 struct
14165 D3D11_UAV_DIMENSION dimension;
14166 unsigned int miplevel_count;
14167 unsigned int depth_or_array_size;
14168 DXGI_FORMAT format;
14169 } texture;
14170 struct uav_desc uav_desc;
14172 invalid_desc_tests[] =
14174 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
14175 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
14176 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
14177 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
14178 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
14179 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
14180 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
14181 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
14182 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
14183 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
14184 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
14185 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
14186 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
14187 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
14188 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
14189 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
14190 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
14191 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
14192 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
14193 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
14194 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
14195 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
14196 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
14197 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
14198 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
14199 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
14200 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
14201 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
14202 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
14203 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
14204 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
14205 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
14206 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
14208 #undef FMT_UNKNOWN
14209 #undef RGBA8_UNORM
14210 #undef RGBA8_TL
14211 #undef DIM_UNKNOWN
14212 #undef TEX_1D
14213 #undef TEX_1D_ARRAY
14214 #undef TEX_2D
14215 #undef TEX_2D_ARRAY
14216 #undef TEX_3D
14218 device_desc.feature_level = &feature_level;
14219 device_desc.flags = 0;
14220 if (!(device = create_device(&device_desc)))
14222 skip("Failed to create device.\n");
14223 return;
14226 buffer_desc.ByteWidth = 1024;
14227 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
14228 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14229 buffer_desc.CPUAccessFlags = 0;
14230 buffer_desc.MiscFlags = 0;
14231 buffer_desc.StructureByteStride = 0;
14233 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
14234 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14236 expected_refcount = get_refcount(device) + 1;
14237 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14238 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
14239 refcount = get_refcount(device);
14240 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
14241 tmp = NULL;
14242 expected_refcount = refcount + 1;
14243 ID3D11Buffer_GetDevice(buffer, &tmp);
14244 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
14245 refcount = get_refcount(device);
14246 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
14247 ID3D11Device_Release(tmp);
14249 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14250 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
14251 U(uav_desc).Buffer.FirstElement = 0;
14252 U(uav_desc).Buffer.NumElements = 64;
14253 U(uav_desc).Buffer.Flags = 0;
14255 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
14256 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14258 expected_refcount = get_refcount(device) + 1;
14259 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
14260 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
14261 refcount = get_refcount(device);
14262 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
14263 tmp = NULL;
14264 expected_refcount = refcount + 1;
14265 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
14266 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
14267 refcount = get_refcount(device);
14268 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
14269 ID3D11Device_Release(tmp);
14271 ID3D11UnorderedAccessView_Release(uav);
14272 ID3D11Buffer_Release(buffer);
14274 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
14275 buffer_desc.StructureByteStride = 4;
14277 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14278 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
14280 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
14281 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
14283 memset(&uav_desc, 0, sizeof(uav_desc));
14284 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
14286 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
14287 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
14288 uav_desc.ViewDimension);
14289 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
14290 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
14291 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
14293 ID3D11UnorderedAccessView_Release(uav);
14294 ID3D11Buffer_Release(buffer);
14296 texture2d_desc.Width = 512;
14297 texture2d_desc.Height = 512;
14298 texture2d_desc.SampleDesc.Count = 1;
14299 texture2d_desc.SampleDesc.Quality = 0;
14300 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
14301 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14302 texture2d_desc.CPUAccessFlags = 0;
14303 texture2d_desc.MiscFlags = 0;
14305 texture3d_desc.Width = 64;
14306 texture3d_desc.Height = 64;
14307 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
14308 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14309 texture3d_desc.CPUAccessFlags = 0;
14310 texture3d_desc.MiscFlags = 0;
14312 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14314 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
14316 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
14318 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
14319 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
14320 texture2d_desc.Format = tests[i].texture.format;
14322 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14323 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
14324 texture = (ID3D11Resource *)texture2d;
14326 else
14328 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
14329 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
14330 texture3d_desc.Format = tests[i].texture.format;
14332 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
14333 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
14334 texture = (ID3D11Resource *)texture3d;
14337 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
14339 current_desc = NULL;
14341 else
14343 current_desc = &uav_desc;
14344 get_uav_desc(current_desc, &tests[i].uav_desc);
14347 expected_refcount = get_refcount(texture);
14348 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
14349 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
14350 refcount = get_refcount(texture);
14351 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
14353 memset(&uav_desc, 0, sizeof(uav_desc));
14354 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
14355 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
14357 ID3D11UnorderedAccessView_Release(uav);
14358 ID3D11Resource_Release(texture);
14361 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
14363 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
14364 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
14366 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
14368 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
14369 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
14370 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
14372 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14373 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
14374 texture = (ID3D11Resource *)texture2d;
14376 else
14378 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
14379 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
14380 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
14382 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
14383 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
14384 texture = (ID3D11Resource *)texture3d;
14387 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
14388 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
14389 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
14391 ID3D11Resource_Release(texture);
14394 refcount = ID3D11Device_Release(device);
14395 ok(!refcount, "Device has %u references left.\n", refcount);
14398 static void test_immediate_constant_buffer(void)
14400 struct d3d11_test_context test_context;
14401 D3D11_TEXTURE2D_DESC texture_desc;
14402 ID3D11DeviceContext *context;
14403 ID3D11RenderTargetView *rtv;
14404 unsigned int index[4] = {0};
14405 ID3D11Texture2D *texture;
14406 ID3D11PixelShader *ps;
14407 ID3D11Device *device;
14408 ID3D11Buffer *cb;
14409 unsigned int i;
14410 HRESULT hr;
14412 static const DWORD ps_code[] =
14414 #if 0
14415 uint index;
14417 static const int int_array[6] =
14419 310, 111, 212, -513, -318, 0,
14422 static const uint uint_array[6] =
14424 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
14427 static const float float_array[6] =
14429 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
14432 float4 main() : SV_Target
14434 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
14436 #endif
14437 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
14438 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14439 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14440 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
14441 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
14442 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
14443 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
14444 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
14445 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
14446 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
14447 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
14448 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
14449 0x0100003e,
14451 static struct vec4 expected_result[] =
14453 { 310.0f, 2.0f, 76.00f, 1.0f},
14454 { 111.0f, 7.0f, 83.50f, 1.0f},
14455 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
14456 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
14457 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
14458 { 0.0f, 0.0f, 0.0f, 1.0f},
14461 if (!init_test_context(&test_context, NULL))
14462 return;
14464 device = test_context.device;
14465 context = test_context.immediate_context;
14467 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14468 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14469 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14471 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
14472 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14474 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14475 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14476 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14477 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14479 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14480 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14481 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14483 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
14485 *index = i;
14486 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
14488 draw_quad(&test_context);
14489 check_texture_vec4(texture, &expected_result[i], 0);
14492 ID3D11Buffer_Release(cb);
14493 ID3D11PixelShader_Release(ps);
14494 ID3D11Texture2D_Release(texture);
14495 ID3D11RenderTargetView_Release(rtv);
14496 release_test_context(&test_context);
14499 static void test_fp_specials(void)
14501 struct d3d11_test_context test_context;
14502 D3D11_TEXTURE2D_DESC texture_desc;
14503 ID3D11DeviceContext *context;
14504 ID3D11RenderTargetView *rtv;
14505 ID3D11Texture2D *texture;
14506 ID3D11PixelShader *ps;
14507 ID3D11Device *device;
14508 HRESULT hr;
14510 static const DWORD ps_code[] =
14512 #if 0
14513 float4 main() : SV_Target
14515 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
14517 #endif
14518 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
14519 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14520 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14521 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
14522 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
14523 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
14525 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
14527 if (!init_test_context(&test_context, NULL))
14528 return;
14530 device = test_context.device;
14531 context = test_context.immediate_context;
14533 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14534 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14535 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14537 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14538 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14539 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14540 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14542 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14543 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14545 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14547 draw_quad(&test_context);
14548 check_texture_uvec4(texture, &expected_result);
14550 ID3D11PixelShader_Release(ps);
14551 ID3D11Texture2D_Release(texture);
14552 ID3D11RenderTargetView_Release(rtv);
14553 release_test_context(&test_context);
14556 static void test_uint_shader_instructions(void)
14558 struct shader
14560 const DWORD *code;
14561 size_t size;
14562 D3D_FEATURE_LEVEL required_feature_level;
14565 struct d3d11_test_context test_context;
14566 D3D11_TEXTURE2D_DESC texture_desc;
14567 D3D_FEATURE_LEVEL feature_level;
14568 ID3D11DeviceContext *context;
14569 ID3D11RenderTargetView *rtv;
14570 ID3D11Texture2D *texture;
14571 ID3D11PixelShader *ps;
14572 ID3D11Device *device;
14573 ID3D11Buffer *cb;
14574 unsigned int i;
14575 HRESULT hr;
14577 static const DWORD ps_bfi_code[] =
14579 #if 0
14580 uint bits, offset, insert, base;
14582 uint4 main() : SV_Target
14584 uint mask = ((1 << bits) - 1) << offset;
14585 return ((insert << offset) & mask) | (base & ~mask);
14587 #endif
14588 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
14589 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14590 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14591 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
14592 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14593 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
14594 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
14596 static const DWORD ps_bfi2_code[] =
14598 #if 0
14599 ps_5_0
14600 dcl_globalFlags refactoringAllowed
14601 dcl_constantbuffer cb0[1], immediateIndexed
14602 dcl_output o0.xyzw
14603 dcl_temps 1
14604 mov r0.xyzw, cb0[0].xyzw
14605 bfi r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz, r0.wwww
14606 mov o0.xyzw, r0.xyzw
14608 #endif
14609 0x43425844, 0x900f86b6, 0x73f4dabf, 0xea1b1106, 0x591ac790, 0x00000001, 0x00000104, 0x00000003,
14610 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14611 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14612 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000008c, 0x00000050, 0x00000023,
14613 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14614 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14615 0x0b00008c, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
14616 0x00000000, 0x00100ff6, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
14617 0x0100003e,
14619 static const DWORD ps_ibfe_code[] =
14621 #if 0
14622 ps_5_0
14623 dcl_globalFlags refactoringAllowed
14624 dcl_constantbuffer cb0[1], immediateIndexed
14625 dcl_output o0.xyzw
14626 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
14628 #endif
14629 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
14630 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14631 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14632 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
14633 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14634 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
14635 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
14637 static const DWORD ps_ibfe2_code[] =
14639 #if 0
14640 ps_5_0
14641 dcl_globalFlags refactoringAllowed
14642 dcl_constantbuffer cb0[1], immediateIndexed
14643 dcl_output o0.xyzw
14644 dcl_temps 1
14645 mov r0.xyzw, cb0[0].xyzw
14646 ibfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
14647 mov o0.xyzw, r0.xyzw
14649 #endif
14650 0x43425844, 0x347a9c0e, 0x3eff39a4, 0x3dd41cc5, 0xff87ec8d, 0x00000001, 0x000000fc, 0x00000003,
14651 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14652 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14653 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
14654 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14655 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14656 0x0900008b, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
14657 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
14659 static const DWORD ps_ubfe_code[] =
14661 #if 0
14662 uint u;
14664 uint4 main() : SV_Target
14666 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
14668 #endif
14669 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
14670 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14671 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14672 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
14673 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14674 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
14675 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
14676 0x0100003e,
14678 static const DWORD ps_ubfe2_code[] =
14680 #if 0
14681 ps_5_0
14682 dcl_globalFlags refactoringAllowed
14683 dcl_constantbuffer cb0[1], immediateIndexed
14684 dcl_output o0.xyzw
14685 dcl_temps 1
14686 mov r0.xyzw, cb0[0].xyzw
14687 ubfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
14688 mov o0.xyzw, r0.xyzw
14690 #endif
14691 0x43425844, 0xf377b7fc, 0x1e4cb9e7, 0xb9b1020d, 0xde484388, 0x00000001, 0x000000fc, 0x00000003,
14692 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14693 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14694 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
14695 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14696 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14697 0x0900008a, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
14698 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
14700 static const DWORD ps_bfrev_code[] =
14702 #if 0
14703 uint bits;
14705 uint4 main() : SV_Target
14707 return uint4(reversebits(bits), reversebits(reversebits(bits)),
14708 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
14710 #endif
14711 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
14712 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14713 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14714 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
14715 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14716 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
14717 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
14718 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
14719 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
14720 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
14721 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
14723 static const DWORD ps_bits_code[] =
14725 #if 0
14726 uint u;
14727 int i;
14729 uint4 main() : SV_Target
14731 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
14733 #endif
14734 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
14735 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14736 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14737 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
14738 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14739 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
14740 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
14741 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
14742 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
14743 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
14744 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
14745 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
14746 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
14747 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
14749 static const DWORD ps_ftou_code[] =
14751 #if 0
14752 float f;
14754 uint4 main() : SV_Target
14756 return uint4(f, -f, 0, 0);
14758 #endif
14759 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
14760 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14761 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14762 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
14763 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
14764 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
14765 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
14766 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
14768 static const DWORD ps_f16tof32_code[] =
14770 #if 0
14771 uint4 hf;
14773 uint4 main() : SV_Target
14775 return f16tof32(hf);
14777 #endif
14778 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
14779 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14780 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14781 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
14782 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14783 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14784 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
14786 static const DWORD ps_f32tof16_code[] =
14788 #if 0
14789 float4 f;
14791 uint4 main() : SV_Target
14793 return f32tof16(f);
14795 #endif
14796 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
14797 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14798 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14799 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
14800 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14801 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
14803 static const DWORD ps_not_code[] =
14805 #if 0
14806 uint2 bits;
14808 uint4 main() : SV_Target
14810 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
14812 #endif
14813 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
14814 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14815 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14816 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
14817 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14818 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
14819 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
14820 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
14822 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
14823 static const struct shader ps_bfi2 = {ps_bfi2_code, sizeof(ps_bfi2_code), D3D_FEATURE_LEVEL_11_0};
14824 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
14825 static const struct shader ps_ibfe2 = {ps_ibfe2_code, sizeof(ps_ibfe2_code), D3D_FEATURE_LEVEL_11_0};
14826 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
14827 static const struct shader ps_ubfe2 = {ps_ubfe2_code, sizeof(ps_ubfe2_code), D3D_FEATURE_LEVEL_11_0};
14828 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
14829 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
14830 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
14831 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
14832 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
14833 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
14834 static const struct
14836 const struct shader *ps;
14837 unsigned int bits[4];
14838 struct uvec4 expected_result;
14840 tests[] =
14842 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
14843 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
14844 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14845 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14846 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14847 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14848 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
14849 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
14850 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
14851 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
14852 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
14853 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
14854 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
14855 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
14856 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
14857 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
14858 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
14859 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
14860 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
14862 {&ps_bfi2, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14863 {&ps_bfi2, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14864 {&ps_bfi2, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14865 {&ps_bfi2, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14867 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14868 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14869 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14870 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14871 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
14872 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
14873 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14874 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14875 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
14876 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14877 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14878 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14879 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14880 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14881 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14882 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14883 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14884 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14885 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
14886 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
14887 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14888 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14889 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14890 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14891 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14892 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14894 {&ps_ibfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14896 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14897 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
14898 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
14899 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
14900 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
14901 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14902 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
14904 {&ps_ubfe2, { 4, 4, 0x7fffffff}, {0x0000000f, 0x0000000f, 0x0000000f, 0x0000000f}},
14905 {&ps_ubfe2, {23, 8, 0xffffffff}, {0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff}},
14906 {&ps_ubfe2, {30, 1, 0xffffffff}, {0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff}},
14907 {&ps_ubfe2, {15, 15, 0x7fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14908 {&ps_ubfe2, {15, 15, 0xffff00ff}, {0x00007ffe, 0x00007ffe, 0x00007ffe, 0x00007ffe}},
14909 {&ps_ubfe2, {16, 15, 0xffffffff}, {0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff}},
14910 {&ps_ubfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14911 {&ps_ubfe2, {20, 15, 0xffffffff}, {0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff}},
14912 {&ps_ubfe2, {31, 31, 0xffffffff}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
14913 {&ps_ubfe2, {31, 31, 0x80000000}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
14914 {&ps_ubfe2, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14916 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
14917 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
14918 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
14920 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
14921 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
14922 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
14923 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
14924 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
14925 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
14926 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
14927 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
14928 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
14929 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
14930 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
14931 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
14933 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
14934 {&ps_ftou, {BITS_NAN}, { 0, 0}},
14935 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
14936 {&ps_ftou, {BITS_INF}, {~0u, 0}},
14937 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
14938 {&ps_ftou, {BITS_1_0}, { 1, 0}},
14940 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
14941 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
14942 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
14943 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
14945 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
14947 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
14948 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
14951 if (!init_test_context(&test_context, NULL))
14952 return;
14954 device = test_context.device;
14955 context = test_context.immediate_context;
14956 feature_level = ID3D11Device_GetFeatureLevel(device);
14958 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
14959 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14961 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14962 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
14963 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14964 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14966 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14967 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14969 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14971 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14973 if (feature_level < tests[i].ps->required_feature_level)
14974 continue;
14976 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
14977 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14978 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14980 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
14982 draw_quad(&test_context);
14983 check_texture_uvec4(texture, &tests[i].expected_result);
14985 ID3D11PixelShader_Release(ps);
14988 ID3D11Buffer_Release(cb);
14989 ID3D11Texture2D_Release(texture);
14990 ID3D11RenderTargetView_Release(rtv);
14991 release_test_context(&test_context);
14994 static void test_index_buffer_offset(void)
14996 ID3D11Buffer *vb, *ib, *so_buffer, *args_buffer;
14997 struct d3d11_test_context test_context;
14998 ID3D11InputLayout *input_layout;
14999 ID3D11DeviceContext *context;
15000 struct resource_readback rb;
15001 ID3D11GeometryShader *gs;
15002 const struct vec4 *data;
15003 ID3D11VertexShader *vs;
15004 ID3D11Device *device;
15005 UINT stride, offset;
15006 unsigned int i;
15007 HRESULT hr;
15009 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15010 static const DWORD vs_code[] =
15012 #if 0
15013 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
15014 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
15016 out_position = position;
15017 out_attrib = attrib;
15019 #endif
15020 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
15021 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15022 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
15023 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
15024 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15025 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15026 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
15027 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
15028 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
15029 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
15030 0x0100003e,
15032 static const DWORD gs_code[] =
15034 #if 0
15035 struct vertex
15037 float4 position : SV_POSITION;
15038 float4 attrib : ATTRIB;
15041 [maxvertexcount(1)]
15042 void main(point vertex input[1], inout PointStream<vertex> output)
15044 output.Append(input[0]);
15045 output.RestartStrip();
15047 #endif
15048 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
15049 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15050 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
15051 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
15052 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15053 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15054 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
15055 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
15056 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
15057 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
15058 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
15059 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
15061 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
15063 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15064 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
15066 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
15068 {0, "SV_Position", 0, 0, 4, 0},
15069 {0, "ATTRIB", 0, 0, 4, 0},
15071 static const struct
15073 struct vec4 position;
15074 struct vec4 attrib;
15076 vertices[] =
15078 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
15079 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
15080 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
15081 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
15083 static const unsigned int indices[] =
15085 0, 1, 2, 3,
15086 3, 2, 1, 0,
15087 1, 3, 2, 0,
15089 static const struct vec4 expected_data[] =
15091 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
15092 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
15093 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
15094 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
15096 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
15097 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
15098 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
15099 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
15101 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
15102 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
15103 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
15104 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
15106 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
15107 static const D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS argument_data[] =
15109 {4, 1, 0, 0, 0},
15112 if (!init_test_context(&test_context, &feature_level))
15113 return;
15115 device = test_context.device;
15116 context = test_context.immediate_context;
15118 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
15119 vs_code, sizeof(vs_code), &input_layout);
15120 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15122 stride = 32;
15123 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
15124 so_declaration, ARRAY_SIZE(so_declaration),
15125 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
15126 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
15128 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15129 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15131 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
15132 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
15133 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
15135 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15136 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
15138 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
15139 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
15140 stride = sizeof(*vertices);
15141 offset = 0;
15142 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
15144 offset = 0;
15145 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
15147 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
15148 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
15150 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
15151 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
15153 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
15154 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
15156 get_buffer_readback(so_buffer, &rb);
15157 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
15159 data = get_readback_vec4(&rb, i, 0);
15160 ok(compare_vec4(data, &expected_data[i], 0)
15161 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
15162 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
15163 data->x, data->y, data->z, data->w, i);
15165 release_resource_readback(&rb);
15167 /* indirect draws */
15168 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
15169 sizeof(argument_data), argument_data);
15171 offset = 0;
15172 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
15174 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
15175 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
15177 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
15178 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
15180 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
15181 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
15183 get_buffer_readback(so_buffer, &rb);
15184 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
15186 data = get_readback_vec4(&rb, i, 0);
15187 todo_wine_if(i >= 8 && i != 20 && i != 21)
15188 ok(compare_vec4(data, &expected_data[i], 0)
15189 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
15190 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
15191 data->x, data->y, data->z, data->w, i);
15193 release_resource_readback(&rb);
15195 ID3D11Buffer_Release(so_buffer);
15196 ID3D11Buffer_Release(args_buffer);
15197 ID3D11Buffer_Release(ib);
15198 ID3D11Buffer_Release(vb);
15199 ID3D11VertexShader_Release(vs);
15200 ID3D11GeometryShader_Release(gs);
15201 ID3D11InputLayout_Release(input_layout);
15202 release_test_context(&test_context);
15205 static void test_face_culling(void)
15207 struct d3d11_test_context test_context;
15208 D3D11_RASTERIZER_DESC rasterizer_desc;
15209 ID3D11RasterizerState *state;
15210 ID3D11DeviceContext *context;
15211 ID3D11Buffer *cw_vb, *ccw_vb;
15212 ID3D11Device *device;
15213 BOOL broken_warp;
15214 unsigned int i;
15215 HRESULT hr;
15217 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
15218 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
15219 static const DWORD ps_code[] =
15221 #if 0
15222 float4 main(uint front : SV_IsFrontFace) : SV_Target
15224 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
15226 #endif
15227 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
15228 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
15229 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
15230 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
15231 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
15232 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
15233 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
15234 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
15235 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
15236 0x3f800000, 0x0100003e,
15238 static const struct vec2 ccw_quad[] =
15240 {-1.0f, 1.0f},
15241 {-1.0f, -1.0f},
15242 { 1.0f, 1.0f},
15243 { 1.0f, -1.0f},
15245 static const struct
15247 D3D11_CULL_MODE cull_mode;
15248 BOOL front_ccw;
15249 BOOL expected_cw;
15250 BOOL expected_ccw;
15252 tests[] =
15254 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
15255 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
15256 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
15257 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
15258 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
15259 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
15262 if (!init_test_context(&test_context, NULL))
15263 return;
15265 device = test_context.device;
15266 context = test_context.immediate_context;
15268 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15269 draw_color_quad(&test_context, &green);
15270 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15272 cw_vb = test_context.vb;
15273 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
15275 test_context.vb = ccw_vb;
15276 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15277 draw_color_quad(&test_context, &green);
15278 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15280 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
15281 rasterizer_desc.CullMode = D3D11_CULL_BACK;
15282 rasterizer_desc.FrontCounterClockwise = FALSE;
15283 rasterizer_desc.DepthBias = 0;
15284 rasterizer_desc.DepthBiasClamp = 0.0f;
15285 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
15286 rasterizer_desc.DepthClipEnable = TRUE;
15287 rasterizer_desc.ScissorEnable = FALSE;
15288 rasterizer_desc.MultisampleEnable = FALSE;
15289 rasterizer_desc.AntialiasedLineEnable = FALSE;
15291 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15293 rasterizer_desc.CullMode = tests[i].cull_mode;
15294 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
15295 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
15296 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
15298 ID3D11DeviceContext_RSSetState(context, state);
15300 test_context.vb = cw_vb;
15301 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15302 draw_color_quad(&test_context, &green);
15303 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
15305 test_context.vb = ccw_vb;
15306 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15307 draw_color_quad(&test_context, &green);
15308 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
15310 ID3D11RasterizerState_Release(state);
15313 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0;
15315 /* Test SV_IsFrontFace. */
15316 ID3D11PixelShader_Release(test_context.ps);
15317 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
15318 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15320 rasterizer_desc.CullMode = D3D11_CULL_NONE;
15321 rasterizer_desc.FrontCounterClockwise = FALSE;
15322 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
15323 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15324 ID3D11DeviceContext_RSSetState(context, state);
15326 test_context.vb = cw_vb;
15327 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15328 draw_color_quad(&test_context, &green);
15329 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15330 test_context.vb = ccw_vb;
15331 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15332 draw_color_quad(&test_context, &green);
15333 if (!broken_warp)
15334 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
15335 else
15336 win_skip("Broken WARP.\n");
15338 ID3D11RasterizerState_Release(state);
15340 rasterizer_desc.CullMode = D3D11_CULL_NONE;
15341 rasterizer_desc.FrontCounterClockwise = TRUE;
15342 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
15343 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15344 ID3D11DeviceContext_RSSetState(context, state);
15346 test_context.vb = cw_vb;
15347 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15348 draw_color_quad(&test_context, &green);
15349 if (!broken_warp)
15350 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
15351 else
15352 win_skip("Broken WARP.\n");
15353 test_context.vb = ccw_vb;
15354 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15355 draw_color_quad(&test_context, &green);
15356 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15358 ID3D11RasterizerState_Release(state);
15360 test_context.vb = cw_vb;
15361 ID3D11Buffer_Release(ccw_vb);
15362 release_test_context(&test_context);
15365 static void test_line_antialiasing_blending(void)
15367 ID3D11RasterizerState *rasterizer_state;
15368 struct d3d11_test_context test_context;
15369 D3D11_RASTERIZER_DESC rasterizer_desc;
15370 ID3D11BlendState *blend_state;
15371 ID3D11DeviceContext *context;
15372 D3D11_BLEND_DESC blend_desc;
15373 ID3D11Device *device;
15374 HRESULT hr;
15376 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
15377 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
15379 if (!init_test_context(&test_context, NULL))
15380 return;
15382 device = test_context.device;
15383 context = test_context.immediate_context;
15385 memset(&blend_desc, 0, sizeof(blend_desc));
15386 blend_desc.AlphaToCoverageEnable = FALSE;
15387 blend_desc.IndependentBlendEnable = FALSE;
15388 blend_desc.RenderTarget[0].BlendEnable = TRUE;
15389 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
15390 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
15391 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
15392 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
15393 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
15394 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
15395 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
15397 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
15398 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
15399 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
15401 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15402 draw_color_quad(&test_context, &green);
15403 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
15405 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
15406 draw_color_quad(&test_context, &red);
15407 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
15409 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
15410 ID3D11BlendState_Release(blend_state);
15412 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15413 draw_color_quad(&test_context, &green);
15414 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
15416 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
15417 draw_color_quad(&test_context, &red);
15418 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
15420 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
15421 rasterizer_desc.CullMode = D3D11_CULL_BACK;
15422 rasterizer_desc.FrontCounterClockwise = FALSE;
15423 rasterizer_desc.DepthBias = 0;
15424 rasterizer_desc.DepthBiasClamp = 0.0f;
15425 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
15426 rasterizer_desc.DepthClipEnable = TRUE;
15427 rasterizer_desc.ScissorEnable = FALSE;
15428 rasterizer_desc.MultisampleEnable = FALSE;
15429 rasterizer_desc.AntialiasedLineEnable = TRUE;
15431 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
15432 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15433 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
15435 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15436 draw_color_quad(&test_context, &green);
15437 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
15439 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
15440 draw_color_quad(&test_context, &red);
15441 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
15443 ID3D11RasterizerState_Release(rasterizer_state);
15444 release_test_context(&test_context);
15447 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
15448 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
15449 const char *feature_name)
15451 unsigned int i;
15453 for (i = 0; i < format_count; ++i)
15455 DXGI_FORMAT format = formats[i].format;
15456 unsigned int supported = format_support[format] & feature_flag;
15458 if (formats[i].fl_required <= feature_level)
15460 todo_wine ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
15461 format, feature_name, feature_level, format_support[format]);
15462 continue;
15465 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
15467 if (supported)
15468 trace("Optional format %#x - %s supported, feature level %#x.\n",
15469 format, feature_name, feature_level);
15470 continue;
15473 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
15474 format, feature_name, feature_level, format_support[format]);
15478 static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
15480 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
15481 struct device_desc device_desc;
15482 ID3D11Device *device;
15483 DXGI_FORMAT format;
15484 ULONG refcount;
15485 UINT support;
15486 HRESULT hr;
15488 static const struct format_support index_buffers[] =
15490 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
15491 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
15494 device_desc.feature_level = &feature_level;
15495 device_desc.flags = 0;
15496 if (!(device = create_device(&device_desc)))
15498 skip("Failed to create device for feature level %#x.\n", feature_level);
15499 return;
15502 support = 0xdeadbeef;
15503 hr = ID3D11Device_CheckFormatSupport(device, ~0u, &support);
15504 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15505 ok(!support, "Got unexpected format support %#x.\n", support);
15507 memset(format_support, 0, sizeof(format_support));
15508 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
15510 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
15511 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
15512 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
15513 format, hr, format_support[format]);
15516 check_format_support(format_support, feature_level,
15517 index_buffers, ARRAY_SIZE(index_buffers),
15518 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
15520 check_format_support(format_support, feature_level,
15521 display_format_support, ARRAY_SIZE(display_format_support),
15522 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
15524 refcount = ID3D11Device_Release(device);
15525 ok(!refcount, "Device has %u references left.\n", refcount);
15528 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
15530 struct d3d11_test_context test_context;
15531 D3D11_SUBRESOURCE_DATA resource_data;
15532 D3D11_TEXTURE2D_DESC texture_desc;
15533 ID3D11ShaderResourceView *srv;
15534 ID3D11DeviceContext *context;
15535 ID3D11Texture2D *texture;
15536 ID3D11PixelShader *ps;
15537 ID3D11Device *device;
15538 HRESULT hr;
15540 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
15541 static const DWORD ps_code[] =
15543 #if 0
15544 float4 main() : SV_TARGET
15546 return float4(1.0f, 0.0f, 0.0f, 0.5f);
15548 #endif
15549 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
15550 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
15551 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
15552 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
15553 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
15554 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
15555 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
15556 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
15557 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
15558 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
15559 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
15560 0x45475241, 0xabab0054,
15562 static const DWORD ps_texture_code[] =
15564 #if 0
15565 Texture2D t;
15566 SamplerState s;
15568 float4 main() : SV_TARGET
15570 return t.Sample(s, (float2)0);
15572 #endif
15573 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
15574 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
15575 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
15576 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
15577 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
15578 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
15579 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
15580 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
15581 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
15582 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
15583 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
15584 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
15585 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
15586 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15587 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
15589 static const DWORD texture_data[] = {0xffffff00};
15591 if (!init_test_context(&test_context, &feature_level))
15592 return;
15594 device = test_context.device;
15595 context = test_context.immediate_context;
15597 texture_desc.Width = 1;
15598 texture_desc.Height = 1;
15599 texture_desc.MipLevels = 0;
15600 texture_desc.ArraySize = 1;
15601 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15602 texture_desc.SampleDesc.Count = 1;
15603 texture_desc.SampleDesc.Quality = 0;
15604 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15605 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15606 texture_desc.CPUAccessFlags = 0;
15607 texture_desc.MiscFlags = 0;
15608 resource_data.pSysMem = texture_data;
15609 resource_data.SysMemPitch = sizeof(texture_data);
15610 resource_data.SysMemSlicePitch = 0;
15611 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
15612 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
15613 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
15614 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15616 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15617 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
15618 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15619 draw_quad(&test_context);
15620 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
15621 ID3D11PixelShader_Release(ps);
15623 draw_color_quad(&test_context, &color);
15624 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
15626 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
15627 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
15628 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15629 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
15630 draw_quad(&test_context);
15631 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
15632 ID3D11PixelShader_Release(ps);
15634 ID3D11ShaderResourceView_Release(srv);
15635 ID3D11Texture2D_Release(texture);
15636 release_test_context(&test_context);
15639 static void run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
15640 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
15642 static const D3D_FEATURE_LEVEL feature_levels[] =
15644 D3D_FEATURE_LEVEL_11_1,
15645 D3D_FEATURE_LEVEL_11_0,
15646 D3D_FEATURE_LEVEL_10_1,
15647 D3D_FEATURE_LEVEL_10_0,
15648 D3D_FEATURE_LEVEL_9_3,
15649 D3D_FEATURE_LEVEL_9_2,
15650 D3D_FEATURE_LEVEL_9_1
15652 unsigned int i;
15654 assert(begin <= end);
15655 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
15657 if (begin <= feature_levels[i] && feature_levels[i] <= end)
15658 test_func(feature_levels[i]);
15662 static void run_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
15664 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
15665 D3D_FEATURE_LEVEL_11_1, test_func);
15668 static void run_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
15670 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
15671 D3D_FEATURE_LEVEL_9_3, test_func);
15674 static void test_ddy(void)
15676 static const struct
15678 struct vec4 position;
15679 unsigned int color;
15681 quad[] =
15683 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
15684 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
15685 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
15686 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
15688 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
15690 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15691 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
15693 #if 0
15694 struct vs_data
15696 float4 pos : SV_POSITION;
15697 float4 color : COLOR;
15700 void main(in struct vs_data vs_input, out struct vs_data vs_output)
15702 vs_output.pos = vs_input.pos;
15703 vs_output.color = vs_input.color;
15705 #endif
15706 static const DWORD vs_code[] =
15708 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
15709 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15710 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
15711 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15712 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15713 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15714 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
15715 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
15716 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
15717 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
15718 0x0100003e,
15720 #if 0
15721 struct ps_data
15723 float4 pos : SV_POSITION;
15724 float4 color : COLOR;
15727 float4 main(struct ps_data ps_input) : SV_Target
15729 return ddy(ps_input.color) * 240.0 + 0.5;
15731 #endif
15732 static const DWORD ps_code_ddy[] =
15734 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
15735 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15736 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15737 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15738 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15739 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
15740 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
15741 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
15742 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
15743 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
15745 #if 0
15746 struct ps_data
15748 float4 pos : SV_POSITION;
15749 float4 color : COLOR;
15752 float4 main(struct ps_data ps_input) : SV_Target
15754 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
15756 #endif
15757 static const DWORD ps_code_ddy_coarse[] =
15759 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
15760 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15761 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15762 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15763 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15764 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
15765 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
15766 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
15767 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
15768 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
15770 #if 0
15771 struct ps_data
15773 float4 pos : SV_POSITION;
15774 float4 color : COLOR;
15777 float4 main(struct ps_data ps_input) : SV_Target
15779 return ddy_fine(ps_input.color) * 240.0 + 0.5;
15781 #endif
15782 static const DWORD ps_code_ddy_fine[] =
15784 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
15785 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15786 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15787 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15788 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15789 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
15790 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
15791 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
15792 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
15793 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
15795 static const struct
15797 D3D_FEATURE_LEVEL min_feature_level;
15798 const DWORD *ps_code;
15799 unsigned int ps_code_size;
15801 tests[] =
15803 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
15804 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
15805 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
15807 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
15808 struct d3d11_test_context test_context;
15809 D3D11_TEXTURE2D_DESC texture_desc;
15810 D3D_FEATURE_LEVEL feature_level;
15811 ID3D11InputLayout *input_layout;
15812 ID3D11DeviceContext *context;
15813 unsigned int stride, offset;
15814 struct resource_readback rb;
15815 ID3D11RenderTargetView *rtv;
15816 ID3D11Texture2D *texture;
15817 ID3D11VertexShader *vs;
15818 ID3D11PixelShader *ps;
15819 ID3D11Device *device;
15820 ID3D11Buffer *vb;
15821 unsigned int i;
15822 DWORD color;
15823 HRESULT hr;
15825 if (!init_test_context(&test_context, NULL))
15826 return;
15828 device = test_context.device;
15829 context = test_context.immediate_context;
15830 feature_level = ID3D11Device_GetFeatureLevel(device);
15832 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
15833 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15834 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15836 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15837 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15839 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15840 vs_code, sizeof(vs_code), &input_layout);
15841 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15843 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
15845 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15846 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15848 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
15849 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
15850 stride = sizeof(*quad);
15851 offset = 0;
15852 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
15853 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15855 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15857 if (feature_level < tests[i].min_feature_level)
15859 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
15860 feature_level, tests[i].min_feature_level);
15861 continue;
15864 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
15865 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15867 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15869 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15870 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
15871 ID3D11DeviceContext_Draw(context, 4, 0);
15873 get_texture_readback(texture, 0, &rb);
15874 color = get_readback_color(&rb, 320, 190);
15875 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15876 color = get_readback_color(&rb, 255, 240);
15877 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15878 color = get_readback_color(&rb, 320, 240);
15879 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15880 color = get_readback_color(&rb, 385, 240);
15881 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15882 color = get_readback_color(&rb, 320, 290);
15883 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15884 release_resource_readback(&rb);
15886 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
15887 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
15888 ID3D11DeviceContext_Draw(context, 4, 0);
15890 get_texture_readback(test_context.backbuffer, 0, &rb);
15891 color = get_readback_color(&rb, 320, 190);
15892 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15893 color = get_readback_color(&rb, 255, 240);
15894 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15895 color = get_readback_color(&rb, 320, 240);
15896 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15897 color = get_readback_color(&rb, 385, 240);
15898 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15899 color = get_readback_color(&rb, 320, 290);
15900 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15901 release_resource_readback(&rb);
15903 ID3D11PixelShader_Release(ps);
15906 ID3D11VertexShader_Release(vs);
15907 ID3D11Buffer_Release(vb);
15908 ID3D11InputLayout_Release(input_layout);
15909 ID3D11Texture2D_Release(texture);
15910 ID3D11RenderTargetView_Release(rtv);
15911 release_test_context(&test_context);
15914 static void test_shader_input_registers_limits(void)
15916 struct d3d11_test_context test_context;
15917 D3D11_SUBRESOURCE_DATA resource_data;
15918 D3D11_TEXTURE2D_DESC texture_desc;
15919 D3D11_SAMPLER_DESC sampler_desc;
15920 ID3D11ShaderResourceView *srv;
15921 ID3D11DeviceContext *context;
15922 ID3D11SamplerState *sampler;
15923 ID3D11Texture2D *texture;
15924 ID3D11PixelShader *ps;
15925 ID3D11Device *device;
15926 HRESULT hr;
15928 static const DWORD ps_last_register_code[] =
15930 #if 0
15931 Texture2D t : register(t127);
15932 SamplerState s : register(s15);
15934 void main(out float4 target : SV_Target)
15936 target = t.Sample(s, float2(0, 0));
15938 #endif
15939 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
15940 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15941 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15942 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
15943 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
15944 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
15945 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
15947 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
15948 static const DWORD texture_data[] = {0xff00ff00};
15950 if (!init_test_context(&test_context, NULL))
15951 return;
15953 device = test_context.device;
15954 context = test_context.immediate_context;
15956 texture_desc.Width = 1;
15957 texture_desc.Height = 1;
15958 texture_desc.MipLevels = 0;
15959 texture_desc.ArraySize = 1;
15960 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15961 texture_desc.SampleDesc.Count = 1;
15962 texture_desc.SampleDesc.Quality = 0;
15963 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15964 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15965 texture_desc.CPUAccessFlags = 0;
15966 texture_desc.MiscFlags = 0;
15968 resource_data.pSysMem = texture_data;
15969 resource_data.SysMemPitch = sizeof(texture_data);
15970 resource_data.SysMemSlicePitch = 0;
15972 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
15973 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
15975 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
15976 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15978 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
15979 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
15980 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
15981 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
15982 sampler_desc.MipLODBias = 0.0f;
15983 sampler_desc.MaxAnisotropy = 0;
15984 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
15985 sampler_desc.BorderColor[0] = 0.0f;
15986 sampler_desc.BorderColor[1] = 0.0f;
15987 sampler_desc.BorderColor[2] = 0.0f;
15988 sampler_desc.BorderColor[3] = 0.0f;
15989 sampler_desc.MinLOD = 0.0f;
15990 sampler_desc.MaxLOD = 0.0f;
15992 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
15993 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
15995 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
15996 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15997 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15999 ID3D11DeviceContext_PSSetShaderResources(context,
16000 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
16001 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
16002 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16003 draw_quad(&test_context);
16004 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16006 ID3D11PixelShader_Release(ps);
16007 ID3D11SamplerState_Release(sampler);
16008 ID3D11ShaderResourceView_Release(srv);
16009 ID3D11Texture2D_Release(texture);
16010 release_test_context(&test_context);
16013 static void test_unbind_shader_resource_view(void)
16015 struct d3d11_test_context test_context;
16016 D3D11_SUBRESOURCE_DATA resource_data;
16017 ID3D11ShaderResourceView *srv, *srv2;
16018 D3D11_TEXTURE2D_DESC texture_desc;
16019 ID3D11DeviceContext *context;
16020 ID3D11Texture2D *texture;
16021 ID3D11PixelShader *ps;
16022 ID3D11Device *device;
16023 HRESULT hr;
16025 static const DWORD ps_code[] =
16027 #if 0
16028 Texture2D t0;
16029 Texture2D t1;
16030 SamplerState s;
16032 float4 main() : SV_Target
16034 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
16036 #endif
16037 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
16038 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16039 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16040 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
16041 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
16042 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
16043 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
16044 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
16045 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
16046 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
16047 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
16048 0x3f800000, 0x0100003e,
16050 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16051 static const DWORD texture_data[] = {0xff00ff00};
16053 if (!init_test_context(&test_context, NULL))
16054 return;
16056 device = test_context.device;
16057 context = test_context.immediate_context;
16059 texture_desc.Width = 1;
16060 texture_desc.Height = 1;
16061 texture_desc.MipLevels = 0;
16062 texture_desc.ArraySize = 1;
16063 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
16064 texture_desc.SampleDesc.Count = 1;
16065 texture_desc.SampleDesc.Quality = 0;
16066 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16067 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
16068 texture_desc.CPUAccessFlags = 0;
16069 texture_desc.MiscFlags = 0;
16071 resource_data.pSysMem = texture_data;
16072 resource_data.SysMemPitch = sizeof(texture_data);
16073 resource_data.SysMemSlicePitch = 0;
16075 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
16076 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
16077 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
16078 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
16079 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16080 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16081 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16083 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
16084 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
16085 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16086 draw_quad(&test_context);
16087 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16089 srv2 = NULL;
16090 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
16091 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
16092 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16093 draw_quad(&test_context);
16094 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
16096 ID3D11PixelShader_Release(ps);
16097 ID3D11ShaderResourceView_Release(srv);
16098 ID3D11Texture2D_Release(texture);
16099 release_test_context(&test_context);
16102 static void test_stencil_separate(void)
16104 struct d3d11_test_context test_context;
16105 D3D11_TEXTURE2D_DESC texture_desc;
16106 D3D11_DEPTH_STENCIL_DESC ds_desc;
16107 ID3D11DepthStencilState *ds_state;
16108 ID3D11DepthStencilView *ds_view;
16109 D3D11_RASTERIZER_DESC rs_desc;
16110 ID3D11DeviceContext *context;
16111 ID3D11RasterizerState *rs;
16112 ID3D11Texture2D *texture;
16113 ID3D11Device *device;
16114 HRESULT hr;
16116 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
16117 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16118 static const struct vec2 ccw_quad[] =
16120 {-1.0f, -1.0f},
16121 { 1.0f, -1.0f},
16122 {-1.0f, 1.0f},
16123 { 1.0f, 1.0f},
16126 if (!init_test_context(&test_context, NULL))
16127 return;
16129 device = test_context.device;
16130 context = test_context.immediate_context;
16132 texture_desc.Width = 640;
16133 texture_desc.Height = 480;
16134 texture_desc.MipLevels = 1;
16135 texture_desc.ArraySize = 1;
16136 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
16137 texture_desc.SampleDesc.Count = 1;
16138 texture_desc.SampleDesc.Quality = 0;
16139 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16140 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16141 texture_desc.CPUAccessFlags = 0;
16142 texture_desc.MiscFlags = 0;
16143 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16144 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16145 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
16146 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16148 ds_desc.DepthEnable = TRUE;
16149 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
16150 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
16151 ds_desc.StencilEnable = TRUE;
16152 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
16153 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
16154 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
16155 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
16156 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
16157 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
16158 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
16159 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
16160 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
16161 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
16162 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
16163 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
16165 rs_desc.FillMode = D3D11_FILL_SOLID;
16166 rs_desc.CullMode = D3D11_CULL_NONE;
16167 rs_desc.FrontCounterClockwise = FALSE;
16168 rs_desc.DepthBias = 0;
16169 rs_desc.DepthBiasClamp = 0.0f;
16170 rs_desc.SlopeScaledDepthBias = 0.0f;
16171 rs_desc.DepthClipEnable = TRUE;
16172 rs_desc.ScissorEnable = FALSE;
16173 rs_desc.MultisampleEnable = FALSE;
16174 rs_desc.AntialiasedLineEnable = FALSE;
16175 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
16176 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
16178 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
16179 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
16180 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
16181 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
16182 ID3D11DeviceContext_RSSetState(context, rs);
16184 draw_color_quad(&test_context, &green);
16185 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
16187 ID3D11Buffer_Release(test_context.vb);
16188 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
16190 draw_color_quad(&test_context, &green);
16191 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16193 ID3D11RasterizerState_Release(rs);
16194 rs_desc.FrontCounterClockwise = TRUE;
16195 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
16196 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
16197 ID3D11DeviceContext_RSSetState(context, rs);
16199 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
16200 draw_color_quad(&test_context, &green);
16201 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
16203 ID3D11DepthStencilState_Release(ds_state);
16204 ID3D11DepthStencilView_Release(ds_view);
16205 ID3D11RasterizerState_Release(rs);
16206 ID3D11Texture2D_Release(texture);
16207 release_test_context(&test_context);
16210 static void test_uav_load(void)
16212 struct shader
16214 const DWORD *code;
16215 size_t size;
16217 struct texture
16219 UINT width;
16220 UINT height;
16221 UINT miplevel_count;
16222 UINT array_size;
16223 DXGI_FORMAT format;
16224 D3D11_SUBRESOURCE_DATA data[3];
16227 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
16228 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16229 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
16230 struct d3d11_test_context test_context;
16231 const struct texture *current_texture;
16232 ID3D11Texture2D *texture, *rt_texture;
16233 D3D11_TEXTURE2D_DESC texture_desc;
16234 const struct shader *current_ps;
16235 ID3D11UnorderedAccessView *uav;
16236 ID3D11DeviceContext *context;
16237 struct resource_readback rb;
16238 ID3D11PixelShader *ps;
16239 ID3D11Device *device;
16240 unsigned int i, x, y;
16241 ID3D11Buffer *cb;
16242 HRESULT hr;
16244 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16245 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16246 static const DWORD ps_ld_2d_float_code[] =
16248 #if 0
16249 RWTexture2D<float> u;
16251 float main(float4 position : SV_Position) : SV_Target
16253 float2 s;
16254 u.GetDimensions(s.x, s.y);
16255 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
16257 #endif
16258 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
16259 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16260 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16261 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16262 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
16263 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
16264 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
16265 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
16266 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
16267 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
16268 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
16269 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
16270 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16272 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
16273 static const DWORD ps_ld_2d_uint_code[] =
16275 #if 0
16276 RWTexture2D<uint> u;
16278 uint main(float4 position : SV_Position) : SV_Target
16280 float2 s;
16281 u.GetDimensions(s.x, s.y);
16282 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
16284 #endif
16285 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
16286 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16287 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16288 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
16289 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
16290 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
16291 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
16292 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
16293 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
16294 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
16295 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
16296 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
16297 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16299 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
16300 static const DWORD ps_ld_2d_int_code[] =
16302 #if 0
16303 RWTexture2D<int> u;
16305 int main(float4 position : SV_Position) : SV_Target
16307 float2 s;
16308 u.GetDimensions(s.x, s.y);
16309 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
16311 #endif
16312 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
16313 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16314 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16315 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
16316 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
16317 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
16318 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
16319 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
16320 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
16321 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
16322 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
16323 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
16324 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16326 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
16327 static const DWORD ps_ld_2d_uint_arr_code[] =
16329 #if 0
16330 RWTexture2DArray<uint> u;
16332 uint layer;
16334 uint main(float4 position : SV_Position) : SV_Target
16336 float3 s;
16337 u.GetDimensions(s.x, s.y, s.z);
16338 s.z = layer;
16339 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
16341 #endif
16342 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
16343 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16344 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16345 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
16346 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
16347 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
16348 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
16349 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
16350 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
16351 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
16352 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
16353 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
16354 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
16355 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16357 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
16358 static const float float_data[] =
16360 0.50f, 0.25f, 1.00f, 0.00f,
16361 -1.00f, -2.00f, -3.00f, -4.00f,
16362 -0.50f, -0.25f, -1.00f, -0.00f,
16363 1.00f, 2.00f, 3.00f, 4.00f,
16365 static const unsigned int uint_data[] =
16367 0x00, 0x10, 0x20, 0x30,
16368 0x40, 0x50, 0x60, 0x70,
16369 0x80, 0x90, 0xa0, 0xb0,
16370 0xc0, 0xd0, 0xe0, 0xf0,
16372 static const unsigned int uint_data2[] =
16374 0xffff, 0xffff, 0xffff, 0xffff,
16375 0xffff, 0xc000, 0xc000, 0xffff,
16376 0xffff, 0xc000, 0xc000, 0xffff,
16377 0xffff, 0xffff, 0xffff, 0xffff,
16379 static const unsigned int uint_data3[] =
16381 0xaa, 0xaa, 0xcc, 0xcc,
16382 0xaa, 0xaa, 0xdd, 0xdd,
16383 0xbb, 0xbb, 0xee, 0xee,
16384 0xbb, 0xbb, 0xff, 0xff,
16386 static const int int_data[] =
16388 -1, 0x10, 0x20, 0x30,
16389 0x40, 0x50, 0x60, -777,
16390 -666, 0x90, -555, 0xb0,
16391 0xc0, 0xd0, 0xe0, -101,
16393 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
16394 {{float_data, 4 * sizeof(*float_data), 0}}};
16395 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
16396 {{uint_data, 4 * sizeof(*uint_data), 0}}};
16397 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
16398 {{uint_data, 4 * sizeof(*uint_data), 0},
16399 {uint_data2, 4 * sizeof(*uint_data2), 0},
16400 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
16401 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
16402 {{int_data, 4 * sizeof(*int_data), 0}}};
16404 static const struct test
16406 const struct shader *ps;
16407 const struct texture *texture;
16408 struct uav_desc uav_desc;
16409 struct uvec4 constant;
16410 const DWORD *expected_colors;
16412 tests[] =
16414 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
16415 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
16416 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
16417 #define R32_UINT DXGI_FORMAT_R32_UINT
16418 #define R32_SINT DXGI_FORMAT_R32_SINT
16419 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {}, (const DWORD *)float_data},
16420 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {}, (const DWORD *)uint_data},
16421 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {}, (const DWORD *)int_data},
16422 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
16423 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
16424 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
16425 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
16426 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
16427 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
16428 #undef TEX_2D
16429 #undef TEX_2D_ARRAY
16430 #undef R32_FLOAT
16431 #undef R32_UINT
16432 #undef R32_SINT
16435 if (!init_test_context(&test_context, &feature_level))
16436 return;
16438 device = test_context.device;
16439 context = test_context.immediate_context;
16441 texture_desc.Width = 640;
16442 texture_desc.Height = 480;
16443 texture_desc.MipLevels = 1;
16444 texture_desc.ArraySize = 1;
16445 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
16446 texture_desc.SampleDesc.Count = 1;
16447 texture_desc.SampleDesc.Quality = 0;
16448 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16449 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16450 texture_desc.CPUAccessFlags = 0;
16451 texture_desc.MiscFlags = 0;
16452 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
16453 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16455 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
16456 U(rtv_desc).Texture2D.MipSlice = 0;
16458 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
16459 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
16460 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16462 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
16463 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
16464 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16466 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
16467 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
16468 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16470 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16472 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
16473 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16475 ps = NULL;
16476 uav = NULL;
16477 texture = NULL;
16478 current_ps = NULL;
16479 current_texture = NULL;
16480 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16482 const struct test *test = &tests[i];
16483 ID3D11RenderTargetView *current_rtv;
16485 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
16486 NULL, &test->constant, 0, 0);
16488 if (current_ps != test->ps)
16490 if (ps)
16491 ID3D11PixelShader_Release(ps);
16493 current_ps = test->ps;
16495 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
16496 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
16498 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16501 if (current_texture != test->texture)
16503 if (texture)
16504 ID3D11Texture2D_Release(texture);
16506 current_texture = test->texture;
16508 texture_desc.Width = current_texture->width;
16509 texture_desc.Height = current_texture->height;
16510 texture_desc.MipLevels = current_texture->miplevel_count;
16511 texture_desc.ArraySize = current_texture->array_size;
16512 texture_desc.Format = current_texture->format;
16514 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
16515 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
16518 if (uav)
16519 ID3D11UnorderedAccessView_Release(uav);
16521 get_uav_desc(&uav_desc, &test->uav_desc);
16522 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
16523 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
16525 switch (uav_desc.Format)
16527 case DXGI_FORMAT_R32_FLOAT:
16528 current_rtv = rtv_float;
16529 break;
16530 case DXGI_FORMAT_R32_UINT:
16531 current_rtv = rtv_uint;
16532 break;
16533 case DXGI_FORMAT_R32_SINT:
16534 current_rtv = rtv_sint;
16535 break;
16536 default:
16537 trace("Unhandled format %#x.\n", uav_desc.Format);
16538 current_rtv = NULL;
16539 break;
16542 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
16544 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
16545 1, 1, &uav, NULL);
16547 draw_quad(&test_context);
16549 get_texture_readback(rt_texture, 0, &rb);
16550 for (y = 0; y < 4; ++y)
16552 for (x = 0; x < 4; ++x)
16554 DWORD expected = test->expected_colors[y * 4 + x];
16555 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
16556 ok(compare_color(color, expected, 0),
16557 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
16558 i, color, expected, x, y);
16561 release_resource_readback(&rb);
16563 ID3D11PixelShader_Release(ps);
16564 ID3D11Texture2D_Release(texture);
16565 ID3D11UnorderedAccessView_Release(uav);
16567 ID3D11Buffer_Release(cb);
16568 ID3D11RenderTargetView_Release(rtv_float);
16569 ID3D11RenderTargetView_Release(rtv_sint);
16570 ID3D11RenderTargetView_Release(rtv_uint);
16571 ID3D11Texture2D_Release(rt_texture);
16572 release_test_context(&test_context);
16575 static void test_cs_uav_store(void)
16577 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16578 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16579 static const float zero[4] = {0.0f};
16580 D3D11_TEXTURE2D_DESC texture_desc;
16581 ID3D11UnorderedAccessView *uav;
16582 struct device_desc device_desc;
16583 ID3D11DeviceContext *context;
16584 struct vec4 input = {1.0f};
16585 ID3D11Texture2D *texture;
16586 ID3D11ComputeShader *cs;
16587 ID3D11Device *device;
16588 ID3D11Buffer *cb;
16589 ULONG refcount;
16590 HRESULT hr;
16591 RECT rect;
16593 static const DWORD cs_1_thread_code[] =
16595 #if 0
16596 RWTexture2D<float> u;
16598 float value;
16600 [numthreads(1, 1, 1)]
16601 void main()
16603 uint x, y, width, height;
16604 u.GetDimensions(width, height);
16605 for (y = 0; y < height; ++y)
16607 for (x = 0; x < width; ++x)
16608 u[uint2(x, y)] = value;
16611 #endif
16612 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
16613 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16614 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
16615 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16616 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
16617 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
16618 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
16619 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
16620 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
16621 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
16622 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
16623 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
16624 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
16625 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
16626 0x01000016, 0x0100003e,
16628 static const DWORD cs_1_group_code[] =
16630 #if 0
16631 RWTexture2D<float> u;
16633 float value;
16635 [numthreads(16, 16, 1)]
16636 void main(uint3 threadID : SV_GroupThreadID)
16638 uint2 count, size ;
16639 u.GetDimensions(size.x, size.y);
16640 count = size / (uint2)16;
16641 for (uint y = 0; y < count.y; ++y)
16642 for (uint x = 0; x < count.x; ++x)
16643 u[count * threadID.xy + uint2(x, y)] = value;
16645 #endif
16646 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
16647 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16648 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
16649 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16650 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
16651 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
16652 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
16653 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
16654 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
16655 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
16656 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
16657 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
16658 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
16659 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
16660 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
16661 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
16662 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
16664 static const DWORD cs_1_store_code[] =
16666 #if 0
16667 RWTexture2D<float> u;
16669 float value;
16671 [numthreads(1, 1, 1)]
16672 void main(uint3 groupID : SV_GroupID)
16674 u[groupID.xy] = value;
16676 #endif
16677 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
16678 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16679 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16680 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16681 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
16682 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
16684 static const DWORD cs_dispatch_id_code[] =
16686 #if 0
16687 RWTexture2D<float> u;
16689 float value;
16691 [numthreads(4, 4, 1)]
16692 void main(uint3 id : SV_DispatchThreadID)
16694 u[id.xy] = value;
16696 #endif
16697 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
16698 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16699 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16700 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16701 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
16702 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
16704 static const DWORD cs_group_index_code[] =
16706 #if 0
16707 RWTexture2D<float> u;
16709 float value;
16711 [numthreads(32, 1, 1)]
16712 void main(uint index : SV_GroupIndex)
16714 uint2 size;
16715 u.GetDimensions(size.x, size.y);
16716 uint count = size.x * size.y / 32;
16717 index *= count;
16718 for (uint i = 0; i < count; ++i, ++index)
16719 u[uint2(index % size.x, index / size.x)] = value;
16721 #endif
16722 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
16723 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16724 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
16725 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16726 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
16727 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
16728 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
16729 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
16730 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
16731 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
16732 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
16733 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
16734 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
16735 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
16736 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
16737 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
16740 device_desc.feature_level = &feature_level;
16741 device_desc.flags = 0;
16742 if (!(device = create_device(&device_desc)))
16744 skip("Failed to create device for feature level %#x.\n", feature_level);
16745 return;
16748 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
16750 texture_desc.Width = 64;
16751 texture_desc.Height = 64;
16752 texture_desc.MipLevels = 1;
16753 texture_desc.ArraySize = 1;
16754 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
16755 texture_desc.SampleDesc.Count = 1;
16756 texture_desc.SampleDesc.Quality = 0;
16757 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16758 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16759 texture_desc.CPUAccessFlags = 0;
16760 texture_desc.MiscFlags = 0;
16762 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16763 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16765 uav_desc.Format = texture_desc.Format;
16766 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
16767 U(uav_desc).Texture2D.MipSlice = 0;
16769 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
16770 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16772 ID3D11Device_GetImmediateContext(device, &context);
16774 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
16775 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16777 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
16778 check_texture_float(texture, 0.0f, 2);
16780 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
16781 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16782 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16784 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16785 check_texture_float(texture, 1.0f, 2);
16787 input.x = 0.5f;
16788 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16789 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16790 check_texture_float(texture, 0.5f, 2);
16792 ID3D11ComputeShader_Release(cs);
16794 input.x = 2.0f;
16795 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16796 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
16797 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16798 check_texture_float(texture, 0.5f, 2);
16800 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
16801 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16802 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16804 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16805 check_texture_float(texture, 2.0f, 2);
16807 input.x = 4.0f;
16808 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16809 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16810 check_texture_float(texture, 4.0f, 2);
16812 ID3D11ComputeShader_Release(cs);
16814 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
16815 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16816 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16818 input.x = 1.0f;
16819 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16820 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
16821 check_texture_float(texture, 1.0f, 2);
16823 input.x = 0.5f;
16824 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16825 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
16826 SetRect(&rect, 0, 0, 16, 32);
16827 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
16828 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
16829 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16830 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
16831 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16833 ID3D11ComputeShader_Release(cs);
16835 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
16836 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16837 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16839 input.x = 0.6f;
16840 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16841 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
16842 SetRect(&rect, 0, 0, 60, 60);
16843 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
16844 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
16845 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16846 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
16847 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16849 input.x = 0.7f;
16850 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16851 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
16852 check_texture_float(texture, 0.7f, 2);
16854 ID3D11ComputeShader_Release(cs);
16856 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
16857 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16858 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16860 input.x = 0.3f;
16861 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16862 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16863 check_texture_float(texture, 0.3f, 2);
16865 input.x = 0.1f;
16866 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16867 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
16868 check_texture_float(texture, 0.1f, 2);
16870 ID3D11ComputeShader_Release(cs);
16872 ID3D11Buffer_Release(cb);
16873 ID3D11Texture2D_Release(texture);
16874 ID3D11UnorderedAccessView_Release(uav);
16875 ID3D11DeviceContext_Release(context);
16876 refcount = ID3D11Device_Release(device);
16877 ok(!refcount, "Device has %u references left.\n", refcount);
16880 static void test_uav_store_immediate_constant(void)
16882 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16883 struct d3d11_test_context test_context;
16884 ID3D11UnorderedAccessView *uav;
16885 ID3D11DeviceContext *context;
16886 struct resource_readback rb;
16887 ID3D11ComputeShader *cs;
16888 ID3D11Device *device;
16889 ID3D11Buffer *buffer;
16890 float float_data;
16891 int int_data;
16892 HRESULT hr;
16894 static const DWORD cs_store_int_code[] =
16896 #if 0
16897 RWBuffer<int> u;
16899 [numthreads(1, 1, 1)]
16900 void main()
16902 u[0] = 42;
16904 #endif
16905 0x43425844, 0x7246d785, 0x3f4ccbd6, 0x6a7cdbc0, 0xe2b58c72, 0x00000001, 0x000000b8, 0x00000003,
16906 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16907 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16908 0x0400089c, 0x0011e000, 0x00000000, 0x00003333, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
16909 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
16910 0x00004002, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, 0x0100003e,
16912 static const DWORD cs_store_float_code[] =
16914 #if 0
16915 RWBuffer<float> u;
16917 [numthreads(1, 1, 1)]
16918 void main()
16920 u[0] = 1.0;
16922 #endif
16923 0x43425844, 0x525eea68, 0xc4cd5716, 0xc588f9c4, 0x0da27c5a, 0x00000001, 0x000000b8, 0x00000003,
16924 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16925 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16926 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
16927 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
16928 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e,
16930 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16931 static const unsigned int zero[4] = {0};
16933 if (!init_test_context(&test_context, &feature_level))
16934 return;
16936 device = test_context.device;
16937 context = test_context.immediate_context;
16939 buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
16941 uav_desc.Format = DXGI_FORMAT_R32_SINT;
16942 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16943 U(uav_desc).Buffer.FirstElement = 0;
16944 U(uav_desc).Buffer.NumElements = 1;
16945 U(uav_desc).Buffer.Flags = 0;
16946 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16947 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16948 hr = ID3D11Device_CreateComputeShader(device, cs_store_int_code, sizeof(cs_store_int_code), NULL, &cs);
16949 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16951 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
16952 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16953 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16954 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16955 get_buffer_readback(buffer, &rb);
16956 int_data = get_readback_color(&rb, 0, 0);
16957 ok(int_data == 42, "Got unexpected value %u.\n", int_data);
16958 release_resource_readback(&rb);
16960 ID3D11ComputeShader_Release(cs);
16961 ID3D11UnorderedAccessView_Release(uav);
16962 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
16963 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16964 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16965 hr = ID3D11Device_CreateComputeShader(device, cs_store_float_code, sizeof(cs_store_float_code), NULL, &cs);
16966 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16968 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
16969 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16970 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16971 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16972 get_buffer_readback(buffer, &rb);
16973 float_data = get_readback_float(&rb, 0, 0);
16974 ok(float_data == 1.0f, "Got unexpected value %.8e.\n", float_data);
16975 release_resource_readback(&rb);
16977 ID3D11Buffer_Release(buffer);
16978 ID3D11ComputeShader_Release(cs);
16979 ID3D11UnorderedAccessView_Release(uav);
16980 release_test_context(&test_context);
16983 static void test_ps_cs_uav_binding(void)
16985 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16986 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
16987 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16988 ID3D11Texture2D *cs_texture, *ps_texture;
16989 struct d3d11_test_context test_context;
16990 static const float zero[4] = {0.0f};
16991 D3D11_TEXTURE2D_DESC texture_desc;
16992 ID3D11DeviceContext *context;
16993 ID3D11Buffer *cs_cb, *ps_cb;
16994 struct vec4 input = {1.0f};
16995 ID3D11ComputeShader *cs;
16996 ID3D11PixelShader *ps;
16997 ID3D11Device *device;
16998 HRESULT hr;
17000 static const DWORD cs_code[] =
17002 #if 0
17003 RWTexture2D<float> u;
17005 float value;
17007 [numthreads(1, 1, 1)]
17008 void main()
17010 uint x, y, width, height;
17011 u.GetDimensions(width, height);
17012 for (y = 0; y < height; ++y)
17014 for (x = 0; x < width; ++x)
17015 u[uint2(x, y)] = value;
17018 #endif
17019 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
17020 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17021 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
17022 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
17023 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
17024 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
17025 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
17026 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
17027 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
17028 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
17029 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
17030 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
17031 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
17032 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
17033 0x01000016, 0x0100003e,
17035 static const DWORD ps_code[] =
17037 #if 0
17038 RWTexture2D<float> u : register(u1);
17040 float value;
17042 void main()
17044 uint x, y, width, height;
17045 u.GetDimensions(width, height);
17046 for (y = 0; y < height; ++y)
17048 for (x = 0; x < width; ++x)
17049 u[uint2(x, y)] = value;
17052 #endif
17053 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
17054 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17055 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
17056 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
17057 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
17058 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
17059 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
17060 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
17061 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
17062 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
17063 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
17064 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
17065 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
17066 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
17069 if (!init_test_context(&test_context, &feature_level))
17070 return;
17072 device = test_context.device;
17073 context = test_context.immediate_context;
17075 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
17076 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
17078 texture_desc.Width = 64;
17079 texture_desc.Height = 64;
17080 texture_desc.MipLevels = 1;
17081 texture_desc.ArraySize = 1;
17082 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
17083 texture_desc.SampleDesc.Count = 1;
17084 texture_desc.SampleDesc.Quality = 0;
17085 texture_desc.Usage = D3D11_USAGE_DEFAULT;
17086 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17087 texture_desc.CPUAccessFlags = 0;
17088 texture_desc.MiscFlags = 0;
17089 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
17090 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17091 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
17092 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17094 uav_desc.Format = texture_desc.Format;
17095 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
17096 U(uav_desc).Texture2D.MipSlice = 0;
17097 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
17098 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17099 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
17100 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17102 ID3D11Device_GetImmediateContext(device, &context);
17104 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
17105 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
17106 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
17107 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
17108 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
17109 1, &test_context.backbuffer_rtv, NULL, 1, 1, &ps_uav, NULL);
17111 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
17112 check_texture_float(cs_texture, 0.0f, 2);
17113 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
17114 check_texture_float(ps_texture, 0.0f, 2);
17116 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
17117 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17118 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
17119 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17120 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17121 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17123 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17124 check_texture_float(cs_texture, 1.0f, 2);
17125 check_texture_float(ps_texture, 0.0f, 2);
17126 draw_quad(&test_context);
17127 check_texture_float(cs_texture, 1.0f, 2);
17128 check_texture_float(ps_texture, 1.0f, 2);
17130 input.x = 0.5f;
17131 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
17132 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17133 check_texture_float(cs_texture, 0.5f, 2);
17134 check_texture_float(ps_texture, 1.0f, 2);
17135 input.x = 2.0f;
17136 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
17137 draw_quad(&test_context);
17138 check_texture_float(cs_texture, 0.5f, 2);
17139 check_texture_float(ps_texture, 2.0f, 2);
17141 input.x = 8.0f;
17142 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
17143 input.x = 4.0f;
17144 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
17145 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17146 check_texture_float(cs_texture, 8.0f, 2);
17147 check_texture_float(ps_texture, 2.0f, 2);
17148 draw_quad(&test_context);
17149 check_texture_float(cs_texture, 8.0f, 2);
17150 check_texture_float(ps_texture, 4.0f, 2);
17152 ID3D11ComputeShader_Release(cs);
17153 ID3D11PixelShader_Release(ps);
17154 ID3D11Buffer_Release(cs_cb);
17155 ID3D11Buffer_Release(ps_cb);
17156 ID3D11Texture2D_Release(cs_texture);
17157 ID3D11Texture2D_Release(ps_texture);
17158 ID3D11UnorderedAccessView_Release(cs_uav);
17159 ID3D11UnorderedAccessView_Release(ps_uav);
17160 ID3D11DeviceContext_Release(context);
17161 release_test_context(&test_context);
17164 static void test_atomic_instructions(void)
17166 ID3D11UnorderedAccessView *in_uav, *out_uav;
17167 ID3D11Buffer *cb, *in_buffer, *out_buffer;
17168 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
17169 struct d3d11_test_context test_context;
17170 struct resource_readback rb, out_rb;
17171 D3D11_TEXTURE2D_DESC texture_desc;
17172 D3D11_BUFFER_DESC buffer_desc;
17173 ID3D11DeviceContext *context;
17174 ID3D11RenderTargetView *rtv;
17175 ID3D11Texture2D *texture;
17176 ID3D11ComputeShader *cs;
17177 ID3D11PixelShader *ps;
17178 ID3D11Device *device;
17179 D3D11_VIEWPORT vp;
17180 unsigned int i, j;
17181 HRESULT hr;
17183 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17184 static const unsigned int zero[4] = {0, 0, 0, 0};
17185 static const DWORD ps_atomics_code[] =
17187 #if 0
17188 RWByteAddressBuffer u;
17190 uint4 v;
17191 int4 i;
17193 void main()
17195 u.InterlockedAnd(0 * 4, v.x);
17196 u.InterlockedCompareStore(1 * 4, v.y, v.x);
17197 u.InterlockedAdd(2 * 4, v.x);
17198 u.InterlockedOr(3 * 4, v.x);
17199 u.InterlockedMax(4 * 4, i.x);
17200 u.InterlockedMin(5 * 4, i.x);
17201 u.InterlockedMax(6 * 4, v.x);
17202 u.InterlockedMin(7 * 4, v.x);
17203 u.InterlockedXor(8 * 4, v.x);
17205 #endif
17206 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
17207 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17208 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
17209 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
17210 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
17211 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
17212 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
17213 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
17214 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
17215 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
17216 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
17217 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
17218 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
17219 0x00000000, 0x00000000, 0x0100003e,
17221 static const DWORD cs_atomics_code[] =
17223 #if 0
17224 RWByteAddressBuffer u;
17225 RWByteAddressBuffer u2;
17227 uint4 v;
17228 int4 i;
17230 [numthreads(1, 1, 1)]
17231 void main()
17233 uint r;
17234 u.InterlockedAnd(0 * 4, v.x, r);
17235 u2.Store(0 * 4, r);
17236 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
17237 u2.Store(1 * 4, r);
17238 u.InterlockedAdd(2 * 4, v.x, r);
17239 u2.Store(2 * 4, r);
17240 u.InterlockedOr(3 * 4, v.x, r);
17241 u2.Store(3 * 4, r);
17242 u.InterlockedMax(4 * 4, i.x, r);
17243 u2.Store(4 * 4, r);
17244 u.InterlockedMin(5 * 4, i.x, r);
17245 u2.Store(5 * 4, r);
17246 u.InterlockedMax(6 * 4, v.x, r);
17247 u2.Store(6 * 4, r);
17248 u.InterlockedMin(7 * 4, v.x, r);
17249 u2.Store(7 * 4, r);
17250 u.InterlockedXor(8 * 4, v.x, r);
17251 u2.Store(8 * 4, r);
17253 #endif
17254 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
17255 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17256 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
17257 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
17258 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
17259 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
17260 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
17261 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
17262 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
17263 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
17264 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
17265 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
17266 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
17267 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
17268 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
17269 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
17270 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
17271 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
17272 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
17273 0x0010000a, 0x00000000, 0x0100003e,
17276 static const char * const instructions[] =
17278 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
17279 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
17281 static const char * const imm_instructions[] =
17283 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
17284 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
17286 static const struct test
17288 struct uvec4 v;
17289 struct ivec4 i;
17290 unsigned int input[ARRAY_SIZE(instructions)];
17291 unsigned int expected_result[ARRAY_SIZE(instructions)];
17293 tests[] =
17295 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
17296 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
17299 if (!init_test_context(&test_context, &feature_level))
17300 return;
17302 device = test_context.device;
17303 context = test_context.immediate_context;
17305 texture_desc.Width = 1;
17306 texture_desc.Height = 1;
17307 texture_desc.MipLevels = 1;
17308 texture_desc.ArraySize = 1;
17309 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
17310 texture_desc.SampleDesc.Count = 1;
17311 texture_desc.SampleDesc.Quality = 0;
17312 texture_desc.Usage = D3D11_USAGE_DEFAULT;
17313 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
17314 texture_desc.CPUAccessFlags = 0;
17315 texture_desc.MiscFlags = 0;
17316 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17317 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17318 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
17319 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17321 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
17322 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17323 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
17325 buffer_desc.ByteWidth = sizeof(tests->input);
17326 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17327 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17328 buffer_desc.CPUAccessFlags = 0;
17329 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
17330 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
17331 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17332 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
17333 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17335 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
17336 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
17337 U(uav_desc).Buffer.FirstElement = 0;
17338 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
17339 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
17340 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
17341 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17342 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
17343 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17345 vp.TopLeftX = 0.0f;
17346 vp.TopLeftY = 0.0f;
17347 vp.Width = texture_desc.Width;
17348 vp.Height = texture_desc.Height;
17349 vp.MinDepth = 0.0f;
17350 vp.MaxDepth = 1.0f;
17351 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
17353 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
17354 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17355 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17357 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
17358 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17359 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
17361 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17363 const struct test *test = &tests[i];
17365 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17366 NULL, &test->v, 0, 0);
17368 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
17369 NULL, test->input, 0, 0);
17371 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
17372 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
17373 0, 1, &in_uav, NULL);
17375 draw_quad(&test_context);
17376 get_buffer_readback(in_buffer, &rb);
17377 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
17379 unsigned int value = get_readback_color(&rb, j, 0);
17380 unsigned int expected = test->expected_result[j];
17382 todo_wine_if(expected != test->input[j]
17383 && (!strcmp(instructions[j], "atomic_imax")
17384 || !strcmp(instructions[j], "atomic_imin")))
17385 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
17386 "with inputs (%u, %u), (%d), %#x (%d).\n",
17387 i, value, value, expected, expected, instructions[j],
17388 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
17390 release_resource_readback(&rb);
17392 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
17393 NULL, test->input, 0, 0);
17394 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
17396 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
17397 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
17399 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17400 get_buffer_readback(in_buffer, &rb);
17401 get_buffer_readback(out_buffer, &out_rb);
17402 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
17404 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
17405 || !strcmp(imm_instructions[j], "imm_atomic_imin");
17406 unsigned int out_value = get_readback_color(&out_rb, j, 0);
17407 unsigned int value = get_readback_color(&rb, j, 0);
17408 unsigned int expected = test->expected_result[j];
17410 todo_wine_if(expected != test->input[j] && todo_instruction)
17411 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
17412 "with inputs (%u, %u), (%d), %#x (%d).\n",
17413 i, value, value, expected, expected, imm_instructions[j],
17414 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
17416 todo_wine_if(todo_instruction && out_value != test->input[j])
17417 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
17418 out_value, test->input[j], imm_instructions[j]);
17420 release_resource_readback(&out_rb);
17421 release_resource_readback(&rb);
17424 ID3D11Buffer_Release(cb);
17425 ID3D11Buffer_Release(in_buffer);
17426 ID3D11Buffer_Release(out_buffer);
17427 ID3D11ComputeShader_Release(cs);
17428 ID3D11PixelShader_Release(ps);
17429 ID3D11RenderTargetView_Release(rtv);
17430 ID3D11Texture2D_Release(texture);
17431 ID3D11UnorderedAccessView_Release(in_uav);
17432 ID3D11UnorderedAccessView_Release(out_uav);
17433 release_test_context(&test_context);
17436 static void test_sm4_ret_instruction(void)
17438 struct d3d11_test_context test_context;
17439 ID3D11DeviceContext *context;
17440 ID3D11PixelShader *ps;
17441 struct uvec4 constant;
17442 ID3D11Device *device;
17443 ID3D11Buffer *cb;
17444 HRESULT hr;
17446 static const DWORD ps_code[] =
17448 #if 0
17449 uint c;
17451 float4 main() : SV_TARGET
17453 if (c == 1)
17454 return float4(1, 0, 0, 1);
17455 if (c == 2)
17456 return float4(0, 1, 0, 1);
17457 if (c == 3)
17458 return float4(0, 0, 1, 1);
17459 return float4(1, 1, 1, 1);
17461 #endif
17462 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
17463 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17464 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17465 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
17466 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
17467 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
17468 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
17469 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
17470 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
17471 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
17472 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
17473 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
17474 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
17475 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
17476 0x0100003e,
17479 if (!init_test_context(&test_context, NULL))
17480 return;
17482 device = test_context.device;
17483 context = test_context.immediate_context;
17485 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17486 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
17487 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17488 memset(&constant, 0, sizeof(constant));
17489 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
17490 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17492 draw_quad(&test_context);
17493 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
17495 constant.x = 1;
17496 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17497 draw_quad(&test_context);
17498 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
17500 constant.x = 2;
17501 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17502 draw_quad(&test_context);
17503 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17505 constant.x = 3;
17506 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17507 draw_quad(&test_context);
17508 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
17510 constant.x = 4;
17511 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17512 draw_quad(&test_context);
17513 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
17515 ID3D11Buffer_Release(cb);
17516 ID3D11PixelShader_Release(ps);
17517 release_test_context(&test_context);
17520 static void test_primitive_restart(void)
17522 struct d3d11_test_context test_context;
17523 ID3D11Buffer *ib32, *ib16, *vb;
17524 ID3D11DeviceContext *context;
17525 unsigned int stride, offset;
17526 ID3D11InputLayout *layout;
17527 ID3D11VertexShader *vs;
17528 ID3D11PixelShader *ps;
17529 ID3D11Device *device;
17530 unsigned int i;
17531 HRESULT hr;
17532 RECT rect;
17534 static const DWORD ps_code[] =
17536 #if 0
17537 struct vs_out
17539 float4 position : SV_Position;
17540 float4 color : color;
17543 float4 main(vs_out input) : SV_TARGET
17545 return input.color;
17547 #endif
17548 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
17549 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17550 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17551 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
17552 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17553 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
17554 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
17555 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
17557 static const DWORD vs_code[] =
17559 #if 0
17560 struct vs_out
17562 float4 position : SV_Position;
17563 float4 color : color;
17566 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
17568 output.position = position;
17569 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
17571 #endif
17572 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
17573 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
17574 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
17575 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
17576 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
17577 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
17578 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
17579 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
17580 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
17581 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
17582 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
17583 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
17584 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
17586 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17588 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17590 static const struct vec2 vertices[] =
17592 {-1.00f, -1.0f},
17593 {-1.00f, 1.0f},
17594 {-0.25f, -1.0f},
17595 {-0.25f, 1.0f},
17596 { 0.25f, -1.0f},
17597 { 0.25f, 1.0f},
17598 { 1.00f, -1.0f},
17599 { 1.00f, 1.0f},
17601 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
17602 static const unsigned short indices16[] =
17604 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
17606 static const unsigned int indices32[] =
17608 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
17611 if (!init_test_context(&test_context, NULL))
17612 return;
17614 device = test_context.device;
17615 context = test_context.immediate_context;
17617 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17618 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17619 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17620 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
17622 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
17623 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
17625 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17626 vs_code, sizeof(vs_code), &layout);
17627 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17629 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
17631 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17632 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17634 ID3D11DeviceContext_IASetInputLayout(context, layout);
17635 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
17636 stride = sizeof(*vertices);
17637 offset = 0;
17638 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
17640 for (i = 0; i < 2; ++i)
17642 if (!i)
17643 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
17644 else
17645 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
17647 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17648 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
17649 SetRect(&rect, 0, 0, 240, 480);
17650 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
17651 SetRect(&rect, 240, 0, 400, 480);
17652 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
17653 SetRect(&rect, 400, 0, 640, 480);
17654 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
17657 ID3D11Buffer_Release(ib16);
17658 ID3D11Buffer_Release(ib32);
17659 ID3D11Buffer_Release(vb);
17660 ID3D11InputLayout_Release(layout);
17661 ID3D11PixelShader_Release(ps);
17662 ID3D11VertexShader_Release(vs);
17663 release_test_context(&test_context);
17666 static void test_resinfo_instruction(void)
17668 struct shader
17670 const DWORD *code;
17671 size_t size;
17674 struct d3d11_test_context test_context;
17675 D3D11_TEXTURE3D_DESC texture3d_desc;
17676 D3D11_TEXTURE2D_DESC texture_desc;
17677 const struct shader *current_ps;
17678 D3D_FEATURE_LEVEL feature_level;
17679 ID3D11ShaderResourceView *srv;
17680 ID3D11DeviceContext *context;
17681 ID3D11Texture2D *rtv_texture;
17682 ID3D11RenderTargetView *rtv;
17683 ID3D11Resource *texture;
17684 struct uvec4 constant;
17685 ID3D11PixelShader *ps;
17686 ID3D11Device *device;
17687 unsigned int i, type;
17688 ID3D11Buffer *cb;
17689 HRESULT hr;
17691 static const DWORD ps_2d_code[] =
17693 #if 0
17694 Texture2D t;
17696 uint type;
17697 uint level;
17699 float4 main() : SV_TARGET
17701 if (!type)
17703 float width, height, miplevels;
17704 t.GetDimensions(level, width, height, miplevels);
17705 return float4(width, height, miplevels, 0);
17707 else
17709 uint width, height, miplevels;
17710 t.GetDimensions(level, width, height, miplevels);
17711 return float4(width, height, miplevels, 0);
17714 #endif
17715 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
17716 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17717 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17718 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
17719 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
17720 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17721 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17722 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
17723 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
17724 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
17725 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
17726 0x01000015, 0x0100003e,
17728 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
17729 static const DWORD ps_2d_array_code[] =
17731 #if 0
17732 Texture2DArray t;
17734 uint type;
17735 uint level;
17737 float4 main() : SV_TARGET
17739 if (!type)
17741 float width, height, elements, miplevels;
17742 t.GetDimensions(level, width, height, elements, miplevels);
17743 return float4(width, height, elements, miplevels);
17745 else
17747 uint width, height, elements, miplevels;
17748 t.GetDimensions(level, width, height, elements, miplevels);
17749 return float4(width, height, elements, miplevels);
17752 #endif
17753 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
17754 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17755 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17756 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
17757 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
17758 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17759 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17760 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
17761 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
17762 0x0100003e, 0x01000015, 0x0100003e,
17764 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
17765 static const DWORD ps_3d_code[] =
17767 #if 0
17768 Texture3D t;
17770 uint type;
17771 uint level;
17773 float4 main() : SV_TARGET
17775 if (!type)
17777 float width, height, depth, miplevels;
17778 t.GetDimensions(level, width, height, depth, miplevels);
17779 return float4(width, height, depth, miplevels);
17781 else
17783 uint width, height, depth, miplevels;
17784 t.GetDimensions(level, width, height, depth, miplevels);
17785 return float4(width, height, depth, miplevels);
17788 #endif
17789 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
17790 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17791 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17792 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
17793 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
17794 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17795 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17796 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
17797 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
17798 0x0100003e, 0x01000015, 0x0100003e,
17800 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
17801 static const DWORD ps_cube_code[] =
17803 #if 0
17804 TextureCube t;
17806 uint type;
17807 uint level;
17809 float4 main() : SV_TARGET
17811 if (!type)
17813 float width, height, miplevels;
17814 t.GetDimensions(level, width, height, miplevels);
17815 return float4(width, height, miplevels, 0);
17817 else
17819 uint width, height, miplevels;
17820 t.GetDimensions(level, width, height, miplevels);
17821 return float4(width, height, miplevels, 0);
17824 #endif
17825 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
17826 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17827 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17828 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
17829 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
17830 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17831 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17832 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
17833 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
17834 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
17835 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
17836 0x01000015, 0x0100003e,
17838 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
17839 static const DWORD ps_cube_array_code[] =
17841 #if 0
17842 TextureCubeArray t;
17844 uint type;
17845 uint level;
17847 float4 main() : SV_TARGET
17849 if (!type)
17851 float width, height, elements, miplevels;
17852 t.GetDimensions(level, width, height, elements, miplevels);
17853 return float4(width, height, miplevels, 0);
17855 else
17857 uint width, height, elements, miplevels;
17858 t.GetDimensions(level, width, height, elements, miplevels);
17859 return float4(width, height, miplevels, 0);
17862 #endif
17863 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
17864 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17865 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17866 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
17867 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
17868 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
17869 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
17870 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
17871 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
17872 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
17873 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
17874 0x0100003e, 0x01000015, 0x0100003e,
17876 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
17877 static const struct ps_test
17879 const struct shader *ps;
17880 struct
17882 unsigned int width;
17883 unsigned int height;
17884 unsigned int depth;
17885 unsigned int miplevel_count;
17886 unsigned int array_size;
17887 unsigned int cube_count;
17888 } texture_desc;
17889 unsigned int miplevel;
17890 struct vec4 expected_result;
17892 ps_tests[] =
17894 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
17895 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
17896 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
17897 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
17899 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
17900 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
17901 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
17902 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
17904 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
17905 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
17906 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
17907 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
17908 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
17909 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
17910 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
17911 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
17912 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
17914 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
17915 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
17916 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
17917 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
17918 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
17920 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
17921 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
17922 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
17925 if (!init_test_context(&test_context, NULL))
17926 return;
17928 device = test_context.device;
17929 context = test_context.immediate_context;
17930 feature_level = ID3D11Device_GetFeatureLevel(device);
17932 texture_desc.Width = 64;
17933 texture_desc.Height = 64;
17934 texture_desc.MipLevels = 1;
17935 texture_desc.ArraySize = 1;
17936 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17937 texture_desc.SampleDesc.Count = 1;
17938 texture_desc.SampleDesc.Quality = 0;
17939 texture_desc.Usage = D3D11_USAGE_DEFAULT;
17940 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
17941 texture_desc.CPUAccessFlags = 0;
17942 texture_desc.MiscFlags = 0;
17943 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
17944 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17945 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
17946 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17948 memset(&constant, 0, sizeof(constant));
17949 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
17951 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17952 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17954 ps = NULL;
17955 current_ps = NULL;
17956 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
17958 const struct ps_test *test = &ps_tests[i];
17960 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
17962 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
17963 continue;
17966 if (current_ps != test->ps)
17968 if (ps)
17969 ID3D11PixelShader_Release(ps);
17971 current_ps = test->ps;
17973 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
17974 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
17975 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17978 if (test->texture_desc.depth != 1)
17980 texture3d_desc.Width = test->texture_desc.width;
17981 texture3d_desc.Height = test->texture_desc.height;
17982 texture3d_desc.Depth = test->texture_desc.depth;
17983 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
17984 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
17985 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
17986 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
17987 texture3d_desc.CPUAccessFlags = 0;
17988 texture3d_desc.MiscFlags = 0;
17989 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
17990 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
17992 else
17994 texture_desc.Width = test->texture_desc.width;
17995 texture_desc.Height = test->texture_desc.height;
17996 texture_desc.MipLevels = test->texture_desc.miplevel_count;
17997 texture_desc.ArraySize = test->texture_desc.array_size;
17998 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
17999 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18000 texture_desc.MiscFlags = 0;
18001 if (test->texture_desc.cube_count)
18002 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
18003 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
18004 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
18007 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
18008 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
18009 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18011 for (type = 0; type < 2; ++type)
18013 constant.x = type;
18014 constant.y = test->miplevel;
18015 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
18017 draw_quad(&test_context);
18018 check_texture_vec4(rtv_texture, &test->expected_result, 0);
18021 ID3D11Resource_Release(texture);
18022 ID3D11ShaderResourceView_Release(srv);
18024 ID3D11PixelShader_Release(ps);
18026 ID3D11Buffer_Release(cb);
18027 ID3D11RenderTargetView_Release(rtv);
18028 ID3D11Texture2D_Release(rtv_texture);
18029 release_test_context(&test_context);
18032 static void test_sm5_bufinfo_instruction(void)
18034 struct shader
18036 const DWORD *code;
18037 size_t size;
18040 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18041 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
18042 struct d3d11_test_context test_context;
18043 D3D11_TEXTURE2D_DESC texture_desc;
18044 const struct shader *current_ps;
18045 ID3D11UnorderedAccessView *uav;
18046 ID3D11ShaderResourceView *srv;
18047 D3D11_BUFFER_DESC buffer_desc;
18048 ID3D11DeviceContext *context;
18049 ID3D11RenderTargetView *rtv;
18050 ID3D11Texture2D *texture;
18051 ID3D11PixelShader *ps;
18052 ID3D11Buffer *buffer;
18053 ID3D11Device *device;
18054 unsigned int i;
18055 HRESULT hr;
18057 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18058 static const DWORD ps_uav_structured_code[] =
18060 #if 0
18061 struct s
18063 uint4 u;
18064 bool b;
18067 RWStructuredBuffer<s> b;
18069 uint4 main(void) : SV_Target
18071 uint count, stride;
18072 b.GetDimensions(count, stride);
18073 return uint4(count, stride, 0, 1);
18075 #endif
18076 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
18077 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18078 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18079 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
18080 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
18081 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
18082 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
18083 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
18085 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
18086 static const DWORD ps_uav_structured32_code[] =
18088 #if 0
18089 struct s
18091 uint4 u;
18092 bool4 b;
18095 RWStructuredBuffer<s> b;
18097 uint4 main(void) : SV_Target
18099 uint count, stride;
18100 b.GetDimensions(count, stride);
18101 return uint4(count, stride, 0, 1);
18103 #endif
18104 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
18105 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18106 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18107 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
18108 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
18109 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
18110 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
18111 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
18113 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
18114 static const DWORD ps_srv_structured_code[] =
18116 #if 0
18117 StructuredBuffer<bool> b;
18119 uint4 main(void) : SV_Target
18121 uint count, stride;
18122 b.GetDimensions(count, stride);
18123 return uint4(count, stride, 0, 1);
18125 #endif
18126 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
18127 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18128 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18129 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
18130 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
18131 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
18132 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
18133 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
18135 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
18136 static const DWORD ps_uav_raw_code[] =
18138 #if 0
18139 RWByteAddressBuffer b;
18141 uint4 main(void) : SV_Target
18143 uint width;
18144 b.GetDimensions(width);
18145 return width;
18147 #endif
18148 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
18149 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18150 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18151 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
18152 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
18153 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
18154 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18156 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
18157 static const DWORD ps_srv_raw_code[] =
18159 #if 0
18160 ByteAddressBuffer b;
18162 uint4 main(void) : SV_Target
18164 uint width;
18165 b.GetDimensions(width);
18166 return width;
18168 #endif
18169 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
18170 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18171 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18172 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
18173 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
18174 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
18175 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18177 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
18178 static const DWORD ps_uav_typed_code[] =
18180 #if 0
18181 RWBuffer<float> b;
18183 uint4 main(void) : SV_Target
18185 uint width;
18186 b.GetDimensions(width);
18187 return width;
18189 #endif
18190 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
18191 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18192 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18193 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
18194 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
18195 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
18196 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18198 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
18199 static const DWORD ps_srv_typed_code[] =
18201 #if 0
18202 Buffer<float> b;
18204 uint4 main(void) : SV_Target
18206 uint width;
18207 b.GetDimensions(width);
18208 return width;
18210 #endif
18211 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
18212 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18213 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18214 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
18215 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
18216 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
18217 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18219 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
18220 static const struct test
18222 const struct shader *ps;
18223 BOOL uav;
18224 unsigned int buffer_size;
18225 unsigned int buffer_misc_flags;
18226 unsigned int buffer_structure_byte_stride;
18227 DXGI_FORMAT view_format;
18228 unsigned int view_element_idx;
18229 unsigned int view_element_count;
18230 struct uvec4 expected_result;
18232 tests[] =
18234 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
18235 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
18236 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
18237 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
18238 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
18239 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
18240 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
18241 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
18242 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
18243 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
18244 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
18245 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
18246 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
18247 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
18248 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
18249 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
18250 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
18251 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
18252 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
18253 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
18254 #undef RAW
18255 #undef STRUCTURED
18258 if (!init_test_context(&test_context, &feature_level))
18259 return;
18261 device = test_context.device;
18262 context = test_context.immediate_context;
18264 texture_desc.Width = 64;
18265 texture_desc.Height = 64;
18266 texture_desc.MipLevels = 1;
18267 texture_desc.ArraySize = 1;
18268 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
18269 texture_desc.SampleDesc.Count = 1;
18270 texture_desc.SampleDesc.Quality = 0;
18271 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18272 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
18273 texture_desc.CPUAccessFlags = 0;
18274 texture_desc.MiscFlags = 0;
18275 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18276 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18277 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18278 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18280 ps = NULL;
18281 current_ps = NULL;
18282 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18284 const struct test *test = &tests[i];
18286 if (current_ps != test->ps)
18288 if (ps)
18289 ID3D11PixelShader_Release(ps);
18291 current_ps = test->ps;
18293 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
18294 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
18295 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18298 buffer_desc.ByteWidth = test->buffer_size;
18299 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18300 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
18301 buffer_desc.CPUAccessFlags = 0;
18302 buffer_desc.MiscFlags = test->buffer_misc_flags;
18303 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
18304 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18305 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
18307 if (test->uav)
18309 uav_desc.Format = test->view_format;
18310 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
18311 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
18312 U(uav_desc).Buffer.NumElements = test->view_element_count;
18313 U(uav_desc).Buffer.Flags = 0;
18314 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
18315 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
18316 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
18317 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
18318 srv = NULL;
18320 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
18321 1, 1, &uav, NULL);
18323 else
18325 srv_desc.Format = test->view_format;
18326 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
18327 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
18328 U(srv_desc).BufferEx.NumElements = test->view_element_count;
18329 U(srv_desc).BufferEx.Flags = 0;
18330 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
18331 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
18332 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
18333 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
18334 uav = NULL;
18336 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18337 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18340 draw_quad(&test_context);
18341 check_texture_uvec4(texture, &test->expected_result);
18343 if (srv)
18344 ID3D11ShaderResourceView_Release(srv);
18345 if (uav)
18346 ID3D11UnorderedAccessView_Release(uav);
18347 ID3D11Buffer_Release(buffer);
18349 ID3D11PixelShader_Release(ps);
18351 ID3D11RenderTargetView_Release(rtv);
18352 ID3D11Texture2D_Release(texture);
18353 release_test_context(&test_context);
18356 static void test_render_target_device_mismatch(void)
18358 struct d3d11_test_context test_context;
18359 struct device_desc device_desc = {0};
18360 ID3D11DeviceContext *context;
18361 ID3D11RenderTargetView *rtv;
18362 ID3D11Device *device;
18363 ULONG refcount;
18365 if (!init_test_context(&test_context, NULL))
18366 return;
18368 device = create_device(&device_desc);
18369 ok(!!device, "Failed to create device.\n");
18371 ID3D11Device_GetImmediateContext(device, &context);
18373 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
18374 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
18375 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
18376 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
18377 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
18378 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
18379 ID3D11RenderTargetView_Release(rtv);
18381 rtv = NULL;
18382 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18384 ID3D11DeviceContext_Release(context);
18385 refcount = ID3D11Device_Release(device);
18386 ok(!refcount, "Device has %u references left.\n", refcount);
18387 release_test_context(&test_context);
18390 static void test_buffer_srv(void)
18392 struct shader
18394 const DWORD *code;
18395 size_t size;
18396 BOOL requires_raw_and_structured_buffers;
18398 struct buffer
18400 unsigned int byte_count;
18401 unsigned int data_offset;
18402 const void *data;
18403 unsigned int structure_byte_stride;
18406 BOOL raw_and_structured_buffers_supported;
18407 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
18408 struct d3d11_test_context test_context;
18409 D3D11_SUBRESOURCE_DATA resource_data;
18410 const struct buffer *current_buffer;
18411 const struct shader *current_shader;
18412 ID3D11ShaderResourceView *srv;
18413 D3D11_BUFFER_DESC buffer_desc;
18414 ID3D11DeviceContext *context;
18415 DWORD color, expected_color;
18416 struct resource_readback rb;
18417 ID3D11Buffer *cb, *buffer;
18418 ID3D11PixelShader *ps;
18419 ID3D11Device *device;
18420 unsigned int i, x, y;
18421 struct vec4 cb_size;
18422 HRESULT hr;
18424 static const DWORD ps_float4_code[] =
18426 #if 0
18427 Buffer<float4> b;
18429 float2 size;
18431 float4 main(float4 position : SV_POSITION) : SV_Target
18433 float2 p;
18434 int2 coords;
18435 p.x = position.x / 640.0f;
18436 p.y = position.y / 480.0f;
18437 coords = int2(p.x * size.x, p.y * size.y);
18438 return b.Load(coords.y * size.x + coords.x);
18440 #endif
18441 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
18442 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18443 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
18444 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18445 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
18446 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
18447 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
18448 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
18449 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
18450 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
18451 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
18452 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
18453 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
18455 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
18456 static const DWORD ps_structured_code[] =
18458 #if 0
18459 StructuredBuffer<float4> b;
18461 float2 size;
18463 float4 main(float4 position : SV_POSITION) : SV_Target
18465 float2 p;
18466 int2 coords;
18467 p.x = position.x / 640.0f;
18468 p.y = position.y / 480.0f;
18469 coords = int2(p.x * size.x, p.y * size.y);
18470 return b[coords.y * size.x + coords.x];
18472 #endif
18473 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
18474 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
18475 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
18476 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
18477 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
18478 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
18479 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
18480 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
18481 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
18482 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
18483 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
18484 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
18485 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
18486 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
18488 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
18489 static const DWORD rgba16[] =
18491 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
18492 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
18493 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
18494 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
18496 static const DWORD rgba4[] =
18498 0xffffffff, 0xff0000ff,
18499 0xff000000, 0xff00ff00,
18501 static const BYTE r4[] =
18503 0xde, 0xad,
18504 0xba, 0xbe,
18506 static const struct vec4 rgba_float[] =
18508 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
18509 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
18511 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
18512 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
18513 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
18514 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
18515 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
18516 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
18517 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
18518 &rgba_float, sizeof(*rgba_float)};
18519 static const DWORD rgba16_colors2x2[] =
18521 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
18522 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
18523 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
18524 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
18526 static const DWORD rgba16_colors1x1[] =
18528 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18529 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18530 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18531 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18533 static const DWORD rgba4_colors[] =
18535 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
18536 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
18537 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
18538 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
18540 static const DWORD r4_colors[] =
18542 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
18543 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
18544 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
18545 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
18547 static const DWORD zero_colors[16] = {0};
18548 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
18550 static const struct test
18552 const struct shader *shader;
18553 const struct buffer *buffer;
18554 DXGI_FORMAT srv_format;
18555 unsigned int srv_first_element;
18556 unsigned int srv_element_count;
18557 struct vec2 size;
18558 const DWORD *expected_colors;
18560 tests[] =
18562 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
18563 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
18564 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
18565 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
18566 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
18567 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
18568 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
18569 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
18570 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
18571 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
18572 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
18575 if (!init_test_context(&test_context, NULL))
18576 return;
18578 device = test_context.device;
18579 context = test_context.immediate_context;
18580 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
18581 || check_compute_shaders_via_sm4_support(device);
18583 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
18584 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18586 buffer_desc.ByteWidth = 256;
18587 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18588 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18589 buffer_desc.CPUAccessFlags = 0;
18590 buffer_desc.MiscFlags = 0;
18591 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18592 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18593 srv_desc.Format = DXGI_FORMAT_R8_UNORM;
18594 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
18595 U(srv_desc).Buffer.FirstElement = 0;
18596 U(srv_desc).Buffer.NumElements = 0;
18597 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
18598 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18599 ID3D11Buffer_Release(buffer);
18601 ps = NULL;
18602 srv = NULL;
18603 buffer = NULL;
18604 current_shader = NULL;
18605 current_buffer = NULL;
18606 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18608 const struct test *test = &tests[i];
18610 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
18612 skip("Test %u: Raw and structured buffers are not supported.\n", i);
18613 continue;
18615 /* Structured buffer views with an offset don't seem to work on WARP. */
18616 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
18617 && is_warp_device(device))
18619 skip("Test %u: Broken WARP.\n", i);
18620 continue;
18623 if (current_shader != test->shader)
18625 if (ps)
18626 ID3D11PixelShader_Release(ps);
18628 current_shader = test->shader;
18630 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
18631 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
18632 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18635 if (current_buffer != test->buffer)
18637 if (buffer)
18638 ID3D11Buffer_Release(buffer);
18640 current_buffer = test->buffer;
18641 if (current_buffer)
18643 BYTE *data = NULL;
18645 buffer_desc.ByteWidth = current_buffer->byte_count;
18646 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18647 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18648 buffer_desc.CPUAccessFlags = 0;
18649 buffer_desc.MiscFlags = 0;
18650 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
18651 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
18652 resource_data.SysMemPitch = 0;
18653 resource_data.SysMemSlicePitch = 0;
18654 if (current_buffer->data_offset)
18656 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, current_buffer->byte_count);
18657 ok(!!data, "Failed to allocate memory.\n");
18658 memcpy(data + current_buffer->data_offset, current_buffer->data,
18659 current_buffer->byte_count - current_buffer->data_offset);
18660 resource_data.pSysMem = data;
18662 else
18664 resource_data.pSysMem = current_buffer->data;
18666 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
18667 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
18668 HeapFree(GetProcessHeap(), 0, data);
18670 else
18672 buffer = NULL;
18676 if (srv)
18677 ID3D11ShaderResourceView_Release(srv);
18678 if (current_buffer)
18680 srv_desc.Format = test->srv_format;
18681 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
18682 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
18683 U(srv_desc).Buffer.NumElements = test->srv_element_count;
18684 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
18685 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
18687 else
18689 srv = NULL;
18691 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18693 cb_size.x = test->size.x;
18694 cb_size.y = test->size.y;
18695 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
18697 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
18698 draw_quad(&test_context);
18700 get_texture_readback(test_context.backbuffer, 0, &rb);
18701 for (y = 0; y < 4; ++y)
18703 for (x = 0; x < 4; ++x)
18705 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
18706 expected_color = test->expected_colors[y * 4 + x];
18707 ok(compare_color(color, expected_color, 1),
18708 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
18709 i, color, expected_color, x, y);
18712 release_resource_readback(&rb);
18714 if (srv)
18715 ID3D11ShaderResourceView_Release(srv);
18716 if (buffer)
18717 ID3D11Buffer_Release(buffer);
18719 ID3D11Buffer_Release(cb);
18720 ID3D11PixelShader_Release(ps);
18721 release_test_context(&test_context);
18724 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
18726 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18727 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
18728 struct d3d11_test_context test_context;
18729 D3D11_SUBRESOURCE_DATA resource_data;
18730 D3D11_TEXTURE2D_DESC texture_desc;
18731 ID3D11UnorderedAccessView *uav;
18732 ID3D11ShaderResourceView *srv;
18733 D3D11_BUFFER_DESC buffer_desc;
18734 ID3D11Buffer *cb, *raw_buffer;
18735 ID3D11DeviceContext *context;
18736 struct resource_readback rb;
18737 ID3D11RenderTargetView *rtv;
18738 ID3D11Texture2D *texture;
18739 ID3D11ComputeShader *cs;
18740 ID3D11PixelShader *ps;
18741 ID3D11Device *device;
18742 unsigned int i, data;
18743 struct uvec4 offset;
18744 HRESULT hr;
18746 static const unsigned int buffer_data[] =
18748 0xffffffff, 0x00000000,
18750 static const DWORD ps_code[] =
18752 #if 0
18753 ByteAddressBuffer buffer;
18755 uint offset;
18757 uint main() : SV_Target0
18759 return buffer.Load(offset);
18761 #endif
18762 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
18763 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
18764 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
18765 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
18766 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
18767 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
18768 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
18769 0x00000000,
18771 static const DWORD cs_code[] =
18773 #if 0
18774 RWByteAddressBuffer buffer;
18776 uint2 input;
18778 [numthreads(1, 1, 1)]
18779 void main()
18781 buffer.Store(input.x, input.y);
18783 #endif
18784 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
18785 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18786 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
18787 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
18788 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
18789 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
18791 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
18793 if (!init_test_context(&test_context, &feature_level))
18794 return;
18796 device = test_context.device;
18797 context = test_context.immediate_context;
18799 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
18801 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18802 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18803 if (SUCCEEDED(hr))
18804 ID3D11PixelShader_Release(ps);
18805 skip("Raw buffers are not supported.\n");
18806 release_test_context(&test_context);
18807 return;
18810 if (is_intel_device(device))
18812 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
18813 * This test checks what happens when offsets are not properly aligned.
18814 * The behavior seems to be undefined on Intel hardware. */
18815 win_skip("Skipping the test on Intel hardware.\n");
18816 release_test_context(&test_context);
18817 return;
18820 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18821 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18823 memset(&offset, 0, sizeof(offset));
18824 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
18826 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18827 texture_desc.Format = DXGI_FORMAT_R32_UINT;
18828 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18829 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18830 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18831 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18833 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18835 buffer_desc.ByteWidth = sizeof(buffer_data);
18836 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18837 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18838 buffer_desc.CPUAccessFlags = 0;
18839 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
18840 resource_data.pSysMem = buffer_data;
18841 resource_data.SysMemPitch = 0;
18842 resource_data.SysMemSlicePitch = 0;
18843 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
18844 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18846 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
18847 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
18848 U(srv_desc).BufferEx.FirstElement = 0;
18849 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
18850 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
18851 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
18852 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
18854 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18855 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18856 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18858 offset.x = 0;
18859 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18860 NULL, &offset, 0, 0);
18861 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18862 draw_quad(&test_context);
18863 check_texture_color(texture, buffer_data[0], 0);
18864 offset.x = 1;
18865 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18866 NULL, &offset, 0, 0);
18867 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18868 draw_quad(&test_context);
18869 check_texture_color(texture, buffer_data[0], 0);
18870 offset.x = 2;
18871 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18872 NULL, &offset, 0, 0);
18873 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18874 draw_quad(&test_context);
18875 check_texture_color(texture, buffer_data[0], 0);
18876 offset.x = 3;
18877 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18878 NULL, &offset, 0, 0);
18879 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18880 draw_quad(&test_context);
18881 check_texture_color(texture, buffer_data[0], 0);
18883 offset.x = 4;
18884 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18885 NULL, &offset, 0, 0);
18886 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18887 draw_quad(&test_context);
18888 check_texture_color(texture, buffer_data[1], 0);
18889 offset.x = 7;
18890 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18891 NULL, &offset, 0, 0);
18892 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18893 draw_quad(&test_context);
18894 check_texture_color(texture, buffer_data[1], 0);
18896 if (feature_level < D3D_FEATURE_LEVEL_11_0)
18898 skip("Feature level 11_0 required for unaligned UAV test.\n");
18899 goto done;
18902 ID3D11Buffer_Release(raw_buffer);
18903 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
18904 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
18905 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18907 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
18908 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
18909 U(uav_desc).Buffer.FirstElement = 0;
18910 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
18911 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
18912 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
18913 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18915 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
18916 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18918 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18919 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
18920 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
18922 offset.x = 0;
18923 offset.y = 0xffffffff;
18924 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18925 NULL, &offset, 0, 0);
18926 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18927 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18928 get_buffer_readback(raw_buffer, &rb);
18929 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18931 data = get_readback_color(&rb, i, 0);
18932 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18934 release_resource_readback(&rb);
18936 offset.x = 1;
18937 offset.y = 0xffffffff;
18938 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18939 NULL, &offset, 0, 0);
18940 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18941 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18942 get_buffer_readback(raw_buffer, &rb);
18943 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18945 data = get_readback_color(&rb, i, 0);
18946 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18948 release_resource_readback(&rb);
18950 offset.x = 2;
18951 offset.y = 0xffffffff;
18952 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18953 NULL, &offset, 0, 0);
18954 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18955 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18956 get_buffer_readback(raw_buffer, &rb);
18957 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18959 data = get_readback_color(&rb, i, 0);
18960 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18962 release_resource_readback(&rb);
18964 offset.x = 3;
18965 offset.y = 0xffffffff;
18966 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18967 NULL, &offset, 0, 0);
18968 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18969 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18970 get_buffer_readback(raw_buffer, &rb);
18971 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18973 data = get_readback_color(&rb, i, 0);
18974 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18976 release_resource_readback(&rb);
18978 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18979 offset.x = 3;
18980 offset.y = 0xffff;
18981 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18982 NULL, &offset, 0, 0);
18983 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18984 offset.x = 4;
18985 offset.y = 0xa;
18986 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18987 NULL, &offset, 0, 0);
18988 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18989 get_buffer_readback(raw_buffer, &rb);
18990 data = get_readback_color(&rb, 0, 0);
18991 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
18992 data = get_readback_color(&rb, 1, 0);
18993 ok(data == 0xa, "Got unexpected result %#x.\n", data);
18994 release_resource_readback(&rb);
18996 ID3D11ComputeShader_Release(cs);
18997 ID3D11UnorderedAccessView_Release(uav);
18999 done:
19000 ID3D11Buffer_Release(cb);
19001 ID3D11Buffer_Release(raw_buffer);
19002 ID3D11PixelShader_Release(ps);
19003 ID3D11RenderTargetView_Release(rtv);
19004 ID3D11ShaderResourceView_Release(srv);
19005 ID3D11Texture2D_Release(texture);
19006 release_test_context(&test_context);
19009 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
19010 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
19012 D3D11_MAPPED_SUBRESOURCE map_desc;
19013 unsigned int counter;
19015 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
19017 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
19018 D3D11_MAP_READ, 0, &map_desc)))
19019 return 0xdeadbeef;
19020 counter = *(unsigned int *)map_desc.pData;
19021 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
19022 return counter;
19025 static int compare_id(const void *a, const void *b)
19027 return *(int *)a - *(int *)b;
19030 static void test_uav_counters(void)
19032 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
19033 ID3D11ComputeShader *cs_producer, *cs_consumer;
19034 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19035 struct d3d11_test_context test_context;
19036 ID3D11UnorderedAccessView *uav, *uav2;
19037 unsigned int data, id[128], i;
19038 D3D11_BUFFER_DESC buffer_desc;
19039 ID3D11DeviceContext *context;
19040 struct resource_readback rb;
19041 ID3D11Device *device;
19042 D3D11_BOX box;
19043 HRESULT hr;
19045 static const DWORD cs_producer_code[] =
19047 #if 0
19048 RWStructuredBuffer<uint> u;
19050 [numthreads(4, 1, 1)]
19051 void main(uint3 dispatch_id : SV_DispatchThreadID)
19053 uint counter = u.IncrementCounter();
19054 u[counter] = dispatch_id.x;
19056 #endif
19057 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
19058 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19059 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
19060 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
19061 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
19062 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
19063 0x0002000a, 0x0100003e,
19065 static const DWORD cs_consumer_code[] =
19067 #if 0
19068 RWStructuredBuffer<uint> u;
19069 RWStructuredBuffer<uint> u2;
19071 [numthreads(4, 1, 1)]
19072 void main()
19074 uint counter = u.DecrementCounter();
19075 u2[counter] = u[counter];
19077 #endif
19078 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
19079 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19080 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
19081 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
19082 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
19083 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
19084 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
19085 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
19087 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19089 if (!init_test_context(&test_context, &feature_level))
19090 return;
19092 device = test_context.device;
19093 context = test_context.immediate_context;
19095 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
19096 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19097 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
19098 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19100 memset(&buffer_desc, 0, sizeof(buffer_desc));
19101 buffer_desc.ByteWidth = sizeof(unsigned int);
19102 buffer_desc.Usage = D3D11_USAGE_STAGING;
19103 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
19104 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
19105 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19107 buffer_desc.ByteWidth = 1024;
19108 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19109 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19110 buffer_desc.CPUAccessFlags = 0;
19111 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19112 buffer_desc.StructureByteStride = sizeof(unsigned int);
19113 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19114 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19115 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
19116 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19117 U(uav_desc).Buffer.FirstElement = 0;
19118 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
19119 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
19120 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19121 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19122 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
19123 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19124 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
19125 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19127 data = read_uav_counter(context, staging_buffer, uav);
19128 ok(!data, "Got unexpected initial value %u.\n", data);
19129 data = 8;
19130 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19131 data = read_uav_counter(context, staging_buffer, uav);
19132 ok(data == 8, "Got unexpected value %u.\n", data);
19133 data = ~0u;
19134 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19135 data = read_uav_counter(context, staging_buffer, uav);
19136 ok(data == 8, "Got unexpected value %u.\n", data);
19137 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19138 data = read_uav_counter(context, staging_buffer, uav);
19139 ok(data == 8, "Got unexpected value %u.\n", data);
19141 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
19142 data = 0;
19143 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19144 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
19145 data = read_uav_counter(context, staging_buffer, uav);
19146 ok(!data, "Got unexpected value %u.\n", data);
19148 /* produce */
19149 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
19150 data = read_uav_counter(context, staging_buffer, uav);
19151 ok(data == 64, "Got unexpected value %u.\n", data);
19152 get_buffer_readback(buffer, &rb);
19153 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
19154 release_resource_readback(&rb);
19155 qsort(id, 64, sizeof(*id), compare_id);
19156 for (i = 0; i < 64; ++i)
19158 if (id[i] != i)
19159 break;
19161 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
19163 /* consume */
19164 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
19165 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
19166 data = read_uav_counter(context, staging_buffer, uav);
19167 ok(!data, "Got unexpected value %u.\n", data);
19168 get_buffer_readback(buffer2, &rb);
19169 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
19170 release_resource_readback(&rb);
19171 qsort(id, 64, sizeof(*id), compare_id);
19172 for (i = 0; i < 64; ++i)
19174 if (id[i] != i)
19175 break;
19177 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
19179 /* produce on CPU */
19180 for (i = 0; i < 8; ++i)
19181 id[i] = 0xdeadbeef;
19182 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
19183 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
19184 data = 8;
19185 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19186 data = read_uav_counter(context, staging_buffer, uav);
19187 ok(data == 8, "Got unexpected value %u.\n", data);
19189 /* consume */
19190 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19191 data = read_uav_counter(context, staging_buffer, uav);
19192 ok(data == 4, "Got unexpected value %u.\n", data);
19193 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19194 data = read_uav_counter(context, staging_buffer, uav);
19195 ok(!data, "Got unexpected value %u.\n", data);
19196 get_buffer_readback(buffer2, &rb);
19197 for (i = 0; i < 8; ++i)
19199 data = get_readback_color(&rb, i, 0);
19200 ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
19202 release_resource_readback(&rb);
19204 ID3D11Buffer_Release(buffer);
19205 ID3D11Buffer_Release(buffer2);
19206 ID3D11Buffer_Release(staging_buffer);
19207 ID3D11ComputeShader_Release(cs_producer);
19208 ID3D11ComputeShader_Release(cs_consumer);
19209 ID3D11UnorderedAccessView_Release(uav);
19210 ID3D11UnorderedAccessView_Release(uav2);
19211 release_test_context(&test_context);
19214 static void test_dispatch_indirect(void)
19216 struct stats
19218 unsigned int dispatch_count;
19219 unsigned int thread_count;
19220 unsigned int max_x;
19221 unsigned int max_y;
19222 unsigned int max_z;
19225 ID3D11Buffer *append_buffer, *stats_buffer, *args_buffer, *staging_buffer;
19226 ID3D11UnorderedAccessView *uav, *stats_uav;
19227 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19228 ID3D11ComputeShader *cs_append, *cs_stats;
19229 struct d3d11_test_context test_context;
19230 D3D11_BUFFER_DESC buffer_desc;
19231 ID3D11DeviceContext *context;
19232 struct resource_readback rb;
19233 ID3D11Device *device;
19234 unsigned int data, i;
19235 struct stats *stats;
19236 HRESULT hr;
19238 static const DWORD cs_append_code[] =
19240 #if 0
19241 struct dispatch_args
19243 uint x, y, z;
19246 AppendStructuredBuffer<dispatch_args> u;
19248 [numthreads(1, 1, 1)]
19249 void main()
19251 dispatch_args args = {4, 2, 1};
19252 u.Append(args);
19253 args.y = 1;
19254 u.Append(args);
19255 args.x = 3;
19256 u.Append(args);
19258 #endif
19259 0x43425844, 0x954de75a, 0x8bb1b78b, 0x84ded464, 0x9d9532b7, 0x00000001, 0x00000158, 0x00000003,
19260 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19261 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000104, 0x00050050, 0x00000041, 0x0100086a,
19262 0x0400009e, 0x0011e000, 0x00000000, 0x0000000c, 0x02000068, 0x00000001, 0x0400009b, 0x00000001,
19263 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x0c0000a8,
19264 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002, 0x00000004,
19265 0x00000002, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000,
19266 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002,
19267 0x00000004, 0x00000001, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
19268 0x00000000, 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
19269 0x00004002, 0x00000003, 0x00000001, 0x00000001, 0x00000000, 0x0100003e,
19271 static const DWORD cs_stats_code[] =
19273 #if 0
19274 struct stats
19276 uint dispatch_count;
19277 uint thread_count;
19278 uint max_x;
19279 uint max_y;
19280 uint max_z;
19283 RWStructuredBuffer<stats> u;
19285 [numthreads(1, 1, 1)]
19286 void main(uint3 id : SV_DispatchThreadID)
19288 if (all(!id))
19289 InterlockedAdd(u[0].dispatch_count, 1);
19290 InterlockedAdd(u[0].thread_count, 1);
19291 InterlockedMax(u[0].max_x, id.x);
19292 InterlockedMax(u[0].max_y, id.y);
19293 InterlockedMax(u[0].max_z, id.z);
19295 #endif
19296 0x43425844, 0xbd3f2e4e, 0xb0f61ff7, 0xa8e10584, 0x2f61aec9, 0x00000001, 0x000001bc, 0x00000003,
19297 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19298 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000168, 0x00050050, 0x0000005a, 0x0100086a,
19299 0x0400009e, 0x0011e000, 0x00000000, 0x00000014, 0x0200005f, 0x00020072, 0x02000068, 0x00000001,
19300 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x09000020, 0x00100072, 0x00000000, 0x00020246,
19301 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000001, 0x00100012, 0x00000000,
19302 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00100012, 0x00000000, 0x0010002a,
19303 0x00000000, 0x0010000a, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x0a0000ad, 0x0011e000,
19304 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001,
19305 0x01000015, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000,
19306 0x00000000, 0x00004001, 0x00000001, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002, 0x00000000,
19307 0x00000008, 0x00000000, 0x00000000, 0x0002000a, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002,
19308 0x00000000, 0x0000000c, 0x00000000, 0x00000000, 0x0002001a, 0x090000b0, 0x0011e000, 0x00000000,
19309 0x00004002, 0x00000000, 0x00000010, 0x00000000, 0x00000000, 0x0002002a, 0x0100003e,
19311 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19312 static const unsigned int zero[4] = {0, 0, 0, 0};
19314 if (!init_test_context(&test_context, &feature_level))
19315 return;
19317 device = test_context.device;
19318 context = test_context.immediate_context;
19320 hr = ID3D11Device_CreateComputeShader(device, cs_append_code, sizeof(cs_append_code), NULL, &cs_append);
19321 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19322 hr = ID3D11Device_CreateComputeShader(device, cs_stats_code, sizeof(cs_stats_code), NULL, &cs_stats);
19323 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19325 memset(&buffer_desc, 0, sizeof(buffer_desc));
19326 buffer_desc.ByteWidth = sizeof(unsigned int);
19327 buffer_desc.Usage = D3D11_USAGE_STAGING;
19328 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
19329 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
19330 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19332 buffer_desc.ByteWidth = 60;
19333 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19334 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19335 buffer_desc.CPUAccessFlags = 0;
19336 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19337 buffer_desc.StructureByteStride = 3 * sizeof(unsigned int);
19338 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &append_buffer);
19339 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19340 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
19341 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19342 U(uav_desc).Buffer.FirstElement = 0;
19343 U(uav_desc).Buffer.NumElements = 5;
19344 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
19345 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)append_buffer, &uav_desc, &uav);
19346 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19348 /* We use a separate buffer because D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
19349 * and D3D11_RESOURCE_MISC_BUFFER_STRUCTURED are mutually exclusive flags.
19351 buffer_desc.BindFlags = 0;
19352 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
19353 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &args_buffer);
19354 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19356 buffer_desc.ByteWidth = sizeof(*stats);
19357 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19358 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19359 buffer_desc.StructureByteStride = sizeof(*stats);
19360 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &stats_buffer);
19361 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19362 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)stats_buffer, NULL, &stats_uav);
19363 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19365 data = read_uav_counter(context, staging_buffer, uav);
19366 ok(!data, "Got unexpected initial value %u.\n", data);
19367 data = 8;
19368 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19369 data = read_uav_counter(context, staging_buffer, uav);
19370 ok(data == 8, "Got unexpected value %u.\n", data);
19372 ID3D11DeviceContext_CSSetShader(context, cs_append, NULL, 0);
19373 data = 0;
19374 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19375 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19376 data = read_uav_counter(context, staging_buffer, uav);
19377 ok(data == 3, "Got unexpected value %u.\n", data);
19378 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)args_buffer, (ID3D11Resource *)append_buffer);
19380 ID3D11DeviceContext_CSSetShader(context, cs_stats, NULL, 0);
19381 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, stats_uav, zero);
19382 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &stats_uav, NULL);
19383 data = read_uav_counter(context, staging_buffer, uav);
19384 for (i = 0; i < data; ++i)
19385 ID3D11DeviceContext_DispatchIndirect(context, args_buffer, i * 3 * sizeof(unsigned int));
19386 get_buffer_readback(stats_buffer, &rb);
19387 stats = rb.map_desc.pData;
19388 ok(stats->dispatch_count == 3, "Got unexpected dispatch count %u.\n", stats->dispatch_count);
19389 ok(stats->thread_count == 15, "Got unexpected thread count %u.\n", stats->thread_count);
19390 ok(stats->max_x == 3, "Got unexpected max x %u.\n", stats->max_x);
19391 ok(stats->max_y == 1, "Got unexpected max y %u.\n", stats->max_y);
19392 ok(stats->max_z == 0, "Got unexpected max z %u.\n", stats->max_z);
19393 release_resource_readback(&rb);
19395 ID3D11Buffer_Release(append_buffer);
19396 ID3D11Buffer_Release(args_buffer);
19397 ID3D11Buffer_Release(staging_buffer);
19398 ID3D11Buffer_Release(stats_buffer);
19399 ID3D11ComputeShader_Release(cs_append);
19400 ID3D11ComputeShader_Release(cs_stats);
19401 ID3D11UnorderedAccessView_Release(uav);
19402 ID3D11UnorderedAccessView_Release(stats_uav);
19403 release_test_context(&test_context);
19406 static void test_compute_shader_registers(void)
19408 struct data
19410 unsigned int group_id[3];
19411 unsigned int group_index;
19412 unsigned int dispatch_id[3];
19413 unsigned int thread_id[3];
19416 struct d3d11_test_context test_context;
19417 unsigned int i, x, y, group_x, group_y;
19418 ID3D11UnorderedAccessView *uav;
19419 D3D11_BUFFER_DESC buffer_desc;
19420 ID3D11DeviceContext *context;
19421 struct resource_readback rb;
19422 ID3D11Buffer *cb, *buffer;
19423 struct uvec4 dimensions;
19424 ID3D11ComputeShader *cs;
19425 const struct data *data;
19426 ID3D11Device *device;
19427 HRESULT hr;
19429 static const DWORD cs_code[] =
19431 #if 0
19432 struct data
19434 uint3 group_id;
19435 uint group_index;
19436 uint3 dispatch_id;
19437 uint3 group_thread_id;
19440 RWStructuredBuffer<data> u;
19442 uint2 dim;
19444 [numthreads(3, 2, 1)]
19445 void main(uint3 group_id : SV_GroupID,
19446 uint group_index : SV_GroupIndex,
19447 uint3 dispatch_id : SV_DispatchThreadID,
19448 uint3 group_thread_id : SV_GroupThreadID)
19450 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
19451 u[i].group_id = group_id;
19452 u[i].group_index = group_index;
19453 u[i].dispatch_id = dispatch_id;
19454 u[i].group_thread_id = group_thread_id;
19456 #endif
19457 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
19458 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19459 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
19460 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
19461 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
19462 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
19463 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
19464 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
19465 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
19466 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
19467 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
19468 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
19469 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
19470 0x0100003e,
19472 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19474 if (!init_test_context(&test_context, &feature_level))
19475 return;
19477 device = test_context.device;
19478 context = test_context.immediate_context;
19480 buffer_desc.ByteWidth = 10240;
19481 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19482 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19483 buffer_desc.CPUAccessFlags = 0;
19484 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19485 buffer_desc.StructureByteStride = 40;
19486 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
19487 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19488 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19489 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19490 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19492 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
19494 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
19495 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19497 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19498 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
19499 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19501 dimensions.x = 2;
19502 dimensions.y = 3;
19503 dimensions.z = 1;
19504 dimensions.w = 0;
19505 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
19506 NULL, &dimensions, 0, 0);
19507 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
19509 get_buffer_readback(buffer, &rb);
19510 i = 0;
19511 data = rb.map_desc.pData;
19512 for (y = 0; y < dimensions.y; ++y)
19514 for (group_y = 0; group_y < 2; ++group_y)
19516 for (x = 0; x < dimensions.x; ++x)
19518 for (group_x = 0; group_x < 3; ++group_x)
19520 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
19521 const unsigned int group_index = group_y * 3 + group_x;
19522 const struct data *d = &data[i];
19524 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
19525 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
19526 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
19527 i, x, y, group_x, group_y);
19528 ok(d->group_index == group_index,
19529 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
19530 d->group_index, group_index, i, x, y, group_x, group_y);
19531 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
19532 && !d->dispatch_id[2],
19533 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
19534 "at %u (%u, %u, %u, %u).\n",
19535 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
19536 dispatch_id[0], dispatch_id[1], 0,
19537 i, x, y, group_x, group_y);
19538 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
19539 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
19540 "at %u (%u, %u, %u, %u).\n",
19541 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
19542 i, x, y, group_x, group_y);
19543 ++i;
19548 release_resource_readback(&rb);
19550 ID3D11Buffer_Release(cb);
19551 ID3D11Buffer_Release(buffer);
19552 ID3D11ComputeShader_Release(cs);
19553 ID3D11UnorderedAccessView_Release(uav);
19554 release_test_context(&test_context);
19557 static void test_tgsm(void)
19559 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19560 struct d3d11_test_context test_context;
19561 ID3D11UnorderedAccessView *uav, *uav2;
19562 struct resource_readback rb, rb2;
19563 unsigned int i, data, expected;
19564 ID3D11Buffer *buffer, *buffer2;
19565 D3D11_BUFFER_DESC buffer_desc;
19566 ID3D11DeviceContext *context;
19567 ID3D11ComputeShader *cs;
19568 ID3D11Device *device;
19569 float float_data;
19570 HRESULT hr;
19572 static const DWORD raw_tgsm_code[] =
19574 #if 0
19575 RWByteAddressBuffer u;
19576 groupshared uint m;
19578 [numthreads(32, 1, 1)]
19579 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
19581 if (!local_idx)
19582 m = group_id.x;
19583 GroupMemoryBarrierWithGroupSync();
19584 InterlockedAdd(m, group_id.x);
19585 GroupMemoryBarrierWithGroupSync();
19586 if (!local_idx)
19587 u.Store(4 * group_id.x, m);
19589 #endif
19590 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
19591 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19592 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
19593 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
19594 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
19595 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
19596 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
19597 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
19598 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
19599 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
19600 0x01000015, 0x0100003e,
19602 static const DWORD structured_tgsm_code[] =
19604 #if 0
19605 #define GROUP_SIZE 32
19607 RWByteAddressBuffer u;
19608 RWByteAddressBuffer u2;
19609 groupshared uint m[GROUP_SIZE];
19611 [numthreads(GROUP_SIZE, 1, 1)]
19612 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
19614 uint sum, original, i;
19616 if (!local_idx)
19618 for (i = 0; i < GROUP_SIZE; ++i)
19619 m[i] = 2 * group_id.x;
19621 GroupMemoryBarrierWithGroupSync();
19622 InterlockedAdd(m[local_idx], 1);
19623 GroupMemoryBarrierWithGroupSync();
19624 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
19625 u.InterlockedExchange(4 * group_id.x, sum, original);
19626 u2.Store(4 * group_id.x, original);
19628 #endif
19629 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
19630 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19631 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
19632 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
19633 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
19634 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
19635 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
19636 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
19637 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
19638 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
19639 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
19640 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
19641 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
19642 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
19643 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
19644 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
19645 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
19646 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
19647 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
19648 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
19649 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
19650 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
19652 static const DWORD structured_tgsm_float_code[] =
19654 #if 0
19655 #define GROUP_SIZE 32
19657 struct data
19659 float f;
19660 uint u;
19663 RWBuffer<float> u;
19664 RWBuffer<uint> u2;
19665 groupshared data m[GROUP_SIZE];
19667 [numthreads(GROUP_SIZE, 1, 1)]
19668 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
19669 uint thread_id : SV_DispatchThreadID)
19671 uint i;
19672 if (!local_idx)
19674 for (i = 0; i < GROUP_SIZE; ++i)
19676 m[i].f = group_id.x;
19677 m[i].u = group_id.x;
19680 GroupMemoryBarrierWithGroupSync();
19681 for (i = 0; i < local_idx; ++i)
19683 m[local_idx].f += group_id.x;
19684 m[local_idx].u += group_id.x;
19686 u[thread_id.x] = m[local_idx].f;
19687 u2[thread_id.x] = m[local_idx].u;
19689 #endif
19690 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
19691 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19692 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
19693 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
19694 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
19695 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
19696 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
19697 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
19698 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
19699 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
19700 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
19701 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
19702 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
19703 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
19704 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
19705 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
19706 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
19707 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
19708 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
19709 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
19710 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
19711 0x00100556, 0x00000000, 0x0100003e,
19713 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19714 static const unsigned int zero[4] = {0};
19716 if (!init_test_context(&test_context, &feature_level))
19717 return;
19719 device = test_context.device;
19720 context = test_context.immediate_context;
19722 buffer_desc.ByteWidth = 1024;
19723 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19724 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19725 buffer_desc.CPUAccessFlags = 0;
19726 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
19727 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19728 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19730 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
19731 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19732 U(uav_desc).Buffer.FirstElement = 0;
19733 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
19734 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
19735 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19736 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19738 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
19739 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19741 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19742 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19744 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19745 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
19746 get_buffer_readback(buffer, &rb);
19747 for (i = 0; i < 64; ++i)
19749 data = get_readback_color(&rb, i, 0);
19750 expected = 33 * i;
19751 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
19753 release_resource_readback(&rb);
19755 ID3D11Buffer_Release(buffer);
19756 ID3D11ComputeShader_Release(cs);
19757 ID3D11UnorderedAccessView_Release(uav);
19759 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19760 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19761 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19762 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19763 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
19764 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19765 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
19766 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19767 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
19768 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19770 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19771 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19772 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
19774 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19775 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
19776 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
19777 get_buffer_readback(buffer, &rb);
19778 get_buffer_readback(buffer2, &rb2);
19779 for (i = 0; i < 32; ++i)
19781 expected = 64 * i + 32;
19782 data = get_readback_color(&rb, i, 0);
19783 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
19784 data = get_readback_color(&rb2, i, 0);
19785 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
19787 release_resource_readback(&rb);
19788 release_resource_readback(&rb2);
19790 ID3D11Buffer_Release(buffer);
19791 ID3D11Buffer_Release(buffer2);
19792 ID3D11ComputeShader_Release(cs);
19793 ID3D11UnorderedAccessView_Release(uav);
19794 ID3D11UnorderedAccessView_Release(uav2);
19796 buffer_desc.MiscFlags = 0;
19797 U(uav_desc).Buffer.Flags = 0;
19798 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19799 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19800 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
19801 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19802 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19803 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
19804 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19805 uav_desc.Format = DXGI_FORMAT_R32_UINT;
19806 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
19807 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19808 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
19809 sizeof(structured_tgsm_float_code), NULL, &cs);
19810 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19812 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19813 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19814 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
19816 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19817 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
19818 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
19819 get_buffer_readback(buffer, &rb);
19820 get_buffer_readback(buffer2, &rb2);
19821 for (i = 0; i < 96; ++i)
19823 expected = (i % 32 + 1) * (i / 32);
19824 float_data = get_readback_float(&rb, i, 0);
19825 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
19826 data = get_readback_color(&rb2, i, 0);
19827 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
19829 release_resource_readback(&rb);
19830 release_resource_readback(&rb2);
19832 ID3D11Buffer_Release(buffer);
19833 ID3D11Buffer_Release(buffer2);
19834 ID3D11ComputeShader_Release(cs);
19835 ID3D11UnorderedAccessView_Release(uav);
19836 ID3D11UnorderedAccessView_Release(uav2);
19837 release_test_context(&test_context);
19840 static void test_geometry_shader(void)
19842 static const struct
19844 struct vec4 position;
19845 unsigned int color;
19847 vertex[] =
19849 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
19851 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
19853 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
19854 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
19856 #if 0
19857 struct vs_data
19859 float4 pos : SV_POSITION;
19860 float4 color : COLOR;
19863 void main(in struct vs_data vs_input, out struct vs_data vs_output)
19865 vs_output.pos = vs_input.pos;
19866 vs_output.color = vs_input.color;
19868 #endif
19869 static const DWORD vs_code[] =
19871 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
19872 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19873 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19874 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19875 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19876 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19877 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
19878 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
19879 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
19880 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
19881 0x0100003e,
19883 #if 0
19884 struct gs_data
19886 float4 pos : SV_POSITION;
19887 float4 color : COLOR;
19890 [maxvertexcount(4)]
19891 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
19893 float offset = 0.2 * vin[0].pos.w;
19894 gs_data v;
19896 v.color = vin[0].color;
19898 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
19899 vout.Append(v);
19900 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
19901 vout.Append(v);
19902 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
19903 vout.Append(v);
19904 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
19905 vout.Append(v);
19907 #endif
19908 static const DWORD gs_code[] =
19910 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
19911 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19912 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19913 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19914 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19915 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19916 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
19917 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
19918 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
19919 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
19920 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
19921 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
19922 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
19923 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
19924 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
19925 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
19926 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
19927 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
19928 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
19929 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
19930 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
19931 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
19932 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
19933 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
19934 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
19935 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
19936 0x00000001, 0x01000013, 0x0100003e,
19938 static const DWORD gs_5_0_code[] =
19940 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
19941 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19942 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19943 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19944 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
19945 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
19946 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
19947 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
19948 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
19949 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
19950 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
19951 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
19952 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
19953 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
19954 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
19955 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
19956 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
19957 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
19958 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
19959 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
19960 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
19961 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
19962 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
19963 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
19964 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
19965 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
19966 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
19967 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
19968 0x0100003e,
19970 #if 0
19971 struct ps_data
19973 float4 pos : SV_POSITION;
19974 float4 color : COLOR;
19977 float4 main(struct ps_data ps_input) : SV_Target
19979 return ps_input.color;
19981 #endif
19982 static const DWORD ps_code[] =
19984 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
19985 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19986 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
19987 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19988 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19989 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
19990 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
19991 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
19993 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
19994 struct d3d11_test_context test_context;
19995 ID3D11InputLayout *input_layout;
19996 ID3D11DeviceContext *context;
19997 unsigned int stride, offset;
19998 struct resource_readback rb;
19999 ID3D11GeometryShader *gs;
20000 ID3D11VertexShader *vs;
20001 ID3D11PixelShader *ps;
20002 ID3D11Device *device;
20003 ID3D11Buffer *vb;
20004 DWORD color;
20005 HRESULT hr;
20007 if (!init_test_context(&test_context, NULL))
20008 return;
20010 device = test_context.device;
20011 context = test_context.immediate_context;
20013 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
20014 vs_code, sizeof(vs_code), &input_layout);
20015 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
20017 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
20019 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
20020 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
20021 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
20022 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
20023 else
20024 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
20025 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
20026 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20027 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20029 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
20030 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
20031 stride = sizeof(*vertex);
20032 offset = 0;
20033 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
20034 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
20035 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
20036 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20038 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
20039 ID3D11DeviceContext_Draw(context, 1, 0);
20041 get_texture_readback(test_context.backbuffer, 0, &rb);
20042 color = get_readback_color(&rb, 320, 190);
20043 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
20044 color = get_readback_color(&rb, 255, 240);
20045 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
20046 color = get_readback_color(&rb, 320, 240);
20047 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
20048 color = get_readback_color(&rb, 385, 240);
20049 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
20050 color = get_readback_color(&rb, 320, 290);
20051 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
20052 release_resource_readback(&rb);
20054 ID3D11PixelShader_Release(ps);
20055 ID3D11GeometryShader_Release(gs);
20056 ID3D11VertexShader_Release(vs);
20057 ID3D11Buffer_Release(vb);
20058 ID3D11InputLayout_Release(input_layout);
20059 release_test_context(&test_context);
20062 struct triangle
20064 struct vec4 v[3];
20067 #define check_triangles(buffer, triangles, count) check_triangles_(__LINE__, buffer, triangles, count)
20068 static void check_triangles_(unsigned int line, ID3D11Buffer *buffer,
20069 const struct triangle *triangles, unsigned int triangle_count)
20071 const struct triangle *current, *expected;
20072 struct resource_readback rb;
20073 unsigned int i, j, offset;
20074 BOOL all_match = TRUE;
20076 get_buffer_readback(buffer, &rb);
20078 for (i = 0; i < triangle_count; ++i)
20080 current = get_readback_data(&rb, i, 0, sizeof(*current));
20081 expected = &triangles[i];
20083 offset = ~0u;
20084 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
20086 if (compare_vec4(&current->v[0], &expected->v[j], 0))
20088 offset = j;
20089 break;
20093 if (offset == ~0u)
20095 all_match = FALSE;
20096 break;
20099 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
20101 if (!compare_vec4(&current->v[j], &expected->v[(j + offset) % 3], 0))
20103 all_match = FALSE;
20104 break;
20107 if (!all_match)
20108 break;
20111 ok_(__FILE__, line)(all_match, "Triangle %u vertices {%.8e, %.8e, %.8e, %.8e}, "
20112 "{%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e} "
20113 "do not match {%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e}, "
20114 "{%.8e, %.8e, %.8e, %.8e}.\n", i,
20115 current->v[0].x, current->v[0].y, current->v[0].z, current->v[0].w,
20116 current->v[1].x, current->v[1].y, current->v[1].z, current->v[1].w,
20117 current->v[2].x, current->v[2].y, current->v[2].z, current->v[2].w,
20118 expected->v[0].x, expected->v[0].y, expected->v[0].z, expected->v[0].w,
20119 expected->v[1].x, expected->v[1].y, expected->v[1].z, expected->v[1].w,
20120 expected->v[2].x, expected->v[2].y, expected->v[2].z, expected->v[2].w);
20122 release_resource_readback(&rb);
20125 static void test_quad_tessellation(void)
20127 #if 0
20128 struct point_data
20130 float4 position : SV_POSITION;
20133 struct patch_constant_data
20135 float edges[4] : SV_TessFactor;
20136 float inside[2] : SV_InsideTessFactor;
20139 float4 tess_factors;
20140 float2 inside_tess_factors;
20142 patch_constant_data patch_constant(InputPatch<point_data, 4> input)
20144 patch_constant_data output;
20146 output.edges[0] = tess_factors.x;
20147 output.edges[1] = tess_factors.y;
20148 output.edges[2] = tess_factors.z;
20149 output.edges[3] = tess_factors.w;
20150 output.inside[0] = inside_tess_factors.x;
20151 output.inside[1] = inside_tess_factors.y;
20153 return output;
20156 [domain("quad")]
20157 [outputcontrolpoints(4)]
20158 [outputtopology("triangle_ccw")]
20159 [partitioning("integer")]
20160 [patchconstantfunc("patch_constant")]
20161 point_data hs_main(InputPatch<point_data, 4> input,
20162 uint i : SV_OutputControlPointID)
20164 return input[i];
20167 [domain("quad")]
20168 point_data ds_main(patch_constant_data input,
20169 float2 tess_coord : SV_DomainLocation,
20170 const OutputPatch<point_data, 4> patch)
20172 point_data output;
20174 float4 a = lerp(patch[0].position, patch[1].position, tess_coord.x);
20175 float4 b = lerp(patch[2].position, patch[3].position, tess_coord.x);
20176 output.position = lerp(a, b, tess_coord.y);
20178 return output;
20180 #endif
20181 static const DWORD hs_quad_ccw_code[] =
20183 0x43425844, 0xdf8df700, 0x58b08fb1, 0xbd23d2c3, 0xcf884094, 0x00000001, 0x000002b8, 0x00000004,
20184 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
20185 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
20186 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20187 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
20188 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
20189 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
20190 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
20191 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
20192 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
20193 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
20194 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
20195 0x01002097, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
20196 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
20197 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
20198 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20199 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
20200 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
20201 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20202 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
20203 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
20204 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
20206 static const DWORD ds_quad_code[] =
20208 0x43425844, 0xeb6b7631, 0x07f5469e, 0xed0cbf4a, 0x7158b3a6, 0x00000001, 0x00000284, 0x00000004,
20209 0x00000030, 0x00000064, 0x00000128, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
20210 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
20211 0x004e4f49, 0x47534350, 0x000000bc, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b,
20212 0x00000003, 0x00000000, 0x00000001, 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001,
20213 0x00000001, 0x00000098, 0x00000002, 0x0000000b, 0x00000003, 0x00000002, 0x00000001, 0x00000098,
20214 0x00000003, 0x0000000b, 0x00000003, 0x00000003, 0x00000001, 0x000000a6, 0x00000000, 0x0000000c,
20215 0x00000003, 0x00000004, 0x00000001, 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005,
20216 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365,
20217 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
20218 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853,
20219 0x00000120, 0x00040050, 0x00000048, 0x01002093, 0x01001895, 0x0100086a, 0x0200005f, 0x0001c032,
20220 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20221 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, 0x80219e46, 0x00000041, 0x00000002,
20222 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, 0x001000f2, 0x00000000, 0x0001c006,
20223 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, 0x0a000000, 0x001000f2, 0x00000001,
20224 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, 0x00000001, 0x00000000, 0x09000032,
20225 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, 0x00219e46, 0x00000000, 0x00000000,
20226 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x80100e46, 0x00000041, 0x00000001,
20227 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
20228 0x0100003e,
20230 #if 0
20232 [outputtopology("triangle_cw")]
20234 #endif
20235 static const DWORD hs_quad_cw_code[] =
20237 0x43425844, 0x1ab30cc8, 0x94174771, 0x61f4cdd0, 0xa287f62c, 0x00000001, 0x000002b8, 0x00000004,
20238 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
20239 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
20240 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20241 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
20242 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
20243 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
20244 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
20245 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
20246 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
20247 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
20248 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
20249 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
20250 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
20251 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
20252 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20253 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
20254 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
20255 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20256 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
20257 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
20258 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
20260 #if 0
20261 struct point_data
20263 float4 pos : SV_POSITION;
20266 [maxvertexcount(3)]
20267 void main(triangle point_data vin[3], inout TriangleStream<point_data> vout)
20269 for (uint i = 0; i < 3; ++i)
20270 vout.Append(vin[i]);
20272 #endif
20273 static const DWORD gs_code[] =
20275 0x43425844, 0x8e49d18d, 0x6d08d6e5, 0xb7015628, 0xf9351fdd, 0x00000001, 0x00000164, 0x00000003,
20276 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
20277 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
20278 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
20279 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000000c8, 0x00020040,
20280 0x00000032, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068, 0x00000001,
20281 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000003,
20282 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
20283 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010001a, 0x00000000,
20284 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x01000013,
20285 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016,
20286 0x0100003e,
20288 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
20290 {0, "SV_POSITION", 0, 0, 4, 0},
20292 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20293 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
20294 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
20295 static const BYTE zero_data[1024];
20296 static const struct triangle expected_quad_ccw[] =
20298 {{{-1.0f, -1.0f, 0.0f, 1.0f},
20299 { 1.0f, -1.0f, 0.0f, 1.0f},
20300 {-1.0f, 1.0f, 0.0f, 1.0f}}},
20301 {{{-1.0f, 1.0f, 0.0f, 1.0f},
20302 { 1.0f, -1.0f, 0.0f, 1.0f},
20303 { 1.0f, 1.0f, 0.0f, 1.0f}}},
20304 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
20305 { 0.0f, 0.0f, 0.0f, 0.0f},
20306 { 0.0f, 0.0f, 0.0f, 0.0f}}},
20308 static const struct triangle expected_quad_cw[] =
20310 {{{-1.0f, -1.0f, 0.0f, 1.0f},
20311 {-1.0f, 1.0f, 0.0f, 1.0f},
20312 { 1.0f, -1.0f, 0.0f, 1.0f}}},
20313 {{{-1.0f, 1.0f, 0.0f, 1.0f},
20314 { 1.0f, 1.0f, 0.0f, 1.0f},
20315 { 1.0f, -1.0f, 0.0f, 1.0f}}},
20316 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
20317 { 0.0f, 0.0f, 0.0f, 0.0f},
20318 { 0.0f, 0.0f, 0.0f, 0.0f}}},
20320 struct
20322 float tess_factors[4];
20323 float inside_tess_factors[2];
20324 DWORD padding[2];
20325 } constant;
20327 D3D11_QUERY_DATA_SO_STATISTICS so_statistics;
20328 struct d3d11_test_context test_context;
20329 ID3D11DeviceContext *context;
20330 ID3D11Buffer *cb, *so_buffer;
20331 D3D11_QUERY_DESC query_desc;
20332 ID3D11Asynchronous *query;
20333 ID3D11GeometryShader *gs;
20334 ID3D11DomainShader *ds;
20335 const UINT offset = 0;
20336 ID3D11HullShader *hs;
20337 ID3D11Device *device;
20338 unsigned int i;
20339 HRESULT hr;
20341 if (!init_test_context(&test_context, &feature_level))
20342 return;
20344 device = test_context.device;
20345 context = test_context.immediate_context;
20347 draw_color_quad(&test_context, &white);
20348 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20350 set_quad_color(&test_context, &green);
20351 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
20353 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
20354 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
20355 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0, NULL, &gs);
20356 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
20357 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
20359 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
20360 constant.tess_factors[i] = 1.0f;
20361 for (i = 0; i < ARRAY_SIZE(constant.inside_tess_factors); ++i)
20362 constant.inside_tess_factors[i] = 1.0f;
20363 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
20364 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb);
20365 hr = ID3D11Device_CreateHullShader(device, hs_quad_ccw_code, sizeof(hs_quad_ccw_code), NULL, &hs);
20366 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
20367 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
20368 hr = ID3D11Device_CreateDomainShader(device, ds_quad_code, sizeof(ds_quad_code), NULL, &ds);
20369 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
20370 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
20372 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20373 ID3D11DeviceContext_Draw(context, 4, 0);
20374 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20375 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
20376 check_triangles(so_buffer, expected_quad_ccw, ARRAY_SIZE(expected_quad_ccw));
20378 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
20380 ID3D11HullShader_Release(hs);
20381 hr = ID3D11Device_CreateHullShader(device, hs_quad_cw_code, sizeof(hs_quad_cw_code), NULL, &hs);
20382 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
20383 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
20385 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20386 ID3D11DeviceContext_Draw(context, 4, 0);
20387 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20388 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
20389 check_triangles(so_buffer, expected_quad_cw, ARRAY_SIZE(expected_quad_cw));
20391 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
20393 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20394 query_desc.Query = D3D11_QUERY_SO_STATISTICS_STREAM0;
20395 query_desc.MiscFlags = 0;
20396 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
20397 ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
20398 ID3D11DeviceContext_Begin(context, query);
20400 set_quad_color(&test_context, &white);
20401 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
20402 constant.tess_factors[i] = 2.0f;
20403 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20404 ID3D11DeviceContext_Draw(context, 4, 0);
20405 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20407 set_quad_color(&test_context, &green);
20408 constant.tess_factors[0] = 0.0f; /* A patch is discarded. */
20409 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20410 ID3D11DeviceContext_Draw(context, 4, 0);
20411 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20413 ID3D11DeviceContext_End(context, query);
20414 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
20415 ok(so_statistics.NumPrimitivesWritten == 8, "Got unexpected primitives written %u.\n",
20416 (unsigned int)so_statistics.NumPrimitivesWritten);
20417 ok(so_statistics.PrimitivesStorageNeeded == 8, "Got unexpected primitives storage needed %u.\n",
20418 (unsigned int)so_statistics.PrimitivesStorageNeeded);
20419 ID3D11DeviceContext_Begin(context, query);
20421 constant.tess_factors[0] = 5.0f;
20422 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20423 ID3D11DeviceContext_Draw(context, 4, 0);
20424 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20426 ID3D11DeviceContext_End(context, query);
20427 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
20428 ok(so_statistics.NumPrimitivesWritten == 11, "Got unexpected primitives written %u.\n",
20429 (unsigned int)so_statistics.NumPrimitivesWritten);
20430 ok(so_statistics.PrimitivesStorageNeeded == 11, "Got unexpected primitives storage needed %u.\n",
20431 (unsigned int)so_statistics.PrimitivesStorageNeeded);
20432 ID3D11Asynchronous_Release(query);
20434 ID3D11Buffer_Release(so_buffer);
20435 ID3D11GeometryShader_Release(gs);
20436 ID3D11DomainShader_Release(ds);
20437 ID3D11HullShader_Release(hs);
20438 ID3D11Buffer_Release(cb);
20439 release_test_context(&test_context);
20442 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
20443 static void check_so_desc_(unsigned int line, ID3D11Device *device,
20444 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
20445 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
20446 unsigned int rasterizer_stream)
20448 ID3D11GeometryShader *gs;
20449 HRESULT hr;
20451 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
20452 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
20453 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
20454 if (SUCCEEDED(hr))
20455 ID3D11GeometryShader_Release(gs);
20458 #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)
20459 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
20460 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
20461 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
20462 unsigned int rasterizer_stream)
20464 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
20465 HRESULT hr;
20467 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
20468 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
20469 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
20470 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
20471 if (SUCCEEDED(hr))
20472 ID3D11GeometryShader_Release(gs);
20475 static void test_stream_output(void)
20477 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
20478 struct d3d11_test_context test_context;
20479 unsigned int i, count;
20480 ID3D11Device *device;
20482 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20483 static const DWORD vs_code[] =
20485 #if 0
20486 struct data
20488 float4 position : SV_Position;
20489 float4 attrib1 : ATTRIB1;
20490 float3 attrib2 : attrib2;
20491 float2 attrib3 : ATTriB3;
20492 float attrib4 : ATTRIB4;
20495 void main(in data i, out data o)
20497 o = i;
20499 #endif
20500 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
20501 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20502 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20503 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20504 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20505 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
20506 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20507 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20508 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20509 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20510 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20511 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20512 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
20513 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
20514 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20515 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20516 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
20517 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
20518 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
20519 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
20521 static const DWORD gs_code[] =
20523 #if 0
20524 struct data
20526 float4 position : SV_Position;
20527 float4 attrib1 : ATTRIB1;
20528 float3 attrib2 : attrib2;
20529 float2 attrib3 : ATTriB3;
20530 float attrib4 : ATTRIB4;
20533 [maxvertexcount(1)]
20534 void main(point data i[1], inout PointStream<data> o)
20536 o.Append(i[0]);
20538 #endif
20539 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
20540 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20541 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20542 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20543 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20544 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
20545 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20546 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20547 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20548 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20549 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20550 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20551 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
20552 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
20553 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
20554 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20555 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20556 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
20557 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
20558 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
20559 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
20561 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
20563 {0, "SV_Position", 0, 0, 4, 0},
20565 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
20567 {0, "SV_Position", 0, 0, 4, 0},
20568 {0, NULL, 0, 0, 0, 0},
20570 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
20572 /* SemanticName and SemanticIndex */
20574 {0, "sv_position", 0, 0, 4, 0},
20575 {0, "attrib", 1, 0, 4, 0},
20578 {0, "sv_position", 0, 0, 4, 0},
20579 {0, "ATTRIB", 1, 0, 4, 0},
20581 /* Gaps */
20583 {0, "SV_POSITION", 0, 0, 4, 0},
20584 {0, NULL, 0, 0, 8, 0},
20585 {0, "ATTRIB", 1, 0, 4, 0},
20588 {0, "SV_POSITION", 0, 0, 4, 0},
20589 {0, NULL, 0, 0, 4, 0},
20590 {0, NULL, 0, 0, 4, 0},
20591 {0, "ATTRIB", 1, 0, 4, 0},
20593 /* ComponentCount */
20595 {0, "ATTRIB", 1, 0, 4, 0},
20598 {0, "ATTRIB", 2, 0, 3, 0},
20601 {0, "ATTRIB", 3, 0, 2, 0},
20604 {0, "ATTRIB", 4, 0, 1, 0},
20606 /* ComponentIndex */
20608 {0, "ATTRIB", 1, 1, 3, 0},
20611 {0, "ATTRIB", 1, 2, 2, 0},
20614 {0, "ATTRIB", 1, 3, 1, 0},
20617 {0, "ATTRIB", 3, 1, 1, 0},
20619 /* OutputSlot */
20621 {0, "attrib", 1, 0, 4, 0},
20624 {0, "attrib", 1, 0, 4, 1},
20627 {0, "attrib", 1, 0, 4, 2},
20630 {0, "attrib", 1, 0, 4, 3},
20633 {0, "attrib", 1, 0, 4, 0},
20634 {0, "attrib", 2, 0, 3, 1},
20635 {0, NULL, 0, 0, 1, 1},
20636 {0, "attrib", 3, 0, 2, 2},
20637 {0, NULL, 0, 0, 2, 2},
20638 {0, "attrib", 4, 0, 1, 3},
20639 {0, NULL, 0, 0, 7, 3},
20642 {0, "attrib", 1, 0, 4, 0},
20643 {0, "attrib", 2, 0, 3, 1},
20644 {0, NULL, 0, 0, 1, 1},
20645 {0, "attrib", 3, 0, 2, 2},
20646 {0, NULL, 0, 0, 1, 2},
20647 {0, NULL, 0, 0, 1, 2},
20648 {0, "attrib", 4, 0, 1, 3},
20649 {0, NULL, 0, 0, 3, 3},
20650 {0, NULL, 0, 0, 1, 3},
20651 {0, NULL, 0, 0, 1, 3},
20652 {0, NULL, 0, 0, 1, 3},
20653 {0, NULL, 0, 0, 1, 3},
20656 {0, "attrib", 1, 0, 4, 0},
20657 {0, "attrib", 2, 0, 3, 0},
20658 {0, "attrib", 3, 0, 2, 0},
20659 {0, NULL, 0, 0, 1, 0},
20660 {0, "attrib", 4, 0, 1, 0},
20663 {0, "attrib", 1, 0, 4, 0},
20664 {0, "attrib", 2, 0, 3, 0},
20665 {0, "attrib", 3, 0, 2, 3},
20666 {0, NULL, 0, 0, 1, 3},
20667 {0, "attrib", 4, 0, 1, 3},
20669 /* Multiple occurrences of the same output */
20671 {0, "ATTRIB", 1, 0, 2, 0},
20672 {0, "ATTRIB", 1, 2, 2, 1},
20675 {0, "ATTRIB", 1, 0, 1, 0},
20676 {0, "ATTRIB", 1, 1, 3, 0},
20679 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
20681 /* SemanticName and SemanticIndex */
20683 {0, "SV_Position", 0, 0, 4, 0},
20684 {0, "ATTRIB", 0, 0, 4, 0},
20687 {0, "sv_position", 0, 0, 4, 0},
20688 {0, "ATTRIB_", 1, 0, 4, 0},
20690 /* Gaps */
20692 {0, "SV_POSITION", 0, 0, 4, 0},
20693 {0, NULL, 0, 1, 8, 0},
20694 {0, "ATTRIB", 1, 0, 4, 0},
20697 {0, "SV_POSITION", 0, 0, 4, 0},
20698 {0, NULL, 1, 0, 8, 0},
20699 {0, "ATTRIB", 1, 0, 4, 0},
20701 /* Buffer stride */
20703 {0, "SV_POSITION", 0, 0, 4, 0},
20704 {0, NULL, 0, 0, 8, 0},
20705 {0, NULL, 0, 0, 8, 0},
20706 {0, "ATTRIB", 1, 0, 4, 0},
20708 /* ComponentCount */
20710 {0, "ATTRIB", 2, 0, 5, 0},
20713 {0, "ATTRIB", 2, 0, 4, 0},
20716 {0, "ATTRIB", 3, 0, 3, 0},
20719 {0, "ATTRIB", 4, 0, 2, 0},
20721 /* ComponentIndex */
20723 {0, "ATTRIB", 1, 1, 4, 0},
20726 {0, "ATTRIB", 1, 2, 3, 0},
20729 {0, "ATTRIB", 1, 3, 2, 0},
20732 {0, "ATTRIB", 1, 4, 0, 0},
20735 {0, "ATTRIB", 1, 4, 1, 0},
20738 {0, "ATTRIB", 3, 2, 1, 0},
20741 {0, "ATTRIB", 3, 2, 0, 0},
20743 /* OutputSlot */
20745 {0, "attrib", 1, 0, 4, 4},
20748 {0, "attrib", 1, 0, 4, 4},
20751 {0, "attrib", 1, 0, 4, 4},
20754 {0, "attrib", 1, 0, 4, 4},
20757 {0, "attrib", 1, 0, 4, 0},
20758 {0, "attrib", 2, 0, 3, 1},
20759 {0, NULL, 0, 0, 1, 1},
20760 {0, "attrib", 3, 0, 2, 2},
20761 {0, NULL, 0, 0, 2, 2},
20762 {0, "attrib", 4, 0, 1, 3},
20763 {0, NULL, 0, 0, 3, 4},
20766 {0, "attrib", 1, 0, 4, 0},
20767 {0, "attrib", 2, 0, 3, 0},
20768 {0, "attrib", 3, 0, 2, 0},
20769 {0, NULL, 0, 0, 1, 0},
20770 {0, "attrib", 4, 0, 1, 0},
20771 {0, NULL, 0, 0, 3, 3},
20772 {0, NULL, 0, 0, 1, 3},
20773 {0, NULL, 0, 0, 1, 3},
20774 {0, NULL, 0, 0, 1, 3},
20775 {0, NULL, 0, 0, 1, 3},
20778 {0, "attrib", 1, 0, 4, 0},
20779 {0, NULL, 0, 0, 3, 1},
20780 {0, NULL, 0, 0, 1, 1},
20781 {0, NULL, 0, 0, 1, 2},
20782 {0, "attrib", 2, 0, 3, 3},
20783 {0, NULL, 0, 0, 1, 3},
20786 {0, "attrib", 2, 0, 3, 3},
20787 {0, NULL, 0, 0, 3, 1},
20788 {0, NULL, 0, 0, 1, 3},
20789 {0, "attrib", 1, 0, 4, 0},
20790 {0, NULL, 0, 0, 1, 2},
20791 {0, NULL, 0, 0, 1, 1},
20793 /* Stream */
20795 {1, "attrib", 1, 0, 4, 0},
20798 {4, "attrib", 1, 0, 4, 0},
20800 /* Multiple occurrences of the same output */
20802 {0, "ATTRIB", 1, 0, 4, 0},
20803 {0, "ATTRIB", 1, 0, 4, 1},
20806 {0, "ATTRIB", 1, 0, 4, 0},
20807 {0, "ATTRIB", 1, 0, 3, 0},
20811 if (!init_test_context(&test_context, &feature_level))
20812 return;
20814 device = test_context.device;
20816 for (i = 0; i < ARRAY_SIZE(stride); ++i)
20817 stride[i] = 64;
20819 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20820 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20821 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20822 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20823 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20824 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20826 todo_wine
20827 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
20828 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20829 todo_wine
20830 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
20831 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20833 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
20834 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20835 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
20836 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
20837 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20839 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
20840 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20841 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
20842 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20844 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
20846 unsigned int max_output_slot = 0;
20847 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
20849 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
20850 max_output_slot = max(max_output_slot, e->OutputSlot);
20851 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
20852 break;
20855 /* Buffer strides are required for all buffers. */
20856 if (!max_output_slot)
20858 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20859 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20860 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20861 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20862 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20863 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20864 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20865 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
20866 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20867 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
20869 else
20871 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20872 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20873 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20874 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
20878 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
20880 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
20882 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
20883 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
20884 break;
20887 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20888 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20889 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20890 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20891 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20892 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
20893 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20894 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
20897 /* Buffer strides */
20898 stride[1] = 63;
20899 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20900 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
20901 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20902 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20903 stride[1] = 1;
20904 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20905 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20906 stride[0] = 0;
20907 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20908 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20910 /* Rasterizer stream */
20911 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
20912 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
20913 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20914 NULL, 0, D3D11_SO_STREAM_COUNT);
20916 release_test_context(&test_context);
20919 static void test_fl10_stream_output_desc(void)
20921 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
20922 struct d3d11_test_context test_context;
20923 unsigned int i, count;
20924 ID3D11Device *device;
20926 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
20927 static const DWORD vs_code[] =
20929 #if 0
20930 struct data
20932 float4 position : SV_Position;
20933 float4 attrib1 : ATTRIB1;
20934 float3 attrib2 : attrib2;
20935 float2 attrib3 : ATTriB3;
20936 float attrib4 : ATTRIB4;
20939 void main(in data i, out data o)
20941 o = i;
20943 #endif
20944 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
20945 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20946 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20947 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20948 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20949 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
20950 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20951 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20952 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20953 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20954 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20955 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20956 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
20957 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
20958 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20959 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20960 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
20961 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
20962 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
20963 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
20965 static const DWORD gs_code[] =
20967 #if 0
20968 struct data
20970 float4 position : SV_Position;
20971 float4 attrib1 : ATTRIB1;
20972 float3 attrib2 : attrib2;
20973 float2 attrib3 : ATTriB3;
20974 float attrib4 : ATTRIB4;
20977 [maxvertexcount(1)]
20978 void main(point data i[1], inout PointStream<data> o)
20980 o.Append(i[0]);
20982 #endif
20983 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
20984 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20985 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20986 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20987 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20988 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
20989 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20990 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20991 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20992 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20993 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20994 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20995 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
20996 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
20997 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
20998 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20999 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
21000 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
21001 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
21002 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
21003 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
21005 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
21007 {0, "SV_Position", 0, 0, 4, 0},
21009 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
21011 {0, "SV_Position", 0, 0, 4, 0},
21012 {0, NULL, 0, 0, 0, 0},
21014 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
21016 /* Gaps */
21018 {0, "SV_POSITION", 0, 0, 4, 0},
21019 {0, NULL, 0, 0, 8, 0},
21020 {0, "ATTRIB", 1, 0, 4, 0},
21023 {0, "SV_POSITION", 0, 0, 4, 0},
21024 {0, NULL, 0, 0, 4, 0},
21025 {0, NULL, 0, 0, 4, 0},
21026 {0, "ATTRIB", 1, 0, 4, 0},
21028 /* OutputSlot */
21030 {0, "attrib", 1, 0, 4, 0},
21031 {0, "attrib", 2, 0, 3, 0},
21032 {0, "attrib", 3, 0, 2, 0},
21033 {0, "attrib", 4, 0, 1, 0},
21036 {0, "attrib", 1, 0, 4, 0},
21037 {0, "attrib", 2, 0, 3, 1},
21038 {0, "attrib", 3, 0, 2, 2},
21039 {0, "attrib", 4, 0, 1, 3},
21042 {0, "attrib", 1, 0, 4, 0},
21043 {0, "attrib", 2, 0, 3, 3},
21046 {0, "attrib", 1, 0, 4, 0},
21047 {0, "attrib", 2, 0, 3, 0},
21048 {0, "attrib", 3, 0, 2, 0},
21049 {0, NULL, 0, 0, 1, 0},
21050 {0, "attrib", 4, 0, 1, 0},
21052 /* Multiple occurrences of the same output */
21054 {0, "ATTRIB", 1, 0, 2, 0},
21055 {0, "ATTRIB", 1, 2, 2, 1},
21058 {0, "ATTRIB", 1, 0, 1, 0},
21059 {0, "ATTRIB", 1, 1, 3, 0},
21062 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
21064 /* OutputSlot */
21066 {0, "attrib", 1, 0, 4, 0},
21067 {0, NULL, 0, 0, 4, 0},
21068 {0, "attrib", 4, 0, 1, 3},
21071 {0, "attrib", 1, 0, 4, 0},
21072 {0, NULL, 0, 0, 4, 0},
21073 {0, NULL, 0, 0, 4, 0},
21074 {0, "attrib", 4, 0, 1, 3},
21077 {0, "attrib", 1, 0, 4, 0},
21078 {0, "attrib", 2, 0, 3, 0},
21079 {0, "attrib", 3, 0, 2, 0},
21080 {0, "attrib", 4, 0, 1, 1},
21083 {0, "attrib", 1, 0, 4, 0},
21084 {0, "attrib", 2, 0, 3, 0},
21085 {0, "attrib", 3, 0, 2, 3},
21086 {0, NULL, 0, 0, 1, 3},
21087 {0, "attrib", 4, 0, 1, 3},
21090 {0, "attrib", 1, 0, 4, 0},
21091 {0, "attrib", 1, 0, 3, 1},
21092 {0, "attrib", 1, 0, 2, 2},
21093 {0, "attrib", 1, 0, 1, 3},
21094 {0, NULL, 0, 0, 3, 3},
21098 if (!init_test_context(&test_context, &feature_level))
21099 return;
21101 device = test_context.device;
21103 for (i = 0; i < ARRAY_SIZE(stride); ++i)
21104 stride[i] = 64;
21106 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
21107 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
21108 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
21109 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
21111 todo_wine
21112 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
21113 todo_wine
21114 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
21116 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
21117 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
21118 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
21119 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
21120 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
21122 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
21123 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
21125 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
21127 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
21129 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
21130 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
21131 break;
21134 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
21137 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
21139 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
21141 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
21142 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
21143 break;
21146 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
21147 stride, 1, 0);
21148 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
21149 stride, 2, 0);
21150 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
21151 stride, 3, 0);
21152 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
21153 stride, 4, 0);
21156 /* Buffer strides */
21157 stride[1] = 63;
21158 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21159 &stride[1], 1, 0);
21160 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21161 stride, 2, 0);
21162 stride[0] = 0;
21163 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21164 stride, 1, 0);
21166 /* Rasterizer stream */
21167 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21168 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
21169 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
21170 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21171 NULL, 0, i);
21172 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
21174 release_test_context(&test_context);
21177 static void test_stream_output_resume(void)
21179 struct d3d11_test_context test_context;
21180 ID3D11Buffer *cb, *so_buffer, *buffer;
21181 unsigned int i, j, idx, offset;
21182 ID3D11DeviceContext *context;
21183 struct resource_readback rb;
21184 ID3D11GeometryShader *gs;
21185 const struct vec4 *data;
21186 ID3D11Device *device;
21187 HRESULT hr;
21189 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21190 static const DWORD gs_code[] =
21192 #if 0
21193 float4 constant;
21195 struct vertex
21197 float4 position : SV_POSITION;
21200 struct element
21202 float4 position : SV_POSITION;
21203 float4 so_output : so_output;
21206 [maxvertexcount(3)]
21207 void main(triangle vertex input[3], inout PointStream<element> output)
21209 element o;
21210 o.so_output = constant;
21211 o.position = input[0].position;
21212 output.Append(o);
21213 o.position = input[1].position;
21214 output.Append(o);
21215 o.position = input[2].position;
21216 output.Append(o);
21218 #endif
21219 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
21220 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21221 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
21222 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
21223 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
21224 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
21225 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
21226 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
21227 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
21228 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
21229 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
21230 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
21231 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
21232 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
21234 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
21236 {0, "so_output", 0, 0, 4, 0},
21238 static const struct vec4 constants[] =
21240 {0.5f, 0.250f, 0.0f, 0.0f},
21241 {0.0f, 0.125f, 0.0f, 1.0f},
21242 {1.0f, 1.000f, 1.0f, 0.0f}
21244 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
21245 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
21246 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
21248 if (!init_test_context(&test_context, &feature_level))
21249 return;
21251 device = test_context.device;
21252 context = test_context.immediate_context;
21254 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
21255 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
21256 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
21258 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
21259 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
21261 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21262 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
21264 offset = 0;
21265 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
21267 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
21268 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
21270 draw_color_quad(&test_context, &red);
21271 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
21273 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21274 draw_color_quad(&test_context, &green);
21275 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
21277 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
21278 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21279 draw_color_quad(&test_context, &red);
21280 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
21282 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21283 draw_color_quad(&test_context, &red);
21284 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
21286 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
21287 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21288 draw_color_quad(&test_context, &white);
21289 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
21291 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21292 draw_color_quad(&test_context, &green);
21293 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
21295 buffer = NULL;
21296 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
21297 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21298 draw_color_quad(&test_context, &white);
21299 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
21301 idx = 0;
21302 get_buffer_readback(so_buffer, &rb);
21303 for (i = 0; i < ARRAY_SIZE(constants); ++i)
21305 for (j = 0; j < 6; ++j) /* 2 triangles */
21307 data = get_readback_vec4(&rb, idx++, 0);
21308 ok(compare_vec4(data, &constants[i], 0),
21309 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
21310 data->x, data->y, data->z, data->w, idx, i, j);
21313 release_resource_readback(&rb);
21315 ID3D11Buffer_Release(cb);
21316 ID3D11Buffer_Release(so_buffer);
21317 ID3D11GeometryShader_Release(gs);
21318 release_test_context(&test_context);
21321 static void test_stream_output_components(void)
21323 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
21324 struct d3d11_test_context test_context;
21325 ID3D11InputLayout *input_layout[2];
21326 ID3D11Buffer *vb[2], *so_buffer;
21327 ID3D11DeviceContext *context;
21328 struct resource_readback rb;
21329 unsigned int stride, offset;
21330 ID3D11GeometryShader *gs;
21331 ID3D11VertexShader *vs;
21332 ID3D11PixelShader *ps;
21333 ID3D11Device *device;
21334 const float *result;
21335 unsigned int i, j;
21336 HRESULT hr;
21338 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21339 static const DWORD vs_code[] =
21341 #if 0
21342 struct vertex
21344 float4 position : POSITION;
21345 float4 color : COLOR;
21346 float4 color2 : COLOR2;
21349 void main(in vertex i, out vertex o)
21351 o = i;
21353 #endif
21354 0x43425844, 0x95991b76, 0x4898640b, 0xe36ad9d6, 0xfbfe78b4, 0x00000001, 0x00000194, 0x00000003,
21355 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
21356 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
21357 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
21358 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
21359 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
21360 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
21361 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
21362 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
21363 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
21364 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
21365 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
21366 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
21368 static const DWORD gs_code[] =
21370 #if 0
21371 struct vertex
21373 float4 position : POSITION;
21374 float4 color : COLOR;
21375 float4 color2 : COLOR2;
21378 [maxvertexcount(1)]
21379 void main(point vertex input[1], inout PointStream<vertex> output)
21381 output.Append(input[0]);
21383 #endif
21384 0x43425844, 0x218f7d27, 0x555fa7f1, 0x282c545f, 0x3989c843, 0x00000001, 0x000001c0, 0x00000003,
21385 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
21386 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
21387 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
21388 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
21389 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
21390 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
21391 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
21392 0x000000bc, 0x00020040, 0x0000002f, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x0400005f,
21393 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000002, 0x0100085d,
21394 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x03000065,
21395 0x001020f2, 0x00000002, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
21396 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001,
21397 0x06000036, 0x001020f2, 0x00000002, 0x00201e46, 0x00000000, 0x00000002, 0x01000013, 0x0100003e,
21399 static const DWORD ps_code[] =
21401 #if 0
21402 float4 main(float4 position : SV_Position,
21403 float2 texcoord : TEXCOORD) : SV_Target
21405 return float4(position.xy, texcoord);
21407 #endif
21408 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
21409 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
21410 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
21411 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
21412 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
21413 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
21414 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
21415 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
21416 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
21418 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
21420 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
21421 {"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
21422 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
21424 static const D3D11_INPUT_ELEMENT_DESC layout_desc2[] =
21426 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
21427 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
21428 {"COLOR", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
21430 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
21432 {0, "POSITION", 0, 0, 4, 0},
21433 {0, "COLOR", 0, 0, 3, 0},
21434 {0, "COLOR", 2, 0, 2, 0},
21436 static const D3D11_SO_DECLARATION_ENTRY so_declaration2[] =
21438 {0, "POSITION", 0, 0, 1, 0},
21439 {0, "POSITION", 0, 1, 1, 0},
21440 {0, "POSITION", 0, 2, 1, 0},
21441 {0, "POSITION", 0, 3, 1, 0},
21442 {0, "COLOR", 0, 0, 1, 0},
21443 {0, "COLOR", 0, 1, 1, 0},
21444 {0, "COLOR", 0, 2, 1, 0},
21445 {0, "COLOR", 2, 0, 1, 0},
21446 {0, "COLOR", 2, 1, 1, 0},
21448 static const D3D11_SO_DECLARATION_ENTRY so_declaration3[] =
21450 {0, "COLOR", 0, 2, 2, 0},
21451 {0, "COLOR", 2, 3, 1, 0},
21453 static const struct
21455 struct vec4 position;
21456 struct vec3 color;
21457 struct vec2 color2;
21459 vb_data[] =
21461 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.5f, 1.0f}},
21462 {{-1.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
21463 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f}, {0.5f, 0.4f}},
21464 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.1f, 0.6f}},
21466 static const struct
21468 struct vec4 position;
21469 struct vec4 color;
21470 struct vec4 color2;
21472 vb_data2[] =
21474 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
21475 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
21476 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
21477 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
21479 static const unsigned int vb_stride[] = {sizeof(*vb_data), sizeof(*vb_data2)};
21480 static const float expected_data[] =
21482 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f,
21483 -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
21484 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, 0.4f,
21485 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.1f, 0.6f,
21487 static const float expected_data2[] =
21489 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
21490 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
21491 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
21492 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
21494 static const float expected_data3[] =
21496 3.0f, 4.0f, 8.0f, 1.2f, 1.3f, 1.7f, 2.0f, 2.1f, 2.5f, 2.7f, 2.8f, 3.2f,
21498 static const struct
21500 BOOL with_ps;
21501 unsigned int vb_idx;
21502 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
21503 unsigned int so_entry_count;
21504 const float *expected_data;
21505 unsigned int expected_data_size;
21507 tests[] =
21509 {TRUE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
21510 {TRUE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
21511 {TRUE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
21512 {TRUE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
21513 {TRUE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
21515 {FALSE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
21516 {FALSE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
21517 {FALSE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
21518 {FALSE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
21519 {FALSE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
21522 if (!init_test_context(&test_context, &feature_level))
21523 return;
21525 device = test_context.device;
21526 context = test_context.immediate_context;
21528 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
21529 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data2), vb_data2);
21531 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
21532 vs_code, sizeof(vs_code), &input_layout[0]);
21533 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
21534 hr = ID3D11Device_CreateInputLayout(device, layout_desc2, ARRAY_SIZE(layout_desc2),
21535 vs_code, sizeof(vs_code), &input_layout[1]);
21536 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
21538 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
21539 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
21540 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
21541 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21543 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
21544 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
21546 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
21548 gs = NULL;
21549 current_so_declaration = NULL;
21550 for (i = 0; i < ARRAY_SIZE(tests); ++i)
21552 ID3D11DeviceContext_PSSetShader(context, tests[i].with_ps ? ps : NULL, NULL, 0);
21554 if (current_so_declaration != tests[i].so_declaration)
21556 if (gs)
21557 ID3D11GeometryShader_Release(gs);
21559 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
21560 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
21561 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
21562 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
21563 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21564 current_so_declaration = tests[i].so_declaration;
21567 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].vb_idx]);
21568 stride = vb_stride[tests[i].vb_idx];
21569 offset = 0;
21570 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[tests[i].vb_idx], &stride, &offset);
21572 offset = 0;
21573 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
21575 ID3D11DeviceContext_Draw(context, 4, 0);
21577 get_buffer_readback(so_buffer, &rb);
21578 result = rb.map_desc.pData;
21579 for (j = 0; j < tests[i].expected_data_size; ++j)
21581 float expected_value = tests[i].expected_data[j];
21582 ok(compare_float(result[j], expected_value, 2),
21583 "Test %u: Got %.8e, expected %.8e at %u.\n",
21584 i, result[j], expected_value, j);
21586 release_resource_readback(&rb);
21589 for (i = 0; i < ARRAY_SIZE(vb); ++i)
21590 ID3D11Buffer_Release(vb[i]);
21591 ID3D11Buffer_Release(so_buffer);
21592 ID3D11VertexShader_Release(vs);
21593 ID3D11GeometryShader_Release(gs);
21594 ID3D11PixelShader_Release(ps);
21595 for (i = 0; i < ARRAY_SIZE(input_layout); ++i)
21596 ID3D11InputLayout_Release(input_layout[i]);
21597 release_test_context(&test_context);
21600 static void test_gather(void)
21602 struct
21604 int width, height;
21605 int offset_x, offset_y;
21606 } constant;
21607 struct d3d11_test_context test_context;
21608 D3D11_TEXTURE2D_DESC texture_desc;
21609 ID3D11ShaderResourceView *srv;
21610 ID3D11Texture2D *texture, *rt;
21611 ID3D11DeviceContext *context;
21612 ID3D11RenderTargetView *rtv;
21613 struct resource_readback rb;
21614 ID3D11PixelShader *ps;
21615 ID3D11Device *device;
21616 unsigned int x, y;
21617 ID3D11Buffer *cb;
21618 HRESULT hr;
21620 static const DWORD gather4_code[] =
21622 #if 0
21623 SamplerState s;
21624 Texture2D<float4> t;
21626 int2 size;
21628 float4 main(float4 position : SV_Position) : SV_Target
21630 return t.Gather(s, position.xy / size);
21632 #endif
21633 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
21634 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21635 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21636 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21637 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
21638 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21639 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21640 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21641 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21642 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
21643 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
21645 static const DWORD gather4_offset_code[] =
21647 #if 0
21648 SamplerState s;
21649 Texture2D<float4> t;
21651 int2 size;
21653 float4 main(float4 position : SV_Position) : SV_Target
21655 return t.Gather(s, position.xy / size, int2(1, 1));
21657 #endif
21658 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
21659 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21660 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21661 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21662 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
21663 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21664 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21665 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21666 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21667 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
21668 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
21670 static const DWORD gather4_green_code[] =
21672 #if 0
21673 SamplerState s;
21674 Texture2D<float4> t;
21676 int2 size;
21678 float4 main(float4 position : SV_Position) : SV_Target
21680 return t.GatherGreen(s, position.xy / size);
21682 #endif
21683 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
21684 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21685 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21686 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21687 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
21688 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21689 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21690 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21691 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21692 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21693 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
21695 static const DWORD gather4_po_code[] =
21697 #if 0
21698 SamplerState s;
21699 Texture2D<float4> t;
21701 int2 size;
21702 int2 offset;
21704 float4 main(float4 position : SV_Position) : SV_Target
21706 return t.Gather(s, position.xy / size, offset);
21708 #endif
21709 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
21710 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21711 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21712 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21713 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
21714 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21715 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21716 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21717 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21718 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21719 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
21720 0x00000000, 0x0100003e,
21722 static const struct vec4 texture_data[] =
21724 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
21725 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
21726 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
21727 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
21729 static const struct vec4 expected_gather4[] =
21731 {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},
21732 {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},
21733 {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},
21734 {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},
21736 static const struct vec4 expected_gather4_offset[] =
21738 {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},
21739 {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},
21740 {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},
21741 {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},
21743 static const struct vec4 expected_gather4_green[] =
21745 {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},
21746 {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},
21747 {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},
21748 {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},
21750 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
21751 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
21753 if (!init_test_context(&test_context, NULL))
21754 return;
21756 device = test_context.device;
21757 context = test_context.immediate_context;
21759 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
21761 skip("Shader model 4.1 required for gather4 instruction.\n");
21762 release_test_context(&test_context);
21763 return;
21766 texture_desc.Width = 4;
21767 texture_desc.Height = 4;
21768 texture_desc.MipLevels = 1;
21769 texture_desc.ArraySize = 1;
21770 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
21771 texture_desc.SampleDesc.Count = 1;
21772 texture_desc.SampleDesc.Quality = 0;
21773 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21774 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21775 texture_desc.CPUAccessFlags = 0;
21776 texture_desc.MiscFlags = 0;
21777 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
21778 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21779 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
21780 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
21781 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
21783 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
21784 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
21785 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21786 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
21787 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
21788 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
21790 constant.width = texture_desc.Width;
21791 constant.height = texture_desc.Height;
21792 constant.offset_x = 1;
21793 constant.offset_y = 1;
21794 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
21795 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
21797 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
21798 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21799 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21801 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21802 draw_quad(&test_context);
21803 get_texture_readback(rt, 0, &rb);
21804 for (y = 0; y < texture_desc.Height; ++y)
21806 for (x = 0; x < texture_desc.Width; ++x)
21808 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
21809 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21810 ok(compare_vec4(got, expected, 0),
21811 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21812 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21815 release_resource_readback(&rb);
21817 ID3D11PixelShader_Release(ps);
21818 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
21819 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21820 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21822 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21823 draw_quad(&test_context);
21824 get_texture_readback(rt, 0, &rb);
21825 for (y = 0; y < texture_desc.Height; ++y)
21827 for (x = 0; x < texture_desc.Width; ++x)
21829 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
21830 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21831 ok(compare_vec4(got, expected, 0),
21832 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21833 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21836 release_resource_readback(&rb);
21838 ID3D11PixelShader_Release(ps);
21840 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
21842 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
21843 goto done;
21846 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
21847 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21848 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21850 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21851 draw_quad(&test_context);
21852 get_texture_readback(rt, 0, &rb);
21853 for (y = 0; y < texture_desc.Height; ++y)
21855 for (x = 0; x < texture_desc.Width; ++x)
21857 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
21858 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21859 ok(compare_vec4(got, expected, 0),
21860 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21861 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21864 release_resource_readback(&rb);
21866 ID3D11PixelShader_Release(ps);
21867 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
21868 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21869 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21871 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21872 draw_quad(&test_context);
21873 get_texture_readback(rt, 0, &rb);
21874 for (y = 0; y < texture_desc.Height; ++y)
21876 for (x = 0; x < texture_desc.Width; ++x)
21878 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
21879 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21880 ok(compare_vec4(got, expected, 0),
21881 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21882 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21885 release_resource_readback(&rb);
21887 constant.offset_x = 0;
21888 constant.offset_y = 0;
21889 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
21890 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21891 draw_quad(&test_context);
21892 get_texture_readback(rt, 0, &rb);
21893 for (y = 0; y < texture_desc.Height; ++y)
21895 for (x = 0; x < texture_desc.Width; ++x)
21897 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
21898 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21899 ok(compare_vec4(got, expected, 0),
21900 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21901 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21904 release_resource_readback(&rb);
21906 ID3D11PixelShader_Release(ps);
21908 done:
21909 ID3D11Buffer_Release(cb);
21910 ID3D11Texture2D_Release(rt);
21911 ID3D11Texture2D_Release(texture);
21912 ID3D11RenderTargetView_Release(rtv);
21913 ID3D11ShaderResourceView_Release(srv);
21914 release_test_context(&test_context);
21917 static void test_gather_c(void)
21919 struct
21921 int width, height;
21922 int offset_x, offset_y;
21923 float compare_value;
21924 int padding[3];
21925 } constant;
21926 struct d3d11_test_context test_context;
21927 D3D11_TEXTURE2D_DESC texture_desc;
21928 D3D11_SAMPLER_DESC sampler_desc;
21929 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
21930 ID3D11ShaderResourceView *srv;
21931 ID3D11Texture2D *texture, *rt;
21932 ID3D11DeviceContext *context;
21933 ID3D11SamplerState *sampler;
21934 ID3D11RenderTargetView *rtv;
21935 struct resource_readback rb;
21936 ID3D11PixelShader *ps;
21937 ID3D11Device *device;
21938 unsigned int x, y;
21939 ID3D11Buffer *cb;
21940 HRESULT hr;
21942 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21943 static const DWORD gather4_c_code[] =
21945 #if 0
21946 SamplerComparisonState s;
21947 Texture2D<float4> t;
21949 int2 size;
21950 int2 offset;
21951 float compare;
21953 float4 main(float4 position : SV_Position) : SV_Target
21955 return t.GatherCmp(s, position.xy / size, compare);
21957 #endif
21958 0x43425844, 0xd3d04479, 0x901e9208, 0x7074fd0c, 0xbcadb2da, 0x00000001, 0x00000168, 0x00000003,
21959 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21960 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21961 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21962 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
21963 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
21964 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21965 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21966 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21967 0x00000000, 0x00100046, 0x00000000, 0x8e00007e, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21968 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0020800a, 0x00000000,
21969 0x00000001, 0x0100003e,
21971 static const DWORD gather4_po_c_code[] =
21973 #if 0
21974 SamplerComparisonState s;
21975 Texture2D<float4> t;
21977 int2 size;
21978 int2 offset;
21979 float compare;
21981 float4 main(float4 position : SV_Position) : SV_Target
21983 return t.GatherCmp(s, position.xy / size, compare, offset);
21985 #endif
21986 0x43425844, 0x501de13e, 0x472d2d20, 0x6df0fee4, 0xef27d9e6, 0x00000001, 0x00000174, 0x00000003,
21987 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21988 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21989 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21990 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d8, 0x00000050,
21991 0x00000036, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
21992 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21993 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21994 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21995 0x00000000, 0x00100046, 0x00000000, 0x91000080, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21996 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
21997 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
21999 static const float texture_data[] =
22001 0.00f, 0.10f, 0.20f, 0.30f,
22002 0.40f, 0.50f, 0.60f, 0.70f,
22003 0.80f, 0.90f, 0.05f, 0.15f,
22004 0.25f, 0.35f, 0.45f, 0.55f,
22006 static const struct vec4 expected_gather4_c[] =
22008 {0.0f, 1.00, 0.00, 0.0f}, {1.0f, 1.00, 0.00, 0.0f}, {1.0f, 1.00, 0.00, 0.0f}, {1.0f, 1.00, 0.00, 0.0f},
22009 {1.0f, 1.00, 1.00, 0.0f}, {1.0f, 0.00, 1.00, 1.0f}, {0.0f, 0.00, 1.00, 1.0f}, {0.0f, 0.00, 1.00, 1.0f},
22010 {0.0f, 0.00, 1.00, 1.0f}, {0.0f, 0.00, 0.00, 1.0f}, {0.0f, 1.00, 0.00, 0.0f}, {1.0f, 1.00, 0.00, 0.0f},
22011 {0.0f, 0.00, 0.00, 0.0f}, {0.0f, 0.00, 0.00, 0.0f}, {0.0f, 1.00, 1.00, 0.0f}, {1.0f, 1.00, 1.00, 1.0f},
22013 static const struct vec4 expected_gather4_po_c[] =
22015 {1.0f, 0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f},
22016 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 0.0f, 0.0f},
22017 {0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f},
22018 {0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f},
22020 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
22021 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
22023 if (!init_test_context(&test_context, &feature_level))
22024 return;
22026 device = test_context.device;
22027 context = test_context.immediate_context;
22029 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
22030 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
22031 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
22032 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
22033 sampler_desc.MipLODBias = 0.0f;
22034 sampler_desc.MaxAnisotropy = 0;
22035 sampler_desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
22036 sampler_desc.BorderColor[0] = 0.0f;
22037 sampler_desc.BorderColor[1] = 0.0f;
22038 sampler_desc.BorderColor[2] = 0.0f;
22039 sampler_desc.BorderColor[3] = 0.0f;
22040 sampler_desc.MinLOD = 0.0f;
22041 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
22043 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
22044 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
22045 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
22047 texture_desc.Width = 4;
22048 texture_desc.Height = 4;
22049 texture_desc.MipLevels = 1;
22050 texture_desc.ArraySize = 1;
22051 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
22052 texture_desc.SampleDesc.Count = 1;
22053 texture_desc.SampleDesc.Quality = 0;
22054 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22055 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
22056 texture_desc.CPUAccessFlags = 0;
22057 texture_desc.MiscFlags = 0;
22058 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
22059 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22060 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
22061 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
22062 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
22064 constant.width = texture_desc.Width;
22065 constant.height = texture_desc.Height;
22066 constant.offset_x = 1;
22067 constant.offset_y = 1;
22068 constant.compare_value = 0.5f;
22069 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
22070 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22072 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
22073 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
22074 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
22075 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22077 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
22078 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
22079 U(srv_desc).Texture2D.MostDetailedMip = 0;
22080 U(srv_desc).Texture2D.MipLevels = 1;
22081 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
22082 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
22083 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
22085 hr = ID3D11Device_CreatePixelShader(device, gather4_c_code, sizeof(gather4_c_code), NULL, &ps);
22086 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22087 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22089 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
22090 draw_quad(&test_context);
22091 get_texture_readback(rt, 0, &rb);
22092 for (y = 0; y < texture_desc.Height; ++y)
22094 for (x = 0; x < texture_desc.Width; ++x)
22096 const struct vec4 *expected = &expected_gather4_c[y * texture_desc.Width + x];
22097 const struct vec4 *got = get_readback_vec4(&rb, x, y);
22098 ok(compare_vec4(got, expected, 0),
22099 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
22100 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
22103 release_resource_readback(&rb);
22104 ID3D11PixelShader_Release(ps);
22106 hr = ID3D11Device_CreatePixelShader(device, gather4_po_c_code, sizeof(gather4_po_c_code), NULL, &ps);
22107 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22108 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22110 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
22111 draw_quad(&test_context);
22112 get_texture_readback(rt, 0, &rb);
22113 for (y = 0; y < texture_desc.Height; ++y)
22115 for (x = 0; x < texture_desc.Width; ++x)
22117 const struct vec4 *expected = &expected_gather4_po_c[y * texture_desc.Width + x];
22118 const struct vec4 *got = get_readback_vec4(&rb, x, y);
22119 ok(compare_vec4(got, expected, 0),
22120 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
22121 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
22124 release_resource_readback(&rb);
22125 ID3D11PixelShader_Release(ps);
22127 ID3D11ShaderResourceView_Release(srv);
22128 ID3D11Texture2D_Release(texture);
22130 ID3D11Buffer_Release(cb);
22131 ID3D11Texture2D_Release(rt);
22132 ID3D11RenderTargetView_Release(rtv);
22133 ID3D11SamplerState_Release(sampler);
22134 release_test_context(&test_context);
22137 static void test_fractional_viewports(void)
22139 struct d3d11_test_context test_context;
22140 D3D11_TEXTURE2D_DESC texture_desc;
22141 ID3D11InputLayout *input_layout;
22142 ID3D11DeviceContext *context;
22143 struct resource_readback rb;
22144 ID3D11RenderTargetView *rtv;
22145 ID3D11VertexShader *vs;
22146 ID3D11PixelShader *ps;
22147 unsigned int i, x, y;
22148 ID3D11Device *device;
22149 ID3D11Texture2D *rt;
22150 UINT offset, stride;
22151 D3D11_VIEWPORT vp;
22152 ID3D11Buffer *vb;
22153 HRESULT hr;
22155 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22156 static const DWORD vs_code[] =
22158 #if 0
22159 void main(in float4 in_position : POSITION,
22160 in float2 in_texcoord : TEXCOORD,
22161 out float4 position : SV_Position,
22162 out float2 texcoord : TEXCOORD)
22164 position = in_position;
22165 texcoord = in_texcoord;
22167 #endif
22168 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
22169 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
22170 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
22171 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
22172 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
22173 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
22174 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
22175 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
22176 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
22177 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
22178 0x00000001, 0x0100003e,
22180 static const DWORD ps_code[] =
22182 #if 0
22183 float4 main(float4 position : SV_Position,
22184 float2 texcoord : TEXCOORD) : SV_Target
22186 return float4(position.xy, texcoord);
22188 #endif
22189 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
22190 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
22191 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
22192 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
22193 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
22194 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
22195 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
22196 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
22197 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
22199 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
22201 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
22202 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
22204 static const struct
22206 struct vec2 position;
22207 struct vec2 texcoord;
22209 quad[] =
22211 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
22212 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
22213 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
22214 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
22216 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
22217 static const float viewport_offsets[] =
22219 0.0f, 0.5f, 0.25f, 0.125f, 0.0625f, 0.03125f, 0.015625f, 0.0078125f, 0.00390625f,
22220 1.0f / 128.0f, 63.0f / 128.0f,
22223 if (!init_test_context(&test_context, &feature_level))
22224 return;
22225 device = test_context.device;
22226 context = test_context.immediate_context;
22228 texture_desc.Width = 4;
22229 texture_desc.Height = 4;
22230 texture_desc.MipLevels = 1;
22231 texture_desc.ArraySize = 1;
22232 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
22233 texture_desc.SampleDesc.Count = 1;
22234 texture_desc.SampleDesc.Quality = 0;
22235 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22236 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
22237 texture_desc.CPUAccessFlags = 0;
22238 texture_desc.MiscFlags = 0;
22239 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
22240 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22241 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
22242 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
22243 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
22245 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
22246 vs_code, sizeof(vs_code), &input_layout);
22247 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
22248 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
22250 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
22251 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
22252 stride = sizeof(*quad);
22253 offset = 0;
22254 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
22256 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
22257 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
22258 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
22260 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22261 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22262 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22264 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
22266 vp.TopLeftX = viewport_offsets[i];
22267 vp.TopLeftY = viewport_offsets[i];
22268 vp.Width = texture_desc.Width;
22269 vp.Height = texture_desc.Height;
22270 vp.MinDepth = 0.0f;
22271 vp.MaxDepth = 1.0f;
22272 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
22273 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
22274 ID3D11DeviceContext_Draw(context, 4, 0);
22275 get_texture_readback(rt, 0, &rb);
22276 for (y = 0; y < texture_desc.Height; ++y)
22278 for (x = 0; x < texture_desc.Width; ++x)
22280 const struct vec4 *v = get_readback_vec4(&rb, x, y);
22281 struct vec4 expected = {x + 0.5f, y + 0.5f,
22282 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
22283 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
22284 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
22285 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
22286 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
22287 todo_wine
22288 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
22289 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
22290 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
22293 release_resource_readback(&rb);
22296 ID3D11InputLayout_Release(input_layout);
22297 ID3D11Buffer_Release(vb);
22298 ID3D11VertexShader_Release(vs);
22299 ID3D11PixelShader_Release(ps);
22300 ID3D11RenderTargetView_Release(rtv);
22301 ID3D11Texture2D_Release(rt);
22302 release_test_context(&test_context);
22305 static void test_early_depth_stencil(void)
22307 ID3D11DepthStencilState *depth_stencil_state;
22308 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
22309 ID3D11Texture2D *texture, *depth_texture;
22310 struct d3d11_test_context test_context;
22311 D3D11_TEXTURE2D_DESC texture_desc;
22312 ID3D11UnorderedAccessView *uav;
22313 ID3D11DeviceContext *context;
22314 ID3D11DepthStencilView *dsv;
22315 ID3D11PixelShader *ps;
22316 ID3D11Device *device;
22317 D3D11_VIEWPORT vp;
22318 HRESULT hr;
22320 static const DWORD ps_code[] =
22322 #if 0
22323 RWTexture2D<int> u;
22325 [earlydepthstencil]
22326 float4 main() : SV_Target
22328 InterlockedAdd(u[uint2(0, 0)], 1);
22329 return float4(1.0f, 1.0f, 1.0f, 1.0f);
22331 #endif
22332 0x43425844, 0xda4325ad, 0xc01d3815, 0xfd610cc9, 0x8ed1e351, 0x00000001, 0x000000ec, 0x00000003,
22333 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22334 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22335 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000074, 0x00000050, 0x0000001d,
22336 0x0100286a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x03000065, 0x001020f2, 0x00000000,
22337 0x0a0000ad, 0x0011e000, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
22338 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
22339 0x3f800000, 0x3f800000, 0x0100003e,
22341 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22342 static const UINT values[4] = {0};
22344 if (!init_test_context(&test_context, &feature_level))
22345 return;
22347 device = test_context.device;
22348 context = test_context.immediate_context;
22350 depth_stencil_desc.DepthEnable = TRUE;
22351 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
22352 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
22353 depth_stencil_desc.StencilEnable = FALSE;
22354 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
22355 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
22357 texture_desc.Width = 1;
22358 texture_desc.Height = 1;
22359 texture_desc.MipLevels = 1;
22360 texture_desc.ArraySize = 1;
22361 texture_desc.Format = DXGI_FORMAT_R32_SINT;
22362 texture_desc.SampleDesc.Count = 1;
22363 texture_desc.SampleDesc.Quality = 0;
22364 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22365 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22366 texture_desc.CPUAccessFlags = 0;
22367 texture_desc.MiscFlags = 0;
22368 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22369 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22370 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
22371 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22373 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
22374 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
22375 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22376 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
22377 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
22378 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22379 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
22380 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
22382 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22383 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22384 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22386 memset(&vp, 0, sizeof(vp));
22387 vp.Width = 1.0f;
22388 vp.Height = 100.0f;
22389 vp.MinDepth = 0.5f;
22390 vp.MaxDepth = 0.5f;
22391 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
22392 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
22393 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
22394 1, &test_context.backbuffer_rtv, dsv, 1, 1, &uav, NULL);
22396 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
22398 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
22399 draw_quad(&test_context);
22400 check_texture_color(texture, 100, 1);
22401 draw_quad(&test_context);
22402 check_texture_color(texture, 200, 1);
22403 check_texture_float(depth_texture, 0.6f, 1);
22405 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.3f, 0);
22406 draw_quad(&test_context);
22407 draw_quad(&test_context);
22408 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.55f, 0);
22409 draw_quad(&test_context);
22410 check_texture_color(texture, 300, 1);
22412 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
22413 draw_quad(&test_context);
22414 check_texture_color(texture, 400, 1);
22415 check_texture_float(depth_texture, 0.5f, 1);
22417 ID3D11Texture2D_Release(depth_texture);
22418 ID3D11DepthStencilView_Release(dsv);
22419 ID3D11DepthStencilState_Release(depth_stencil_state);
22420 ID3D11PixelShader_Release(ps);
22421 ID3D11Texture2D_Release(texture);
22422 ID3D11UnorderedAccessView_Release(uav);
22423 release_test_context(&test_context);
22426 static void test_conservative_depth_output(void)
22428 struct shader
22430 const DWORD *code;
22431 size_t size;
22434 ID3D11DepthStencilState *depth_stencil_state;
22435 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
22436 struct d3d11_test_context test_context;
22437 const struct shader *current_shader;
22438 D3D11_TEXTURE2D_DESC texture_desc;
22439 ID3D11DeviceContext *context;
22440 ID3D11DepthStencilView *dsv;
22441 ID3D11Texture2D *texture;
22442 ID3D11PixelShader *ps;
22443 DWORD expected_color;
22444 float expected_depth;
22445 ID3D11Device *device;
22446 struct vec4 ps_depth;
22447 ID3D11Buffer *cb;
22448 unsigned int i;
22449 HRESULT hr;
22451 static const DWORD ps_depth_le_code[] =
22453 #if 0
22454 float depth;
22456 float4 main(out float out_depth : SV_DepthLessEqual) : SV_Target0
22458 out_depth = depth;
22459 return float4(0.0f, 1.0f, 0.f, 1.0f);
22461 #endif
22462 0x43425844, 0x045c8d00, 0xc49e2ebe, 0x76f6022a, 0xf6996ecc, 0x00000001, 0x00000108, 0x00000003,
22463 0x0000002c, 0x0000003c, 0x00000098, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22464 0x00000054, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22465 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
22466 0x65677261, 0x56530074, 0x7065445f, 0x654c6874, 0x71457373, 0x006c6175, 0x58454853, 0x00000068,
22467 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065,
22468 0x001020f2, 0x00000000, 0x02000065, 0x00027001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
22469 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00027001, 0x0020800a, 0x00000000,
22470 0x00000000, 0x0100003e,
22472 static const struct shader ps_depth_le = {ps_depth_le_code, sizeof(ps_depth_le_code)};
22473 static const DWORD ps_depth_ge_code[] =
22475 #if 0
22476 float depth;
22478 float4 main(out float out_depth : SV_DepthGreaterEqual) : SV_Target0
22480 out_depth = depth;
22481 return float4(0.0f, 1.0f, 0.f, 1.0f);
22483 #endif
22484 0x43425844, 0xd17af83e, 0xa32c01cc, 0x0d8e9665, 0xe6dc17c2, 0x00000001, 0x0000010c, 0x00000003,
22485 0x0000002c, 0x0000003c, 0x0000009c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22486 0x00000058, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22487 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
22488 0x65677261, 0x56530074, 0x7065445f, 0x72476874, 0x65746165, 0x75714572, 0xab006c61, 0x58454853,
22489 0x00000068, 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
22490 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x00026001, 0x08000036, 0x001020f2, 0x00000000,
22491 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00026001, 0x0020800a,
22492 0x00000000, 0x00000000, 0x0100003e,
22494 static const struct shader ps_depth_ge = {ps_depth_ge_code, sizeof(ps_depth_ge_code)};
22495 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22496 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
22497 static const struct
22499 const struct shader *ps;
22500 float vs_depth;
22501 float ps_depth;
22502 BOOL passes_depth_test;
22504 tests[] =
22506 {&ps_depth_le, 0.7f, 0.7f, TRUE},
22507 {&ps_depth_le, 0.7f, 0.4f, FALSE},
22508 {&ps_depth_le, 0.4f, 0.4f, FALSE},
22509 /* {&ps_depth_le, 0.4f, 0.6f, FALSE}, undefined result */
22510 {&ps_depth_ge, 0.7f, 0.7f, TRUE},
22511 /* {&ps_depth_ge, 0.7f, 0.4f, TRUE}, undefined result */
22512 {&ps_depth_ge, 0.4f, 0.4f, FALSE},
22513 {&ps_depth_ge, 0.4f, 0.6f, TRUE},
22516 if (!init_test_context(&test_context, &feature_level))
22517 return;
22519 device = test_context.device;
22520 context = test_context.immediate_context;
22522 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_depth), NULL);
22524 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
22525 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
22526 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22527 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
22528 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22529 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22530 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
22531 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
22533 depth_stencil_desc.DepthEnable = TRUE;
22534 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
22535 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_GREATER_EQUAL;
22536 depth_stencil_desc.StencilEnable = FALSE;
22537 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
22538 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
22540 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22541 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
22542 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
22544 ps = NULL;
22545 current_shader = NULL;
22546 for (i = 0; i < ARRAY_SIZE(tests); ++i)
22548 if (current_shader != tests[i].ps)
22550 if (ps)
22551 ID3D11PixelShader_Release(ps);
22553 current_shader = tests[i].ps;
22554 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
22555 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22556 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22559 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
22560 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
22561 ps_depth.x = tests[i].ps_depth;
22562 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_depth, 0, 0);
22563 draw_quad_z(&test_context, tests[i].vs_depth);
22565 expected_color = tests[i].passes_depth_test ? 0xff00ff00 : 0xffffffff;
22566 expected_depth = tests[i].passes_depth_test ? max(tests[i].vs_depth, tests[i].ps_depth) : 0.5f;
22567 check_texture_color(test_context.backbuffer, expected_color, 0);
22568 check_texture_float(texture, expected_depth, 1);
22571 ID3D11Buffer_Release(cb);
22572 ID3D11PixelShader_Release(ps);
22573 ID3D11DepthStencilView_Release(dsv);
22574 ID3D11DepthStencilState_Release(depth_stencil_state);
22575 ID3D11Texture2D_Release(texture);
22576 release_test_context(&test_context);
22579 static void test_format_compatibility(void)
22581 ID3D11Texture2D *dst_texture, *src_texture;
22582 D3D11_SUBRESOURCE_DATA resource_data;
22583 D3D11_TEXTURE2D_DESC texture_desc;
22584 ID3D11DeviceContext *context;
22585 struct resource_readback rb;
22586 DWORD colour, expected;
22587 ID3D11Device *device;
22588 unsigned int i, j;
22589 ULONG refcount;
22590 HRESULT hr;
22592 static const struct
22594 DXGI_FORMAT src_format;
22595 DXGI_FORMAT dst_format;
22596 size_t texel_size;
22597 BOOL success;
22599 test_data[] =
22601 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
22602 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
22603 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
22604 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
22605 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
22606 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
22607 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
22608 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
22609 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
22610 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
22611 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
22612 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
22613 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
22614 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
22615 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
22616 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
22617 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
22618 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
22619 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
22621 static const DWORD initial_data[16] = {0};
22622 static const DWORD bitmap_data[] =
22624 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
22625 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
22626 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
22627 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
22630 if (!(device = create_device(NULL)))
22632 skip("Failed to create device.\n");
22633 return;
22635 ID3D11Device_GetImmediateContext(device, &context);
22637 texture_desc.Height = 4;
22638 texture_desc.MipLevels = 1;
22639 texture_desc.ArraySize = 1;
22640 texture_desc.SampleDesc.Count = 1;
22641 texture_desc.SampleDesc.Quality = 0;
22642 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
22643 texture_desc.CPUAccessFlags = 0;
22644 texture_desc.MiscFlags = 0;
22646 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
22648 unsigned int x, y, texel_dwords;
22649 D3D11_BOX box;
22651 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
22652 texture_desc.Format = test_data[i].src_format;
22653 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
22655 resource_data.pSysMem = bitmap_data;
22656 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
22657 resource_data.SysMemSlicePitch = 0;
22659 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
22660 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
22662 texture_desc.Format = test_data[i].dst_format;
22663 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22665 resource_data.pSysMem = initial_data;
22667 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
22668 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
22670 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
22671 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0, 1, 1, 0,
22672 (ID3D11Resource *)src_texture, 0, &box);
22674 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
22675 get_texture_readback(dst_texture, 0, &rb);
22676 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
22678 x = j % 4;
22679 y = j / 4;
22680 colour = get_readback_color(&rb, x, y);
22681 expected = test_data[i].success && x >= texel_dwords && y
22682 ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
22683 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
22684 i, colour, x, y, expected);
22686 release_resource_readback(&rb);
22688 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
22690 get_texture_readback(dst_texture, 0, &rb);
22691 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
22693 x = j % 4;
22694 y = j / 4;
22695 colour = get_readback_color(&rb, x, y);
22696 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
22697 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
22698 i, colour, x, y, expected);
22700 release_resource_readback(&rb);
22702 ID3D11Texture2D_Release(dst_texture);
22703 ID3D11Texture2D_Release(src_texture);
22706 ID3D11DeviceContext_Release(context);
22707 refcount = ID3D11Device_Release(device);
22708 ok(!refcount, "Device has %u references left.\n", refcount);
22711 static void check_clip_distance(struct d3d11_test_context *test_context, ID3D11Buffer *vb)
22713 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
22714 struct vertex
22716 float clip_distance0;
22717 float clip_distance1;
22720 ID3D11DeviceContext *context = test_context->immediate_context;
22721 struct resource_readback rb;
22722 struct vertex vertices[4];
22723 unsigned int i;
22724 RECT rect;
22726 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22727 vertices[i].clip_distance0 = 1.0f;
22728 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22729 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22730 ID3D11DeviceContext_Draw(context, 4, 0);
22731 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
22733 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22734 vertices[i].clip_distance0 = 0.0f;
22735 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22736 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22737 ID3D11DeviceContext_Draw(context, 4, 0);
22738 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
22740 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22741 vertices[i].clip_distance0 = -1.0f;
22742 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22743 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22744 ID3D11DeviceContext_Draw(context, 4, 0);
22745 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
22747 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22748 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
22749 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22750 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22751 ID3D11DeviceContext_Draw(context, 4, 0);
22752 get_texture_readback(test_context->backbuffer, 0, &rb);
22753 SetRect(&rect, 0, 0, 320, 480);
22754 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
22755 SetRect(&rect, 320, 0, 320, 480);
22756 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
22757 release_resource_readback(&rb);
22759 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22760 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
22761 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22762 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22763 ID3D11DeviceContext_Draw(context, 4, 0);
22764 get_texture_readback(test_context->backbuffer, 0, &rb);
22765 SetRect(&rect, 0, 0, 640, 240);
22766 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
22767 SetRect(&rect, 0, 240, 640, 240);
22768 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
22769 release_resource_readback(&rb);
22772 static void test_clip_distance(void)
22774 struct d3d11_test_context test_context;
22775 ID3D11Buffer *vs_cb, *tess_cb, *gs_cb;
22776 D3D_FEATURE_LEVEL feature_level;
22777 ID3D11DomainShader *ds = NULL;
22778 ID3D11DeviceContext *context;
22779 struct resource_readback rb;
22780 unsigned int offset, stride;
22781 ID3D11HullShader *hs = NULL;
22782 ID3D11GeometryShader *gs;
22783 ID3D11Device *device;
22784 ID3D11Buffer *vb;
22785 unsigned int i;
22786 HRESULT hr;
22787 RECT rect;
22789 static const DWORD vs_code[] =
22791 #if 0
22792 bool use_constant;
22793 float clip_distance;
22795 struct input
22797 float4 position : POSITION;
22798 float distance0 : CLIP_DISTANCE0;
22799 float distance1 : CLIP_DISTANCE1;
22802 struct vertex
22804 float4 position : SV_POSITION;
22805 float user_clip : CLIP_DISTANCE;
22806 float clip : SV_ClipDistance;
22809 void main(input vin, out vertex vertex)
22811 vertex.position = vin.position;
22812 vertex.user_clip = vin.distance0;
22813 vertex.clip = vin.distance0;
22814 if (use_constant)
22815 vertex.clip = clip_distance;
22817 #endif
22818 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
22819 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
22820 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
22821 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
22822 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
22823 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
22824 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
22825 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
22826 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
22827 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
22828 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
22829 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
22830 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
22831 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
22832 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
22834 static const DWORD vs_multiple_code[] =
22836 #if 0
22837 bool use_constant;
22838 float clip_distance0;
22839 float clip_distance1;
22841 struct input
22843 float4 position : POSITION;
22844 float distance0 : CLIP_DISTANCE0;
22845 float distance1 : CLIP_DISTANCE1;
22848 struct vertex
22850 float4 position : SV_POSITION;
22851 float user_clip : CLIP_DISTANCE;
22852 float2 clip : SV_ClipDistance;
22855 void main(input vin, out vertex vertex)
22857 vertex.position = vin.position;
22858 vertex.user_clip = vin.distance0;
22859 vertex.clip.x = vin.distance0;
22860 if (use_constant)
22861 vertex.clip.x = clip_distance0;
22862 vertex.clip.y = vin.distance1;
22863 if (use_constant)
22864 vertex.clip.y = clip_distance1;
22866 #endif
22867 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
22868 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
22869 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
22870 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
22871 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
22872 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
22873 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
22874 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
22875 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
22876 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
22877 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
22878 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
22879 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
22880 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
22881 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
22882 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
22883 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
22885 #if 0
22886 bool use_constant;
22887 float clip_distance0;
22888 float clip_distance1;
22889 float tessellation_factor;
22891 struct vertex
22893 float4 position : SV_POSITION;
22894 float user_clip : CLIP_DISTANCE;
22895 float clip : SV_ClipDistance;
22898 struct patch_constant_data
22900 float edges[4] : SV_TessFactor;
22901 float inside[2] : SV_InsideTessFactor;
22904 patch_constant_data patch_constant()
22906 patch_constant_data output;
22908 output.edges[0] = tessellation_factor;
22909 output.edges[1] = tessellation_factor;
22910 output.edges[2] = tessellation_factor;
22911 output.edges[3] = tessellation_factor;
22912 output.inside[0] = tessellation_factor;
22913 output.inside[1] = tessellation_factor;
22915 return output;
22918 [domain("quad")]
22919 [outputcontrolpoints(4)]
22920 [outputtopology("triangle_cw")]
22921 [partitioning("pow2")]
22922 [patchconstantfunc("patch_constant")]
22923 vertex hs_main(InputPatch<vertex, 4> input,
22924 uint i : SV_OutputControlPointID)
22926 vertex o;
22927 o.position = input[i].position;
22928 o.user_clip = input[i].user_clip;
22929 o.clip = input[i].user_clip;
22930 return o;
22933 float4 interpolate_vec(float4 a, float4 b, float4 c, float4 d, float2 tess_coord)
22935 float4 e = lerp(a, b, tess_coord.x);
22936 float4 f = lerp(c, d, tess_coord.x);
22937 return lerp(e, f, tess_coord.y);
22940 float interpolate(float a, float b, float c, float d, float2 tess_coord)
22942 float e = lerp(a, b, tess_coord.x);
22943 float f = lerp(c, d, tess_coord.x);
22944 return lerp(e, f, tess_coord.y);
22947 [domain("quad")]
22948 vertex ds_main(patch_constant_data input,
22949 float2 tess_coord : SV_DomainLocation,
22950 const OutputPatch<vertex, 4> patch)
22952 vertex output;
22954 output.position = interpolate_vec(patch[0].position, patch[1].position,
22955 patch[2].position, patch[3].position, tess_coord);
22956 output.user_clip = interpolate(patch[0].user_clip, patch[1].user_clip,
22957 patch[2].user_clip, patch[3].user_clip, tess_coord);
22958 output.clip = interpolate(patch[0].clip, patch[1].clip,
22959 patch[2].clip, patch[3].clip, tess_coord);
22960 if (use_constant)
22961 output.clip = clip_distance0;
22963 return output;
22965 #endif
22966 static const DWORD hs_code[] =
22968 0x43425844, 0x5a6d7564, 0x5f30a6c9, 0x2cf3b848, 0x5b4c6dca, 0x00000001, 0x00000414, 0x00000004,
22969 0x00000030, 0x000000b4, 0x00000138, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
22970 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
22971 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
22972 0x00000002, 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
22973 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003,
22974 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c,
22975 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002,
22976 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f,
22977 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc,
22978 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
22979 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
22980 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
22981 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
22982 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
22983 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
22984 0x00000210, 0x00030050, 0x00000084, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01001096,
22985 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x01000072, 0x0200005f,
22986 0x00016000, 0x0400005f, 0x002010f2, 0x00000004, 0x00000000, 0x0400005f, 0x00201012, 0x00000004,
22987 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
22988 0x00102012, 0x00000002, 0x02000068, 0x00000001, 0x04000036, 0x00100012, 0x00000000, 0x00016001,
22989 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x07000036,
22990 0x00102012, 0x00000001, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x07000036, 0x00102012,
22991 0x00000002, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x0100003e, 0x01000073, 0x02000099,
22992 0x00000004, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x0000000b, 0x04000067,
22993 0x00102012, 0x00000001, 0x0000000c, 0x04000067, 0x00102012, 0x00000002, 0x0000000d, 0x04000067,
22994 0x00102012, 0x00000003, 0x0000000e, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000000,
22995 0x00000004, 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x07000036, 0x00902012, 0x0010000a,
22996 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002,
22997 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000004, 0x0000000f, 0x04000067, 0x00102012,
22998 0x00000005, 0x00000010, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000004, 0x00000002,
22999 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x08000036, 0x00d02012, 0x00000004, 0x0010000a,
23000 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e,
23002 static const DWORD ds_code[] =
23004 0x43425844, 0xc54dc020, 0x063a9622, 0x6f649eb9, 0xceb1dd36, 0x00000001, 0x0000054c, 0x00000004,
23005 0x00000030, 0x000000b4, 0x00000178, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
23006 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
23007 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
23008 0x00000002, 0x00000101, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
23009 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc, 0x00000006,
23010 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000001, 0x00000098,
23011 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000001, 0x00000098, 0x00000002, 0x0000000b,
23012 0x00000003, 0x00000002, 0x00000001, 0x00000098, 0x00000003, 0x0000000b, 0x00000003, 0x00000003,
23013 0x00000001, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000001, 0x000000a6,
23014 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
23015 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000007c,
23016 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
23017 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000,
23018 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43,
23019 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x58454853,
23020 0x00000348, 0x00040050, 0x000000d2, 0x01002093, 0x01001895, 0x0100086a, 0x04000059, 0x00208e46,
23021 0x00000000, 0x00000001, 0x0200005f, 0x0001c032, 0x0400005f, 0x002190f2, 0x00000004, 0x00000000,
23022 0x0400005f, 0x00219012, 0x00000004, 0x00000001, 0x0400005f, 0x00219012, 0x00000004, 0x00000002,
23023 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067,
23024 0x00102012, 0x00000002, 0x00000002, 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000,
23025 0x80219e46, 0x00000041, 0x00000002, 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032,
23026 0x001000f2, 0x00000000, 0x0001c006, 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000,
23027 0x0a000000, 0x001000f2, 0x00000001, 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46,
23028 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001,
23029 0x00219e46, 0x00000000, 0x00000000, 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
23030 0x80100e46, 0x00000041, 0x00000001, 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46,
23031 0x00000000, 0x00100e46, 0x00000001, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041,
23032 0x00000002, 0x00000001, 0x0021900a, 0x00000003, 0x00000001, 0x09000032, 0x00100012, 0x00000000,
23033 0x0001c00a, 0x0010000a, 0x00000000, 0x0021900a, 0x00000002, 0x00000001, 0x0a000000, 0x00100022,
23034 0x00000000, 0x8021900a, 0x00000041, 0x00000000, 0x00000001, 0x0021900a, 0x00000001, 0x00000001,
23035 0x09000032, 0x00100022, 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000,
23036 0x00000001, 0x08000000, 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a,
23037 0x00000000, 0x08000032, 0x00102012, 0x00000001, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a,
23038 0x00000000, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041, 0x00000002, 0x00000002,
23039 0x0021900a, 0x00000003, 0x00000002, 0x09000032, 0x00100012, 0x00000000, 0x0001c00a, 0x0010000a,
23040 0x00000000, 0x0021900a, 0x00000002, 0x00000002, 0x0a000000, 0x00100022, 0x00000000, 0x8021900a,
23041 0x00000041, 0x00000000, 0x00000002, 0x0021900a, 0x00000001, 0x00000002, 0x09000032, 0x00100022,
23042 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000, 0x00000002, 0x08000000,
23043 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a, 0x00000000, 0x08000032,
23044 0x00100012, 0x00000000, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000, 0x0b000037,
23045 0x00102012, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
23046 0x0010000a, 0x00000000, 0x0100003e,
23048 static const DWORD gs_code[] =
23050 #if 0
23051 bool use_constant;
23052 float clip_distance;
23054 struct vertex
23056 float4 position : SV_POSITION;
23057 float user_clip : CLIP_DISTANCE;
23058 float clip : SV_ClipDistance;
23061 [maxvertexcount(3)]
23062 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
23064 vertex o;
23065 o = input[0];
23066 o.clip = input[0].user_clip;
23067 if (use_constant)
23068 o.clip = clip_distance;
23069 output.Append(o);
23070 o = input[1];
23071 o.clip = input[1].user_clip;
23072 if (use_constant)
23073 o.clip = clip_distance;
23074 output.Append(o);
23075 o = input[2];
23076 o.clip = input[2].user_clip;
23077 if (use_constant)
23078 o.clip = clip_distance;
23079 output.Append(o);
23081 #endif
23082 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
23083 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
23084 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
23085 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
23086 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
23087 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
23088 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
23089 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
23090 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
23091 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
23092 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
23093 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
23094 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
23095 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
23096 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
23097 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
23098 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
23099 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
23100 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
23101 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
23102 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
23103 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
23104 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
23105 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
23106 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
23107 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
23109 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
23111 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
23112 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
23113 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
23115 struct
23117 float clip_distance0;
23118 float clip_distance1;
23120 vertices[] =
23122 {1.0f, 1.0f},
23123 {1.0f, 1.0f},
23124 {1.0f, 1.0f},
23125 {1.0f, 1.0f},
23127 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
23128 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
23129 struct
23131 BOOL use_constant;
23132 float clip_distance0;
23133 float clip_distance1;
23134 float tessellation_factor;
23135 } cb_data;
23137 if (!init_test_context(&test_context, NULL))
23138 return;
23139 device = test_context.device;
23140 context = test_context.immediate_context;
23141 feature_level = ID3D11Device_GetFeatureLevel(device);
23143 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
23144 vs_code, sizeof(vs_code), &test_context.input_layout);
23145 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
23147 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
23148 stride = sizeof(*vertices);
23149 offset = 0;
23150 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
23152 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
23153 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
23155 memset(&cb_data, 0, sizeof(cb_data));
23156 cb_data.tessellation_factor = 1.0f;
23157 vs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
23158 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &vs_cb);
23159 tess_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
23160 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &tess_cb);
23161 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, 1, &tess_cb);
23162 gs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
23163 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &gs_cb);
23165 /* vertex shader */
23166 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23167 draw_color_quad(&test_context, &green);
23168 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23170 check_clip_distance(&test_context, vb);
23172 cb_data.use_constant = TRUE;
23173 cb_data.clip_distance0 = -1.0f;
23174 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
23176 /* tessellation shaders */
23177 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
23179 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
23181 hr = ID3D11Device_CreateHullShader(device, hs_code, sizeof(hs_code), NULL, &hs);
23182 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
23183 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
23184 hr = ID3D11Device_CreateDomainShader(device, ds_code, sizeof(ds_code), NULL, &ds);
23185 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
23186 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
23188 check_clip_distance(&test_context, vb);
23190 cb_data.use_constant = FALSE;
23191 cb_data.tessellation_factor = 2.0f;
23192 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
23194 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
23195 vertices[i].clip_distance0 = 1.0f;
23196 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23197 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23198 ID3D11DeviceContext_Draw(context, 4, 0);
23199 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23201 cb_data.use_constant = TRUE;
23202 cb_data.clip_distance0 = -1.0f;
23203 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
23205 else
23207 skip("Tessellation shaders are not supported.\n");
23210 /* geometry shader */
23211 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
23212 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
23213 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
23215 check_clip_distance(&test_context, vb);
23217 cb_data.use_constant = TRUE;
23218 cb_data.clip_distance0 = 1.0f;
23219 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
23220 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23221 ID3D11DeviceContext_Draw(context, 4, 0);
23222 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23224 /* multiple clip distances */
23225 ID3D11DeviceContext_HSSetShader(context, NULL, NULL, 0);
23226 ID3D11DeviceContext_DSSetShader(context, NULL, NULL, 0);
23227 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
23229 ID3D11VertexShader_Release(test_context.vs);
23230 hr = ID3D11Device_CreateVertexShader(device, vs_multiple_code, sizeof(vs_multiple_code),
23231 NULL, &test_context.vs);
23232 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
23234 cb_data.use_constant = FALSE;
23235 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
23237 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
23238 vertices[i].clip_distance0 = 1.0f;
23239 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23240 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23241 draw_color_quad(&test_context, &green);
23242 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23244 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
23246 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
23247 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
23249 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23250 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23251 draw_color_quad(&test_context, &green);
23252 get_texture_readback(test_context.backbuffer, 0, &rb);
23253 SetRect(&rect, 0, 0, 320, 240);
23254 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
23255 SetRect(&rect, 0, 240, 320, 480);
23256 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
23257 SetRect(&rect, 320, 0, 640, 480);
23258 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
23259 release_resource_readback(&rb);
23261 cb_data.use_constant = TRUE;
23262 cb_data.clip_distance0 = 0.0f;
23263 cb_data.clip_distance1 = 0.0f;
23264 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
23265 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23266 draw_color_quad(&test_context, &green);
23267 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23269 if (hs)
23270 ID3D11HullShader_Release(hs);
23271 if (ds)
23272 ID3D11DomainShader_Release(ds);
23273 ID3D11GeometryShader_Release(gs);
23274 ID3D11Buffer_Release(vb);
23275 ID3D11Buffer_Release(vs_cb);
23276 ID3D11Buffer_Release(tess_cb);
23277 ID3D11Buffer_Release(gs_cb);
23278 release_test_context(&test_context);
23281 static void test_combined_clip_and_cull_distances(void)
23283 struct d3d11_test_context test_context;
23284 ID3D11DeviceContext *context;
23285 struct resource_readback rb;
23286 unsigned int offset, stride;
23287 ID3D11Device *device;
23288 unsigned int i, j, k;
23289 ID3D11Buffer *vb;
23290 HRESULT hr;
23292 static const DWORD vs_code[] =
23294 #if 0
23295 struct input
23297 float4 position : POSITION;
23298 float clip0 : CLIP_DISTANCE0;
23299 float clip1 : CLIP_DISTANCE1;
23300 float clip2 : CLIP_DISTANCE2;
23301 float clip3 : CLIP_DISTANCE3;
23302 float cull0 : CULL_DISTANCE0;
23303 float cull1 : CULL_DISTANCE1;
23304 float cull2 : CULL_DISTANCE2;
23305 float cull3 : CULL_DISTANCE3;
23308 struct vertex
23310 float4 position : SV_Position;
23311 float3 clip0 : SV_ClipDistance1;
23312 float3 cull0 : SV_CullDistance1;
23313 float clip1 : SV_ClipDistance2;
23314 float cull1 : SV_CullDistance2;
23317 void main(input vin, out vertex vertex)
23319 vertex.position = vin.position;
23320 vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2);
23321 vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2);
23322 vertex.clip1 = vin.clip3;
23323 vertex.cull1 = vin.cull3;
23325 #endif
23326 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003,
23327 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0,
23328 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000,
23329 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
23330 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9,
23331 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000,
23332 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006,
23333 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7,
23334 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300,
23335 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f,
23336 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
23337 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c,
23338 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003,
23339 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002,
23340 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e,
23341 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f,
23342 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
23343 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f,
23344 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007,
23345 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
23346 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067,
23347 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036,
23348 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a,
23349 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042,
23350 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004,
23351 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002,
23352 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036,
23353 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e,
23355 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
23357 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
23358 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
23359 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
23360 {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
23361 {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
23362 {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
23363 {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
23364 {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
23365 {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
23367 struct
23369 float clip_distance[4];
23370 float cull_distance[4];
23372 vertices[4] =
23374 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
23375 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
23376 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
23377 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
23379 static const struct test
23381 float vertices[4];
23382 BOOL triangle_visible[2];
23384 cull_distance_tests[] =
23386 {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
23387 {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
23388 {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
23389 {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
23390 {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
23391 {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
23392 {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
23393 {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
23394 {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
23396 {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}},
23397 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
23398 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
23399 {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
23400 {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}},
23402 {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}},
23404 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
23405 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
23407 if (!init_test_context(&test_context, NULL))
23408 return;
23409 device = test_context.device;
23410 context = test_context.immediate_context;
23412 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
23413 vs_code, sizeof(vs_code), &test_context.input_layout);
23414 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
23416 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
23417 stride = sizeof(*vertices);
23418 offset = 0;
23419 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
23421 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
23422 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
23424 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23425 draw_color_quad(&test_context, &green);
23426 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23428 for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i)
23430 for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j)
23432 const struct test *test = &cull_distance_tests[j];
23433 unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)];
23434 unsigned int color;
23436 for (k = 0; k < ARRAY_SIZE(vertices); ++k)
23437 vertices[k].cull_distance[i] = test->vertices[k];
23438 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23440 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23441 draw_color_quad(&test_context, &green);
23443 for (k = 0; k < ARRAY_SIZE(expected_color); ++k)
23444 expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff;
23446 if (expected_color[0] == expected_color[1])
23448 check_texture_color(test_context.backbuffer, *expected_color, 1);
23450 else
23452 get_texture_readback(test_context.backbuffer, 0, &rb);
23453 color = get_readback_color(&rb, 160, 240);
23454 ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color);
23455 color = get_readback_color(&rb, 480, 240);
23456 ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color);
23457 release_resource_readback(&rb);
23461 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
23462 vertices[j].cull_distance[i] = 1.0f;
23465 for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i)
23467 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
23468 vertices[j].clip_distance[i] = -1.0f;
23469 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23471 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23472 draw_color_quad(&test_context, &green);
23473 check_texture_color(test_context.backbuffer, 0xffffffff, 1);
23475 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
23476 vertices[j].clip_distance[i] = 1.0f;
23479 memset(vertices, 0, sizeof(vertices));
23480 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23481 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23482 draw_color_quad(&test_context, &green);
23483 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23485 ID3D11Buffer_Release(vb);
23486 release_test_context(&test_context);
23489 START_TEST(d3d11)
23491 test_create_device();
23492 run_for_each_feature_level(test_device_interfaces);
23493 test_get_immediate_context();
23494 test_create_texture2d();
23495 test_texture2d_interfaces();
23496 test_create_texture3d();
23497 test_texture3d_interfaces();
23498 test_create_buffer();
23499 test_create_depthstencil_view();
23500 test_depthstencil_view_interfaces();
23501 test_create_rendertarget_view();
23502 test_create_shader_resource_view();
23503 run_for_each_feature_level(test_create_shader);
23504 test_create_sampler_state();
23505 test_create_blend_state();
23506 test_create_depthstencil_state();
23507 test_create_rasterizer_state();
23508 test_create_query();
23509 test_occlusion_query();
23510 test_pipeline_statistics_query();
23511 test_timestamp_query();
23512 test_device_removed_reason();
23513 test_private_data();
23514 run_for_each_feature_level(test_state_refcounting);
23515 test_device_context_state();
23516 test_blend();
23517 test_texture();
23518 test_cube_maps();
23519 test_depth_stencil_sampling();
23520 test_sample_c_lz();
23521 test_multiple_render_targets();
23522 test_render_target_views();
23523 test_layered_rendering();
23524 test_scissor();
23525 test_clear_state();
23526 test_il_append_aligned();
23527 test_instance_id();
23528 test_fragment_coords();
23529 test_update_subresource();
23530 test_copy_subresource_region();
23531 test_resource_map();
23532 test_check_multisample_quality_levels();
23533 run_for_each_feature_level(test_swapchain_formats);
23534 test_swapchain_views();
23535 test_swapchain_flip();
23536 test_clear_render_target_view();
23537 test_clear_depth_stencil_view();
23538 test_clear_buffer_unordered_access_view();
23539 test_initial_depth_stencil_state();
23540 test_draw_depth_only();
23541 test_draw_uav_only();
23542 test_cb_relative_addressing();
23543 test_vs_input_relative_addressing();
23544 test_getdc();
23545 test_shader_stage_input_output_matching();
23546 test_shader_interstage_interface();
23547 test_sm4_if_instruction();
23548 test_sm4_breakc_instruction();
23549 test_sm4_continuec_instruction();
23550 test_sm4_discard_instruction();
23551 test_sm5_swapc_instruction();
23552 test_create_input_layout();
23553 test_input_assembler();
23554 test_null_sampler();
23555 test_check_feature_support();
23556 test_create_unordered_access_view();
23557 test_immediate_constant_buffer();
23558 test_fp_specials();
23559 test_uint_shader_instructions();
23560 test_index_buffer_offset();
23561 test_face_culling();
23562 test_line_antialiasing_blending();
23563 run_for_each_feature_level(test_required_format_support);
23564 run_for_each_9_x_feature_level(test_fl9_draw);
23565 test_ddy();
23566 test_shader_input_registers_limits();
23567 test_unbind_shader_resource_view();
23568 test_stencil_separate();
23569 test_uav_load();
23570 test_cs_uav_store();
23571 test_uav_store_immediate_constant();
23572 test_ps_cs_uav_binding();
23573 test_atomic_instructions();
23574 test_sm4_ret_instruction();
23575 test_primitive_restart();
23576 test_resinfo_instruction();
23577 test_sm5_bufinfo_instruction();
23578 test_render_target_device_mismatch();
23579 test_buffer_srv();
23580 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
23581 test_unaligned_raw_buffer_access);
23582 test_uav_counters();
23583 test_dispatch_indirect();
23584 test_compute_shader_registers();
23585 test_tgsm();
23586 test_geometry_shader();
23587 test_quad_tessellation();
23588 test_stream_output();
23589 test_fl10_stream_output_desc();
23590 test_stream_output_resume();
23591 test_stream_output_components();
23592 test_gather();
23593 test_gather_c();
23594 test_fractional_viewports();
23595 test_early_depth_stencil();
23596 test_conservative_depth_output();
23597 test_format_compatibility();
23598 test_clip_distance();
23599 test_combined_clip_and_cull_distances();