d3d11: Disallow 0-sized buffer shader resource views.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blobf636a85db2357ba368a1965e447a78d2c00914ea
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 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1272 hr = ID3D11Device_CreateVertexShader(device, vs_code, vs_code_size, NULL, &context->vs);
1273 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1276 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1277 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1278 stride = sizeof(*quad);
1279 offset = 0;
1280 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1281 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1283 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1286 #define draw_quad(context) draw_quad_(__LINE__, context)
1287 static void draw_quad_(unsigned int line, struct d3d11_test_context *context)
1289 static const DWORD vs_code[] =
1291 #if 0
1292 float4 main(float4 position : POSITION) : SV_POSITION
1294 return position;
1296 #endif
1297 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1298 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1299 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1300 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1301 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1302 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1303 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1304 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1305 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1306 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1307 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1308 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1309 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1310 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1311 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1314 draw_quad_vs(__LINE__, context, vs_code, sizeof(vs_code));
1317 #define draw_quad_z(context, z) draw_quad_z_(__LINE__, context, z)
1318 static void draw_quad_z_(unsigned int line, struct d3d11_test_context *context, float z)
1320 static const DWORD vs_code[] =
1322 #if 0
1323 float depth;
1325 void main(float4 in_position : POSITION, out float4 out_position : SV_Position)
1327 out_position = in_position;
1328 out_position.z = depth;
1330 #endif
1331 0x43425844, 0x22d7ff76, 0xd53b167c, 0x1b49ccf1, 0xbebfec39, 0x00000001, 0x00000100, 0x00000003,
1332 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1333 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000b0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1334 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1335 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x52444853, 0x00000064, 0x00010040,
1336 0x00000019, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010b2, 0x00000000,
1337 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x05000036, 0x001020b2, 0x00000000, 0x00101c46,
1338 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
1341 struct vec4 data = {z};
1343 if (!context->vs_cb)
1344 context->vs_cb = create_buffer(context->device, D3D11_BIND_CONSTANT_BUFFER, sizeof(data), NULL);
1346 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1347 (ID3D11Resource *)context->vs_cb, 0, NULL, &data, 0, 0);
1349 ID3D11DeviceContext_VSSetConstantBuffers(context->immediate_context, 0, 1, &context->vs_cb);
1350 draw_quad_vs(__LINE__, context, vs_code, sizeof(vs_code));
1353 static void set_quad_color(struct d3d11_test_context *context, const struct vec4 *color)
1355 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1356 (ID3D11Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1359 #define draw_color_quad(context, color) draw_color_quad_(__LINE__, context, color)
1360 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context, const struct vec4 *color)
1362 static const DWORD ps_color_code[] =
1364 #if 0
1365 float4 color;
1367 float4 main() : SV_TARGET
1369 return color;
1371 #endif
1372 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1373 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1374 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1375 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1376 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1377 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1378 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1379 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1380 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1381 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1382 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1385 ID3D11Device *device = context->device;
1386 HRESULT hr;
1388 if (!context->ps)
1390 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1391 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1394 if (!context->ps_cb)
1395 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1397 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1398 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1400 set_quad_color(context, color);
1402 draw_quad_(line, context);
1405 static void test_create_device(void)
1407 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1409 D3D_FEATURE_LEVEL_11_0,
1410 D3D_FEATURE_LEVEL_10_1,
1411 D3D_FEATURE_LEVEL_10_0,
1412 D3D_FEATURE_LEVEL_9_3,
1413 D3D_FEATURE_LEVEL_9_2,
1414 D3D_FEATURE_LEVEL_9_1,
1416 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1417 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1418 ID3D11DeviceContext *immediate_context;
1419 IDXGISwapChain *swapchain;
1420 ID3D11Device *device;
1421 ULONG refcount;
1422 HWND window;
1423 HRESULT hr;
1425 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1426 &device, NULL, NULL)))
1428 skip("Failed to create HAL device.\n");
1429 if ((device = create_device(NULL)))
1431 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
1432 ID3D11Device_Release(device);
1434 return;
1437 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
1438 trace("Feature level %#x.\n", supported_feature_level);
1439 ID3D11Device_Release(device);
1441 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
1442 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1444 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
1445 &feature_level, NULL);
1446 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1447 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1448 feature_level, supported_feature_level);
1450 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
1451 ARRAY_SIZE(default_feature_levels), D3D11_SDK_VERSION, NULL, &feature_level, NULL);
1452 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1453 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1454 feature_level, supported_feature_level);
1456 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
1457 &immediate_context);
1458 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1460 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
1461 refcount = get_refcount(immediate_context);
1462 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1464 ID3D11DeviceContext_GetDevice(immediate_context, &device);
1465 refcount = ID3D11Device_Release(device);
1466 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1468 refcount = ID3D11DeviceContext_Release(immediate_context);
1469 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
1471 device = (ID3D11Device *)0xdeadbeef;
1472 feature_level = 0xdeadbeef;
1473 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1474 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1475 &device, &feature_level, &immediate_context);
1476 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
1477 ok(!device, "Got unexpected device pointer %p.\n", device);
1478 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1479 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1481 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
1483 swapchain_desc.BufferDesc.Width = 800;
1484 swapchain_desc.BufferDesc.Height = 600;
1485 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
1486 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
1487 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1488 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1489 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1490 swapchain_desc.SampleDesc.Count = 1;
1491 swapchain_desc.SampleDesc.Quality = 0;
1492 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1493 swapchain_desc.BufferCount = 1;
1494 swapchain_desc.OutputWindow = window;
1495 swapchain_desc.Windowed = TRUE;
1496 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1497 swapchain_desc.Flags = 0;
1499 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1500 &swapchain_desc, NULL, NULL, NULL, NULL);
1501 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1503 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1504 &swapchain_desc, NULL, NULL, &feature_level, NULL);
1505 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1506 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1507 feature_level, supported_feature_level);
1509 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1510 &swapchain_desc, &swapchain, &device, NULL, NULL);
1511 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1513 memset(&obtained_desc, 0, sizeof(obtained_desc));
1514 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
1515 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
1516 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
1517 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
1518 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
1519 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
1520 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
1521 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
1522 obtained_desc.BufferDesc.RefreshRate.Numerator);
1523 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
1524 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
1525 obtained_desc.BufferDesc.RefreshRate.Denominator);
1526 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
1527 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
1528 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
1529 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
1530 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
1531 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
1532 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
1533 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
1534 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
1535 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
1536 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
1537 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
1538 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
1539 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
1540 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
1541 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
1542 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
1543 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
1544 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
1545 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
1546 ok(obtained_desc.Flags == swapchain_desc.Flags,
1547 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
1549 refcount = IDXGISwapChain_Release(swapchain);
1550 ok(!refcount, "Swapchain has %u references left.\n", refcount);
1552 feature_level = ID3D11Device_GetFeatureLevel(device);
1553 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1554 feature_level, supported_feature_level);
1556 refcount = ID3D11Device_Release(device);
1557 ok(!refcount, "Device has %u references left.\n", refcount);
1559 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1560 NULL, NULL, &device, NULL, NULL);
1561 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1562 ID3D11Device_Release(device);
1564 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1565 NULL, NULL, NULL, NULL, NULL);
1566 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1568 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1569 NULL, NULL, NULL, &feature_level, NULL);
1570 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1571 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1572 feature_level, supported_feature_level);
1574 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1575 NULL, NULL, NULL, NULL, &immediate_context);
1576 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1577 ID3D11DeviceContext_Release(immediate_context);
1579 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1580 &swapchain_desc, NULL, NULL, NULL, NULL);
1581 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1583 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1584 &swapchain_desc, &swapchain, NULL, NULL, NULL);
1585 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1586 IDXGISwapChain_Release(swapchain);
1588 swapchain_desc.OutputWindow = NULL;
1589 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1590 &swapchain_desc, NULL, NULL, NULL, NULL);
1591 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1592 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1593 &swapchain_desc, NULL, &device, NULL, NULL);
1594 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1595 ID3D11Device_Release(device);
1597 swapchain = (IDXGISwapChain *)0xdeadbeef;
1598 device = (ID3D11Device *)0xdeadbeef;
1599 feature_level = 0xdeadbeef;
1600 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1601 swapchain_desc.OutputWindow = NULL;
1602 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1603 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1604 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1605 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1606 ok(!device, "Got unexpected device pointer %p.\n", device);
1607 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1608 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1610 swapchain = (IDXGISwapChain *)0xdeadbeef;
1611 device = (ID3D11Device *)0xdeadbeef;
1612 feature_level = 0xdeadbeef;
1613 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1614 swapchain_desc.OutputWindow = window;
1615 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
1616 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1617 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1618 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1619 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1620 ok(!device, "Got unexpected device pointer %p.\n", device);
1621 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1622 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1624 DestroyWindow(window);
1627 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
1629 struct device_desc device_desc;
1630 IDXGIAdapter *dxgi_adapter;
1631 IDXGIDevice *dxgi_device;
1632 ID3D11Device *device;
1633 IUnknown *iface;
1634 ULONG refcount;
1635 HRESULT hr;
1637 device_desc.feature_level = &feature_level;
1638 device_desc.flags = 0;
1639 if (!(device = create_device(&device_desc)))
1641 skip("Failed to create device for feature level %#x.\n", feature_level);
1642 return;
1645 check_interface(device, &IID_IUnknown, TRUE, FALSE);
1646 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
1647 check_interface(device, &IID_IDXGIDevice, TRUE, FALSE);
1648 check_interface(device, &IID_IDXGIDevice1, TRUE, FALSE);
1649 check_interface(device, &IID_ID3D10Multithread, TRUE, TRUE); /* Not available on all Windows versions. */
1650 todo_wine check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
1651 todo_wine check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
1652 check_interface(device, &IID_ID3D11InfoQueue, FALSE, FALSE); /* Non-debug mode. */
1654 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1655 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1656 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1657 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1658 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1659 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1660 IUnknown_Release(iface);
1661 IDXGIAdapter_Release(dxgi_adapter);
1662 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1663 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1664 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1665 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
1666 IUnknown_Release(iface);
1667 IDXGIAdapter_Release(dxgi_adapter);
1668 IDXGIDevice_Release(dxgi_device);
1670 refcount = ID3D11Device_Release(device);
1671 ok(!refcount, "Device has %u references left.\n", refcount);
1673 device_desc.feature_level = &feature_level;
1674 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
1675 if (!(device = create_device(&device_desc)))
1677 skip("Failed to create debug device for feature level %#x.\n", feature_level);
1678 return;
1681 todo_wine check_interface(device, &IID_ID3D11InfoQueue, TRUE, FALSE);
1683 refcount = ID3D11Device_Release(device);
1684 ok(!refcount, "Device has %u references left.\n", refcount);
1687 static void test_get_immediate_context(void)
1689 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
1690 ULONG expected_refcount, refcount;
1691 ID3D11Device *device;
1693 if (!(device = create_device(NULL)))
1695 skip("Failed to create device.\n");
1696 return;
1699 expected_refcount = get_refcount(device) + 1;
1700 ID3D11Device_GetImmediateContext(device, &immediate_context);
1701 refcount = get_refcount(device);
1702 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1703 previous_immediate_context = immediate_context;
1705 ID3D11Device_GetImmediateContext(device, &immediate_context);
1706 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1707 refcount = get_refcount(device);
1708 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1710 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
1711 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1712 refcount = ID3D11DeviceContext_Release(immediate_context);
1713 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1715 ID3D11Device_GetImmediateContext(device, &immediate_context);
1716 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1717 refcount = ID3D11DeviceContext_Release(immediate_context);
1718 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1720 refcount = ID3D11Device_Release(device);
1721 ok(!refcount, "Device has %u references left.\n", refcount);
1724 static void test_create_texture2d(void)
1726 ULONG refcount, expected_refcount;
1727 D3D11_SUBRESOURCE_DATA data = {0};
1728 D3D_FEATURE_LEVEL feature_level;
1729 ID3D11Device *device, *tmp;
1730 D3D11_TEXTURE2D_DESC desc;
1731 ID3D11Texture2D *texture;
1732 UINT quality_level_count;
1733 unsigned int i;
1734 HRESULT hr;
1736 static const struct
1738 DXGI_FORMAT format;
1739 UINT array_size;
1740 D3D11_BIND_FLAG bind_flags;
1741 UINT misc_flags;
1742 BOOL succeeds;
1743 BOOL todo;
1745 tests[] =
1747 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1748 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1749 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1750 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1751 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1752 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1753 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1754 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1755 FALSE, FALSE},
1756 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1757 FALSE, FALSE},
1758 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1759 FALSE, FALSE},
1760 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1761 TRUE, FALSE},
1762 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1763 TRUE, FALSE},
1764 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1765 TRUE, FALSE},
1766 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1767 TRUE, FALSE},
1768 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1769 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1770 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1771 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1772 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1773 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1774 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1775 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1776 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1777 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1778 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1779 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1780 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1781 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1782 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1783 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1784 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1785 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1786 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1787 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1788 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1789 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1790 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1791 TRUE, FALSE},
1792 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1793 TRUE, FALSE},
1794 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1795 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
1796 FALSE, TRUE},
1797 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1798 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
1799 FALSE, TRUE},
1800 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1801 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1802 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1803 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1804 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1805 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1806 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1807 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1808 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1809 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1810 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1811 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1812 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1813 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1814 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1815 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1816 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1817 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1818 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1819 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1820 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1821 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1822 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1823 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1824 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1825 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1826 FALSE, TRUE},
1827 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1828 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1829 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1830 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1831 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1834 if (!(device = create_device(NULL)))
1836 skip("Failed to create device.\n");
1837 return;
1840 feature_level = ID3D11Device_GetFeatureLevel(device);
1842 desc.Width = 512;
1843 desc.Height = 512;
1844 desc.MipLevels = 1;
1845 desc.ArraySize = 1;
1846 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1847 desc.SampleDesc.Count = 1;
1848 desc.SampleDesc.Quality = 0;
1849 desc.Usage = D3D11_USAGE_DEFAULT;
1850 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1851 desc.CPUAccessFlags = 0;
1852 desc.MiscFlags = 0;
1854 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
1855 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1857 expected_refcount = get_refcount(device) + 1;
1858 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1859 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1860 refcount = get_refcount(device);
1861 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1862 tmp = NULL;
1863 expected_refcount = refcount + 1;
1864 ID3D11Texture2D_GetDevice(texture, &tmp);
1865 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1866 refcount = get_refcount(device);
1867 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1868 ID3D11Device_Release(tmp);
1870 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1871 ID3D11Texture2D_Release(texture);
1873 desc.MipLevels = 0;
1874 expected_refcount = get_refcount(device) + 1;
1875 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1876 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1877 refcount = get_refcount(device);
1878 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1879 tmp = NULL;
1880 expected_refcount = refcount + 1;
1881 ID3D11Texture2D_GetDevice(texture, &tmp);
1882 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1883 refcount = get_refcount(device);
1884 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1885 ID3D11Device_Release(tmp);
1887 ID3D11Texture2D_GetDesc(texture, &desc);
1888 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1889 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1890 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1891 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1892 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1893 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1894 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1895 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1896 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1897 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1898 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1900 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1901 ID3D11Texture2D_Release(texture);
1903 desc.MipLevels = 1;
1904 desc.ArraySize = 2;
1905 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1906 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1908 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1909 ID3D11Texture2D_Release(texture);
1911 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1912 desc.ArraySize = 1;
1913 desc.SampleDesc.Count = 2;
1914 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1915 if (quality_level_count)
1917 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1918 ID3D11Texture2D_Release(texture);
1919 desc.SampleDesc.Quality = quality_level_count;
1920 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1922 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1924 /* We assume 15 samples multisampling is never supported in practice. */
1925 desc.SampleDesc.Count = 15;
1926 desc.SampleDesc.Quality = 0;
1927 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1928 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1930 desc.SampleDesc.Count = 1;
1931 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1933 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
1934 BOOL todo = tests[i].todo;
1936 if (feature_level < D3D_FEATURE_LEVEL_10_1
1937 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
1938 && tests[i].array_size > 6)
1940 expected_hr = E_INVALIDARG;
1941 todo = TRUE;
1944 desc.ArraySize = tests[i].array_size;
1945 desc.Format = tests[i].format;
1946 desc.BindFlags = tests[i].bind_flags;
1947 desc.MiscFlags = tests[i].misc_flags;
1948 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, (ID3D11Texture2D **)&texture);
1950 todo_wine_if(todo)
1951 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
1952 i, hr, desc.Format);
1954 if (SUCCEEDED(hr))
1955 ID3D11Texture2D_Release(texture);
1958 refcount = ID3D11Device_Release(device);
1959 ok(!refcount, "Device has %u references left.\n", refcount);
1962 static void test_texture2d_interfaces(void)
1964 ID3D10Texture2D *d3d10_texture;
1965 D3D11_TEXTURE2D_DESC desc;
1966 ID3D11Texture2D *texture;
1967 ID3D11Device *device;
1968 unsigned int i;
1969 ULONG refcount;
1970 HRESULT hr;
1972 static const struct test
1974 BOOL implements_d3d10_interfaces;
1975 UINT bind_flags;
1976 UINT misc_flags;
1977 UINT expected_bind_flags;
1978 UINT expected_misc_flags;
1980 desc_conversion_tests[] =
1983 TRUE,
1984 D3D11_BIND_SHADER_RESOURCE, 0,
1985 D3D10_BIND_SHADER_RESOURCE, 0
1988 TRUE,
1989 D3D11_BIND_UNORDERED_ACCESS, 0,
1990 D3D11_BIND_UNORDERED_ACCESS, 0
1993 FALSE,
1994 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1995 0, 0
1998 TRUE,
1999 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2000 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2003 TRUE,
2004 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
2005 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2009 if (!(device = create_device(NULL)))
2011 skip("Failed to create ID3D11Device, skipping tests.\n");
2012 return;
2015 desc.Width = 512;
2016 desc.Height = 512;
2017 desc.MipLevels = 0;
2018 desc.ArraySize = 1;
2019 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2020 desc.SampleDesc.Count = 1;
2021 desc.SampleDesc.Quality = 0;
2022 desc.Usage = D3D11_USAGE_DEFAULT;
2023 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2024 desc.CPUAccessFlags = 0;
2025 desc.MiscFlags = 0;
2027 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2028 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2029 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2030 hr = check_interface(texture, &IID_ID3D10Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
2031 ID3D11Texture2D_Release(texture);
2032 if (FAILED(hr))
2034 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
2035 ID3D11Device_Release(device);
2036 return;
2039 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2041 const struct test *current = &desc_conversion_tests[i];
2042 D3D10_TEXTURE2D_DESC d3d10_desc;
2043 ID3D10Device *d3d10_device;
2045 desc.Width = 512;
2046 desc.Height = 512;
2047 desc.MipLevels = 1;
2048 desc.ArraySize = 1;
2049 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2050 desc.SampleDesc.Count = 1;
2051 desc.SampleDesc.Quality = 0;
2052 desc.Usage = D3D11_USAGE_DEFAULT;
2053 desc.BindFlags = current->bind_flags;
2054 desc.CPUAccessFlags = 0;
2055 desc.MiscFlags = current->misc_flags;
2057 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2058 /* Shared resources are not supported by REF and WARP devices. */
2059 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2060 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2061 if (FAILED(hr))
2063 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
2064 continue;
2067 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2069 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2070 ID3D11Texture2D_Release(texture);
2072 if (current->implements_d3d10_interfaces)
2074 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2076 else
2078 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2079 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
2080 continue;
2083 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
2085 ok(d3d10_desc.Width == desc.Width,
2086 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2087 ok(d3d10_desc.Height == desc.Height,
2088 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2089 ok(d3d10_desc.MipLevels == desc.MipLevels,
2090 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2091 ok(d3d10_desc.ArraySize == desc.ArraySize,
2092 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2093 ok(d3d10_desc.Format == desc.Format,
2094 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2095 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
2096 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
2097 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2098 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
2099 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2100 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2101 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2102 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2103 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2104 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2105 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2106 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2108 d3d10_device = (ID3D10Device *)0xdeadbeef;
2109 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
2110 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2111 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2113 ID3D10Texture2D_Release(d3d10_texture);
2116 refcount = ID3D11Device_Release(device);
2117 ok(!refcount, "Device has %u references left.\n", refcount);
2120 static void test_create_texture3d(void)
2122 ULONG refcount, expected_refcount;
2123 D3D11_SUBRESOURCE_DATA data = {0};
2124 ID3D11Device *device, *tmp;
2125 D3D11_TEXTURE3D_DESC desc;
2126 ID3D11Texture3D *texture;
2127 unsigned int i;
2128 HRESULT hr;
2130 static const struct
2132 DXGI_FORMAT format;
2133 D3D11_BIND_FLAG bind_flags;
2134 BOOL succeeds;
2135 BOOL todo;
2137 tests[] =
2139 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
2140 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
2141 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2142 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2143 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2144 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2145 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2146 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2147 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2148 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2149 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2150 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2153 if (!(device = create_device(NULL)))
2155 skip("Failed to create ID3D11Device, skipping tests.\n");
2156 return;
2159 desc.Width = 64;
2160 desc.Height = 64;
2161 desc.Depth = 64;
2162 desc.MipLevels = 1;
2163 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2164 desc.Usage = D3D11_USAGE_DEFAULT;
2165 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2166 desc.CPUAccessFlags = 0;
2167 desc.MiscFlags = 0;
2169 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2170 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2172 expected_refcount = get_refcount(device) + 1;
2173 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2174 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2175 refcount = get_refcount(device);
2176 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2177 tmp = NULL;
2178 expected_refcount = refcount + 1;
2179 ID3D11Texture3D_GetDevice(texture, &tmp);
2180 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2181 refcount = get_refcount(device);
2182 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2183 ID3D11Device_Release(tmp);
2185 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2186 ID3D11Texture3D_Release(texture);
2188 desc.MipLevels = 0;
2189 expected_refcount = get_refcount(device) + 1;
2190 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2191 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2192 refcount = get_refcount(device);
2193 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2194 tmp = NULL;
2195 expected_refcount = refcount + 1;
2196 ID3D11Texture3D_GetDevice(texture, &tmp);
2197 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2198 refcount = get_refcount(device);
2199 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2200 ID3D11Device_Release(tmp);
2202 ID3D11Texture3D_GetDesc(texture, &desc);
2203 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2204 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2205 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2206 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2207 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2208 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2209 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2210 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2211 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2213 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2214 ID3D11Texture3D_Release(texture);
2216 desc.MipLevels = 1;
2217 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2219 desc.Format = tests[i].format;
2220 desc.BindFlags = tests[i].bind_flags;
2221 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, (ID3D11Texture3D **)&texture);
2223 todo_wine_if(tests[i].todo)
2224 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2226 if (SUCCEEDED(hr))
2227 ID3D11Texture3D_Release(texture);
2230 refcount = ID3D11Device_Release(device);
2231 ok(!refcount, "Device has %u references left.\n", refcount);
2234 static void test_texture3d_interfaces(void)
2236 ID3D10Texture3D *d3d10_texture;
2237 D3D11_TEXTURE3D_DESC desc;
2238 ID3D11Texture3D *texture;
2239 ID3D11Device *device;
2240 unsigned int i;
2241 ULONG refcount;
2242 HRESULT hr;
2244 static const struct test
2246 BOOL implements_d3d10_interfaces;
2247 UINT bind_flags;
2248 UINT misc_flags;
2249 UINT expected_bind_flags;
2250 UINT expected_misc_flags;
2252 desc_conversion_tests[] =
2255 TRUE,
2256 D3D11_BIND_SHADER_RESOURCE, 0,
2257 D3D10_BIND_SHADER_RESOURCE, 0
2260 TRUE,
2261 D3D11_BIND_UNORDERED_ACCESS, 0,
2262 D3D11_BIND_UNORDERED_ACCESS, 0
2265 FALSE,
2266 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2267 0, 0
2270 TRUE,
2271 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2272 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2276 if (!(device = create_device(NULL)))
2278 skip("Failed to create ID3D11Device.\n");
2279 return;
2282 desc.Width = 64;
2283 desc.Height = 64;
2284 desc.Depth = 64;
2285 desc.MipLevels = 0;
2286 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2287 desc.Usage = D3D11_USAGE_DEFAULT;
2288 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2289 desc.CPUAccessFlags = 0;
2290 desc.MiscFlags = 0;
2292 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2293 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2294 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2295 hr = check_interface(texture, &IID_ID3D10Texture3D, TRUE, TRUE); /* Not available on all Windows versions. */
2296 ID3D11Texture3D_Release(texture);
2297 if (FAILED(hr))
2299 win_skip("3D textures do not implement ID3D10Texture3D.\n");
2300 ID3D11Device_Release(device);
2301 return;
2304 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2306 const struct test *current = &desc_conversion_tests[i];
2307 D3D10_TEXTURE3D_DESC d3d10_desc;
2308 ID3D10Device *d3d10_device;
2310 desc.Width = 64;
2311 desc.Height = 64;
2312 desc.Depth = 64;
2313 desc.MipLevels = 1;
2314 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2315 desc.Usage = D3D11_USAGE_DEFAULT;
2316 desc.BindFlags = current->bind_flags;
2317 desc.CPUAccessFlags = 0;
2318 desc.MiscFlags = current->misc_flags;
2320 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2321 /* Shared resources are not supported by REF and WARP devices. */
2322 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2323 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
2324 if (FAILED(hr))
2326 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
2327 continue;
2330 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2332 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2333 ID3D11Texture3D_Release(texture);
2335 if (current->implements_d3d10_interfaces)
2337 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
2339 else
2341 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
2342 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2343 continue;
2346 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
2348 ok(d3d10_desc.Width == desc.Width,
2349 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2350 ok(d3d10_desc.Height == desc.Height,
2351 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2352 ok(d3d10_desc.Depth == desc.Depth,
2353 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
2354 ok(d3d10_desc.MipLevels == desc.MipLevels,
2355 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2356 ok(d3d10_desc.Format == desc.Format,
2357 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2358 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2359 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2360 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2361 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2362 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2363 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2364 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2365 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2367 d3d10_device = (ID3D10Device *)0xdeadbeef;
2368 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
2369 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2370 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2372 ID3D10Texture3D_Release(d3d10_texture);
2375 refcount = ID3D11Device_Release(device);
2376 ok(!refcount, "Device has %u references left.\n", refcount);
2379 static void test_create_buffer(void)
2381 ID3D10Buffer *d3d10_buffer;
2382 HRESULT expected_hr, hr;
2383 D3D11_BUFFER_DESC desc;
2384 ID3D11Buffer *buffer;
2385 ID3D11Device *device;
2386 unsigned int i;
2387 ULONG refcount;
2389 static const struct test
2391 BOOL succeeds;
2392 BOOL implements_d3d10_interfaces;
2393 UINT bind_flags;
2394 UINT misc_flags;
2395 UINT structure_stride;
2396 UINT expected_bind_flags;
2397 UINT expected_misc_flags;
2399 tests[] =
2402 TRUE, TRUE,
2403 D3D11_BIND_VERTEX_BUFFER, 0, 0,
2404 D3D10_BIND_VERTEX_BUFFER, 0
2407 TRUE, TRUE,
2408 D3D11_BIND_INDEX_BUFFER, 0, 0,
2409 D3D10_BIND_INDEX_BUFFER, 0
2412 TRUE, TRUE,
2413 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
2414 D3D10_BIND_CONSTANT_BUFFER, 0
2417 TRUE, TRUE,
2418 D3D11_BIND_SHADER_RESOURCE, 0, 0,
2419 D3D10_BIND_SHADER_RESOURCE, 0
2422 TRUE, TRUE,
2423 D3D11_BIND_STREAM_OUTPUT, 0, 0,
2424 D3D10_BIND_STREAM_OUTPUT, 0
2427 TRUE, TRUE,
2428 D3D11_BIND_RENDER_TARGET, 0, 0,
2429 D3D10_BIND_RENDER_TARGET, 0
2432 TRUE, TRUE,
2433 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
2434 D3D11_BIND_UNORDERED_ACCESS, 0
2437 TRUE, TRUE,
2438 0, D3D11_RESOURCE_MISC_SHARED, 0,
2439 0, D3D10_RESOURCE_MISC_SHARED
2442 TRUE, TRUE,
2443 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
2444 0, 0
2447 FALSE, FALSE,
2448 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2451 FALSE, FALSE,
2452 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2455 FALSE, FALSE,
2456 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2459 TRUE, TRUE,
2460 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2461 D3D10_BIND_SHADER_RESOURCE, 0
2464 FALSE, FALSE,
2465 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2468 FALSE, FALSE,
2469 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2472 TRUE, TRUE,
2473 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2474 D3D11_BIND_UNORDERED_ACCESS, 0
2477 FALSE, FALSE,
2478 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2480 /* Structured buffers do not implement ID3D10Buffer. */
2482 TRUE, FALSE,
2483 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2486 TRUE, FALSE,
2487 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2490 FALSE, FALSE,
2491 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
2494 FALSE, FALSE,
2495 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
2498 FALSE, FALSE,
2499 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
2502 FALSE, FALSE,
2503 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
2506 FALSE, FALSE,
2507 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
2510 TRUE, FALSE,
2511 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
2514 FALSE, FALSE,
2515 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
2518 TRUE, FALSE,
2519 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
2522 TRUE, FALSE,
2523 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
2526 FALSE, FALSE,
2527 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
2530 TRUE, FALSE,
2531 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
2534 TRUE, TRUE,
2535 0, 0, 513,
2536 0, 0
2539 TRUE, TRUE,
2540 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
2541 D3D10_BIND_CONSTANT_BUFFER, 0
2544 TRUE, TRUE,
2545 D3D11_BIND_SHADER_RESOURCE, 0, 513,
2546 D3D10_BIND_SHADER_RESOURCE, 0
2549 TRUE, TRUE,
2550 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
2551 D3D11_BIND_UNORDERED_ACCESS, 0
2554 FALSE, FALSE,
2555 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2558 FALSE, FALSE,
2559 D3D11_BIND_SHADER_RESOURCE,
2560 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2563 TRUE, TRUE,
2564 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
2565 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2569 if (!(device = create_device(NULL)))
2571 skip("Failed to create ID3D11Device.\n");
2572 return;
2575 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
2576 hr = check_interface(buffer, &IID_ID3D10Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
2577 ID3D11Buffer_Release(buffer);
2578 if (FAILED(hr))
2580 win_skip("Buffers do not implement ID3D10Buffer.\n");
2581 ID3D11Device_Release(device);
2582 return;
2585 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2587 const struct test *current = &tests[i];
2588 D3D11_BUFFER_DESC obtained_desc;
2589 D3D10_BUFFER_DESC d3d10_desc;
2590 ID3D10Device *d3d10_device;
2592 desc.ByteWidth = 1024;
2593 desc.Usage = D3D11_USAGE_DEFAULT;
2594 desc.BindFlags = current->bind_flags;
2595 desc.CPUAccessFlags = 0;
2596 desc.MiscFlags = current->misc_flags;
2597 desc.StructureByteStride = current->structure_stride;
2599 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2600 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
2601 /* Shared resources are not supported by REF and WARP devices. */
2602 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
2603 i, hr, expected_hr);
2604 if (FAILED(hr))
2606 if (hr == E_OUTOFMEMORY)
2607 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2608 continue;
2611 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
2612 desc.StructureByteStride = 0;
2614 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
2616 ok(obtained_desc.ByteWidth == desc.ByteWidth,
2617 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
2618 ok(obtained_desc.Usage == desc.Usage,
2619 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
2620 ok(obtained_desc.BindFlags == desc.BindFlags,
2621 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
2622 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
2623 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
2624 ok(obtained_desc.MiscFlags == desc.MiscFlags,
2625 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
2626 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
2627 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
2629 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2630 ID3D11Buffer_Release(buffer);
2632 if (current->implements_d3d10_interfaces)
2634 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
2636 else
2638 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
2639 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2640 continue;
2643 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
2645 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
2646 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
2647 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2648 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2649 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2650 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2651 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2652 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2653 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2654 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2656 d3d10_device = (ID3D10Device *)0xdeadbeef;
2657 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
2658 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2659 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2661 ID3D10Buffer_Release(d3d10_buffer);
2664 memset(&desc, 0, sizeof(desc));
2665 desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
2666 for (i = 0; i <= 32; ++i)
2668 desc.ByteWidth = i;
2669 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
2670 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2671 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
2672 if (SUCCEEDED(hr))
2673 ID3D11Buffer_Release(buffer);
2676 refcount = ID3D11Device_Release(device);
2677 ok(!refcount, "Device has %u references left.\n", refcount);
2680 static void test_create_depthstencil_view(void)
2682 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2683 D3D11_TEXTURE2D_DESC texture_desc;
2684 ULONG refcount, expected_refcount;
2685 ID3D11DepthStencilView *dsview;
2686 ID3D11Device *device, *tmp;
2687 ID3D11Texture2D *texture;
2688 unsigned int i;
2689 HRESULT hr;
2691 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2692 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2693 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2694 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
2695 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
2696 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
2697 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
2698 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
2699 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
2700 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
2701 static const struct
2703 struct
2705 unsigned int miplevel_count;
2706 unsigned int array_size;
2707 DXGI_FORMAT format;
2708 } texture;
2709 struct dsv_desc dsv_desc;
2710 struct dsv_desc expected_dsv_desc;
2712 tests[] =
2714 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2715 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2716 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2717 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2718 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2719 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2720 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2721 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2722 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2723 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2724 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2725 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2726 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2727 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2728 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2729 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2730 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2731 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2732 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2733 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2734 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2735 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2736 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2737 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2738 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2739 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2740 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2742 static const struct
2744 struct
2746 unsigned int miplevel_count;
2747 unsigned int array_size;
2748 DXGI_FORMAT format;
2749 } texture;
2750 struct dsv_desc dsv_desc;
2752 invalid_desc_tests[] =
2754 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2755 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2756 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2757 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2758 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2759 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2760 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2761 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2762 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2763 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2764 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2765 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2766 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2768 #undef FMT_UNKNOWN
2769 #undef D24S8
2770 #undef R24S8_TL
2771 #undef DIM_UNKNOWN
2772 #undef TEX_1D
2773 #undef TEX_1D_ARRAY
2774 #undef TEX_2D
2775 #undef TEX_2D_ARRAY
2776 #undef TEX_2DMS
2777 #undef TEX_2DMS_ARR
2779 if (!(device = create_device(NULL)))
2781 skip("Failed to create device.\n");
2782 return;
2785 texture_desc.Width = 512;
2786 texture_desc.Height = 512;
2787 texture_desc.MipLevels = 1;
2788 texture_desc.ArraySize = 1;
2789 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2790 texture_desc.SampleDesc.Count = 1;
2791 texture_desc.SampleDesc.Quality = 0;
2792 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2793 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2794 texture_desc.CPUAccessFlags = 0;
2795 texture_desc.MiscFlags = 0;
2797 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2798 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2800 expected_refcount = get_refcount(device) + 1;
2801 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
2802 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2803 refcount = get_refcount(device);
2804 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2805 tmp = NULL;
2806 expected_refcount = refcount + 1;
2807 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
2808 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2809 refcount = get_refcount(device);
2810 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2811 ID3D11Device_Release(tmp);
2813 memset(&dsv_desc, 0, sizeof(dsv_desc));
2814 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2815 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2816 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
2817 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2818 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
2819 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2821 ID3D11DepthStencilView_Release(dsview);
2822 ID3D11Texture2D_Release(texture);
2824 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2826 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
2828 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2829 texture_desc.ArraySize = tests[i].texture.array_size;
2830 texture_desc.Format = tests[i].texture.format;
2832 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2833 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2835 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
2837 current_desc = NULL;
2839 else
2841 current_desc = &dsv_desc;
2842 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2845 expected_refcount = get_refcount(texture);
2846 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
2847 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2848 refcount = get_refcount(texture);
2849 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2851 /* Not available on all Windows versions. */
2852 check_interface(dsview, &IID_ID3D10DepthStencilView, TRUE, TRUE);
2854 memset(&dsv_desc, 0, sizeof(dsv_desc));
2855 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2856 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2858 ID3D11DepthStencilView_Release(dsview);
2859 ID3D11Texture2D_Release(texture);
2862 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2864 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2865 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2866 texture_desc.Format = invalid_desc_tests[i].texture.format;
2868 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2869 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2871 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2872 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2873 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2875 ID3D11Texture2D_Release(texture);
2878 refcount = ID3D11Device_Release(device);
2879 ok(!refcount, "Device has %u references left.\n", refcount);
2882 static void test_depthstencil_view_interfaces(void)
2884 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
2885 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2886 ID3D10DepthStencilView *d3d10_dsview;
2887 D3D11_TEXTURE2D_DESC texture_desc;
2888 ID3D11DepthStencilView *dsview;
2889 ID3D11Texture2D *texture;
2890 ID3D11Device *device;
2891 ULONG refcount;
2892 HRESULT hr;
2894 if (!(device = create_device(NULL)))
2896 skip("Failed to create device.\n");
2897 return;
2900 texture_desc.Width = 512;
2901 texture_desc.Height = 512;
2902 texture_desc.MipLevels = 1;
2903 texture_desc.ArraySize = 1;
2904 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2905 texture_desc.SampleDesc.Count = 1;
2906 texture_desc.SampleDesc.Quality = 0;
2907 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2908 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2909 texture_desc.CPUAccessFlags = 0;
2910 texture_desc.MiscFlags = 0;
2912 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2913 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2915 dsv_desc.Format = texture_desc.Format;
2916 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
2917 dsv_desc.Flags = 0;
2918 U(dsv_desc).Texture2D.MipSlice = 0;
2920 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2921 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2923 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
2924 ID3D11DepthStencilView_Release(dsview);
2925 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2926 "Depth stencil view should implement ID3D10DepthStencilView.\n");
2928 if (FAILED(hr))
2930 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
2931 goto done;
2934 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
2935 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
2936 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
2937 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
2938 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2939 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
2941 ID3D10DepthStencilView_Release(d3d10_dsview);
2943 done:
2944 ID3D11Texture2D_Release(texture);
2946 refcount = ID3D11Device_Release(device);
2947 ok(!refcount, "Device has %u references left.\n", refcount);
2950 static void test_create_rendertarget_view(void)
2952 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
2953 D3D11_TEXTURE3D_DESC texture3d_desc;
2954 D3D11_TEXTURE2D_DESC texture2d_desc;
2955 D3D11_SUBRESOURCE_DATA data = {0};
2956 ULONG refcount, expected_refcount;
2957 D3D11_BUFFER_DESC buffer_desc;
2958 ID3D11RenderTargetView *rtview;
2959 ID3D11Device *device, *tmp;
2960 ID3D11Texture3D *texture3d;
2961 ID3D11Texture2D *texture2d;
2962 ID3D11Resource *texture;
2963 ID3D11Buffer *buffer;
2964 unsigned int i;
2965 HRESULT hr;
2967 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2968 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2969 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2970 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
2971 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
2972 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
2973 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
2974 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
2975 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
2976 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
2977 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
2978 static const struct
2980 struct
2982 unsigned int miplevel_count;
2983 unsigned int depth_or_array_size;
2984 DXGI_FORMAT format;
2985 } texture;
2986 struct rtv_desc rtv_desc;
2987 struct rtv_desc expected_rtv_desc;
2989 tests[] =
2991 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2992 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2993 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2994 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2995 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2996 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2997 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2998 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2999 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3000 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3001 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
3002 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
3003 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
3004 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
3005 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
3006 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
3007 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
3008 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3009 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3010 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3011 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3012 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3013 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3014 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3015 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3016 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3017 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3018 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3019 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3020 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3021 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
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, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
3024 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
3025 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
3026 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
3027 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3028 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3029 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
3030 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
3031 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
3032 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
3033 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
3034 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
3036 static const struct
3038 struct
3040 D3D11_RTV_DIMENSION dimension;
3041 unsigned int miplevel_count;
3042 unsigned int depth_or_array_size;
3043 DXGI_FORMAT format;
3044 } texture;
3045 struct rtv_desc rtv_desc;
3047 invalid_desc_tests[] =
3049 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3050 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3051 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3052 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3053 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
3054 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
3055 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
3056 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3057 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
3058 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
3059 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
3060 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
3061 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
3062 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
3063 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
3064 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3065 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3066 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3067 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3068 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3069 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3070 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3071 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3072 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
3073 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
3074 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3075 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3076 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
3077 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3078 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3079 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
3080 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
3081 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
3082 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
3083 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
3085 #undef FMT_UNKNOWN
3086 #undef RGBA8_UNORM
3087 #undef RGBA8_TL
3088 #undef DIM_UNKNOWN
3089 #undef TEX_1D
3090 #undef TEX_1D_ARRAY
3091 #undef TEX_2D
3092 #undef TEX_2D_ARRAY
3093 #undef TEX_2DMS
3094 #undef TEX_2DMS_ARR
3095 #undef TEX_3D
3097 if (!(device = create_device(NULL)))
3099 skip("Failed to create device.\n");
3100 return;
3103 buffer_desc.ByteWidth = 1024;
3104 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3105 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3106 buffer_desc.CPUAccessFlags = 0;
3107 buffer_desc.MiscFlags = 0;
3108 buffer_desc.StructureByteStride = 0;
3110 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
3111 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3113 expected_refcount = get_refcount(device) + 1;
3114 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3115 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3116 refcount = get_refcount(device);
3117 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3118 tmp = NULL;
3119 expected_refcount = refcount + 1;
3120 ID3D11Buffer_GetDevice(buffer, &tmp);
3121 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3122 refcount = get_refcount(device);
3123 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3124 ID3D11Device_Release(tmp);
3126 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3127 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
3128 U1(U(rtv_desc).Buffer).ElementOffset = 0;
3129 U2(U(rtv_desc).Buffer).ElementWidth = 64;
3131 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
3132 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3134 expected_refcount = get_refcount(device) + 1;
3135 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
3136 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
3137 refcount = get_refcount(device);
3138 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3139 tmp = NULL;
3140 expected_refcount = refcount + 1;
3141 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
3142 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3143 refcount = get_refcount(device);
3144 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3145 ID3D11Device_Release(tmp);
3147 /* Not available on all Windows versions. */
3148 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3150 ID3D11RenderTargetView_Release(rtview);
3151 ID3D11Buffer_Release(buffer);
3153 texture2d_desc.Width = 512;
3154 texture2d_desc.Height = 512;
3155 texture2d_desc.SampleDesc.Count = 1;
3156 texture2d_desc.SampleDesc.Quality = 0;
3157 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3158 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3159 texture2d_desc.CPUAccessFlags = 0;
3160 texture2d_desc.MiscFlags = 0;
3162 texture3d_desc.Width = 64;
3163 texture3d_desc.Height = 64;
3164 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3165 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3166 texture3d_desc.CPUAccessFlags = 0;
3167 texture3d_desc.MiscFlags = 0;
3169 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3171 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3173 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3175 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3176 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3177 texture2d_desc.Format = tests[i].texture.format;
3179 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3180 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3181 texture = (ID3D11Resource *)texture2d;
3183 else
3185 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3186 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3187 texture3d_desc.Format = tests[i].texture.format;
3189 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3190 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3191 texture = (ID3D11Resource *)texture3d;
3194 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
3196 current_desc = NULL;
3198 else
3200 current_desc = &rtv_desc;
3201 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3204 expected_refcount = get_refcount(texture);
3205 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3206 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3207 refcount = get_refcount(texture);
3208 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3210 /* Not available on all Windows versions. */
3211 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3213 memset(&rtv_desc, 0, sizeof(rtv_desc));
3214 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
3215 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3217 ID3D11RenderTargetView_Release(rtview);
3218 ID3D11Resource_Release(texture);
3221 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3223 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
3224 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
3226 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3228 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3229 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3230 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3232 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3233 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3234 texture = (ID3D11Resource *)texture2d;
3236 else
3238 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3239 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3240 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3242 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3243 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3244 texture = (ID3D11Resource *)texture3d;
3247 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3248 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3249 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3251 ID3D11Resource_Release(texture);
3254 refcount = ID3D11Device_Release(device);
3255 ok(!refcount, "Device has %u references left.\n", refcount);
3258 static void test_create_shader_resource_view(void)
3260 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
3261 D3D11_TEXTURE3D_DESC texture3d_desc;
3262 D3D11_TEXTURE2D_DESC texture2d_desc;
3263 ULONG refcount, expected_refcount;
3264 ID3D11ShaderResourceView *srview;
3265 D3D_FEATURE_LEVEL feature_level;
3266 D3D11_BUFFER_DESC buffer_desc;
3267 ID3D11Device *device, *tmp;
3268 ID3D11Texture3D *texture3d;
3269 ID3D11Texture2D *texture2d;
3270 ID3D11Resource *texture;
3271 ID3D11Buffer *buffer;
3272 unsigned int i;
3273 HRESULT hr;
3275 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3276 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3277 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3278 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
3279 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
3280 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
3281 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
3282 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
3283 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
3284 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
3285 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
3286 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
3287 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3288 static const struct
3290 struct
3292 unsigned int miplevel_count;
3293 unsigned int depth_or_array_size;
3294 DXGI_FORMAT format;
3295 } texture;
3296 struct srv_desc srv_desc;
3297 struct srv_desc expected_srv_desc;
3299 tests[] =
3301 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3302 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3303 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3304 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3305 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3306 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3307 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3308 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3309 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3310 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3311 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3312 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3313 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3314 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3315 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3316 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3317 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3318 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3319 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3320 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3321 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3322 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3323 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3324 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3325 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3326 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3327 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3328 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3329 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3330 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3331 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3332 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3333 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3334 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3335 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3336 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3337 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3338 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3339 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3340 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3341 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3342 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3343 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3344 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3345 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3346 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
3348 static const struct
3350 struct
3352 D3D11_SRV_DIMENSION dimension;
3353 unsigned int miplevel_count;
3354 unsigned int depth_or_array_size;
3355 DXGI_FORMAT format;
3356 } texture;
3357 struct srv_desc srv_desc;
3359 invalid_desc_tests[] =
3361 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3362 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3363 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3364 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3365 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3366 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3367 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3368 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3369 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3370 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3371 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3372 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3373 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3374 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3375 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3376 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3377 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3378 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3379 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3380 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3381 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3382 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3383 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3384 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3385 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
3386 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
3387 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3388 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3389 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3390 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
3391 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
3392 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
3393 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
3394 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
3395 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3396 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3397 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3398 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3399 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3400 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3401 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3402 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3403 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3404 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3405 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3406 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3407 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3408 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3409 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3410 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3411 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3412 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3414 #undef FMT_UNKNOWN
3415 #undef RGBA8_UNORM
3416 #undef DIM_UNKNOWN
3417 #undef TEX_1D
3418 #undef TEX_1D_ARRAY
3419 #undef TEX_2D
3420 #undef TEX_2D_ARRAY
3421 #undef TEX_2DMS
3422 #undef TEX_2DMS_ARR
3423 #undef TEX_3D
3424 #undef TEX_CUBE
3425 #undef CUBE_ARRAY
3427 if (!(device = create_device(NULL)))
3429 skip("Failed to create device.\n");
3430 return;
3432 feature_level = ID3D11Device_GetFeatureLevel(device);
3434 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
3436 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3437 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3439 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3440 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
3441 U1(U(srv_desc).Buffer).ElementOffset = 0;
3442 U2(U(srv_desc).Buffer).ElementWidth = 64;
3444 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
3445 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3447 expected_refcount = get_refcount(device) + 1;
3448 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
3449 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
3450 refcount = get_refcount(device);
3451 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3452 tmp = NULL;
3453 expected_refcount = refcount + 1;
3454 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
3455 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3456 refcount = get_refcount(device);
3457 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3458 ID3D11Device_Release(tmp);
3460 /* Not available on all Windows versions. */
3461 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
3462 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3464 ID3D11ShaderResourceView_Release(srview);
3465 ID3D11Buffer_Release(buffer);
3467 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
3469 buffer_desc.ByteWidth = 1024;
3470 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3471 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3472 buffer_desc.CPUAccessFlags = 0;
3473 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
3474 buffer_desc.StructureByteStride = 4;
3476 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3477 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3479 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3480 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
3482 memset(&srv_desc, 0, sizeof(srv_desc));
3483 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3485 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
3486 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
3487 srv_desc.ViewDimension);
3488 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
3489 U1(U(srv_desc).Buffer).FirstElement);
3490 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
3491 U2(U(srv_desc).Buffer).NumElements);
3493 ID3D11ShaderResourceView_Release(srview);
3494 ID3D11Buffer_Release(buffer);
3496 else
3498 skip("Structured buffers require feature level 11_0.\n");
3501 texture2d_desc.Width = 512;
3502 texture2d_desc.Height = 512;
3503 texture2d_desc.SampleDesc.Count = 1;
3504 texture2d_desc.SampleDesc.Quality = 0;
3505 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3506 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3507 texture2d_desc.CPUAccessFlags = 0;
3509 texture3d_desc.Width = 64;
3510 texture3d_desc.Height = 64;
3511 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3512 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3513 texture3d_desc.CPUAccessFlags = 0;
3514 texture3d_desc.MiscFlags = 0;
3516 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3518 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
3520 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
3522 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3523 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3524 texture2d_desc.Format = tests[i].texture.format;
3525 texture2d_desc.MiscFlags = 0;
3527 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3528 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3529 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3531 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
3532 && (texture2d_desc.ArraySize != 6
3533 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3534 && feature_level < D3D_FEATURE_LEVEL_10_1)
3536 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3537 continue;
3540 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3541 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3542 texture = (ID3D11Resource *)texture2d;
3544 else
3546 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3547 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3548 texture3d_desc.Format = tests[i].texture.format;
3550 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3551 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3552 texture = (ID3D11Resource *)texture3d;
3555 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
3557 current_desc = NULL;
3559 else
3561 current_desc = &srv_desc;
3562 get_srv_desc(current_desc, &tests[i].srv_desc);
3565 expected_refcount = get_refcount(texture);
3566 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3567 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3568 refcount = get_refcount(texture);
3569 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3571 /* Not available on all Windows versions. */
3572 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
3573 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3575 memset(&srv_desc, 0, sizeof(srv_desc));
3576 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3577 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3579 ID3D11ShaderResourceView_Release(srview);
3580 ID3D11Resource_Release(texture);
3583 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3585 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
3586 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
3588 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
3590 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3591 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3592 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3593 texture2d_desc.MiscFlags = 0;
3595 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3596 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3597 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3599 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3600 && feature_level < D3D_FEATURE_LEVEL_10_1)
3602 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3603 continue;
3606 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3607 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3608 texture = (ID3D11Resource *)texture2d;
3610 else
3612 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3613 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3614 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3616 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3617 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3618 texture = (ID3D11Resource *)texture3d;
3621 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3622 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3623 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3625 ID3D11Resource_Release(texture);
3628 refcount = ID3D11Device_Release(device);
3629 ok(!refcount, "Device has %u references left.\n", refcount);
3632 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
3634 #if 0
3635 float4 light;
3636 float4x4 mat;
3638 struct input
3640 float4 position : POSITION;
3641 float3 normal : NORMAL;
3644 struct output
3646 float4 position : POSITION;
3647 float4 diffuse : COLOR;
3650 output main(const input v)
3652 output o;
3654 o.position = mul(v.position, mat);
3655 o.diffuse = dot((float3)light, v.normal);
3657 return o;
3659 #endif
3660 static const DWORD vs_4_1[] =
3662 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
3663 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
3664 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
3665 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
3666 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3667 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
3668 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
3669 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3670 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
3671 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
3672 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
3673 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
3674 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
3675 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
3676 0x0100003e,
3678 static const DWORD vs_4_0[] =
3680 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3681 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3682 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3683 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3684 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3685 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3686 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3687 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3688 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3689 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3690 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3691 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3692 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3693 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3694 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3695 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3697 static const DWORD vs_3_0[] =
3699 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3700 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3701 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3702 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3703 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3704 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3705 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3706 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3707 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3708 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3709 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3710 0x0000ffff,
3712 static const DWORD vs_2_0[] =
3714 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3715 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3716 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3717 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3718 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3719 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3720 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3721 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3722 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3723 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3724 0x90e40001, 0x0000ffff,
3727 #if 0
3728 float4 main(const float4 color : COLOR) : SV_TARGET
3730 float4 o;
3732 o = color;
3734 return o;
3736 #endif
3737 static const DWORD ps_4_1[] =
3739 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
3740 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3741 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3742 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3743 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
3744 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3745 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3747 static const DWORD ps_4_0[] =
3749 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
3750 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3751 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3752 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3753 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3754 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3755 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3757 static const DWORD ps_4_0_level_9_0[] =
3759 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
3760 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
3761 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
3762 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
3763 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
3764 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
3765 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
3766 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
3767 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3768 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
3769 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3770 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3771 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
3772 0xabab0054,
3774 static const DWORD ps_4_0_level_9_1[] =
3776 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
3777 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3778 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3779 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3780 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3781 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3782 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3783 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3784 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3785 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3786 0x45475241, 0xabab0054,
3788 static const DWORD ps_4_0_level_9_3[] =
3790 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
3791 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3792 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3793 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3794 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3795 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3796 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3797 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3798 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3799 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3800 0x45475241, 0xabab0054,
3803 #if 0
3804 struct gs_out
3806 float4 pos : SV_POSITION;
3809 [maxvertexcount(4)]
3810 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3812 float offset = 0.1 * vin[0].w;
3813 gs_out v;
3815 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3816 vout.Append(v);
3817 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3818 vout.Append(v);
3819 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3820 vout.Append(v);
3821 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3822 vout.Append(v);
3824 #endif
3825 static const DWORD gs_4_1[] =
3827 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
3828 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3829 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3830 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3831 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
3832 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
3833 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
3834 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
3835 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
3836 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3837 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
3838 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3839 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
3840 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3841 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
3842 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3843 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
3844 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3846 static const DWORD gs_4_0[] =
3848 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3849 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3850 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3851 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3852 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3853 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3854 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3855 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3856 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3857 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3858 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3859 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3860 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3861 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3862 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3863 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3864 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3865 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3868 ULONG refcount, expected_refcount;
3869 struct device_desc device_desc;
3870 ID3D11Device *device, *tmp;
3871 ID3D11GeometryShader *gs;
3872 ID3D11VertexShader *vs;
3873 ID3D11PixelShader *ps;
3874 HRESULT hr;
3876 device_desc.feature_level = &feature_level;
3877 device_desc.flags = 0;
3878 if (!(device = create_device(&device_desc)))
3880 skip("Failed to create device for feature level %#x.\n", feature_level);
3881 return;
3884 /* level_9 shaders */
3885 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
3886 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3887 ID3D11PixelShader_Release(ps);
3889 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
3890 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3891 ID3D11PixelShader_Release(ps);
3893 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
3894 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3895 ID3D11PixelShader_Release(ps);
3897 /* vertex shader */
3898 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
3899 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3901 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
3902 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3904 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
3905 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
3906 hr, feature_level);
3908 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3909 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
3910 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3911 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3912 else
3913 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3915 refcount = get_refcount(device);
3916 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3917 refcount, expected_refcount);
3918 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3920 tmp = NULL;
3921 expected_refcount = refcount + 1;
3922 ID3D11VertexShader_GetDevice(vs, &tmp);
3923 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3924 refcount = get_refcount(device);
3925 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3926 refcount, expected_refcount);
3927 ID3D11Device_Release(tmp);
3929 /* Not available on all Windows versions. */
3930 check_interface(vs, &IID_ID3D10VertexShader, TRUE, TRUE);
3932 refcount = ID3D11VertexShader_Release(vs);
3933 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3936 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
3937 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3939 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3940 hr, feature_level);
3941 refcount = ID3D11VertexShader_Release(vs);
3942 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3944 else
3946 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3947 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3948 hr, feature_level);
3949 if (SUCCEEDED(hr))
3950 ID3D11VertexShader_Release(vs);
3953 /* pixel shader */
3954 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3955 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
3956 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3957 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3958 else
3959 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3961 refcount = get_refcount(device);
3962 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3963 refcount, expected_refcount);
3964 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3966 tmp = NULL;
3967 expected_refcount = refcount + 1;
3968 ID3D11PixelShader_GetDevice(ps, &tmp);
3969 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3970 refcount = get_refcount(device);
3971 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3972 refcount, expected_refcount);
3973 ID3D11Device_Release(tmp);
3975 /* Not available on all Windows versions. */
3976 check_interface(ps, &IID_ID3D10PixelShader, TRUE, TRUE);
3978 refcount = ID3D11PixelShader_Release(ps);
3979 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3982 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
3983 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3985 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
3986 hr, feature_level);
3987 refcount = ID3D11PixelShader_Release(ps);
3988 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3990 else
3992 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3993 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3994 if (SUCCEEDED(hr))
3995 ID3D11PixelShader_Release(ps);
3998 /* geometry shader */
3999 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4000 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
4001 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4002 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4003 else
4004 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4006 refcount = get_refcount(device);
4007 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4008 refcount, expected_refcount);
4009 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4011 tmp = NULL;
4012 expected_refcount = refcount + 1;
4013 ID3D11GeometryShader_GetDevice(gs, &tmp);
4014 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4015 refcount = get_refcount(device);
4016 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4017 refcount, expected_refcount);
4018 ID3D11Device_Release(tmp);
4020 /* Not available on all Windows versions. */
4021 check_interface(gs, &IID_ID3D10GeometryShader, TRUE, TRUE);
4023 refcount = ID3D11GeometryShader_Release(gs);
4024 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4027 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
4028 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4030 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4031 hr, feature_level);
4032 refcount = ID3D11GeometryShader_Release(gs);
4033 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4035 else
4037 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4038 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4039 hr, feature_level);
4040 if (SUCCEEDED(hr))
4041 ID3D11GeometryShader_Release(gs);
4044 refcount = ID3D11Device_Release(device);
4045 ok(!refcount, "Device has %u references left.\n", refcount);
4048 static void test_create_sampler_state(void)
4050 static const struct test
4052 D3D11_FILTER filter;
4053 D3D10_FILTER expected_filter;
4055 desc_conversion_tests[] =
4057 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
4058 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
4059 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
4060 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
4061 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
4062 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
4063 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
4064 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
4065 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
4066 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
4067 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
4069 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
4070 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
4072 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
4073 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
4075 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
4076 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
4078 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
4079 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
4080 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
4083 ID3D11SamplerState *sampler_state1, *sampler_state2;
4084 ID3D10SamplerState *d3d10_sampler_state;
4085 ULONG refcount, expected_refcount;
4086 ID3D11Device *device, *tmp;
4087 D3D11_SAMPLER_DESC desc;
4088 unsigned int i;
4089 HRESULT hr;
4091 if (!(device = create_device(NULL)))
4093 skip("Failed to create device.\n");
4094 return;
4097 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
4098 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4100 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
4101 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4102 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4103 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
4104 desc.MipLODBias = 0.0f;
4105 desc.MaxAnisotropy = 16;
4106 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4107 desc.BorderColor[0] = 0.0f;
4108 desc.BorderColor[1] = 1.0f;
4109 desc.BorderColor[2] = 0.0f;
4110 desc.BorderColor[3] = 1.0f;
4111 desc.MinLOD = 0.0f;
4112 desc.MaxLOD = 16.0f;
4114 expected_refcount = get_refcount(device) + 1;
4115 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4116 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4117 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
4118 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4119 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4120 refcount = get_refcount(device);
4121 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4122 tmp = NULL;
4123 expected_refcount = refcount + 1;
4124 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
4125 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4126 refcount = get_refcount(device);
4127 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4128 ID3D11Device_Release(tmp);
4130 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
4131 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4132 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4133 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4134 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4135 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4136 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4137 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4138 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4139 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4140 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4141 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4142 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4144 refcount = ID3D11SamplerState_Release(sampler_state2);
4145 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4146 refcount = ID3D11SamplerState_Release(sampler_state1);
4147 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4149 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4151 const struct test *current = &desc_conversion_tests[i];
4152 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4154 desc.Filter = current->filter;
4155 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4156 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4157 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4158 desc.MipLODBias = 0.0f;
4159 desc.MaxAnisotropy = 16;
4160 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4161 desc.BorderColor[0] = 0.0f;
4162 desc.BorderColor[1] = 1.0f;
4163 desc.BorderColor[2] = 0.0f;
4164 desc.BorderColor[3] = 1.0f;
4165 desc.MinLOD = 0.0f;
4166 desc.MaxLOD = 16.0f;
4168 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4169 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4171 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
4172 (void **)&d3d10_sampler_state);
4173 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4174 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4175 if (FAILED(hr))
4177 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
4178 ID3D11SamplerState_Release(sampler_state1);
4179 break;
4182 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4183 expected_desc.Filter = current->expected_filter;
4184 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4185 expected_desc.MaxAnisotropy = 0;
4186 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4187 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4189 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
4190 ok(d3d10_desc.Filter == expected_desc.Filter,
4191 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
4192 ok(d3d10_desc.AddressU == expected_desc.AddressU,
4193 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
4194 ok(d3d10_desc.AddressV == expected_desc.AddressV,
4195 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
4196 ok(d3d10_desc.AddressW == expected_desc.AddressW,
4197 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
4198 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
4199 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
4200 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4201 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
4202 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4203 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
4204 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
4205 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
4206 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
4207 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
4208 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4209 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
4210 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
4211 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
4212 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
4213 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
4214 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
4216 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
4217 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4218 refcount = ID3D11SamplerState_Release(sampler_state1);
4219 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4222 refcount = ID3D11Device_Release(device);
4223 ok(!refcount, "Device has %u references left.\n", refcount);
4226 static void test_create_blend_state(void)
4228 static const D3D11_BLEND_DESC desc_conversion_tests[] =
4231 FALSE, FALSE,
4234 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4235 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
4240 FALSE, TRUE,
4243 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4244 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4247 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4248 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
4251 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4252 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4255 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4256 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
4259 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4260 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4263 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4264 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4267 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4268 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4271 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4272 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4277 FALSE, TRUE,
4280 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4281 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4284 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
4285 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4288 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
4289 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4292 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4293 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4296 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
4297 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4300 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
4301 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4304 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4305 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4308 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4309 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4315 ID3D11BlendState *blend_state1, *blend_state2;
4316 D3D11_BLEND_DESC desc, obtained_desc;
4317 ID3D10BlendState *d3d10_blend_state;
4318 D3D10_BLEND_DESC d3d10_blend_desc;
4319 ULONG refcount, expected_refcount;
4320 ID3D11Device *device, *tmp;
4321 unsigned int i, j;
4322 HRESULT hr;
4324 if (!(device = create_device(NULL)))
4326 skip("Failed to create device.\n");
4327 return;
4330 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
4331 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4333 memset(&desc, 0, sizeof(desc));
4334 desc.AlphaToCoverageEnable = FALSE;
4335 desc.IndependentBlendEnable = FALSE;
4336 desc.RenderTarget[0].BlendEnable = FALSE;
4337 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
4338 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
4339 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
4340 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
4341 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
4342 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
4343 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
4345 expected_refcount = get_refcount(device) + 1;
4346 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
4347 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4348 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
4349 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4350 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4351 refcount = get_refcount(device);
4352 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4353 tmp = NULL;
4354 expected_refcount = refcount + 1;
4355 ID3D11BlendState_GetDevice(blend_state1, &tmp);
4356 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4357 refcount = get_refcount(device);
4358 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4359 ID3D11Device_Release(tmp);
4361 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
4362 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
4363 obtained_desc.AlphaToCoverageEnable);
4364 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
4365 obtained_desc.IndependentBlendEnable);
4366 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4368 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
4369 "Got unexpected blend enable %#x for render target %u.\n",
4370 obtained_desc.RenderTarget[i].BlendEnable, i);
4371 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
4372 "Got unexpected src blend %u for render target %u.\n",
4373 obtained_desc.RenderTarget[i].SrcBlend, i);
4374 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
4375 "Got unexpected dest blend %u for render target %u.\n",
4376 obtained_desc.RenderTarget[i].DestBlend, i);
4377 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
4378 "Got unexpected blend op %u for render target %u.\n",
4379 obtained_desc.RenderTarget[i].BlendOp, i);
4380 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
4381 "Got unexpected src blend alpha %u for render target %u.\n",
4382 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
4383 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
4384 "Got unexpected dest blend alpha %u for render target %u.\n",
4385 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
4386 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
4387 "Got unexpected blend op alpha %u for render target %u.\n",
4388 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
4389 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
4390 "Got unexpected render target write mask %#x for render target %u.\n",
4391 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
4394 /* Not available on all Windows versions. */
4395 check_interface(blend_state1, &IID_ID3D10BlendState, TRUE, TRUE);
4396 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
4398 refcount = ID3D11BlendState_Release(blend_state1);
4399 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4400 refcount = ID3D11BlendState_Release(blend_state2);
4401 ok(!refcount, "Blend state has %u references left.\n", refcount);
4403 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4405 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
4407 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
4408 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4410 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
4411 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4412 "Blend state should implement ID3D10BlendState.\n");
4413 if (FAILED(hr))
4415 win_skip("Blend state does not implement ID3D10BlendState.\n");
4416 ID3D11BlendState_Release(blend_state1);
4417 break;
4420 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
4421 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
4422 "Got unexpected alpha to coverage enable %#x for test %u.\n",
4423 d3d10_blend_desc.AlphaToCoverageEnable, i);
4424 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
4425 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
4426 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
4427 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
4428 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
4429 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
4430 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
4431 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
4432 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
4433 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
4434 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
4435 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
4436 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
4438 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
4439 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
4440 "Got unexpected blend enable %#x for test %u, render target %u.\n",
4441 d3d10_blend_desc.BlendEnable[j], i, j);
4442 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
4443 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
4444 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
4447 ID3D10BlendState_Release(d3d10_blend_state);
4449 refcount = ID3D11BlendState_Release(blend_state1);
4450 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4453 refcount = ID3D11Device_Release(device);
4454 ok(!refcount, "Device has %u references left.\n", refcount);
4457 static void test_create_depthstencil_state(void)
4459 ID3D11DepthStencilState *ds_state1, *ds_state2;
4460 ULONG refcount, expected_refcount;
4461 D3D11_DEPTH_STENCIL_DESC ds_desc;
4462 ID3D11Device *device, *tmp;
4463 HRESULT hr;
4465 if (!(device = create_device(NULL)))
4467 skip("Failed to create device.\n");
4468 return;
4471 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
4472 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4474 ds_desc.DepthEnable = TRUE;
4475 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
4476 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
4477 ds_desc.StencilEnable = FALSE;
4478 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
4479 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
4480 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4481 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4482 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4483 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4484 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4485 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4486 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4487 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4489 expected_refcount = get_refcount(device) + 1;
4490 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4491 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4492 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4493 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4494 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4495 refcount = get_refcount(device);
4496 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4497 tmp = NULL;
4498 expected_refcount = refcount + 1;
4499 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
4500 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4501 refcount = get_refcount(device);
4502 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4503 ID3D11Device_Release(tmp);
4505 /* Not available on all Windows versions. */
4506 check_interface(ds_state1, &IID_ID3D10DepthStencilState, TRUE, TRUE);
4508 refcount = ID3D11DepthStencilState_Release(ds_state2);
4509 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4510 refcount = ID3D11DepthStencilState_Release(ds_state1);
4511 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4513 ds_desc.DepthEnable = FALSE;
4514 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
4515 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
4516 ds_desc.StencilEnable = FALSE;
4517 ds_desc.StencilReadMask = 0;
4518 ds_desc.StencilWriteMask = 0;
4519 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
4520 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
4521 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
4522 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
4523 ds_desc.BackFace = ds_desc.FrontFace;
4525 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4526 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4528 memset(&ds_desc, 0, sizeof(ds_desc));
4529 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
4530 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4531 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
4532 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4533 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4534 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4535 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
4536 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4537 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
4538 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4539 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4540 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4541 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4542 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4543 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4544 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4545 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4546 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4547 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4548 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4549 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4550 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4551 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4552 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4553 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4554 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4556 ID3D11DepthStencilState_Release(ds_state1);
4558 refcount = ID3D11Device_Release(device);
4559 ok(!refcount, "Device has %u references left.\n", refcount);
4562 static void test_create_rasterizer_state(void)
4564 ID3D11RasterizerState *rast_state1, *rast_state2;
4565 ID3D10RasterizerState *d3d10_rast_state;
4566 ULONG refcount, expected_refcount;
4567 D3D10_RASTERIZER_DESC d3d10_desc;
4568 D3D11_RASTERIZER_DESC desc;
4569 ID3D11Device *device, *tmp;
4570 HRESULT hr;
4572 if (!(device = create_device(NULL)))
4574 skip("Failed to create device.\n");
4575 return;
4578 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
4579 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4581 desc.FillMode = D3D11_FILL_SOLID;
4582 desc.CullMode = D3D11_CULL_BACK;
4583 desc.FrontCounterClockwise = FALSE;
4584 desc.DepthBias = 0;
4585 desc.DepthBiasClamp = 0.0f;
4586 desc.SlopeScaledDepthBias = 0.0f;
4587 desc.DepthClipEnable = TRUE;
4588 desc.ScissorEnable = FALSE;
4589 desc.MultisampleEnable = FALSE;
4590 desc.AntialiasedLineEnable = FALSE;
4592 expected_refcount = get_refcount(device) + 1;
4593 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
4594 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4595 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
4596 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4597 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4598 refcount = get_refcount(device);
4599 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4600 tmp = NULL;
4601 expected_refcount = refcount + 1;
4602 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
4603 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4604 refcount = get_refcount(device);
4605 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4606 ID3D11Device_Release(tmp);
4608 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
4609 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4610 "Rasterizer state should implement ID3D10RasterizerState.\n");
4611 if (SUCCEEDED(hr))
4613 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
4614 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
4615 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
4616 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
4617 d3d10_desc.FrontCounterClockwise);
4618 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
4619 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
4620 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
4621 d3d10_desc.SlopeScaledDepthBias);
4622 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
4623 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
4624 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
4625 d3d10_desc.MultisampleEnable);
4626 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
4627 d3d10_desc.AntialiasedLineEnable);
4629 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
4630 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4633 refcount = ID3D11RasterizerState_Release(rast_state2);
4634 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4635 refcount = ID3D11RasterizerState_Release(rast_state1);
4636 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4638 refcount = ID3D11Device_Release(device);
4639 ok(!refcount, "Device has %u references left.\n", refcount);
4642 static void test_create_query(void)
4644 static const struct
4646 D3D11_QUERY query;
4647 D3D_FEATURE_LEVEL required_feature_level;
4648 BOOL is_predicate;
4649 BOOL can_use_create_predicate;
4650 BOOL todo;
4652 tests[] =
4654 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4655 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4656 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4657 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4658 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4659 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
4660 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4661 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
4662 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
4663 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4664 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
4665 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4666 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
4667 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4668 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
4669 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4672 ULONG refcount, expected_refcount;
4673 D3D_FEATURE_LEVEL feature_level;
4674 D3D11_QUERY_DESC query_desc;
4675 ID3D11Predicate *predicate;
4676 ID3D11Device *device, *tmp;
4677 HRESULT hr, expected_hr;
4678 ID3D11Query *query;
4679 unsigned int i;
4681 if (!(device = create_device(NULL)))
4683 skip("Failed to create device.\n");
4684 return;
4686 feature_level = ID3D11Device_GetFeatureLevel(device);
4688 hr = ID3D11Device_CreateQuery(device, NULL, &query);
4689 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4690 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
4691 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4693 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4695 if (tests[i].required_feature_level > feature_level)
4697 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
4698 continue;
4701 query_desc.Query = tests[i].query;
4702 query_desc.MiscFlags = 0;
4704 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
4705 todo_wine_if(tests[i].todo)
4706 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4708 query_desc.Query = tests[i].query;
4709 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
4710 todo_wine_if(tests[i].todo)
4711 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4712 if (FAILED(hr))
4713 continue;
4715 check_interface(query, &IID_ID3D11Predicate, tests[i].is_predicate, FALSE);
4716 ID3D11Query_Release(query);
4718 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
4719 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
4720 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4722 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
4723 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4724 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4725 if (SUCCEEDED(hr))
4726 ID3D11Predicate_Release(predicate);
4729 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
4730 expected_refcount = get_refcount(device) + 1;
4731 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4732 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4733 refcount = get_refcount(device);
4734 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4735 tmp = NULL;
4736 expected_refcount = refcount + 1;
4737 ID3D11Predicate_GetDevice(predicate, &tmp);
4738 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4739 refcount = get_refcount(device);
4740 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4741 ID3D11Device_Release(tmp);
4742 /* Not available on all Windows versions. */
4743 check_interface(predicate, &IID_ID3D10Predicate, TRUE, TRUE);
4744 ID3D11Predicate_Release(predicate);
4746 refcount = ID3D11Device_Release(device);
4747 ok(!refcount, "Device has %u references left.\n", refcount);
4750 #define get_query_data(a, b, c, d) get_query_data_(__LINE__, a, b, c, d)
4751 static void get_query_data_(unsigned int line, ID3D11DeviceContext *context,
4752 ID3D11Asynchronous *query, void *data, unsigned int data_size)
4754 unsigned int i;
4755 HRESULT hr;
4757 for (i = 0; i < 500; ++i)
4759 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4760 break;
4761 Sleep(10);
4763 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4764 memset(data, 0xff, data_size);
4765 hr = ID3D11DeviceContext_GetData(context, query, data, data_size, 0);
4766 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4769 static void test_occlusion_query(void)
4771 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4772 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4774 struct d3d11_test_context test_context;
4775 D3D11_TEXTURE2D_DESC texture_desc;
4776 ID3D11DeviceContext *context;
4777 ID3D11RenderTargetView *rtv;
4778 D3D11_QUERY_DESC query_desc;
4779 ID3D11Asynchronous *query;
4780 unsigned int data_size, i;
4781 ID3D11Texture2D *texture;
4782 ID3D11Device *device;
4783 D3D11_VIEWPORT vp;
4784 union
4786 UINT64 uint;
4787 DWORD dword[2];
4788 } data;
4789 HRESULT hr;
4791 if (!init_test_context(&test_context, NULL))
4792 return;
4794 device = test_context.device;
4795 context = test_context.immediate_context;
4797 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4799 query_desc.Query = D3D11_QUERY_OCCLUSION;
4800 query_desc.MiscFlags = 0;
4801 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4802 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4803 data_size = ID3D11Asynchronous_GetDataSize(query);
4804 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4806 memset(&data, 0xff, sizeof(data));
4807 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4808 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4809 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4810 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4811 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4812 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4814 ID3D11DeviceContext_End(context, query);
4815 ID3D11DeviceContext_Begin(context, query);
4816 ID3D11DeviceContext_Begin(context, query);
4818 memset(&data, 0xff, sizeof(data));
4819 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4820 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4821 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4822 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4823 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4824 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4826 draw_color_quad(&test_context, &red);
4828 ID3D11DeviceContext_End(context, query);
4829 get_query_data(context, query, &data, sizeof(data));
4830 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4832 memset(&data, 0xff, sizeof(data));
4833 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
4834 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4835 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
4836 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4837 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
4838 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4839 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
4840 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4841 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4842 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4844 memset(&data, 0xff, sizeof(data));
4845 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
4846 ok(hr == S_OK, "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 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
4851 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4852 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
4853 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4855 ID3D11DeviceContext_Begin(context, query);
4856 ID3D11DeviceContext_End(context, query);
4857 ID3D11DeviceContext_End(context, query);
4859 get_query_data(context, query, &data, sizeof(data));
4860 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4861 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4862 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4864 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4865 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4866 texture_desc.MipLevels = 1;
4867 texture_desc.ArraySize = 1;
4868 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4869 texture_desc.SampleDesc.Count = 1;
4870 texture_desc.SampleDesc.Quality = 0;
4871 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4872 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4873 texture_desc.CPUAccessFlags = 0;
4874 texture_desc.MiscFlags = 0;
4875 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4876 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4877 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
4878 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4880 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
4881 vp.TopLeftX = 0.0f;
4882 vp.TopLeftY = 0.0f;
4883 vp.Width = texture_desc.Width;
4884 vp.Height = texture_desc.Height;
4885 vp.MinDepth = 0.0f;
4886 vp.MaxDepth = 1.0f;
4887 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4889 ID3D11DeviceContext_Begin(context, query);
4890 for (i = 0; i < 100; i++)
4891 draw_color_quad(&test_context, &red);
4892 ID3D11DeviceContext_End(context, query);
4894 get_query_data(context, query, &data, sizeof(data));
4895 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4896 || (data.dword[0] == 0xffffffff && !data.dword[1])
4897 || broken(!data.uint),
4898 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4899 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4900 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4902 ID3D11Asynchronous_Release(query);
4904 /* The following test exercises a code path in wined3d. A wined3d context
4905 * associated with the query is destroyed when the swapchain is released. */
4906 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4907 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4909 vp.Width = 64.0f;
4910 vp.Height = 64.0f;
4911 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4912 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4913 ID3D11DeviceContext_Begin(context, query);
4914 draw_color_quad(&test_context, &red);
4915 ID3D11DeviceContext_End(context, query);
4917 ID3D11RenderTargetView_Release(test_context.backbuffer_rtv);
4918 ID3D11Texture2D_Release(test_context.backbuffer);
4919 IDXGISwapChain_Release(test_context.swapchain);
4920 test_context.swapchain = create_swapchain(device, test_context.window, NULL);
4921 hr = IDXGISwapChain_GetBuffer(test_context.swapchain, 0, &IID_ID3D11Texture2D,
4922 (void **)&test_context.backbuffer);
4923 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
4924 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer,
4925 NULL, &test_context.backbuffer_rtv);
4926 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4927 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
4928 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4930 get_query_data(context, query, &data, sizeof(data));
4931 /* This test occasionally succeeds with CSMT enabled because of a race condition. */
4932 if (0)
4933 todo_wine ok(data.dword[0] == 0x1000 && !data.dword[1],
4934 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4936 ID3D11Asynchronous_Release(query);
4937 ID3D11RenderTargetView_Release(rtv);
4938 ID3D11Texture2D_Release(texture);
4939 release_test_context(&test_context);
4942 static void test_pipeline_statistics_query(void)
4944 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4945 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4947 D3D11_QUERY_DATA_PIPELINE_STATISTICS data;
4948 struct d3d11_test_context test_context;
4949 ID3D11DeviceContext *context;
4950 D3D11_QUERY_DESC query_desc;
4951 ID3D11Asynchronous *query;
4952 unsigned int data_size;
4953 ID3D11Device *device;
4954 HRESULT hr;
4956 if (!init_test_context(&test_context, NULL))
4957 return;
4959 device = test_context.device;
4960 context = test_context.immediate_context;
4962 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4964 query_desc.Query = D3D11_QUERY_PIPELINE_STATISTICS;
4965 query_desc.MiscFlags = 0;
4966 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4967 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4968 data_size = ID3D11Asynchronous_GetDataSize(query);
4969 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4971 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4972 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4973 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4974 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4976 ID3D11DeviceContext_End(context, query);
4977 ID3D11DeviceContext_Begin(context, query);
4978 ID3D11DeviceContext_Begin(context, query);
4980 memset(&data, 0xff, sizeof(data));
4981 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4982 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4983 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4984 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4985 ok(data.IAVertices == ~(UINT64)0, "Data was modified.\n");
4987 draw_quad(&test_context);
4989 ID3D11DeviceContext_End(context, query);
4990 get_query_data(context, query, &data, sizeof(data));
4991 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
4992 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
4993 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
4994 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
4995 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
4996 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
4997 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
4998 todo_wine
4999 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5000 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5001 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5002 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5004 ID3D11DeviceContext_Begin(context, query);
5005 draw_color_quad(&test_context, &red);
5006 ID3D11DeviceContext_End(context, query);
5007 get_query_data(context, query, &data, sizeof(data));
5008 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5009 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5010 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5011 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5012 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5013 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5014 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5015 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5016 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5017 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5018 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5020 ID3D11Asynchronous_Release(query);
5021 release_test_context(&test_context);
5024 static void test_timestamp_query(void)
5026 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5028 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
5029 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
5030 struct d3d11_test_context test_context;
5031 ID3D11DeviceContext *context;
5032 D3D11_QUERY_DESC query_desc;
5033 unsigned int data_size;
5034 ID3D11Device *device;
5035 UINT64 timestamp;
5036 HRESULT hr;
5038 if (!init_test_context(&test_context, NULL))
5039 return;
5041 device = test_context.device;
5042 context = test_context.immediate_context;
5044 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5045 query_desc.MiscFlags = 0;
5046 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5047 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5048 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
5049 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
5051 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
5052 query_desc.MiscFlags = 0;
5053 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
5054 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5055 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
5056 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
5058 disjoint.Frequency = 0xdeadbeef;
5059 disjoint.Disjoint = 0xdeadbeef;
5060 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5061 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5062 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5063 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5064 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5065 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5067 /* Test a TIMESTAMP_DISJOINT query. */
5068 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5070 disjoint.Frequency = 0xdeadbeef;
5071 disjoint.Disjoint = 0xdeadbeef;
5072 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5073 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5074 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5075 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5076 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5077 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5079 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5080 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5081 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
5082 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5084 prev_disjoint = disjoint;
5086 disjoint.Frequency = 0xdeadbeef;
5087 disjoint.Disjoint = 0xff;
5088 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
5089 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5090 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
5091 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5092 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
5093 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5094 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
5095 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5096 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5097 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
5099 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5100 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5101 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
5102 D3D11_ASYNC_GETDATA_DONOTFLUSH);
5103 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5104 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
5105 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
5107 memset(&timestamp, 0xff, sizeof(timestamp));
5108 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
5109 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5110 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5111 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5112 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5114 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
5115 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5117 memset(&timestamp, 0xff, sizeof(timestamp));
5118 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5119 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5120 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5122 draw_color_quad(&test_context, &red);
5124 ID3D11DeviceContext_End(context, timestamp_query);
5125 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5127 timestamp = 0xdeadbeef;
5128 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5129 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5130 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5132 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5133 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5134 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
5136 timestamp = 0xdeadbeef;
5137 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
5138 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5139 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
5140 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5141 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5142 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5143 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
5144 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5145 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5147 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5148 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5149 disjoint.Frequency = 0xdeadbeef;
5150 disjoint.Disjoint = 0xff;
5151 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5152 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5153 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
5154 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5156 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
5157 ID3D11Asynchronous_Release(timestamp_query);
5158 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5159 query_desc.MiscFlags = 0;
5160 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5161 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5163 draw_color_quad(&test_context, &red);
5165 ID3D11DeviceContext_End(context, timestamp_query);
5166 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5168 ID3D11Asynchronous_Release(timestamp_query);
5169 ID3D11Asynchronous_Release(timestamp_disjoint_query);
5170 release_test_context(&test_context);
5173 static void test_device_removed_reason(void)
5175 ID3D11Device *device;
5176 ULONG refcount;
5177 HRESULT hr;
5179 if (!(device = create_device(NULL)))
5181 skip("Failed to create device.\n");
5182 return;
5185 hr = ID3D11Device_GetDeviceRemovedReason(device);
5186 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5187 hr = ID3D11Device_GetDeviceRemovedReason(device);
5188 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5190 refcount = ID3D11Device_Release(device);
5191 ok(!refcount, "Device has %u references left.\n", refcount);
5194 static void test_private_data(void)
5196 ULONG refcount, expected_refcount;
5197 D3D11_TEXTURE2D_DESC texture_desc;
5198 ID3D10Texture2D *d3d10_texture;
5199 ID3D11Device *test_object;
5200 ID3D11Texture2D *texture;
5201 IDXGIDevice *dxgi_device;
5202 IDXGISurface *surface;
5203 ID3D11Device *device;
5204 IUnknown *ptr;
5205 HRESULT hr;
5206 UINT size;
5208 static const GUID test_guid =
5209 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
5210 static const GUID test_guid2 =
5211 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
5212 static const DWORD data[] = {1, 2, 3, 4};
5214 if (!(device = create_device(NULL)))
5216 skip("Failed to create device.\n");
5217 return;
5220 test_object = create_device(NULL);
5222 texture_desc.Width = 512;
5223 texture_desc.Height = 512;
5224 texture_desc.MipLevels = 1;
5225 texture_desc.ArraySize = 1;
5226 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5227 texture_desc.SampleDesc.Count = 1;
5228 texture_desc.SampleDesc.Quality = 0;
5229 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5230 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5231 texture_desc.CPUAccessFlags = 0;
5232 texture_desc.MiscFlags = 0;
5234 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5235 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5236 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
5237 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
5239 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
5240 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5241 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5242 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5243 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5244 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5245 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5246 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5248 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5249 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5250 size = sizeof(ptr) * 2;
5251 ptr = (IUnknown *)0xdeadbeef;
5252 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5253 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5254 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5255 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5257 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
5258 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
5259 size = sizeof(ptr) * 2;
5260 ptr = (IUnknown *)0xdeadbeef;
5261 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
5262 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5263 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5264 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5265 IDXGIDevice_Release(dxgi_device);
5267 refcount = get_refcount(test_object);
5268 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5269 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5270 expected_refcount = refcount + 1;
5271 refcount = get_refcount(test_object);
5272 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5273 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5274 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5275 refcount = get_refcount(test_object);
5276 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5278 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5279 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5280 --expected_refcount;
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, (IUnknown *)test_object);
5285 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5286 size = sizeof(data);
5287 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
5288 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5289 refcount = get_refcount(test_object);
5290 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5291 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5292 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5293 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5294 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5296 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5297 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5298 ++expected_refcount;
5299 size = 2 * sizeof(ptr);
5300 ptr = NULL;
5301 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5302 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5303 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
5304 ++expected_refcount;
5305 refcount = get_refcount(test_object);
5306 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5307 IUnknown_Release(ptr);
5308 --expected_refcount;
5310 ptr = (IUnknown *)0xdeadbeef;
5311 size = 1;
5312 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5313 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5314 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5315 size = 2 * sizeof(ptr);
5316 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5317 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5318 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5319 refcount = get_refcount(test_object);
5320 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5322 size = 1;
5323 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5324 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
5325 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5326 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5327 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
5328 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5329 size = 0xdeadbabe;
5330 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
5331 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
5332 ok(size == 0, "Got unexpected size %u.\n", size);
5333 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5334 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
5335 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5336 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5338 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
5339 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5340 ptr = NULL;
5341 size = sizeof(ptr);
5342 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
5343 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5344 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5345 IUnknown_Release(ptr);
5347 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
5348 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5349 "Texture should implement ID3D10Texture2D.\n");
5350 if (SUCCEEDED(hr))
5352 ptr = NULL;
5353 size = sizeof(ptr);
5354 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
5355 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5356 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5357 IUnknown_Release(ptr);
5358 ID3D10Texture2D_Release(d3d10_texture);
5361 IDXGISurface_Release(surface);
5362 ID3D11Texture2D_Release(texture);
5363 refcount = ID3D11Device_Release(device);
5364 ok(!refcount, "Device has %u references left.\n", refcount);
5365 refcount = ID3D11Device_Release(test_object);
5366 ok(!refcount, "Test object has %u references left.\n", refcount);
5369 static void test_state_refcounting(const D3D_FEATURE_LEVEL feature_level)
5371 ID3D11RasterizerState *rasterizer_state, *tmp_rasterizer_state;
5372 ID3D11Predicate *predicate, *tmp_predicate;
5373 ID3D11SamplerState *sampler, *tmp_sampler;
5374 ID3D11ShaderResourceView *srv, *tmp_srv;
5375 ID3D11RenderTargetView *rtv, *tmp_rtv;
5376 D3D11_RASTERIZER_DESC rasterizer_desc;
5377 D3D11_TEXTURE2D_DESC texture_desc;
5378 D3D11_QUERY_DESC predicate_desc;
5379 D3D11_SAMPLER_DESC sampler_desc;
5380 struct device_desc device_desc;
5381 ID3D11DeviceContext *context;
5382 ID3D11Texture2D *texture;
5383 ID3D11Device *device;
5384 ULONG refcount;
5385 HRESULT hr;
5387 device_desc.feature_level = &feature_level;
5388 device_desc.flags = 0;
5389 if (!(device = create_device(&device_desc)))
5391 skip("Failed to create device for feature level %#x.\n", feature_level);
5392 return;
5395 ID3D11Device_GetImmediateContext(device, &context);
5397 /* ID3D11SamplerState */
5398 memset(&sampler_desc, 0, sizeof(sampler_desc));
5399 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5400 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5401 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5402 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5403 sampler_desc.MaxLOD = FLT_MAX;
5404 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
5405 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5407 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
5408 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5409 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5410 ID3D11SamplerState_Release(tmp_sampler);
5412 tmp_sampler = sampler;
5413 refcount = get_refcount(sampler);
5414 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
5415 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
5416 refcount = ID3D11SamplerState_Release(sampler);
5417 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5418 sampler = NULL;
5419 ID3D11DeviceContext_PSGetSamplers(context, 0, 1, &sampler);
5420 ok(sampler == tmp_sampler, "Got sampler %p, expected %p.\n", sampler, tmp_sampler);
5421 refcount = ID3D11SamplerState_Release(sampler);
5422 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5424 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
5425 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5426 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5427 refcount = ID3D11SamplerState_Release(tmp_sampler);
5428 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5430 /* ID3D11RasterizerState */
5431 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
5432 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
5433 rasterizer_desc.CullMode = D3D11_CULL_BACK;
5434 rasterizer_desc.DepthClipEnable = TRUE;
5435 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
5436 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5438 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
5439 refcount = ID3D11RasterizerState_Release(rasterizer_state);
5440 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5441 ID3D11DeviceContext_RSGetState(context, &tmp_rasterizer_state);
5442 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
5443 tmp_rasterizer_state, rasterizer_state);
5444 refcount = ID3D11RasterizerState_Release(tmp_rasterizer_state);
5445 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5447 /* ID3D11ShaderResourceView */
5448 memset(&texture_desc, 0, sizeof(texture_desc));
5449 texture_desc.Width = 32;
5450 texture_desc.Height = 32;
5451 texture_desc.MipLevels = 1;
5452 texture_desc.ArraySize = 1;
5453 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5454 texture_desc.SampleDesc.Count = 1;
5455 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5456 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
5457 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5458 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5459 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
5460 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
5461 ID3D11Texture2D_Release(texture);
5463 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
5464 refcount = ID3D11ShaderResourceView_Release(srv);
5465 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5466 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &tmp_srv);
5467 ok(tmp_srv == srv, "Got SRV %p, expected %p.\n", tmp_srv, srv);
5468 refcount = ID3D11ShaderResourceView_Release(tmp_srv);
5469 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5471 /* ID3D11RenderTargetView */
5472 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5473 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5474 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5475 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
5476 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5477 ID3D11Texture2D_Release(texture);
5479 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
5480 refcount = ID3D11RenderTargetView_Release(rtv);
5481 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5482 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &tmp_rtv, NULL);
5483 ok(tmp_rtv == rtv, "Got RTV %p, expected %p.\n", tmp_rtv, rtv);
5484 refcount = ID3D11RenderTargetView_Release(tmp_rtv);
5485 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5487 /* ID3D11Predicate */
5488 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
5490 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
5491 predicate_desc.MiscFlags = 0;
5492 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
5493 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5495 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
5496 refcount = ID3D11Predicate_Release(predicate);
5497 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5498 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, NULL);
5499 ok(tmp_predicate == predicate, "Got predicate %p, expected %p.\n", tmp_predicate, predicate);
5500 refcount = ID3D11Predicate_Release(tmp_predicate);
5501 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5504 ID3D11DeviceContext_Release(context);
5505 refcount = ID3D11Device_Release(device);
5506 ok(!refcount, "Device has %u references left.\n", refcount);
5509 static void test_device_context_state(void)
5511 ID3DDeviceContextState *context_state, *previous_context_state;
5512 ID3D11SamplerState *sampler, *tmp_sampler;
5513 D3D11_SAMPLER_DESC sampler_desc;
5514 D3D_FEATURE_LEVEL feature_level;
5515 ID3D11DeviceContext1 *context;
5516 ID3D11Device *d3d11_device;
5517 ID3D11Device1 *device;
5518 ULONG refcount;
5519 HRESULT hr;
5521 if (!(d3d11_device = create_device(NULL)))
5523 skip("Failed to create device.\n");
5524 return;
5527 hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11Device1, (void **)&device);
5528 ID3D11Device_Release(d3d11_device);
5529 if (FAILED(hr))
5531 skip("ID3D11Device1 is not available.\n");
5532 return;
5535 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
5536 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
5538 feature_level = ID3D11Device1_GetFeatureLevel(device);
5539 ID3D11Device1_GetImmediateContext1(device, &context);
5541 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5542 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5543 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5544 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5545 sampler_desc.MipLODBias = 0.0f;
5546 sampler_desc.MaxAnisotropy = 0;
5547 sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
5548 sampler_desc.BorderColor[0] = 0.0f;
5549 sampler_desc.BorderColor[1] = 1.0f;
5550 sampler_desc.BorderColor[2] = 0.0f;
5551 sampler_desc.BorderColor[3] = 1.0f;
5552 sampler_desc.MinLOD = 0.0f;
5553 sampler_desc.MaxLOD = 16.0f;
5554 hr = ID3D11Device1_CreateSamplerState(device, &sampler_desc, &sampler);
5555 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5557 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5558 tmp_sampler = NULL;
5559 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5560 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5561 ID3D11SamplerState_Release(tmp_sampler);
5563 feature_level = min(feature_level, D3D_FEATURE_LEVEL_10_1);
5564 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
5565 &IID_ID3D10Device, NULL, &context_state);
5566 ok(SUCCEEDED(hr), "Failed to create device context state, hr %#x.\n", hr);
5567 refcount = get_refcount(context_state);
5568 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
5570 /* Enable ID3D10Device behavior. */
5571 previous_context_state = NULL;
5572 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
5573 refcount = ID3DDeviceContextState_Release(context_state);
5574 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5576 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5577 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
5578 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5579 ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler);
5580 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
5582 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
5583 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
5585 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
5586 refcount = ID3DDeviceContextState_Release(context_state);
5587 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5588 refcount = ID3DDeviceContextState_Release(previous_context_state);
5589 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5591 /* ID3DDeviceContextState retains the previous state. */
5592 tmp_sampler = NULL;
5593 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5594 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5595 ID3D11SamplerState_Release(tmp_sampler);
5597 tmp_sampler = NULL;
5598 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
5599 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
5600 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5601 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
5602 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5603 tmp_sampler = NULL;
5604 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5605 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5606 ID3D11SamplerState_Release(tmp_sampler);
5608 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
5609 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
5611 ID3D11SamplerState_Release(sampler);
5612 ID3D11DeviceContext1_Release(context);
5613 refcount = ID3D11Device1_Release(device);
5614 ok(!refcount, "Device has %u references left.\n", refcount);
5617 static void test_blend(void)
5619 ID3D11BlendState *src_blend, *dst_blend;
5620 struct d3d11_test_context test_context;
5621 ID3D11RenderTargetView *offscreen_rtv;
5622 D3D11_TEXTURE2D_DESC texture_desc;
5623 ID3D11InputLayout *input_layout;
5624 ID3D11DeviceContext *context;
5625 D3D11_BLEND_DESC blend_desc;
5626 unsigned int stride, offset;
5627 ID3D11Texture2D *offscreen;
5628 ID3D11VertexShader *vs;
5629 ID3D11PixelShader *ps;
5630 ID3D11Device *device;
5631 D3D11_VIEWPORT vp;
5632 ID3D11Buffer *vb;
5633 DWORD color;
5634 HRESULT hr;
5636 static const DWORD vs_code[] =
5638 #if 0
5639 struct vs_out
5641 float4 position : SV_POSITION;
5642 float4 color : COLOR;
5645 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5647 struct vs_out o;
5649 o.position = position;
5650 o.color = color;
5652 return o;
5654 #endif
5655 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5656 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5657 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5658 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5659 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5660 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5661 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5662 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5663 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5664 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5666 static const DWORD ps_code[] =
5668 #if 0
5669 struct vs_out
5671 float4 position : SV_POSITION;
5672 float4 color : COLOR;
5675 float4 main(struct vs_out i) : SV_TARGET
5677 return i.color;
5679 #endif
5680 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5681 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5682 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5683 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5684 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5685 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5686 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5687 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5689 static const struct
5691 struct vec3 position;
5692 DWORD diffuse;
5694 quads[] =
5696 /* quad1 */
5697 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5698 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5699 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5700 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5701 /* quad2 */
5702 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5703 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5704 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5705 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5707 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
5709 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
5710 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
5712 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5713 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5715 if (!init_test_context(&test_context, NULL))
5716 return;
5718 device = test_context.device;
5719 context = test_context.immediate_context;
5721 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
5722 vs_code, sizeof(vs_code), &input_layout);
5723 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5725 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5727 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
5728 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5729 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5730 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5732 memset(&blend_desc, 0, sizeof(blend_desc));
5733 blend_desc.RenderTarget[0].BlendEnable = TRUE;
5734 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
5735 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
5736 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
5737 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
5738 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
5739 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
5740 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5742 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
5743 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5745 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
5746 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
5747 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
5748 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
5750 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
5751 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5753 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
5754 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5755 stride = sizeof(*quads);
5756 offset = 0;
5757 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
5758 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
5759 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5761 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
5763 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5764 ID3D11DeviceContext_Draw(context, 4, 0);
5765 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5766 ID3D11DeviceContext_Draw(context, 4, 4);
5768 color = get_texture_color(test_context.backbuffer, 320, 360);
5769 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5770 color = get_texture_color(test_context.backbuffer, 320, 120);
5771 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5773 texture_desc.Width = 128;
5774 texture_desc.Height = 128;
5775 texture_desc.MipLevels = 1;
5776 texture_desc.ArraySize = 1;
5777 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5778 texture_desc.SampleDesc.Count = 1;
5779 texture_desc.SampleDesc.Quality = 0;
5780 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5781 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
5782 texture_desc.CPUAccessFlags = 0;
5783 texture_desc.MiscFlags = 0;
5785 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5786 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5788 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
5789 goto done;
5792 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
5793 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5795 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
5797 vp.TopLeftX = 0.0f;
5798 vp.TopLeftY = 0.0f;
5799 vp.Width = 128.0f;
5800 vp.Height = 128.0f;
5801 vp.MinDepth = 0.0f;
5802 vp.MaxDepth = 1.0f;
5803 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
5805 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
5807 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5808 ID3D11DeviceContext_Draw(context, 4, 0);
5809 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5810 ID3D11DeviceContext_Draw(context, 4, 4);
5812 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5813 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5814 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5815 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5817 ID3D11RenderTargetView_Release(offscreen_rtv);
5818 ID3D11Texture2D_Release(offscreen);
5819 done:
5820 ID3D11BlendState_Release(dst_blend);
5821 ID3D11BlendState_Release(src_blend);
5822 ID3D11PixelShader_Release(ps);
5823 ID3D11VertexShader_Release(vs);
5824 ID3D11Buffer_Release(vb);
5825 ID3D11InputLayout_Release(input_layout);
5826 release_test_context(&test_context);
5829 static void test_texture(void)
5831 struct shader
5833 const DWORD *code;
5834 size_t size;
5836 struct texture
5838 UINT width;
5839 UINT height;
5840 UINT miplevel_count;
5841 UINT array_size;
5842 DXGI_FORMAT format;
5843 D3D11_SUBRESOURCE_DATA data[3];
5846 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
5847 struct d3d11_test_context test_context;
5848 const struct texture *current_texture;
5849 D3D11_TEXTURE2D_DESC texture_desc;
5850 D3D11_SAMPLER_DESC sampler_desc;
5851 const struct shader *current_ps;
5852 D3D_FEATURE_LEVEL feature_level;
5853 ID3D11ShaderResourceView *srv;
5854 ID3D11DeviceContext *context;
5855 ID3D11SamplerState *sampler;
5856 struct resource_readback rb;
5857 ID3D11Texture2D *texture;
5858 struct vec4 ps_constant;
5859 ID3D11PixelShader *ps;
5860 ID3D11Device *device;
5861 unsigned int i, x, y;
5862 ID3D11Buffer *cb;
5863 DWORD color;
5864 HRESULT hr;
5866 static const DWORD ps_ld_code[] =
5868 #if 0
5869 Texture2D t;
5871 float miplevel;
5873 float4 main(float4 position : SV_POSITION) : SV_TARGET
5875 float3 p;
5876 t.GetDimensions(miplevel, p.x, p.y, p.z);
5877 p.z = miplevel;
5878 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5879 return t.Load(int3(p));
5881 #endif
5882 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5883 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5884 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5885 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5886 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5887 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5888 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5889 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5890 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5891 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5892 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5893 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5894 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5895 0x00107e46, 0x00000000, 0x0100003e,
5897 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5898 static const DWORD ps_ld_sint8_code[] =
5900 #if 0
5901 Texture2D<int4> t;
5903 float4 main(float4 position : SV_POSITION) : SV_TARGET
5905 float3 p, s;
5906 int4 c;
5908 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5909 t.GetDimensions(0, s.x, s.y, s.z);
5910 p *= s;
5912 c = t.Load(int3(p));
5913 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5915 #endif
5916 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
5917 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5918 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5919 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5920 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5921 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5922 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5923 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5924 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5925 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5926 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5927 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5928 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5929 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5930 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5931 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5932 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5933 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5935 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5936 static const DWORD ps_ld_uint8_code[] =
5938 #if 0
5939 Texture2D<uint4> t;
5941 float4 main(float4 position : SV_POSITION) : SV_TARGET
5943 float3 p, s;
5945 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5946 t.GetDimensions(0, s.x, s.y, s.z);
5947 p *= s;
5949 return t.Load(int3(p)) / (float4)255;
5951 #endif
5952 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5953 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5954 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5955 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5956 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5957 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5958 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5959 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5960 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5961 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5962 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5963 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5964 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5965 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5966 0x3b808081, 0x0100003e,
5968 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5969 static const DWORD ps_sample_code[] =
5971 #if 0
5972 Texture2D t;
5973 SamplerState s;
5975 float4 main(float4 position : SV_POSITION) : SV_Target
5977 float2 p;
5979 p.x = position.x / 640.0f;
5980 p.y = position.y / 480.0f;
5981 return t.Sample(s, p);
5983 #endif
5984 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5985 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5986 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5987 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5988 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5989 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5990 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5991 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5992 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5993 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5995 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
5996 static const DWORD ps_sample_b_code[] =
5998 #if 0
5999 Texture2D t;
6000 SamplerState s;
6002 float bias;
6004 float4 main(float4 position : SV_POSITION) : SV_Target
6006 float2 p;
6008 p.x = position.x / 640.0f;
6009 p.y = position.y / 480.0f;
6010 return t.SampleBias(s, p, bias);
6012 #endif
6013 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
6014 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6015 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6016 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6017 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6018 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6019 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6020 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6021 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
6022 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6023 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6025 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
6026 static const DWORD ps_sample_l_code[] =
6028 #if 0
6029 Texture2D t;
6030 SamplerState s;
6032 float level;
6034 float4 main(float4 position : SV_POSITION) : SV_Target
6036 float2 p;
6038 p.x = position.x / 640.0f;
6039 p.y = position.y / 480.0f;
6040 return t.SampleLevel(s, p, level);
6042 #endif
6043 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
6044 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6045 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6046 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6047 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6048 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6049 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6050 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6051 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
6052 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6053 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6055 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
6056 static const DWORD ps_sample_2d_array_code[] =
6058 #if 0
6059 Texture2DArray t;
6060 SamplerState s;
6062 float layer;
6064 float4 main(float4 position : SV_POSITION) : SV_TARGET
6066 float3 d;
6067 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
6068 t.GetDimensions(d.x, d.y, d.z);
6069 d.z = layer;
6070 return t.Sample(s, p * d);
6072 #endif
6073 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
6074 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6075 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6076 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6077 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
6078 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6079 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6080 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
6081 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
6082 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
6083 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
6084 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
6085 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6087 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
6088 static const DWORD red_data[] =
6090 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6091 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6092 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6093 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6095 static const DWORD green_data[] =
6097 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6098 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6099 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6100 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6102 static const DWORD blue_data[] =
6104 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6105 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6106 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6107 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6109 static const DWORD rgba_level_0[] =
6111 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6112 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6113 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6114 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6116 static const DWORD rgba_level_1[] =
6118 0xffffffff, 0xff0000ff,
6119 0xff000000, 0xff00ff00,
6121 static const DWORD rgba_level_2[] =
6123 0xffff0000,
6125 static const DWORD srgb_data[] =
6127 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
6128 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
6129 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
6130 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
6132 static const BYTE a8_data[] =
6134 0x00, 0x10, 0x20, 0x30,
6135 0x40, 0x50, 0x60, 0x70,
6136 0x80, 0x90, 0xa0, 0xb0,
6137 0xc0, 0xd0, 0xe0, 0xf0,
6139 static const BYTE bc1_data[] =
6141 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6142 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6143 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6144 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6146 static const BYTE bc2_data[] =
6148 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6149 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6150 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6151 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6153 static const BYTE bc3_data[] =
6155 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6156 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6157 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6158 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6160 static const BYTE bc4_data[] =
6162 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6163 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6164 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6165 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6167 static const BYTE bc5_data[] =
6169 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6170 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6171 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6172 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6174 static const BYTE bc6h_u_data[] =
6176 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6177 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6178 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6179 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6181 static const BYTE bc6h_s_data[] =
6183 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6184 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6185 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6186 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6188 static const BYTE bc7_data[] =
6190 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6191 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6192 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6193 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
6195 static const float r32_float[] =
6197 0.0f, 1.0f, 0.5f, 0.50f,
6198 1.0f, 0.0f, 0.0f, 0.75f,
6199 0.0f, 1.0f, 0.5f, 0.25f,
6200 1.0f, 0.0f, 0.0f, 0.75f,
6202 static const DWORD r32_uint[] =
6204 0, 1, 2, 3,
6205 100, 200, 255, 128,
6206 40, 30, 20, 10,
6207 250, 210, 155, 190,
6209 static const DWORD r9g9b9e5_data[] =
6211 0x80000100, 0x80020000, 0x84000000, 0x84000100,
6212 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
6213 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
6214 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
6216 static const struct texture rgba_texture =
6218 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
6220 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
6221 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
6222 {rgba_level_2, sizeof(*rgba_level_2), 0},
6225 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6226 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6227 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
6228 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6229 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
6230 {{a8_data, 4 * sizeof(*a8_data)}}};
6231 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
6232 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
6233 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
6234 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
6235 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
6236 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
6237 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
6238 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
6239 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
6240 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
6241 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
6242 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
6243 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
6244 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
6245 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
6246 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
6247 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6248 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
6249 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6250 static const struct texture array_2d_texture =
6252 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
6254 {red_data, 6 * sizeof(*red_data)},
6255 {green_data, 4 * sizeof(*green_data)},
6256 {blue_data, 5 * sizeof(*blue_data)},
6259 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6260 {{r32_float, 4 * sizeof(*r32_float)}}};
6261 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6262 {{r32_uint, 4 * sizeof(*r32_uint)}}};
6263 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
6264 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
6265 static const DWORD red_colors[] =
6267 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6268 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6269 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6270 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6272 static const DWORD blue_colors[] =
6274 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6275 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6276 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6277 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6279 static const DWORD level_1_colors[] =
6281 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6282 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6283 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6284 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6286 static const DWORD lerp_1_2_colors[] =
6288 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6289 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6290 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6291 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6293 static const DWORD level_2_colors[] =
6295 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6296 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6297 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6298 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6300 static const DWORD srgb_colors[] =
6302 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
6303 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
6304 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
6305 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
6307 static const DWORD a8_colors[] =
6309 0x00000000, 0x10000000, 0x20000000, 0x30000000,
6310 0x40000000, 0x50000000, 0x60000000, 0x70000000,
6311 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
6312 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
6314 static const DWORD bc_colors[] =
6316 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6317 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6318 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6319 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6321 static const DWORD bc4_colors[] =
6323 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
6324 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
6325 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6326 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6328 static const DWORD bc5_colors[] =
6330 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
6331 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
6332 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6333 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6335 static const DWORD bc7_colors[] =
6337 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6338 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6339 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6340 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6342 static const DWORD sint8_colors[] =
6344 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
6345 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
6346 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
6347 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
6349 static const DWORD r32f_colors[] =
6351 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
6352 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6353 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
6354 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6356 static const DWORD r32u_colors[16] =
6358 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6359 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
6360 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
6361 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
6363 static const DWORD r9g9b9e5_colors[16] =
6365 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
6366 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
6367 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
6368 0xff000033, 0xff003300, 0xff330000, 0xff333333,
6370 static const DWORD zero_colors[4 * 4] = {0};
6371 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6373 static const struct texture_test
6375 const struct shader *ps;
6376 const struct texture *texture;
6377 D3D11_FILTER filter;
6378 float lod_bias;
6379 float min_lod;
6380 float max_lod;
6381 float ps_constant;
6382 const DWORD *expected_colors;
6384 texture_tests[] =
6386 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
6387 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
6388 #define MIP_MAX D3D11_FLOAT32_MAX
6389 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6390 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6391 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6392 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6393 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6394 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6395 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6396 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6397 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6398 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6399 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6400 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6401 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6402 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6403 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6404 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6405 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6406 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6407 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6408 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6409 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6410 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6411 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6412 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6413 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6414 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6415 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6416 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6417 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6418 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6419 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6420 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6421 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6422 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6423 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6424 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6425 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6426 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6427 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6428 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
6429 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6430 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6431 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6432 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6433 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6434 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
6435 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
6436 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
6437 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
6438 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
6439 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
6440 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
6441 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
6442 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6443 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6444 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6445 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6446 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
6447 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6448 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
6449 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
6450 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
6451 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
6452 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6453 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
6454 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
6455 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
6456 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
6457 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
6458 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
6459 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
6460 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
6461 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6462 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6463 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6464 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6465 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6466 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6467 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6468 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6469 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6470 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6471 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6472 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
6473 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
6474 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
6475 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
6476 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
6477 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
6478 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
6479 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
6480 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
6481 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
6482 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
6483 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
6484 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
6485 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
6486 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
6487 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
6488 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6489 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6490 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
6491 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6492 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6493 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
6494 #undef POINT
6495 #undef POINT_LINEAR
6496 #undef MIP_MAX
6498 static const struct srv_test
6500 const struct shader *ps;
6501 const struct texture *texture;
6502 struct srv_desc srv_desc;
6503 float ps_constant;
6504 const DWORD *expected_colors;
6506 srv_tests[] =
6508 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
6509 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
6510 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
6511 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
6512 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
6513 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
6514 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
6515 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
6516 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
6517 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
6518 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
6519 #define R32_UINT DXGI_FORMAT_R32_UINT
6520 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
6521 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6522 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6523 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6524 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6525 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6526 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6527 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
6528 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
6529 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
6530 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
6531 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
6532 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
6533 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
6534 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
6535 #undef TEX_2D
6536 #undef TEX_2D_ARRAY
6537 #undef BC1_UNORM
6538 #undef BC1_UNORM_SRGB
6539 #undef BC2_UNORM
6540 #undef BC2_UNORM_SRGB
6541 #undef BC3_UNORM
6542 #undef BC3_UNORM_SRGB
6543 #undef R8G8B8A8_UNORM_SRGB
6544 #undef R8G8B8A8_UNORM
6545 #undef R32_FLOAT
6546 #undef R32_UINT
6547 #undef FMT_UNKNOWN
6550 if (!init_test_context(&test_context, NULL))
6551 return;
6553 device = test_context.device;
6554 context = test_context.immediate_context;
6555 feature_level = ID3D11Device_GetFeatureLevel(device);
6557 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6559 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6561 texture_desc.SampleDesc.Count = 1;
6562 texture_desc.SampleDesc.Quality = 0;
6563 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6564 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6565 texture_desc.CPUAccessFlags = 0;
6566 texture_desc.MiscFlags = 0;
6568 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6569 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
6570 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
6571 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
6572 sampler_desc.MipLODBias = 0.0f;
6573 sampler_desc.MaxAnisotropy = 0;
6574 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
6575 sampler_desc.BorderColor[0] = 0.0f;
6576 sampler_desc.BorderColor[1] = 0.0f;
6577 sampler_desc.BorderColor[2] = 0.0f;
6578 sampler_desc.BorderColor[3] = 0.0f;
6579 sampler_desc.MinLOD = 0.0f;
6580 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6582 ps = NULL;
6583 srv = NULL;
6584 sampler = NULL;
6585 texture = NULL;
6586 current_ps = NULL;
6587 current_texture = NULL;
6588 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6590 const struct texture_test *test = &texture_tests[i];
6592 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
6593 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
6594 && feature_level < D3D_FEATURE_LEVEL_11_0)
6596 skip("Feature level >= 11.0 is required for BC7 tests.\n");
6597 continue;
6600 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
6601 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
6602 && feature_level < D3D_FEATURE_LEVEL_11_0)
6604 skip("Feature level >= 11.0 is required for BC6H tests.\n");
6605 continue;
6608 if (current_ps != test->ps)
6610 if (ps)
6611 ID3D11PixelShader_Release(ps);
6613 current_ps = test->ps;
6615 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6616 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6618 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6621 if (current_texture != test->texture)
6623 if (texture)
6624 ID3D11Texture2D_Release(texture);
6625 if (srv)
6626 ID3D11ShaderResourceView_Release(srv);
6628 current_texture = test->texture;
6630 if (current_texture)
6632 texture_desc.Width = current_texture->width;
6633 texture_desc.Height = current_texture->height;
6634 texture_desc.MipLevels = current_texture->miplevel_count;
6635 texture_desc.ArraySize = current_texture->array_size;
6636 texture_desc.Format = current_texture->format;
6638 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6639 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6641 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6642 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6644 else
6646 texture = NULL;
6647 srv = NULL;
6650 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6653 if (!sampler || (sampler_desc.Filter != test->filter
6654 || sampler_desc.MipLODBias != test->lod_bias
6655 || sampler_desc.MinLOD != test->min_lod
6656 || sampler_desc.MaxLOD != test->max_lod))
6658 if (sampler)
6659 ID3D11SamplerState_Release(sampler);
6661 sampler_desc.Filter = test->filter;
6662 sampler_desc.MipLODBias = test->lod_bias;
6663 sampler_desc.MinLOD = test->min_lod;
6664 sampler_desc.MaxLOD = test->max_lod;
6666 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6667 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6669 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6672 ps_constant.x = test->ps_constant;
6673 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6675 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6677 draw_quad(&test_context);
6679 get_texture_readback(test_context.backbuffer, 0, &rb);
6680 for (y = 0; y < 4; ++y)
6682 for (x = 0; x < 4; ++x)
6684 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6685 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
6686 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6689 release_resource_readback(&rb);
6691 if (srv)
6692 ID3D11ShaderResourceView_Release(srv);
6693 ID3D11SamplerState_Release(sampler);
6694 if (texture)
6695 ID3D11Texture2D_Release(texture);
6696 ID3D11PixelShader_Release(ps);
6698 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
6700 win_skip("SRV tests are broken on WARP.\n");
6701 ID3D11Buffer_Release(cb);
6702 release_test_context(&test_context);
6703 return;
6706 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6707 sampler_desc.MipLODBias = 0.0f;
6708 sampler_desc.MinLOD = 0.0f;
6709 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6711 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6712 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6714 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6716 ps = NULL;
6717 srv = NULL;
6718 texture = NULL;
6719 current_ps = NULL;
6720 current_texture = NULL;
6721 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
6723 const struct srv_test *test = &srv_tests[i];
6725 if (current_ps != test->ps)
6727 if (ps)
6728 ID3D11PixelShader_Release(ps);
6730 current_ps = test->ps;
6732 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6733 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6735 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6738 if (current_texture != test->texture)
6740 if (texture)
6741 ID3D11Texture2D_Release(texture);
6743 current_texture = test->texture;
6745 texture_desc.Width = current_texture->width;
6746 texture_desc.Height = current_texture->height;
6747 texture_desc.MipLevels = current_texture->miplevel_count;
6748 texture_desc.ArraySize = current_texture->array_size;
6749 texture_desc.Format = current_texture->format;
6751 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6752 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6755 if (srv)
6756 ID3D11ShaderResourceView_Release(srv);
6758 get_srv_desc(&srv_desc, &test->srv_desc);
6759 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
6760 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6762 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6764 ps_constant.x = test->ps_constant;
6765 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6767 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6769 draw_quad(&test_context);
6771 get_texture_readback(test_context.backbuffer, 0, &rb);
6772 for (y = 0; y < 4; ++y)
6774 for (x = 0; x < 4; ++x)
6776 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6777 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
6778 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6781 release_resource_readback(&rb);
6783 ID3D11PixelShader_Release(ps);
6784 ID3D11Texture2D_Release(texture);
6785 ID3D11ShaderResourceView_Release(srv);
6786 ID3D11SamplerState_Release(sampler);
6788 ID3D11Buffer_Release(cb);
6789 release_test_context(&test_context);
6792 static void test_cube_maps(void)
6794 struct shader
6796 const DWORD *code;
6797 size_t size;
6800 unsigned int i, j, sub_resource_idx, sub_resource_count;
6801 struct d3d11_test_context test_context;
6802 D3D11_TEXTURE2D_DESC texture_desc;
6803 const struct shader *current_ps;
6804 D3D_FEATURE_LEVEL feature_level;
6805 ID3D11ShaderResourceView *srv;
6806 ID3D11DeviceContext *context;
6807 ID3D11Texture2D *rtv_texture;
6808 ID3D11RenderTargetView *rtv;
6809 struct vec4 expected_result;
6810 ID3D11Resource *texture;
6811 ID3D11PixelShader *ps;
6812 ID3D11Device *device;
6813 float data[64 * 64];
6814 ID3D11Buffer *cb;
6815 HRESULT hr;
6816 RECT rect;
6817 struct
6819 unsigned int face;
6820 unsigned int level;
6821 unsigned int cube;
6822 unsigned int padding;
6823 } constant;
6825 static const DWORD ps_cube_code[] =
6827 #if 0
6828 TextureCube t;
6829 SamplerState s;
6831 uint face;
6832 uint level;
6834 float4 main(float4 position : SV_POSITION) : SV_Target
6836 float2 p;
6837 p.x = position.x / 640.0f;
6838 p.y = position.y / 480.0f;
6840 float3 coord;
6841 switch (face)
6843 case 0:
6844 coord = float3(1.0f, p.x, p.y);
6845 break;
6846 case 1:
6847 coord = float3(-1.0f, p.x, p.y);
6848 break;
6849 case 2:
6850 coord = float3(p.x, 1.0f, p.y);
6851 break;
6852 case 3:
6853 coord = float3(p.x, -1.0f, p.y);
6854 break;
6855 case 4:
6856 coord = float3(p.x, p.y, 1.0f);
6857 break;
6858 case 5:
6859 default:
6860 coord = float3(p.x, p.y, -1.0f);
6861 break;
6863 return t.SampleLevel(s, coord, level);
6865 #endif
6866 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
6867 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6868 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6869 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6870 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
6871 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6872 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6873 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
6874 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
6875 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
6876 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
6877 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
6878 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
6879 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6880 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
6881 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
6882 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
6883 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
6884 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
6885 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
6886 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6887 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
6888 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
6889 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
6890 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
6892 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
6893 static const DWORD ps_cube_array_code[] =
6895 #if 0
6896 TextureCubeArray t;
6897 SamplerState s;
6899 uint face;
6900 uint level;
6901 uint cube;
6903 float4 main(float4 position : SV_POSITION) : SV_Target
6905 float2 p;
6906 p.x = position.x / 640.0f;
6907 p.y = position.y / 480.0f;
6909 float3 coord;
6910 switch (face)
6912 case 0:
6913 coord = float3(1.0f, p.x, p.y);
6914 break;
6915 case 1:
6916 coord = float3(-1.0f, p.x, p.y);
6917 break;
6918 case 2:
6919 coord = float3(p.x, 1.0f, p.y);
6920 break;
6921 case 3:
6922 coord = float3(p.x, -1.0f, p.y);
6923 break;
6924 case 4:
6925 coord = float3(p.x, p.y, 1.0f);
6926 break;
6927 case 5:
6928 default:
6929 coord = float3(p.x, p.y, -1.0f);
6930 break;
6932 return t.SampleLevel(s, float4(coord, cube), level);
6934 #endif
6935 0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
6936 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6937 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6938 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6939 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
6940 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
6941 0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
6942 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
6943 0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
6944 0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6945 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
6946 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
6947 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
6948 0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
6949 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
6950 0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
6951 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
6952 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
6953 0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6954 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
6955 0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
6956 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
6957 0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
6958 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
6959 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
6960 0x00000001, 0x0100003e,
6962 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
6963 static const struct ps_test
6965 const struct shader *ps;
6966 unsigned int miplevel_count;
6967 unsigned int array_size;
6969 ps_tests[] =
6971 {&ps_cube, 1, 6},
6972 {&ps_cube, 2, 6},
6973 {&ps_cube, 3, 6},
6974 {&ps_cube, 0, 6},
6976 {&ps_cube_array, 1, 12},
6977 {&ps_cube_array, 2, 12},
6978 {&ps_cube_array, 3, 12},
6979 {&ps_cube_array, 0, 12},
6982 if (!init_test_context(&test_context, NULL))
6983 return;
6985 device = test_context.device;
6986 context = test_context.immediate_context;
6987 feature_level = ID3D11Device_GetFeatureLevel(device);
6989 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
6990 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
6991 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
6992 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6993 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
6994 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
6996 memset(&constant, 0, sizeof(constant));
6997 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
6999 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7000 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7002 ps = NULL;
7003 current_ps = NULL;
7004 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
7006 const struct ps_test *test = &ps_tests[i];
7008 if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
7010 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
7011 continue;
7014 if (current_ps != test->ps)
7016 if (ps)
7017 ID3D11PixelShader_Release(ps);
7019 current_ps = test->ps;
7021 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
7022 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7023 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7026 if (!test->miplevel_count)
7028 srv = NULL;
7029 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7031 memset(&expected_result, 0, sizeof(expected_result));
7033 memset(&constant, 0, sizeof(constant));
7034 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7035 draw_quad(&test_context);
7036 check_texture_vec4(rtv_texture, &expected_result, 0);
7037 constant.level = 1;
7038 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7039 draw_quad(&test_context);
7040 check_texture_vec4(rtv_texture, &expected_result, 0);
7041 continue;
7044 texture_desc.Width = 64;
7045 texture_desc.Height = 64;
7046 texture_desc.MipLevels = test->miplevel_count;
7047 texture_desc.ArraySize = test->array_size;
7048 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7049 texture_desc.SampleDesc.Count = 1;
7050 texture_desc.SampleDesc.Quality = 0;
7051 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7052 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
7053 texture_desc.CPUAccessFlags = 0;
7054 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
7055 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
7056 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7058 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
7059 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7060 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7062 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7063 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7065 for (j = 0; j < ARRAY_SIZE(data); ++j)
7066 data[j] = sub_resource_idx;
7067 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, sub_resource_idx, NULL,
7068 data, texture_desc.Width * sizeof(*data), 0);
7071 expected_result.y = expected_result.z = 0.0f;
7072 expected_result.w = 1.0f;
7073 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7075 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
7076 constant.level = sub_resource_idx % texture_desc.MipLevels;
7077 constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
7078 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7080 draw_quad(&test_context);
7081 expected_result.x = sub_resource_idx;
7082 /* Avoid testing values affected by seamless cube map filtering. */
7083 SetRect(&rect, 100, 100, 540, 380);
7084 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
7087 ID3D11Resource_Release(texture);
7088 ID3D11ShaderResourceView_Release(srv);
7090 ID3D11PixelShader_Release(ps);
7092 ID3D11Buffer_Release(cb);
7093 ID3D11RenderTargetView_Release(rtv);
7094 ID3D11Texture2D_Release(rtv_texture);
7095 release_test_context(&test_context);
7098 static void test_depth_stencil_sampling(void)
7100 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
7101 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
7102 ID3D11SamplerState *cmp_sampler, *sampler;
7103 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
7104 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
7105 struct d3d11_test_context test_context;
7106 ID3D11Texture2D *texture, *rt_texture;
7107 D3D11_TEXTURE2D_DESC texture_desc;
7108 D3D11_SAMPLER_DESC sampler_desc;
7109 ID3D11DeviceContext *context;
7110 ID3D11DepthStencilView *dsv;
7111 ID3D11RenderTargetView *rtv;
7112 struct vec4 ps_constant;
7113 ID3D11Device *device;
7114 ID3D11Buffer *cb;
7115 unsigned int i;
7116 HRESULT hr;
7118 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
7119 static const DWORD ps_compare_code[] =
7121 #if 0
7122 Texture2D t;
7123 SamplerComparisonState s;
7125 float ref;
7127 float4 main(float4 position : SV_Position) : SV_Target
7129 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
7131 #endif
7132 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
7133 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7134 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7135 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7136 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
7137 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
7138 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7139 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
7140 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
7141 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
7142 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
7143 0x0100003e,
7145 static const DWORD ps_sample_code[] =
7147 #if 0
7148 Texture2D t;
7149 SamplerState s;
7151 float4 main(float4 position : SV_Position) : SV_Target
7153 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
7155 #endif
7156 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
7157 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7158 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7159 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7160 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7161 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7162 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7163 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7164 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7165 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7167 static const DWORD ps_stencil_code[] =
7169 #if 0
7170 Texture2D<uint4> t;
7172 float4 main(float4 position : SV_Position) : SV_Target
7174 float2 s;
7175 t.GetDimensions(s.x, s.y);
7176 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
7178 #endif
7179 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
7180 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7181 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7182 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7183 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
7184 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
7185 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
7186 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
7187 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
7188 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
7189 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
7190 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7191 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
7193 static const DWORD ps_depth_stencil_code[] =
7195 #if 0
7196 SamplerState samp;
7197 Texture2D depth_tex;
7198 Texture2D<uint4> stencil_tex;
7200 float main(float4 position: SV_Position) : SV_Target
7202 float2 s, p;
7203 float depth, stencil;
7204 depth_tex.GetDimensions(s.x, s.y);
7205 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
7206 depth = depth_tex.Sample(samp, p).r;
7207 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
7208 return depth + stencil;
7210 #endif
7211 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
7212 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7213 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7214 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7215 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
7216 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7217 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7218 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
7219 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
7220 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
7221 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
7222 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
7223 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
7224 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
7225 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
7226 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
7228 static const struct test
7230 DXGI_FORMAT typeless_format;
7231 DXGI_FORMAT dsv_format;
7232 DXGI_FORMAT depth_view_format;
7233 DXGI_FORMAT stencil_view_format;
7235 tests[] =
7237 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
7238 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
7239 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
7240 DXGI_FORMAT_R32_FLOAT},
7241 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
7242 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
7243 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
7244 DXGI_FORMAT_R16_UNORM},
7247 if (!init_test_context(&test_context, NULL))
7248 return;
7250 device = test_context.device;
7251 context = test_context.immediate_context;
7253 if (is_amd_device(device))
7255 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
7256 win_skip("Some AMD drivers have a bug affecting the test.\n");
7257 release_test_context(&test_context);
7258 return;
7261 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
7262 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7263 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7264 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7265 sampler_desc.MipLODBias = 0.0f;
7266 sampler_desc.MaxAnisotropy = 0;
7267 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
7268 sampler_desc.BorderColor[0] = 0.0f;
7269 sampler_desc.BorderColor[1] = 0.0f;
7270 sampler_desc.BorderColor[2] = 0.0f;
7271 sampler_desc.BorderColor[3] = 0.0f;
7272 sampler_desc.MinLOD = 0.0f;
7273 sampler_desc.MaxLOD = 0.0f;
7274 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
7275 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7277 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7278 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7279 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
7280 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7282 texture_desc.Width = 640;
7283 texture_desc.Height = 480;
7284 texture_desc.MipLevels = 1;
7285 texture_desc.ArraySize = 1;
7286 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7287 texture_desc.SampleDesc.Count = 1;
7288 texture_desc.SampleDesc.Quality = 0;
7289 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7290 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7291 texture_desc.CPUAccessFlags = 0;
7292 texture_desc.MiscFlags = 0;
7293 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
7294 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7295 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
7296 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
7297 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7299 memset(&ps_constant, 0, sizeof(ps_constant));
7300 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
7301 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7303 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
7304 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7305 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
7306 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7307 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
7308 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7309 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
7310 &ps_depth_stencil);
7311 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7313 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7315 texture_desc.Format = tests[i].typeless_format;
7316 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
7317 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7318 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
7319 texture_desc.Format, hr);
7321 dsv_desc.Format = tests[i].dsv_format;
7322 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
7323 dsv_desc.Flags = 0;
7324 U(dsv_desc).Texture2D.MipSlice = 0;
7325 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7326 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
7327 dsv_desc.Format, hr);
7329 srv_desc.Format = tests[i].depth_view_format;
7330 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
7331 U(srv_desc).Texture2D.MostDetailedMip = 0;
7332 U(srv_desc).Texture2D.MipLevels = 1;
7333 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
7334 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
7335 srv_desc.Format, hr);
7337 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
7338 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
7339 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
7341 ps_constant.x = 0.5f;
7342 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7343 NULL, &ps_constant, 0, 0);
7345 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7346 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7347 draw_quad(&test_context);
7348 check_texture_float(rt_texture, 0.0f, 2);
7350 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
7351 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7352 draw_quad(&test_context);
7353 check_texture_float(rt_texture, 1.0f, 2);
7355 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
7356 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7357 draw_quad(&test_context);
7358 check_texture_float(rt_texture, 0.0f, 2);
7360 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
7361 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7362 draw_quad(&test_context);
7363 check_texture_float(rt_texture, 0.0f, 2);
7365 ps_constant.x = 0.7f;
7366 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7367 NULL, &ps_constant, 0, 0);
7369 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7370 draw_quad(&test_context);
7371 check_texture_float(rt_texture, 1.0f, 2);
7373 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
7374 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7376 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7377 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7378 draw_quad(&test_context);
7379 check_texture_float(rt_texture, 1.0f, 2);
7381 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
7382 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7383 draw_quad(&test_context);
7384 check_texture_float(rt_texture, 0.2f, 2);
7386 if (!tests[i].stencil_view_format)
7388 ID3D11DepthStencilView_Release(dsv);
7389 ID3D11ShaderResourceView_Release(depth_srv);
7390 ID3D11Texture2D_Release(texture);
7391 continue;
7394 srv_desc.Format = tests[i].stencil_view_format;
7395 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
7396 if (hr == E_OUTOFMEMORY)
7398 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
7399 ID3D11DepthStencilView_Release(dsv);
7400 ID3D11ShaderResourceView_Release(depth_srv);
7401 ID3D11Texture2D_Release(texture);
7402 continue;
7404 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
7405 srv_desc.Format, hr);
7407 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
7408 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
7410 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
7411 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7412 draw_quad(&test_context);
7413 check_texture_float(rt_texture, 0.0f, 0);
7415 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
7416 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7417 draw_quad(&test_context);
7418 check_texture_float(rt_texture, 100.0f, 0);
7420 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
7421 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7422 draw_quad(&test_context);
7423 check_texture_float(rt_texture, 255.0f, 0);
7425 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
7426 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
7427 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
7429 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
7430 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7431 draw_quad(&test_context);
7432 check_texture_float(rt_texture, 3.3f, 2);
7434 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
7435 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7436 draw_quad(&test_context);
7437 check_texture_float(rt_texture, 4.0f, 2);
7439 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
7440 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7441 draw_quad(&test_context);
7442 check_texture_float(rt_texture, 0.0f, 2);
7444 ID3D11DepthStencilView_Release(dsv);
7445 ID3D11ShaderResourceView_Release(depth_srv);
7446 ID3D11ShaderResourceView_Release(stencil_srv);
7447 ID3D11Texture2D_Release(texture);
7450 ID3D11Buffer_Release(cb);
7451 ID3D11PixelShader_Release(ps_cmp);
7452 ID3D11PixelShader_Release(ps_depth);
7453 ID3D11PixelShader_Release(ps_depth_stencil);
7454 ID3D11PixelShader_Release(ps_stencil);
7455 ID3D11RenderTargetView_Release(rtv);
7456 ID3D11SamplerState_Release(cmp_sampler);
7457 ID3D11SamplerState_Release(sampler);
7458 ID3D11Texture2D_Release(rt_texture);
7459 release_test_context(&test_context);
7462 static void test_sample_c_lz(void)
7464 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
7465 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
7466 struct d3d11_test_context test_context;
7467 ID3D11Texture2D *texture, *rt_texture;
7468 D3D11_TEXTURE2D_DESC texture_desc;
7469 D3D11_SAMPLER_DESC sampler_desc;
7470 ID3D11ShaderResourceView *srv;
7471 ID3D11DeviceContext *context;
7472 ID3D11DepthStencilView *dsv;
7473 ID3D11RenderTargetView *rtv;
7474 ID3D11SamplerState *sampler;
7475 struct vec4 ps_constant;
7476 ID3D11PixelShader *ps;
7477 ID3D11Device *device;
7478 ID3D11Buffer *cb;
7479 unsigned int i;
7480 HRESULT hr;
7481 RECT rect;
7483 static const float clear_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
7484 static const DWORD ps_array_code[] =
7486 #if 0
7487 Texture2DArray t;
7488 SamplerComparisonState s;
7490 float ref;
7491 float layer;
7493 float4 main(float4 position : SV_Position) : SV_Target
7495 return t.SampleCmpLevelZero(s, float3(position.x / 640.0f, position.y / 480.0f, layer), ref);
7497 #endif
7498 0x43425844, 0xfe28b3c3, 0xdd7ef404, 0x8d5874a1, 0x984ff182, 0x00000001, 0x00000180, 0x00000003,
7499 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7500 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7501 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7502 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000e4, 0x00000041,
7503 0x00000039, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
7504 0x00000000, 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
7505 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
7506 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
7507 0x06000036, 0x00100042, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0c000047, 0x00100012,
7508 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000, 0x0020800a,
7509 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
7511 static const DWORD ps_cube_code[] =
7513 #if 0
7514 TextureCube t;
7515 SamplerComparisonState s;
7517 float ref;
7518 float face;
7520 float4 main(float4 position : SV_Position) : SV_Target
7522 float2 p;
7523 p.x = position.x / 640.0f;
7524 p.y = position.y / 480.0f;
7526 float3 coord;
7527 switch ((uint)face)
7529 case 0:
7530 coord = float3(1.0f, p.x, p.y);
7531 break;
7532 case 1:
7533 coord = float3(-1.0f, p.x, p.y);
7534 break;
7535 case 2:
7536 coord = float3(p.x, 1.0f, p.y);
7537 break;
7538 case 3:
7539 coord = float3(p.x, -1.0f, p.y);
7540 break;
7541 case 4:
7542 coord = float3(p.x, p.y, 1.0f);
7543 break;
7544 case 5:
7545 default:
7546 coord = float3(p.x, p.y, -1.0f);
7547 break;
7550 return t.SampleCmpLevelZero(s, coord, ref);
7552 #endif
7553 0x43425844, 0xde5655e5, 0x1b116fa1, 0xfce9e757, 0x41c28aac, 0x00000001, 0x00000328, 0x00000003,
7554 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7555 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7556 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7557 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
7558 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
7559 0x00000000, 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
7560 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600001c, 0x00100012,
7561 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0300004c, 0x0010000a, 0x00000000, 0x03000006,
7562 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x3f800000, 0x0a000038,
7563 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889,
7564 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, 0x00100012, 0x00000000,
7565 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
7566 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000002,
7567 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000,
7568 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
7569 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
7570 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
7571 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, 0x0a000038, 0x00100032,
7572 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
7573 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x0100000a, 0x0a000038,
7574 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000,
7575 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x01000017,
7576 0x0c000047, 0x00100012, 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000,
7577 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006,
7578 0x00000000, 0x0100003e,
7580 static const float depth_values[] = {1.0f, 0.0f, 0.5f, 0.6f, 0.4f, 0.1f};
7581 static const struct
7583 unsigned int layer;
7584 float d_ref;
7585 float expected;
7587 tests[] =
7589 {0, 0.5f, 0.0f},
7590 {1, 0.5f, 1.0f},
7591 {2, 0.5f, 0.0f},
7592 {3, 0.5f, 0.0f},
7593 {4, 0.5f, 1.0f},
7594 {5, 0.5f, 1.0f},
7596 {0, 0.0f, 0.0f},
7597 {1, 0.0f, 0.0f},
7598 {2, 0.0f, 0.0f},
7599 {3, 0.0f, 0.0f},
7600 {4, 0.0f, 0.0f},
7601 {5, 0.0f, 0.0f},
7603 {0, 1.0f, 0.0f},
7604 {1, 1.0f, 1.0f},
7605 {2, 1.0f, 1.0f},
7606 {3, 1.0f, 1.0f},
7607 {4, 1.0f, 1.0f},
7608 {5, 1.0f, 1.0f},
7611 if (!init_test_context(&test_context, NULL))
7612 return;
7614 device = test_context.device;
7615 context = test_context.immediate_context;
7617 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
7618 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7619 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7620 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7621 sampler_desc.MipLODBias = 0.0f;
7622 sampler_desc.MaxAnisotropy = 0;
7623 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
7624 sampler_desc.BorderColor[0] = 0.0f;
7625 sampler_desc.BorderColor[1] = 0.0f;
7626 sampler_desc.BorderColor[2] = 0.0f;
7627 sampler_desc.BorderColor[3] = 0.0f;
7628 sampler_desc.MinLOD = 0.0f;
7629 sampler_desc.MaxLOD = 10.0f;
7630 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
7631 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7633 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
7634 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7635 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
7636 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7637 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
7638 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7639 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7641 memset(&ps_constant, 0, sizeof(ps_constant));
7642 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
7644 /* 2D array texture */
7645 texture_desc.Width = 32;
7646 texture_desc.Height = 32;
7647 texture_desc.MipLevels = 2;
7648 texture_desc.ArraySize = ARRAY_SIZE(depth_values);
7649 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
7650 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
7651 texture_desc.MiscFlags = 0;
7652 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7653 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7655 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
7657 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
7658 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
7659 dsv_desc.Flags = 0;
7660 U(dsv_desc).Texture2DArray.MipSlice = 0;
7661 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
7662 U(dsv_desc).Texture2DArray.ArraySize = 1;
7664 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7665 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7666 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
7667 ID3D11DepthStencilView_Release(dsv);
7669 U(dsv_desc).Texture2DArray.MipSlice = 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, 1.0f, 0);
7673 ID3D11DepthStencilView_Release(dsv);
7676 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
7677 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
7678 U(srv_desc).Texture2DArray.MostDetailedMip = 0;
7679 U(srv_desc).Texture2DArray.MipLevels = ~0u;
7680 U(srv_desc).Texture2DArray.FirstArraySlice = 0;
7681 U(srv_desc).Texture2DArray.ArraySize = ~0u;
7682 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
7683 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7685 hr = ID3D11Device_CreatePixelShader(device, ps_array_code, sizeof(ps_array_code), NULL, &ps);
7686 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7688 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7689 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7690 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7691 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7693 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7695 ps_constant.x = tests[i].d_ref;
7696 ps_constant.y = tests[i].layer;
7697 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7698 NULL, &ps_constant, 0, 0);
7699 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
7700 draw_quad(&test_context);
7701 check_texture_float(rt_texture, tests[i].expected, 2);
7704 ID3D11Texture2D_Release(texture);
7705 ID3D11ShaderResourceView_Release(srv);
7706 ID3D11PixelShader_Release(ps);
7708 /* cube texture */
7709 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
7710 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7711 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7713 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
7715 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
7716 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
7717 dsv_desc.Flags = 0;
7718 U(dsv_desc).Texture2DArray.MipSlice = 0;
7719 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
7720 U(dsv_desc).Texture2DArray.ArraySize = 1;
7722 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7723 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7724 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
7725 ID3D11DepthStencilView_Release(dsv);
7727 U(dsv_desc).Texture2DArray.MipSlice = 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, 1.0f, 0);
7731 ID3D11DepthStencilView_Release(dsv);
7734 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
7735 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
7736 U(srv_desc).TextureCube.MostDetailedMip = 0;
7737 U(srv_desc).TextureCube.MipLevels = ~0u;
7738 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
7739 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7741 hr = ID3D11Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), NULL, &ps);
7742 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7744 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7745 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7746 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7747 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7749 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7751 ps_constant.x = tests[i].d_ref;
7752 ps_constant.y = tests[i].layer;
7753 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7754 NULL, &ps_constant, 0, 0);
7755 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
7756 draw_quad(&test_context);
7757 /* Avoid testing values affected by seamless cube map filtering. */
7758 SetRect(&rect, 100, 100, 540, 380);
7759 check_texture_sub_resource_float(rt_texture, 0, &rect, tests[i].expected, 2);
7762 ID3D11Texture2D_Release(texture);
7763 ID3D11ShaderResourceView_Release(srv);
7765 ID3D11Buffer_Release(cb);
7766 ID3D11PixelShader_Release(ps);
7767 ID3D11RenderTargetView_Release(rtv);
7768 ID3D11SamplerState_Release(sampler);
7769 ID3D11Texture2D_Release(rt_texture);
7770 release_test_context(&test_context);
7773 static void test_multiple_render_targets(void)
7775 D3D11_TEXTURE2D_DESC texture_desc;
7776 ID3D11InputLayout *input_layout;
7777 unsigned int stride, offset, i;
7778 ID3D11RenderTargetView *rtv[4];
7779 ID3D11DeviceContext *context;
7780 ID3D11Texture2D *rt[4];
7781 ID3D11VertexShader *vs;
7782 ID3D11PixelShader *ps;
7783 ID3D11Device *device;
7784 D3D11_VIEWPORT vp;
7785 ID3D11Buffer *vb;
7786 ULONG refcount;
7787 HRESULT hr;
7789 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
7791 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
7793 static const DWORD vs_code[] =
7795 #if 0
7796 float4 main(float4 position : POSITION) : SV_POSITION
7798 return position;
7800 #endif
7801 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
7802 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7803 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7804 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
7805 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
7806 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7807 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
7809 static const DWORD ps_code[] =
7811 #if 0
7812 struct output
7814 float4 t1 : SV_TARGET0;
7815 float4 t2 : SV_Target1;
7816 float4 t3 : SV_TARGET2;
7817 float4 t4 : SV_Target3;
7820 output main(float4 position : SV_POSITION)
7822 struct output o;
7823 o.t1 = (float4)1.0f;
7824 o.t2 = (float4)0.5f;
7825 o.t3 = (float4)0.2f;
7826 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
7827 return o;
7829 #endif
7830 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
7831 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7832 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7833 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
7834 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
7835 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
7836 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
7837 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
7838 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
7839 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
7840 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
7841 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
7842 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
7843 0x3f800000, 0x0100003e,
7845 static const struct vec2 quad[] =
7847 {-1.0f, -1.0f},
7848 {-1.0f, 1.0f},
7849 { 1.0f, -1.0f},
7850 { 1.0f, 1.0f},
7852 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
7854 if (!(device = create_device(NULL)))
7856 skip("Failed to create device.\n");
7857 return;
7860 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
7861 vs_code, sizeof(vs_code), &input_layout);
7862 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7864 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7866 texture_desc.Width = 640;
7867 texture_desc.Height = 480;
7868 texture_desc.MipLevels = 1;
7869 texture_desc.ArraySize = 1;
7870 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7871 texture_desc.SampleDesc.Count = 1;
7872 texture_desc.SampleDesc.Quality = 0;
7873 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7874 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7875 texture_desc.CPUAccessFlags = 0;
7876 texture_desc.MiscFlags = 0;
7878 for (i = 0; i < ARRAY_SIZE(rt); ++i)
7880 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
7881 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
7883 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
7884 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
7887 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
7888 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7889 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7890 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7892 ID3D11Device_GetImmediateContext(device, &context);
7894 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
7895 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
7896 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7897 stride = sizeof(*quad);
7898 offset = 0;
7899 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
7900 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
7901 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7903 vp.TopLeftX = 0.0f;
7904 vp.TopLeftY = 0.0f;
7905 vp.Width = 640.0f;
7906 vp.Height = 480.0f;
7907 vp.MinDepth = 0.0f;
7908 vp.MaxDepth = 1.0f;
7909 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
7911 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7912 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
7914 ID3D11DeviceContext_Draw(context, 4, 0);
7916 check_texture_color(rt[0], 0xffffffff, 2);
7917 check_texture_color(rt[1], 0x7f7f7f7f, 2);
7918 check_texture_color(rt[2], 0x33333333, 2);
7919 check_texture_color(rt[3], 0xff7f3300, 2);
7921 ID3D11Buffer_Release(vb);
7922 ID3D11PixelShader_Release(ps);
7923 ID3D11VertexShader_Release(vs);
7924 ID3D11InputLayout_Release(input_layout);
7925 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7927 ID3D11RenderTargetView_Release(rtv[i]);
7928 ID3D11Texture2D_Release(rt[i]);
7930 ID3D11DeviceContext_Release(context);
7931 refcount = ID3D11Device_Release(device);
7932 ok(!refcount, "Device has %u references left.\n", refcount);
7935 static void test_render_target_views(void)
7937 struct texture
7939 UINT miplevel_count;
7940 UINT array_size;
7943 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
7944 static struct test
7946 struct texture texture;
7947 struct rtv_desc rtv;
7948 DWORD expected_colors[4];
7950 tests[] =
7952 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7953 {0xff0000ff, 0x00000000}},
7954 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
7955 {0x00000000, 0xff0000ff}},
7956 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7957 {0xff0000ff, 0x00000000}},
7958 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7959 {0x00000000, 0xff0000ff}},
7960 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7961 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7962 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7963 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7964 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7965 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7966 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
7967 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7968 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
7969 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7970 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
7971 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7972 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7973 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7974 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7975 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7976 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7977 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7978 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7979 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7980 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
7981 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7984 struct d3d11_test_context test_context;
7985 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7986 D3D11_TEXTURE2D_DESC texture_desc;
7987 ID3D11DeviceContext *context;
7988 ID3D11RenderTargetView *rtv;
7989 ID3D11Texture2D *texture;
7990 ID3D11Device *device;
7991 unsigned int i, j, k;
7992 void *data;
7993 HRESULT hr;
7995 if (!init_test_context(&test_context, NULL))
7996 return;
7998 device = test_context.device;
7999 context = test_context.immediate_context;
8001 texture_desc.Width = 32;
8002 texture_desc.Height = 32;
8003 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8004 texture_desc.SampleDesc.Count = 1;
8005 texture_desc.SampleDesc.Quality = 0;
8006 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8007 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8008 texture_desc.CPUAccessFlags = 0;
8009 texture_desc.MiscFlags = 0;
8011 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, texture_desc.Width * texture_desc.Height * 4);
8012 ok(!!data, "Failed to allocate memory.\n");
8014 for (i = 0; i < ARRAY_SIZE(tests); ++i)
8016 const struct test *test = &tests[i];
8017 unsigned int sub_resource_count;
8019 texture_desc.MipLevels = test->texture.miplevel_count;
8020 texture_desc.ArraySize = test->texture.array_size;
8022 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8023 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
8025 get_rtv_desc(&rtv_desc, &test->rtv);
8026 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8027 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
8029 for (j = 0; j < texture_desc.ArraySize; ++j)
8031 for (k = 0; k < texture_desc.MipLevels; ++k)
8033 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
8034 ID3D11DeviceContext_UpdateSubresource(context,
8035 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
8038 check_texture_color(texture, 0, 0);
8040 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8041 draw_color_quad(&test_context, &red);
8043 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
8044 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
8045 for (j = 0; j < sub_resource_count; ++j)
8046 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
8048 ID3D11RenderTargetView_Release(rtv);
8049 ID3D11Texture2D_Release(texture);
8052 HeapFree(GetProcessHeap(), 0, data);
8053 release_test_context(&test_context);
8056 static void test_layered_rendering(void)
8058 struct
8060 unsigned int layer_offset;
8061 unsigned int draw_id;
8062 unsigned int padding[2];
8063 } constant;
8064 struct d3d11_test_context test_context;
8065 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
8066 unsigned int i, sub_resource_count;
8067 D3D11_TEXTURE2D_DESC texture_desc;
8068 ID3D11DeviceContext *context;
8069 ID3D11RenderTargetView *rtv;
8070 ID3D11Texture2D *texture;
8071 ID3D11GeometryShader *gs;
8072 ID3D11PixelShader *ps;
8073 ID3D11Device *device;
8074 ID3D11Buffer *cb;
8075 HRESULT hr;
8076 BOOL warp;
8078 static const DWORD gs_5_code[] =
8080 #if 0
8081 uint layer_offset;
8083 struct gs_in
8085 float4 pos : SV_Position;
8088 struct gs_out
8090 float4 pos : SV_Position;
8091 uint layer : SV_RenderTargetArrayIndex;
8094 [instance(4)]
8095 [maxvertexcount(3)]
8096 void main(triangle gs_in vin[3], in uint instance_id : SV_GSInstanceID,
8097 inout TriangleStream<gs_out> vout)
8099 gs_out o;
8100 o.layer = layer_offset + instance_id;
8101 for (uint i = 0; i < 3; ++i)
8103 o.pos = vin[i].pos;
8104 vout.Append(o);
8107 #endif
8108 0x43425844, 0xb52da162, 0x9a13d8ee, 0xf7c30b50, 0xe80bc2e7, 0x00000001, 0x00000218, 0x00000003,
8109 0x0000002c, 0x00000060, 0x000000d0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8110 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
8111 0x3547534f, 0x00000068, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
8112 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000004, 0x00000001,
8113 0x00000001, 0x00000e01, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472,
8114 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x58454853, 0x00000140, 0x00020050, 0x00000050,
8115 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
8116 0x00000000, 0x00000001, 0x0200005f, 0x00025000, 0x02000068, 0x00000001, 0x020000ce, 0x00000004,
8117 0x0100185d, 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
8118 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x00000003, 0x0700001e,
8119 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0002500a, 0x05000036, 0x00100022,
8120 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a,
8121 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000, 0x07000036, 0x001020f2,
8122 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001,
8123 0x0010000a, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x0700001e, 0x00100022, 0x00000000,
8124 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
8126 static const DWORD gs_4_code[] =
8128 #if 0
8129 uint layer_offset;
8131 struct gs_in
8133 float4 pos : SV_Position;
8136 struct gs_out
8138 float4 pos : SV_Position;
8139 uint layer : SV_RenderTargetArrayIndex;
8142 [maxvertexcount(12)]
8143 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
8145 gs_out o;
8146 for (uint instance_id = 0; instance_id < 4; ++instance_id)
8148 o.layer = layer_offset + instance_id;
8149 for (uint i = 0; i < 3; ++i)
8151 o.pos = vin[i].pos;
8152 vout.Append(o);
8154 vout.RestartStrip();
8157 #endif
8158 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
8159 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8160 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
8161 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8162 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
8163 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
8164 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
8165 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
8166 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
8167 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
8168 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
8169 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
8170 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
8171 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
8172 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
8173 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
8174 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
8175 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
8176 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
8178 static const DWORD ps_code[] =
8180 #if 0
8181 uint layer_offset;
8182 uint draw_id;
8184 float4 main(in float4 pos : SV_Position,
8185 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
8187 return float4(layer, draw_id, 0, 0);
8189 #endif
8190 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
8191 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
8192 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
8193 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
8194 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
8195 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
8196 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
8197 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
8198 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
8199 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
8200 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
8202 static const struct vec4 expected_values[] =
8204 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
8205 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
8206 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
8207 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
8210 if (!init_test_context(&test_context, NULL))
8211 return;
8213 device = test_context.device;
8214 context = test_context.immediate_context;
8216 warp = is_warp_device(device);
8218 memset(&constant, 0, sizeof(constant));
8219 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
8220 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
8221 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8223 /* Geometry shader instancing seems broken on WARP. */
8224 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0 || warp)
8226 hr = ID3D11Device_CreateGeometryShader(device, gs_4_code, sizeof(gs_4_code), NULL, &gs);
8227 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
8229 else
8231 hr = ID3D11Device_CreateGeometryShader(device, gs_5_code, sizeof(gs_5_code), NULL, &gs);
8232 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
8234 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
8236 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8237 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8238 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8240 texture_desc.Width = 32;
8241 texture_desc.Height = 32;
8242 texture_desc.MipLevels = 3;
8243 texture_desc.ArraySize = 8;
8244 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8245 texture_desc.SampleDesc.Count = 1;
8246 texture_desc.SampleDesc.Quality = 0;
8247 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8248 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8249 texture_desc.CPUAccessFlags = 0;
8250 texture_desc.MiscFlags = 0;
8251 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8252 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8254 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
8255 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8256 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8257 constant.layer_offset = 0;
8258 constant.draw_id = 0;
8259 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8260 draw_quad(&test_context);
8261 constant.layer_offset = 4;
8262 constant.draw_id = 1;
8263 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8264 draw_quad(&test_context);
8265 ID3D11RenderTargetView_Release(rtv);
8267 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
8268 rtv_desc.Format = texture_desc.Format;
8269 U(rtv_desc).Texture2DArray.MipSlice = 0;
8270 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
8271 U(rtv_desc).Texture2DArray.ArraySize = 1;
8272 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8273 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8274 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8275 constant.layer_offset = 1;
8276 constant.draw_id = 2;
8277 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8278 draw_quad(&test_context);
8279 ID3D11RenderTargetView_Release(rtv);
8281 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
8282 U(rtv_desc).Texture2DArray.MipSlice = 1;
8283 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
8284 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
8285 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8286 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8287 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8288 constant.layer_offset = 0;
8289 constant.draw_id = 3;
8290 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8291 draw_quad(&test_context);
8292 constant.layer_offset = 4;
8293 constant.draw_id = 3;
8294 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8295 draw_quad(&test_context);
8296 ID3D11RenderTargetView_Release(rtv);
8298 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
8299 U(rtv_desc).Texture2DArray.MipSlice = 2;
8300 U(rtv_desc).Texture2DArray.ArraySize = 1;
8301 for (i = 0; i < texture_desc.ArraySize; ++i)
8303 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
8304 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8305 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8306 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8307 constant.layer_offset = 0;
8308 constant.draw_id = 4 + i;
8309 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8310 draw_quad(&test_context);
8311 ID3D11RenderTargetView_Release(rtv);
8314 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
8315 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
8316 for (i = 0; i < sub_resource_count; ++i)
8318 if (warp && (i == 3 || i == 4)) /* Broken on WARP. */
8319 continue;
8320 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
8323 ID3D11Texture2D_Release(texture);
8325 ID3D11Buffer_Release(cb);
8326 ID3D11GeometryShader_Release(gs);
8327 ID3D11PixelShader_Release(ps);
8328 release_test_context(&test_context);
8331 static void test_scissor(void)
8333 struct d3d11_test_context test_context;
8334 ID3D11DeviceContext *immediate_context;
8335 D3D11_RASTERIZER_DESC rs_desc;
8336 ID3D11RasterizerState *rs;
8337 D3D11_RECT scissor_rect;
8338 ID3D11Device *device;
8339 DWORD color;
8340 HRESULT hr;
8342 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
8343 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
8345 if (!init_test_context(&test_context, NULL))
8346 return;
8348 device = test_context.device;
8349 immediate_context = test_context.immediate_context;
8351 rs_desc.FillMode = D3D11_FILL_SOLID;
8352 rs_desc.CullMode = D3D11_CULL_BACK;
8353 rs_desc.FrontCounterClockwise = FALSE;
8354 rs_desc.DepthBias = 0;
8355 rs_desc.DepthBiasClamp = 0.0f;
8356 rs_desc.SlopeScaledDepthBias = 0.0f;
8357 rs_desc.DepthClipEnable = TRUE;
8358 rs_desc.ScissorEnable = TRUE;
8359 rs_desc.MultisampleEnable = FALSE;
8360 rs_desc.AntialiasedLineEnable = FALSE;
8361 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
8362 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
8364 scissor_rect.left = 160;
8365 scissor_rect.top = 120;
8366 scissor_rect.right = 480;
8367 scissor_rect.bottom = 360;
8368 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
8370 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
8371 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
8373 draw_color_quad(&test_context, &green);
8374 color = get_texture_color(test_context.backbuffer, 320, 60);
8375 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8376 color = get_texture_color(test_context.backbuffer, 80, 240);
8377 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8378 color = get_texture_color(test_context.backbuffer, 320, 240);
8379 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8380 color = get_texture_color(test_context.backbuffer, 560, 240);
8381 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8382 color = get_texture_color(test_context.backbuffer, 320, 420);
8383 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8385 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
8386 ID3D11DeviceContext_RSSetState(immediate_context, rs);
8387 draw_color_quad(&test_context, &green);
8388 color = get_texture_color(test_context.backbuffer, 320, 60);
8389 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8390 color = get_texture_color(test_context.backbuffer, 80, 240);
8391 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8392 color = get_texture_color(test_context.backbuffer, 320, 240);
8393 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8394 color = get_texture_color(test_context.backbuffer, 560, 240);
8395 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8396 color = get_texture_color(test_context.backbuffer, 320, 420);
8397 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8399 ID3D11RasterizerState_Release(rs);
8400 release_test_context(&test_context);
8403 static void test_clear_state(void)
8405 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
8406 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8408 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8410 #if 0
8411 float4 main(float4 pos : POSITION) : POSITION
8413 return pos;
8415 #endif
8416 static const DWORD simple_vs[] =
8418 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
8419 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8420 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8421 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8422 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
8423 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
8424 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8426 #if 0
8427 struct data
8429 float4 position : SV_Position;
8432 struct patch_constant_data
8434 float edges[3] : SV_TessFactor;
8435 float inside : SV_InsideTessFactor;
8438 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
8440 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
8441 output.inside = 1.0f;
8444 [domain("tri")]
8445 [outputcontrolpoints(3)]
8446 [partitioning("integer")]
8447 [outputtopology("triangle_ccw")]
8448 [patchconstantfunc("patch_constant")]
8449 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
8451 return input[i];
8454 [domain("tri")]
8455 void ds_main(patch_constant_data input,
8456 float3 tess_coord : SV_DomainLocation,
8457 const OutputPatch<data, 3> patch,
8458 out data output)
8460 output.position = tess_coord.x * patch[0].position
8461 + tess_coord.y * patch[1].position
8462 + tess_coord.z * patch[2].position;
8464 #endif
8465 static const DWORD simple_hs[] =
8467 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
8468 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
8469 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
8470 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
8471 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
8472 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
8473 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
8474 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
8475 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
8476 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
8477 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
8478 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
8479 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
8480 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
8481 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
8482 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
8483 0x00004001, 0x3f800000, 0x0100003e,
8485 static const DWORD simple_ds[] =
8487 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
8488 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
8489 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
8490 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
8491 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
8492 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
8493 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
8494 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
8495 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
8496 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
8497 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
8498 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
8499 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
8500 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
8501 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
8503 #if 0
8504 struct gs_out
8506 float4 pos : SV_POSITION;
8509 [maxvertexcount(4)]
8510 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
8512 float offset = 0.1 * vin[0].w;
8513 gs_out v;
8515 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
8516 vout.Append(v);
8517 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
8518 vout.Append(v);
8519 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
8520 vout.Append(v);
8521 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
8522 vout.Append(v);
8524 #endif
8525 static const DWORD simple_gs[] =
8527 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
8528 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8529 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8530 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8531 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
8532 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
8533 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
8534 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
8535 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
8536 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
8537 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
8538 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
8539 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
8540 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
8541 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
8542 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
8543 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
8544 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
8546 #if 0
8547 float4 main(float4 color : COLOR) : SV_TARGET
8549 return color;
8551 #endif
8552 static const DWORD simple_ps[] =
8554 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
8555 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
8556 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
8557 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8558 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8559 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
8560 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8562 #if 0
8563 [numthreads(1, 1, 1)]
8564 void main() { }
8565 #endif
8566 static const DWORD simple_cs[] =
8568 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
8569 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8570 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
8571 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
8574 D3D11_VIEWPORT tmp_viewport[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
8575 ID3D11ShaderResourceView *tmp_srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
8576 ID3D11ShaderResourceView *srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
8577 ID3D11RenderTargetView *tmp_rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8578 RECT tmp_rect[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
8579 ID3D11SamplerState *tmp_sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
8580 ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8581 ID3D11Texture2D *rt_texture[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8582 ID3D11Buffer *cb[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
8583 ID3D11Buffer *tmp_buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8584 ID3D11SamplerState *sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
8585 ID3D11UnorderedAccessView *tmp_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
8586 ID3D11UnorderedAccessView *cs_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
8587 ID3D11Buffer *buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8588 ID3D11Buffer *cs_uav_buffer[D3D11_PS_CS_UAV_REGISTER_COUNT];
8589 UINT offset[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8590 UINT stride[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8591 ID3D11Buffer *so_buffer[D3D11_SO_BUFFER_SLOT_COUNT];
8592 ID3D11InputLayout *tmp_input_layout, *input_layout;
8593 ID3D11DepthStencilState *tmp_ds_state, *ds_state;
8594 ID3D11BlendState *tmp_blend_state, *blend_state;
8595 ID3D11RasterizerState *tmp_rs_state, *rs_state;
8596 ID3D11Predicate *tmp_predicate, *predicate;
8597 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
8598 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8599 ID3D11DepthStencilView *tmp_dsv, *dsv;
8600 ID3D11UnorderedAccessView *ps_uav;
8601 D3D11_PRIMITIVE_TOPOLOGY topology;
8602 D3D11_TEXTURE2D_DESC texture_desc;
8603 ID3D11GeometryShader *tmp_gs, *gs;
8604 ID3D11ComputeShader *tmp_cs, *cs;
8605 D3D11_DEPTH_STENCIL_DESC ds_desc;
8606 ID3D11VertexShader *tmp_vs, *vs;
8607 ID3D11DomainShader *tmp_ds, *ds;
8608 D3D11_SAMPLER_DESC sampler_desc;
8609 D3D11_QUERY_DESC predicate_desc;
8610 struct device_desc device_desc;
8611 ID3D11PixelShader *tmp_ps, *ps;
8612 ID3D11HullShader *tmp_hs, *hs;
8613 D3D11_RASTERIZER_DESC rs_desc;
8614 ID3D11DeviceContext *context;
8615 D3D11_BLEND_DESC blend_desc;
8616 ID3D11Texture2D *ds_texture;
8617 ID3D11Buffer *ps_uav_buffer;
8618 float blend_factor[4];
8619 ID3D11Device *device;
8620 BOOL predicate_value;
8621 DXGI_FORMAT format;
8622 UINT sample_mask;
8623 UINT stencil_ref;
8624 ULONG refcount;
8625 UINT count, i;
8626 HRESULT hr;
8628 device_desc.feature_level = &feature_level;
8629 device_desc.flags = 0;
8630 if (!(device = create_device(&device_desc)))
8632 skip("Failed to create device.\n");
8633 return;
8636 ID3D11Device_GetImmediateContext(device, &context);
8638 /* Verify the initial state after device creation. */
8640 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8641 tmp_buffer);
8642 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8644 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8646 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8647 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8649 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8651 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8652 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8654 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8656 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
8657 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
8659 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8660 tmp_buffer);
8661 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8663 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8665 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8666 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8668 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8670 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8671 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8673 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8675 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
8676 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
8678 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8679 tmp_buffer);
8680 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8682 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8684 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8685 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8687 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8689 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8690 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8692 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8694 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
8695 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
8697 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8698 tmp_buffer);
8699 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8701 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8703 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8704 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8706 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8708 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8709 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8711 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8713 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
8714 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
8716 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8717 tmp_buffer);
8718 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8720 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8722 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
8723 tmp_srv);
8724 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8726 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8728 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8729 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8731 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8733 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
8734 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
8736 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8737 tmp_buffer);
8738 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8740 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8742 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
8743 tmp_srv);
8744 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8746 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8748 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8749 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8751 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8753 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
8754 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
8755 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8756 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8758 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
8761 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
8762 tmp_buffer, stride, offset);
8763 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
8765 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
8766 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
8767 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
8769 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
8770 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
8771 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
8772 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
8773 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
8774 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
8775 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
8776 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
8778 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
8779 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
8780 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
8781 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
8782 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
8783 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
8784 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
8785 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
8786 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
8787 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
8788 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
8789 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8791 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8793 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
8794 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
8795 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
8796 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8797 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8799 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8801 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
8802 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8804 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
8807 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
8808 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
8809 memset(tmp_rect, 0x55, sizeof(tmp_rect));
8810 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
8811 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
8812 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
8814 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
8815 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
8817 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
8818 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
8819 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
8820 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
8821 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
8822 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
8824 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
8825 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
8826 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
8827 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
8828 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
8830 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
8831 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
8833 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
8834 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
8836 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
8839 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
8840 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
8841 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
8843 /* Create resources. */
8845 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8846 cb[i] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 1024, NULL);
8848 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
8850 buffer[i] = create_buffer(device,
8851 D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_SHADER_RESOURCE,
8852 1024, NULL);
8854 stride[i] = (i + 1) * 4;
8855 offset[i] = (i + 1) * 16;
8858 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
8859 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
8861 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8862 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
8863 U(srv_desc).Buffer.ElementOffset = 0;
8864 U(srv_desc).Buffer.ElementWidth = 64;
8866 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8868 hr = ID3D11Device_CreateShaderResourceView(device,
8869 (ID3D11Resource *)buffer[i % D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
8870 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8873 uav_desc.Format = DXGI_FORMAT_R32_UINT;
8874 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
8875 U(uav_desc).Buffer.FirstElement = 0;
8876 U(uav_desc).Buffer.NumElements = 8;
8877 U(uav_desc).Buffer.Flags = 0;
8879 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8881 cs_uav_buffer[i] = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
8882 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_uav_buffer[i],
8883 &uav_desc, &cs_uav[i]);
8884 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
8887 ps_uav_buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
8888 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_uav_buffer,
8889 &uav_desc, &ps_uav);
8890 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
8892 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
8893 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8894 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8895 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8896 sampler_desc.MipLODBias = 0.0f;
8897 sampler_desc.MaxAnisotropy = 16;
8898 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8899 sampler_desc.BorderColor[0] = 0.0f;
8900 sampler_desc.BorderColor[1] = 0.0f;
8901 sampler_desc.BorderColor[2] = 0.0f;
8902 sampler_desc.BorderColor[3] = 0.0f;
8903 sampler_desc.MinLOD = 0.0f;
8904 sampler_desc.MaxLOD = 16.0f;
8906 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8908 sampler_desc.MinLOD = (float)i;
8910 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
8911 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8914 hr = ID3D11Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
8915 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8917 hr = ID3D11Device_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
8918 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
8920 hr = ID3D11Device_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
8921 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
8923 hr = ID3D11Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
8924 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
8926 hr = ID3D11Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
8927 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8929 hr = ID3D11Device_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
8930 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
8932 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8933 simple_vs, sizeof(simple_vs), &input_layout);
8934 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8936 memset(&blend_desc, 0, sizeof(blend_desc));
8937 blend_desc.AlphaToCoverageEnable = FALSE;
8938 blend_desc.IndependentBlendEnable = FALSE;
8939 blend_desc.RenderTarget[0].BlendEnable = TRUE;
8940 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
8941 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
8942 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
8943 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
8944 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
8945 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
8946 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
8948 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
8949 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8951 ds_desc.DepthEnable = TRUE;
8952 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
8953 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
8954 ds_desc.StencilEnable = FALSE;
8955 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
8956 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
8957 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
8958 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
8959 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
8960 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
8961 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
8962 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
8963 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
8964 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
8966 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
8967 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
8969 texture_desc.Width = 512;
8970 texture_desc.Height = 512;
8971 texture_desc.MipLevels = 1;
8972 texture_desc.ArraySize = 1;
8973 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8974 texture_desc.SampleDesc.Count = 1;
8975 texture_desc.SampleDesc.Quality = 0;
8976 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8977 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8978 texture_desc.CPUAccessFlags = 0;
8979 texture_desc.MiscFlags = 0;
8981 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8983 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
8984 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8987 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
8988 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
8990 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
8991 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8993 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8995 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture[i], NULL, &rtv[i]);
8996 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8999 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)ds_texture, NULL, &dsv);
9000 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
9002 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
9004 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
9006 tmp_viewport[i].TopLeftX = i * 3;
9007 tmp_viewport[i].TopLeftY = i * 4;
9008 tmp_viewport[i].Width = 3;
9009 tmp_viewport[i].Height = 4;
9010 tmp_viewport[i].MinDepth = i * 0.01f;
9011 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
9014 rs_desc.FillMode = D3D11_FILL_SOLID;
9015 rs_desc.CullMode = D3D11_CULL_BACK;
9016 rs_desc.FrontCounterClockwise = FALSE;
9017 rs_desc.DepthBias = 0;
9018 rs_desc.DepthBiasClamp = 0.0f;
9019 rs_desc.SlopeScaledDepthBias = 0.0f;
9020 rs_desc.DepthClipEnable = TRUE;
9021 rs_desc.ScissorEnable = FALSE;
9022 rs_desc.MultisampleEnable = FALSE;
9023 rs_desc.AntialiasedLineEnable = FALSE;
9025 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs_state);
9026 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
9028 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
9029 predicate_desc.MiscFlags = 0;
9031 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
9032 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
9034 /* Setup state. */
9036 /* Some versions of Windows AMD drivers hang while the device is being
9037 * released, if the total number of used resource slots exceeds some limit.
9038 * Do not use all constant buffers slots in order to not trigger this
9039 * driver bug. */
9040 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb[0]);
9041 ID3D11DeviceContext_VSSetConstantBuffers(context, 7, 1, &cb[7]);
9042 ID3D11DeviceContext_VSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9043 ID3D11DeviceContext_VSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9044 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
9046 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb[0]);
9047 ID3D11DeviceContext_HSSetConstantBuffers(context, 7, 1, &cb[7]);
9048 ID3D11DeviceContext_HSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9049 ID3D11DeviceContext_HSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9050 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
9052 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
9053 ID3D11DeviceContext_DSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9054 ID3D11DeviceContext_DSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9055 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
9057 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
9058 ID3D11DeviceContext_GSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9059 ID3D11DeviceContext_GSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9060 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
9062 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
9063 ID3D11DeviceContext_PSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9064 ID3D11DeviceContext_PSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9065 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9067 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
9068 ID3D11DeviceContext_CSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9069 ID3D11DeviceContext_CSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9070 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
9071 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, cs_uav, NULL);
9073 ID3D11DeviceContext_IASetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
9074 buffer, stride, offset);
9075 ID3D11DeviceContext_IASetIndexBuffer(context, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
9076 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
9077 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9079 blend_factor[0] = 0.1f;
9080 blend_factor[1] = 0.2f;
9081 blend_factor[2] = 0.3f;
9082 blend_factor[3] = 0.4f;
9083 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, 0xff00ff00);
9084 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 3);
9085 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
9086 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, rtv, dsv,
9087 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, 1, &ps_uav, NULL);
9089 ID3D11DeviceContext_RSSetScissorRects(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
9090 tmp_rect);
9091 ID3D11DeviceContext_RSSetViewports(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
9092 tmp_viewport);
9093 ID3D11DeviceContext_RSSetState(context, rs_state);
9095 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
9097 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
9099 /* Verify the set state. */
9101 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9102 tmp_buffer);
9103 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9105 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
9106 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9107 tmp_buffer[i], i, expected_cb);
9108 if (tmp_buffer[i])
9109 ID3D11Buffer_Release(tmp_buffer[i]);
9111 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9112 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9114 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9115 tmp_srv[i], i, srv[i]);
9116 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9118 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9119 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9121 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9122 tmp_sampler[i], i, sampler[i]);
9123 ID3D11SamplerState_Release(tmp_sampler[i]);
9125 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
9126 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
9127 ID3D11VertexShader_Release(tmp_vs);
9129 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9130 tmp_buffer);
9131 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9133 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
9134 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9135 tmp_buffer[i], i, expected_cb);
9136 if (tmp_buffer[i])
9137 ID3D11Buffer_Release(tmp_buffer[i]);
9139 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9140 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9142 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9143 tmp_srv[i], i, srv[i]);
9144 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9146 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9147 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9149 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9150 tmp_sampler[i], i, sampler[i]);
9151 ID3D11SamplerState_Release(tmp_sampler[i]);
9153 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
9154 ok(tmp_hs == hs, "Got unexpected hull shader %p, expected %p.\n", tmp_hs, hs);
9155 ID3D11HullShader_Release(tmp_hs);
9157 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9158 tmp_buffer);
9159 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9161 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9162 tmp_buffer[i], i, cb[i]);
9163 ID3D11Buffer_Release(tmp_buffer[i]);
9165 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9166 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9168 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9169 tmp_srv[i], i, srv[i]);
9170 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9172 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9173 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9175 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9176 tmp_sampler[i], i, sampler[i]);
9177 ID3D11SamplerState_Release(tmp_sampler[i]);
9179 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
9180 ok(tmp_ds == ds, "Got unexpected domain shader %p, expected %p.\n", tmp_ds, ds);
9181 ID3D11DomainShader_Release(tmp_ds);
9183 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9184 tmp_buffer);
9185 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9187 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9188 tmp_buffer[i], i, cb[i]);
9189 ID3D11Buffer_Release(tmp_buffer[i]);
9191 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9192 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9194 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9195 tmp_srv[i], i, srv[i]);
9196 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9198 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9199 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9201 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9202 tmp_sampler[i], i, sampler[i]);
9203 ID3D11SamplerState_Release(tmp_sampler[i]);
9205 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
9206 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
9207 ID3D11GeometryShader_Release(tmp_gs);
9209 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9210 tmp_buffer);
9211 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9213 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9214 tmp_buffer[i], i, cb[i]);
9215 ID3D11Buffer_Release(tmp_buffer[i]);
9217 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9218 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9220 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9221 tmp_srv[i], i, srv[i]);
9222 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9224 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9225 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9227 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9228 tmp_sampler[i], i, sampler[i]);
9229 ID3D11SamplerState_Release(tmp_sampler[i]);
9231 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
9232 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
9233 ID3D11PixelShader_Release(tmp_ps);
9235 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9236 tmp_buffer);
9237 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9239 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9240 tmp_buffer[i], i, cb[i]);
9241 ID3D11Buffer_Release(tmp_buffer[i]);
9243 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9244 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9246 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9247 tmp_srv[i], i, srv[i]);
9248 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9250 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9251 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9253 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9254 tmp_sampler[i], i, sampler[i]);
9255 ID3D11SamplerState_Release(tmp_sampler[i]);
9257 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
9258 ok(tmp_cs == cs, "Got unexpected compute shader %p, expected %p.\n", tmp_cs, cs);
9259 ID3D11ComputeShader_Release(tmp_cs);
9260 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9261 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9263 ok(tmp_uav[i] == cs_uav[i], "Got unexpected unordered access view %p in slot %u, expected %p.\n",
9264 tmp_uav[i], i, cs_uav[i]);
9265 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
9268 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
9269 tmp_buffer, stride, offset);
9270 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9272 todo_wine_if(i >= D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
9274 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
9275 tmp_buffer[i], i, buffer[i]);
9276 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
9277 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
9279 if (tmp_buffer[i])
9280 ID3D11Buffer_Release(tmp_buffer[i]);
9282 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
9283 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
9284 ID3D11Buffer_Release(tmp_buffer[0]);
9285 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
9286 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
9287 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
9288 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
9289 tmp_input_layout, input_layout);
9290 ID3D11InputLayout_Release(tmp_input_layout);
9291 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
9292 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
9294 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
9295 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
9296 ID3D11BlendState_Release(tmp_blend_state);
9297 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
9298 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
9299 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
9300 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
9301 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
9302 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
9303 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
9304 ID3D11DepthStencilState_Release(tmp_ds_state);
9305 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
9306 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
9307 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
9309 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
9310 tmp_rtv[i], i, rtv[i]);
9311 ID3D11RenderTargetView_Release(tmp_rtv[i]);
9313 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9314 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
9315 ID3D11DepthStencilView_Release(tmp_dsv);
9316 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
9317 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
9318 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9319 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
9321 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
9322 tmp_rtv[i], i, rtv[i]);
9323 ID3D11RenderTargetView_Release(tmp_rtv[i]);
9325 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9326 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
9327 ID3D11DepthStencilView_Release(tmp_dsv);
9328 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT - 1; ++i)
9330 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9332 ok(tmp_uav[i] == ps_uav, "Got unexpected unordered access view %p in slot %u, expected %p.\n",
9333 tmp_uav[i], i, ps_uav);
9334 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
9336 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
9337 todo_wine ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
9338 "Got unexpected scissor rect count %u.\n", count);
9339 memset(tmp_rect, 0x55, sizeof(tmp_rect));
9340 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
9341 for (i = 0; i < count; ++i)
9343 ok(tmp_rect[i].left == i
9344 && tmp_rect[i].top == i * 2
9345 && tmp_rect[i].right == i + 1
9346 && tmp_rect[i].bottom == (i + 1) * 2,
9347 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
9349 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
9350 todo_wine ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
9351 "Got unexpected viewport count %u.\n", count);
9352 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
9353 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
9354 for (i = 0; i < count; ++i)
9356 ok(tmp_viewport[i].TopLeftX == i * 3
9357 && tmp_viewport[i].TopLeftY == i * 4
9358 && tmp_viewport[i].Width == 3
9359 && tmp_viewport[i].Height == 4
9360 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
9361 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
9362 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
9363 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
9364 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
9366 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
9367 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
9368 ID3D11RasterizerState_Release(tmp_rs_state);
9370 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
9371 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
9373 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
9374 tmp_buffer[i], i, so_buffer[i]);
9375 ID3D11Buffer_Release(tmp_buffer[i]);
9378 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
9379 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
9380 ID3D11Predicate_Release(tmp_predicate);
9381 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
9383 /* Verify ClearState(). */
9385 ID3D11DeviceContext_ClearState(context);
9387 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9388 tmp_buffer);
9389 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9391 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9393 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9394 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9396 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9398 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9399 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9401 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9403 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
9404 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
9406 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9407 tmp_buffer);
9408 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9410 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9412 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9413 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9415 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9417 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9418 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9420 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9422 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
9423 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
9425 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9426 tmp_buffer);
9427 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9429 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9431 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9432 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9434 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9436 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9437 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9439 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9441 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
9442 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
9444 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9445 tmp_buffer);
9446 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9448 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9450 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9451 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9453 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9455 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9456 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9458 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9460 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
9461 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
9463 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9464 tmp_buffer);
9465 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9467 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9469 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9470 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9472 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9474 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9475 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9477 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9479 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
9480 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
9482 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9483 tmp_buffer);
9484 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9486 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9488 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
9489 tmp_srv);
9490 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9492 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9494 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9495 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9497 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9499 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
9500 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
9501 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9502 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9504 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9507 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
9508 tmp_buffer, stride, offset);
9509 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9511 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
9512 todo_wine_if(i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
9514 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
9515 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
9518 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
9519 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
9520 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
9521 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
9522 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
9523 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
9524 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
9525 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
9527 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
9528 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
9529 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
9530 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
9531 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
9532 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
9533 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
9534 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
9535 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
9536 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
9537 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
9538 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9540 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9542 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
9543 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
9544 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
9545 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9546 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9548 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9550 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
9551 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9553 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9556 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
9557 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
9558 memset(tmp_rect, 0x55, sizeof(tmp_rect));
9559 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
9560 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
9561 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
9563 todo_wine_if(!i)
9564 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
9565 "Got unexpected scissor rect %s in slot %u.\n",
9566 wine_dbgstr_rect(&tmp_rect[i]), i);
9568 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
9569 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
9570 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
9571 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
9572 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
9573 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
9575 todo_wine_if(!i)
9576 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
9577 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
9578 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
9579 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
9580 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
9582 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
9583 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
9585 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
9586 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
9588 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
9591 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
9592 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
9593 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
9595 /* Cleanup. */
9597 ID3D11Predicate_Release(predicate);
9598 ID3D11RasterizerState_Release(rs_state);
9599 ID3D11DepthStencilView_Release(dsv);
9600 ID3D11Texture2D_Release(ds_texture);
9602 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9604 ID3D11RenderTargetView_Release(rtv[i]);
9605 ID3D11Texture2D_Release(rt_texture[i]);
9608 ID3D11DepthStencilState_Release(ds_state);
9609 ID3D11BlendState_Release(blend_state);
9610 ID3D11InputLayout_Release(input_layout);
9611 ID3D11VertexShader_Release(vs);
9612 ID3D11HullShader_Release(hs);
9613 ID3D11DomainShader_Release(ds);
9614 ID3D11GeometryShader_Release(gs);
9615 ID3D11PixelShader_Release(ps);
9616 ID3D11ComputeShader_Release(cs);
9618 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9620 ID3D11SamplerState_Release(sampler[i]);
9623 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9625 ID3D11ShaderResourceView_Release(srv[i]);
9628 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9630 ID3D11UnorderedAccessView_Release(cs_uav[i]);
9631 ID3D11Buffer_Release(cs_uav_buffer[i]);
9633 ID3D11UnorderedAccessView_Release(ps_uav);
9634 ID3D11Buffer_Release(ps_uav_buffer);
9636 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
9638 ID3D11Buffer_Release(so_buffer[i]);
9641 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9643 ID3D11Buffer_Release(buffer[i]);
9646 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9648 ID3D11Buffer_Release(cb[i]);
9651 ID3D11DeviceContext_Release(context);
9652 refcount = ID3D11Device_Release(device);
9653 ok(!refcount, "Device has %u references left.\n", refcount);
9656 static void test_il_append_aligned(void)
9658 struct d3d11_test_context test_context;
9659 ID3D11InputLayout *input_layout;
9660 ID3D11DeviceContext *context;
9661 unsigned int stride, offset;
9662 ID3D11VertexShader *vs;
9663 ID3D11PixelShader *ps;
9664 ID3D11Device *device;
9665 ID3D11Buffer *vb[3];
9666 DWORD color;
9667 HRESULT hr;
9669 /* Semantic names are case-insensitive. */
9670 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9672 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9673 D3D11_INPUT_PER_INSTANCE_DATA, 2},
9674 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
9675 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9676 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
9677 D3D11_INPUT_PER_VERTEX_DATA, 0},
9678 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
9679 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9680 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9681 D3D11_INPUT_PER_INSTANCE_DATA, 2},
9683 static const DWORD vs_code[] =
9685 #if 0
9686 struct vs_in
9688 float4 position : POSITION;
9689 float2 color_xy : COLOR0;
9690 float2 color_zw : COLOR1;
9691 unsigned int instance_id : SV_INSTANCEID;
9694 struct vs_out
9696 float4 position : SV_POSITION;
9697 float2 color_xy : COLOR0;
9698 float2 color_zw : COLOR1;
9701 struct vs_out main(struct vs_in i)
9703 struct vs_out o;
9705 o.position = i.position;
9706 o.position.x += i.instance_id * 0.5;
9707 o.color_xy = i.color_xy;
9708 o.color_zw = i.color_zw;
9710 return o;
9712 #endif
9713 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
9714 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
9715 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
9716 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
9717 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
9718 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
9719 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
9720 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
9721 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
9722 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
9723 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
9724 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
9725 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
9726 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
9727 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
9728 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
9729 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
9731 static const DWORD ps_code[] =
9733 #if 0
9734 struct vs_out
9736 float4 position : SV_POSITION;
9737 float2 color_xy : COLOR0;
9738 float2 color_zw : COLOR1;
9741 float4 main(struct vs_out i) : SV_TARGET
9743 return float4(i.color_xy.xy, i.color_zw.xy);
9745 #endif
9746 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
9747 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
9748 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
9749 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
9750 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
9751 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
9752 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
9753 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9754 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9756 static const struct
9758 struct vec4 position;
9760 stream0[] =
9762 {{-1.0f, -1.0f, 0.0f, 1.0f}},
9763 {{-1.0f, 1.0f, 0.0f, 1.0f}},
9764 {{-0.5f, -1.0f, 0.0f, 1.0f}},
9765 {{-0.5f, 1.0f, 0.0f, 1.0f}},
9767 static const struct
9769 struct vec2 color2;
9770 struct vec2 color1;
9772 stream1[] =
9774 {{0.5f, 0.5f}, {0.0f, 1.0f}},
9775 {{0.5f, 0.5f}, {1.0f, 1.0f}},
9777 static const struct
9779 struct vec2 color3;
9780 struct vec2 color0;
9782 stream2[] =
9784 {{0.5f, 0.5f}, {1.0f, 0.0f}},
9785 {{0.5f, 0.5f}, {0.0f, 1.0f}},
9786 {{0.5f, 0.5f}, {0.0f, 0.0f}},
9787 {{0.5f, 0.5f}, {1.0f, 0.0f}},
9789 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9791 if (!init_test_context(&test_context, NULL))
9792 return;
9794 device = test_context.device;
9795 context = test_context.immediate_context;
9797 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9798 vs_code, sizeof(vs_code), &input_layout);
9799 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9801 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
9802 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
9803 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
9805 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
9806 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9807 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9808 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9810 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
9811 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9812 offset = 0;
9813 stride = sizeof(*stream0);
9814 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
9815 stride = sizeof(*stream1);
9816 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
9817 stride = sizeof(*stream2);
9818 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
9819 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
9820 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9822 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9824 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
9826 color = get_texture_color(test_context.backbuffer, 80, 240);
9827 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9828 color = get_texture_color(test_context.backbuffer, 240, 240);
9829 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9830 color = get_texture_color(test_context.backbuffer, 400, 240);
9831 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9832 color = get_texture_color(test_context.backbuffer, 560, 240);
9833 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
9835 ID3D11PixelShader_Release(ps);
9836 ID3D11VertexShader_Release(vs);
9837 ID3D11Buffer_Release(vb[2]);
9838 ID3D11Buffer_Release(vb[1]);
9839 ID3D11Buffer_Release(vb[0]);
9840 ID3D11InputLayout_Release(input_layout);
9841 release_test_context(&test_context);
9844 static void test_instance_id(void)
9846 struct d3d11_test_context test_context;
9847 D3D11_TEXTURE2D_DESC texture_desc;
9848 ID3D11InputLayout *input_layout;
9849 ID3D11RenderTargetView *rtvs[2];
9850 ID3D11Texture2D *render_target;
9851 ID3D11DeviceContext *context;
9852 struct resource_readback rb;
9853 unsigned int stride, offset;
9854 ID3D11Buffer *args_buffer;
9855 ID3D11VertexShader *vs;
9856 ID3D11PixelShader *ps;
9857 ID3D11Device *device;
9858 ID3D11Buffer *vb[2];
9859 unsigned int i;
9860 HRESULT hr;
9862 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9864 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
9865 D3D11_INPUT_PER_VERTEX_DATA, 0},
9866 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9867 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9868 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9869 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9871 static const DWORD vs_code[] =
9873 #if 0
9874 struct vs_in
9876 float4 position : Position;
9877 float color : Color;
9878 float v_offset : V_Offset;
9879 uint instance_id : SV_InstanceId;
9882 struct vs_out
9884 float4 position : SV_Position;
9885 float color : Color;
9886 uint instance_id : InstanceId;
9889 void main(vs_in i, out vs_out o)
9891 o.position = i.position;
9892 o.position.x += i.v_offset;
9893 o.color = i.color;
9894 o.instance_id = i.instance_id;
9896 #endif
9897 0x43425844, 0xcde3cfbf, 0xe2e3d090, 0xe2eb1038, 0x7e5ad1cf, 0x00000001, 0x00000204, 0x00000003,
9898 0x0000002c, 0x000000c4, 0x0000013c, 0x4e475349, 0x00000090, 0x00000004, 0x00000008, 0x00000068,
9899 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
9900 0x00000003, 0x00000001, 0x00000101, 0x00000077, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
9901 0x00000101, 0x00000080, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x69736f50,
9902 0x6e6f6974, 0x6c6f4300, 0x5600726f, 0x66664f5f, 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e,
9903 0xabab0064, 0x4e47534f, 0x00000070, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
9904 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
9905 0x00000e01, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
9906 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
9907 0x000000c0, 0x00010040, 0x00000030, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
9908 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x04000060, 0x00101012, 0x00000003, 0x00000008,
9909 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
9910 0x00102012, 0x00000002, 0x07000000, 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x0010100a,
9911 0x00000002, 0x05000036, 0x001020e2, 0x00000000, 0x00101e56, 0x00000000, 0x05000036, 0x00102012,
9912 0x00000001, 0x0010100a, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000003,
9913 0x0100003e,
9915 static const DWORD ps_code[] =
9917 #if 0
9918 struct vs_out
9920 float4 position : SV_Position;
9921 float color : Color;
9922 uint instance_id : InstanceId;
9925 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
9927 o0 = float4(i.color, i.color, i.color, 1.0f);
9928 o1 = i.instance_id;
9930 #endif
9931 0x43425844, 0xda0ad0bb, 0x4743f5f5, 0xfbc6d0b1, 0x7c8e7df5, 0x00000001, 0x00000170, 0x00000003,
9932 0x0000002c, 0x000000a4, 0x000000f0, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
9933 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
9934 0x00000003, 0x00000001, 0x00000101, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002,
9935 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563,
9936 0xababab00, 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000,
9937 0x00000003, 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
9938 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000078, 0x00000040, 0x0000001e,
9939 0x03001062, 0x00101012, 0x00000001, 0x03000862, 0x00101012, 0x00000002, 0x03000065, 0x001020f2,
9940 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072, 0x00000000, 0x00101006,
9941 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x05000036, 0x001020f2,
9942 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
9944 static const struct vec4 stream0[] =
9946 {-1.00f, 0.0f, 0.0f, 1.0f},
9947 {-1.00f, 1.0f, 0.0f, 1.0f},
9948 {-0.75f, 0.0f, 0.0f, 1.0f},
9949 {-0.75f, 1.0f, 0.0f, 1.0f},
9950 /* indirect draws data */
9951 {-1.00f, -1.0f, 0.0f, 1.0f},
9952 {-1.00f, 0.0f, 0.0f, 1.0f},
9953 {-0.75f, -1.0f, 0.0f, 1.0f},
9954 {-0.75f, 0.0f, 0.0f, 1.0f},
9956 static const struct
9958 BYTE color;
9959 float v_offset;
9961 stream1[] =
9963 {0xf0, 0.00f},
9964 {0x80, 0.25f},
9965 {0x10, 0.50f},
9966 {0x40, 0.75f},
9968 {0xaa, 1.00f},
9969 {0xbb, 1.25f},
9970 {0xcc, 1.50f},
9971 {0x90, 1.75f},
9973 static const D3D11_DRAW_INSTANCED_INDIRECT_ARGS argument_data[] =
9975 {4, 4, 4, 0},
9976 {4, 4, 4, 4},
9978 static const struct
9980 RECT rect;
9981 unsigned int color;
9982 unsigned int instance_id;
9984 expected_results[] =
9986 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
9987 {{ 80, 0, 160, 240}, 0xff808080, 1},
9988 {{160, 0, 240, 240}, 0xff101010, 2},
9989 {{240, 0, 320, 240}, 0xff404040, 3},
9990 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
9991 {{400, 0, 480, 240}, 0xffbbbbbb, 1},
9992 {{480, 0, 560, 240}, 0xffcccccc, 2},
9993 {{560, 0, 640, 240}, 0xff909090, 3},
9994 /* indirect draws results */
9995 {{ 0, 240, 80, 480}, 0xfff0f0f0, 0},
9996 {{ 80, 240, 160, 480}, 0xff808080, 1},
9997 {{160, 240, 240, 480}, 0xff101010, 2},
9998 {{240, 240, 320, 480}, 0xff404040, 3},
9999 {{320, 240, 400, 480}, 0xffaaaaaa, 0},
10000 {{400, 240, 480, 480}, 0xffbbbbbb, 1},
10001 {{480, 240, 560, 480}, 0xffcccccc, 2},
10002 {{560, 240, 640, 480}, 0xff909090, 3},
10004 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
10005 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
10007 if (!init_test_context(&test_context, &feature_level))
10008 return;
10009 device = test_context.device;
10010 context = test_context.immediate_context;
10012 rtvs[0] = test_context.backbuffer_rtv;
10014 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10015 texture_desc.Format = DXGI_FORMAT_R32_UINT;
10016 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
10017 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10018 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtvs[1]);
10019 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10021 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10022 vs_code, sizeof(vs_code), &input_layout);
10023 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10025 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
10026 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10027 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10028 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10030 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
10031 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
10033 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
10034 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10035 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
10036 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10037 offset = 0;
10038 stride = sizeof(*stream0);
10039 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
10040 stride = sizeof(*stream1);
10041 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
10043 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
10044 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[1], white);
10046 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
10047 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
10048 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 4);
10050 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
10051 sizeof(argument_data), argument_data);
10053 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, 0);
10054 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, sizeof(*argument_data));
10056 get_texture_readback(test_context.backbuffer, 0, &rb);
10057 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
10058 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
10059 release_resource_readback(&rb);
10061 get_texture_readback(render_target, 0, &rb);
10062 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
10063 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
10064 release_resource_readback(&rb);
10066 ID3D11Buffer_Release(vb[0]);
10067 ID3D11Buffer_Release(vb[1]);
10068 ID3D11Buffer_Release(args_buffer);
10069 ID3D11RenderTargetView_Release(rtvs[1]);
10070 ID3D11Texture2D_Release(render_target);
10071 ID3D11VertexShader_Release(vs);
10072 ID3D11PixelShader_Release(ps);
10073 ID3D11InputLayout_Release(input_layout);
10074 release_test_context(&test_context);
10077 static void test_fragment_coords(void)
10079 struct d3d11_test_context test_context;
10080 ID3D11PixelShader *ps, *ps_frac;
10081 ID3D11DeviceContext *context;
10082 ID3D11Device *device;
10083 ID3D11Buffer *ps_cb;
10084 DWORD color;
10085 HRESULT hr;
10087 static const DWORD ps_code[] =
10089 #if 0
10090 float2 cutoff;
10092 float4 main(float4 position : SV_POSITION) : SV_TARGET
10094 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
10096 if (position.x > cutoff.x)
10097 ret.y = 1.0;
10098 if (position.y > cutoff.y)
10099 ret.z = 1.0;
10101 return ret;
10103 #endif
10104 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
10105 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10106 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10107 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10108 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
10109 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
10110 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
10111 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
10112 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
10113 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
10114 0x0100003e,
10116 static const DWORD ps_frac_code[] =
10118 #if 0
10119 float4 main(float4 position : SV_POSITION) : SV_TARGET
10121 return float4(frac(position.xy), 0.0, 1.0);
10123 #endif
10124 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
10125 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10126 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10127 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10128 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
10129 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10130 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
10131 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
10133 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10134 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
10136 if (!init_test_context(&test_context, NULL))
10137 return;
10139 device = test_context.device;
10140 context = test_context.immediate_context;
10142 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
10144 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10145 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10146 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
10147 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10149 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
10150 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10152 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
10154 draw_quad(&test_context);
10156 color = get_texture_color(test_context.backbuffer, 319, 239);
10157 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
10158 color = get_texture_color(test_context.backbuffer, 320, 239);
10159 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10160 color = get_texture_color(test_context.backbuffer, 319, 240);
10161 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
10162 color = get_texture_color(test_context.backbuffer, 320, 240);
10163 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
10165 ID3D11Buffer_Release(ps_cb);
10166 cutoff.x = 16.0f;
10167 cutoff.y = 16.0f;
10168 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
10169 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
10171 draw_quad(&test_context);
10173 color = get_texture_color(test_context.backbuffer, 14, 14);
10174 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
10175 color = get_texture_color(test_context.backbuffer, 18, 14);
10176 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10177 color = get_texture_color(test_context.backbuffer, 14, 18);
10178 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
10179 color = get_texture_color(test_context.backbuffer, 18, 18);
10180 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
10182 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
10183 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
10185 ID3D11DeviceContext_Draw(context, 4, 0);
10187 color = get_texture_color(test_context.backbuffer, 14, 14);
10188 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
10190 ID3D11Buffer_Release(ps_cb);
10191 ID3D11PixelShader_Release(ps_frac);
10192 ID3D11PixelShader_Release(ps);
10193 release_test_context(&test_context);
10196 static void test_update_subresource(void)
10198 struct d3d11_test_context test_context;
10199 D3D11_SUBRESOURCE_DATA resource_data;
10200 D3D11_TEXTURE2D_DESC texture_desc;
10201 ID3D11SamplerState *sampler_state;
10202 ID3D11ShaderResourceView *ps_srv;
10203 D3D11_SAMPLER_DESC sampler_desc;
10204 ID3D11DeviceContext *context;
10205 struct resource_readback rb;
10206 ID3D11Texture2D *texture;
10207 ID3D11PixelShader *ps;
10208 ID3D11Device *device;
10209 unsigned int i, j;
10210 D3D11_BOX box;
10211 DWORD color;
10212 HRESULT hr;
10214 static const DWORD ps_code[] =
10216 #if 0
10217 Texture2D t;
10218 SamplerState s;
10220 float4 main(float4 position : SV_POSITION) : SV_Target
10222 float2 p;
10224 p.x = position.x / 640.0f;
10225 p.y = position.y / 480.0f;
10226 return t.Sample(s, p);
10228 #endif
10229 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
10230 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10231 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10232 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10233 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
10234 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10235 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10236 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10237 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
10238 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
10240 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10241 static const DWORD initial_data[16] = {0};
10242 static const DWORD bitmap_data[] =
10244 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
10245 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
10246 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
10247 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
10249 static const DWORD expected_colors[] =
10251 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
10252 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
10253 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
10254 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
10257 if (!init_test_context(&test_context, NULL))
10258 return;
10260 device = test_context.device;
10261 context = test_context.immediate_context;
10263 texture_desc.Width = 4;
10264 texture_desc.Height = 4;
10265 texture_desc.MipLevels = 1;
10266 texture_desc.ArraySize = 1;
10267 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10268 texture_desc.SampleDesc.Count = 1;
10269 texture_desc.SampleDesc.Quality = 0;
10270 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10271 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
10272 texture_desc.CPUAccessFlags = 0;
10273 texture_desc.MiscFlags = 0;
10275 resource_data.pSysMem = initial_data;
10276 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
10277 resource_data.SysMemSlicePitch = 0;
10279 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
10280 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10282 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
10283 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10285 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
10286 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10287 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10288 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10289 sampler_desc.MipLODBias = 0.0f;
10290 sampler_desc.MaxAnisotropy = 0;
10291 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
10292 sampler_desc.BorderColor[0] = 0.0f;
10293 sampler_desc.BorderColor[1] = 0.0f;
10294 sampler_desc.BorderColor[2] = 0.0f;
10295 sampler_desc.BorderColor[3] = 0.0f;
10296 sampler_desc.MinLOD = 0.0f;
10297 sampler_desc.MaxLOD = 0.0f;
10299 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
10300 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10302 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10303 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10305 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
10306 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
10307 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10309 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
10310 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
10312 draw_quad(&test_context);
10313 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10315 set_box(&box, 1, 1, 0, 3, 3, 1);
10316 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10317 bitmap_data, 4 * sizeof(*bitmap_data), 0);
10318 set_box(&box, 0, 3, 0, 3, 4, 1);
10319 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10320 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
10321 set_box(&box, 0, 0, 0, 4, 1, 1);
10322 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10323 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
10324 set_box(&box, 0, 1, 0, 1, 3, 1);
10325 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10326 &bitmap_data[2], sizeof(*bitmap_data), 0);
10327 set_box(&box, 4, 4, 0, 3, 1, 1);
10328 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10329 bitmap_data, sizeof(*bitmap_data), 0);
10330 set_box(&box, 0, 0, 0, 4, 4, 0);
10331 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10332 bitmap_data, 4 * sizeof(*bitmap_data), 0);
10333 draw_quad(&test_context);
10334 get_texture_readback(test_context.backbuffer, 0, &rb);
10335 for (i = 0; i < 4; ++i)
10337 for (j = 0; j < 4; ++j)
10339 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10340 ok(compare_color(color, expected_colors[j + i * 4], 1),
10341 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10342 color, j, i, expected_colors[j + i * 4]);
10345 release_resource_readback(&rb);
10347 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
10348 bitmap_data, 4 * sizeof(*bitmap_data), 0);
10349 draw_quad(&test_context);
10350 get_texture_readback(test_context.backbuffer, 0, &rb);
10351 for (i = 0; i < 4; ++i)
10353 for (j = 0; j < 4; ++j)
10355 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10356 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10357 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10358 color, j, i, bitmap_data[j + i * 4]);
10361 release_resource_readback(&rb);
10363 ID3D11PixelShader_Release(ps);
10364 ID3D11SamplerState_Release(sampler_state);
10365 ID3D11ShaderResourceView_Release(ps_srv);
10366 ID3D11Texture2D_Release(texture);
10367 release_test_context(&test_context);
10370 static void test_copy_subresource_region(void)
10372 ID3D11Texture2D *dst_texture, *src_texture;
10373 struct d3d11_test_context test_context;
10374 ID3D11Buffer *dst_buffer, *src_buffer;
10375 D3D11_SUBRESOURCE_DATA resource_data;
10376 D3D11_TEXTURE2D_DESC texture_desc;
10377 ID3D11SamplerState *sampler_state;
10378 ID3D11ShaderResourceView *ps_srv;
10379 D3D11_SAMPLER_DESC sampler_desc;
10380 ID3D11DeviceContext *context;
10381 struct vec4 float_colors[16];
10382 struct resource_readback rb;
10383 ID3D11PixelShader *ps;
10384 ID3D11Device *device;
10385 unsigned int i, j;
10386 D3D11_BOX box;
10387 DWORD color;
10388 HRESULT hr;
10390 static const DWORD ps_code[] =
10392 #if 0
10393 Texture2D t;
10394 SamplerState s;
10396 float4 main(float4 position : SV_POSITION) : SV_Target
10398 float2 p;
10400 p.x = position.x / 640.0f;
10401 p.y = position.y / 480.0f;
10402 return t.Sample(s, p);
10404 #endif
10405 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
10406 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10407 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10408 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10409 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
10410 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10411 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10412 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10413 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
10414 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
10416 static const DWORD ps_buffer_code[] =
10418 #if 0
10419 float4 buffer[16];
10421 float4 main(float4 position : SV_POSITION) : SV_TARGET
10423 float2 p = (float2)4;
10424 p *= float2(position.x / 640.0f, position.y / 480.0f);
10425 return buffer[(int)p.y * 4 + (int)p.x];
10427 #endif
10428 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
10429 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10430 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10431 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10432 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
10433 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
10434 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
10435 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
10436 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
10437 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
10438 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
10439 0x0010000a, 0x00000000, 0x0100003e,
10441 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10442 static const DWORD initial_data[16] = {0};
10443 static const DWORD bitmap_data[] =
10445 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
10446 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
10447 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
10448 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
10450 static const DWORD expected_colors[] =
10452 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
10453 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
10454 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
10455 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
10458 if (!init_test_context(&test_context, NULL))
10459 return;
10461 device = test_context.device;
10462 context = test_context.immediate_context;
10464 texture_desc.Width = 4;
10465 texture_desc.Height = 4;
10466 texture_desc.MipLevels = 1;
10467 texture_desc.ArraySize = 1;
10468 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10469 texture_desc.SampleDesc.Count = 1;
10470 texture_desc.SampleDesc.Quality = 0;
10471 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10472 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
10473 texture_desc.CPUAccessFlags = 0;
10474 texture_desc.MiscFlags = 0;
10476 resource_data.pSysMem = initial_data;
10477 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
10478 resource_data.SysMemSlicePitch = 0;
10480 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
10481 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10483 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
10485 resource_data.pSysMem = bitmap_data;
10486 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
10487 resource_data.SysMemSlicePitch = 0;
10489 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
10490 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10492 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
10493 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10495 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
10496 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10497 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10498 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10499 sampler_desc.MipLODBias = 0.0f;
10500 sampler_desc.MaxAnisotropy = 0;
10501 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
10502 sampler_desc.BorderColor[0] = 0.0f;
10503 sampler_desc.BorderColor[1] = 0.0f;
10504 sampler_desc.BorderColor[2] = 0.0f;
10505 sampler_desc.BorderColor[3] = 0.0f;
10506 sampler_desc.MinLOD = 0.0f;
10507 sampler_desc.MaxLOD = 0.0f;
10509 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
10510 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10512 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10513 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10515 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
10516 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
10517 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10519 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
10521 set_box(&box, 0, 0, 0, 2, 2, 1);
10522 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10523 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
10524 set_box(&box, 1, 2, 0, 4, 3, 1);
10525 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10526 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
10527 set_box(&box, 0, 3, 0, 4, 4, 1);
10528 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10529 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
10530 set_box(&box, 3, 0, 0, 4, 2, 1);
10531 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10532 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
10533 set_box(&box, 3, 1, 0, 4, 2, 1);
10534 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10535 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
10536 set_box(&box, 0, 0, 0, 4, 4, 0);
10537 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10538 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
10539 draw_quad(&test_context);
10540 get_texture_readback(test_context.backbuffer, 0, &rb);
10541 for (i = 0; i < 4; ++i)
10543 for (j = 0; j < 4; ++j)
10545 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10546 ok(compare_color(color, expected_colors[j + i * 4], 1),
10547 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10548 color, j, i, expected_colors[j + i * 4]);
10551 release_resource_readback(&rb);
10553 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10554 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
10555 draw_quad(&test_context);
10556 get_texture_readback(test_context.backbuffer, 0, &rb);
10557 for (i = 0; i < 4; ++i)
10559 for (j = 0; j < 4; ++j)
10561 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10562 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10563 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10564 color, j, i, bitmap_data[j + i * 4]);
10567 release_resource_readback(&rb);
10569 ID3D11PixelShader_Release(ps);
10570 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
10571 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10573 ID3D11ShaderResourceView_Release(ps_srv);
10574 ps_srv = NULL;
10576 ID3D11SamplerState_Release(sampler_state);
10577 sampler_state = NULL;
10579 ID3D11Texture2D_Release(dst_texture);
10580 ID3D11Texture2D_Release(src_texture);
10582 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
10583 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
10584 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10586 memset(float_colors, 0, sizeof(float_colors));
10587 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
10588 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
10590 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
10592 for (i = 0; i < 4; ++i)
10594 for (j = 0; j < 4; ++j)
10596 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
10597 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
10598 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
10599 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
10602 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
10603 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
10605 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
10606 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
10607 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
10608 draw_quad(&test_context);
10609 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10611 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
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), 0, 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), 1, 1);
10624 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
10625 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
10626 draw_quad(&test_context);
10627 get_texture_readback(test_context.backbuffer, 0, &rb);
10628 for (i = 0; i < 4; ++i)
10630 for (j = 0; j < 4; ++j)
10632 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10633 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10634 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10635 color, j, i, bitmap_data[j + i * 4]);
10638 release_resource_readback(&rb);
10640 ID3D11Buffer_Release(dst_buffer);
10641 ID3D11Buffer_Release(src_buffer);
10642 ID3D11PixelShader_Release(ps);
10643 release_test_context(&test_context);
10646 static void test_resource_map(void)
10648 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
10649 D3D11_TEXTURE3D_DESC texture3d_desc;
10650 D3D11_TEXTURE2D_DESC texture2d_desc;
10651 D3D11_BUFFER_DESC buffer_desc;
10652 ID3D11DeviceContext *context;
10653 ID3D11Texture3D *texture3d;
10654 ID3D11Texture2D *texture2d;
10655 ID3D11Buffer *buffer;
10656 ID3D11Device *device;
10657 ULONG refcount;
10658 HRESULT hr;
10659 DWORD data;
10661 if (!(device = create_device(NULL)))
10663 skip("Failed to create device.\n");
10664 return;
10667 ID3D11Device_GetImmediateContext(device, &context);
10669 buffer_desc.ByteWidth = 1024;
10670 buffer_desc.Usage = D3D11_USAGE_STAGING;
10671 buffer_desc.BindFlags = 0;
10672 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10673 buffer_desc.MiscFlags = 0;
10674 buffer_desc.StructureByteStride = 0;
10676 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
10677 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
10679 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10680 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10682 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10683 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10684 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
10685 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10686 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
10687 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10688 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
10690 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10691 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10692 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
10693 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10694 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
10695 data = *((DWORD *)mapped_subresource.pData);
10696 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10697 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
10699 refcount = ID3D11Buffer_Release(buffer);
10700 ok(!refcount, "Buffer has %u references left.\n", refcount);
10702 texture2d_desc.Width = 512;
10703 texture2d_desc.Height = 512;
10704 texture2d_desc.MipLevels = 1;
10705 texture2d_desc.ArraySize = 1;
10706 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10707 texture2d_desc.SampleDesc.Count = 1;
10708 texture2d_desc.SampleDesc.Quality = 0;
10709 texture2d_desc.Usage = D3D11_USAGE_STAGING;
10710 texture2d_desc.BindFlags = 0;
10711 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10712 texture2d_desc.MiscFlags = 0;
10714 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
10715 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10717 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10718 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10720 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10721 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10722 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10723 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10724 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
10725 mapped_subresource.DepthPitch);
10726 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10727 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
10729 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10730 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10731 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10732 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10733 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
10734 mapped_subresource.DepthPitch);
10735 data = *((DWORD *)mapped_subresource.pData);
10736 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10737 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
10739 refcount = ID3D11Texture2D_Release(texture2d);
10740 ok(!refcount, "2D texture has %u references left.\n", refcount);
10742 texture3d_desc.Width = 64;
10743 texture3d_desc.Height = 64;
10744 texture3d_desc.Depth = 64;
10745 texture3d_desc.MipLevels = 1;
10746 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10747 texture3d_desc.Usage = D3D11_USAGE_STAGING;
10748 texture3d_desc.BindFlags = 0;
10749 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10750 texture3d_desc.MiscFlags = 0;
10752 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
10753 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
10755 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10756 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10758 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10759 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10760 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10761 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10762 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
10763 mapped_subresource.DepthPitch);
10764 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10765 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
10767 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10768 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10769 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10770 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10771 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
10772 mapped_subresource.DepthPitch);
10773 data = *((DWORD *)mapped_subresource.pData);
10774 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10775 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
10777 refcount = ID3D11Texture3D_Release(texture3d);
10778 ok(!refcount, "3D texture has %u references left.\n", refcount);
10780 ID3D11DeviceContext_Release(context);
10782 refcount = ID3D11Device_Release(device);
10783 ok(!refcount, "Device has %u references left.\n", refcount);
10786 static void test_check_multisample_quality_levels(void)
10788 ID3D11Device *device;
10789 UINT quality_levels;
10790 ULONG refcount;
10791 HRESULT hr;
10793 if (!(device = create_device(NULL)))
10795 skip("Failed to create device.\n");
10796 return;
10799 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10800 if (!quality_levels)
10802 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
10803 goto done;
10806 quality_levels = 0xdeadbeef;
10807 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
10808 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10809 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10810 quality_levels = 0xdeadbeef;
10811 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
10812 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10813 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
10815 quality_levels = 0xdeadbeef;
10816 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
10817 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10818 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
10819 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10820 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10822 quality_levels = 0xdeadbeef;
10823 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
10824 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10825 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
10826 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10827 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
10829 quality_levels = 0xdeadbeef;
10830 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
10831 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10832 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10833 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10834 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10836 /* We assume 15 samples multisampling is never supported in practice. */
10837 quality_levels = 0xdeadbeef;
10838 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
10839 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10840 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10841 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
10842 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10843 quality_levels = 0xdeadbeef;
10844 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
10845 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10846 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10847 quality_levels = 0xdeadbeef;
10848 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
10849 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10850 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10852 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
10853 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10854 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10856 done:
10857 refcount = ID3D11Device_Release(device);
10858 ok(!refcount, "Device has %u references left.\n", refcount);
10861 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
10863 DXGI_SWAP_CHAIN_DESC swapchain_desc;
10864 struct device_desc device_desc;
10865 IDXGISwapChain *swapchain;
10866 IDXGIDevice *dxgi_device;
10867 HRESULT hr, expected_hr;
10868 IDXGIAdapter *adapter;
10869 IDXGIFactory *factory;
10870 ID3D11Device *device;
10871 unsigned int i;
10872 ULONG refcount;
10874 swapchain_desc.BufferDesc.Width = 800;
10875 swapchain_desc.BufferDesc.Height = 600;
10876 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
10877 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
10878 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
10879 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
10880 swapchain_desc.SampleDesc.Count = 1;
10881 swapchain_desc.SampleDesc.Quality = 0;
10882 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
10883 swapchain_desc.BufferCount = 1;
10884 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
10885 swapchain_desc.Windowed = TRUE;
10886 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
10887 swapchain_desc.Flags = 0;
10889 device_desc.feature_level = &feature_level;
10890 device_desc.flags = 0;
10891 if (!(device = create_device(&device_desc)))
10893 skip("Failed to create device for feature level %#x.\n", feature_level);
10894 return;
10897 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
10898 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
10899 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
10900 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
10901 IDXGIDevice_Release(dxgi_device);
10902 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
10903 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
10904 IDXGIAdapter_Release(adapter);
10906 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
10907 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10908 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
10909 hr, feature_level);
10910 if (SUCCEEDED(hr))
10911 IDXGISwapChain_Release(swapchain);
10913 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
10915 DXGI_FORMAT format = display_format_support[i].format;
10916 BOOL todo = FALSE;
10918 if (display_format_support[i].fl_required <= feature_level)
10920 expected_hr = S_OK;
10921 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
10922 todo = TRUE;
10924 else if (!display_format_support[i].fl_optional
10925 || display_format_support[i].fl_optional > feature_level)
10927 expected_hr = E_INVALIDARG;
10928 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
10929 todo = TRUE;
10931 else
10933 continue;
10936 swapchain_desc.BufferDesc.Format = format;
10937 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10938 todo_wine_if(todo)
10939 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
10940 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
10941 hr, expected_hr, feature_level, format);
10942 if (FAILED(hr))
10943 continue;
10944 refcount = IDXGISwapChain_Release(swapchain);
10945 ok(!refcount, "Swapchain has %u references left.\n", refcount);
10948 refcount = ID3D11Device_Release(device);
10949 ok(!refcount, "Device has %u references left.\n", refcount);
10950 refcount = IDXGIFactory_Release(factory);
10951 ok(!refcount, "Factory has %u references left.\n", refcount);
10952 DestroyWindow(swapchain_desc.OutputWindow);
10955 static void test_swapchain_views(void)
10957 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10958 struct d3d11_test_context test_context;
10959 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
10960 ID3D11ShaderResourceView *srv;
10961 ID3D11DeviceContext *context;
10962 ID3D11RenderTargetView *rtv;
10963 ID3D11Device *device;
10964 ULONG refcount;
10965 HRESULT hr;
10967 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
10969 if (!init_test_context(&test_context, NULL))
10970 return;
10972 device = test_context.device;
10973 context = test_context.immediate_context;
10975 refcount = get_refcount(test_context.backbuffer);
10976 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
10978 draw_color_quad(&test_context, &color);
10979 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
10981 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10982 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
10983 U(rtv_desc).Texture2D.MipSlice = 0;
10984 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
10985 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10986 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10988 refcount = get_refcount(test_context.backbuffer);
10989 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
10991 draw_color_quad(&test_context, &color);
10992 todo_wine check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
10994 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10995 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
10996 U(srv_desc).Texture2D.MostDetailedMip = 0;
10997 U(srv_desc).Texture2D.MipLevels = 1;
10998 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
10999 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11000 if (SUCCEEDED(hr))
11001 ID3D11ShaderResourceView_Release(srv);
11003 ID3D11RenderTargetView_Release(rtv);
11004 release_test_context(&test_context);
11007 static void test_swapchain_flip(void)
11009 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
11010 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
11011 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
11012 D3D11_TEXTURE2D_DESC texture_desc;
11013 ID3D11InputLayout *input_layout;
11014 ID3D11DeviceContext *context;
11015 unsigned int stride, offset;
11016 struct swapchain_desc desc;
11017 IDXGISwapChain *swapchain;
11018 ID3D11VertexShader *vs;
11019 ID3D11PixelShader *ps;
11020 ID3D11Device *device;
11021 D3D11_VIEWPORT vp;
11022 ID3D11Buffer *vb;
11023 ULONG refcount;
11024 DWORD color;
11025 HWND window;
11026 HRESULT hr;
11027 RECT rect;
11029 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11031 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11033 static const DWORD vs_code[] =
11035 #if 0
11036 float4 main(float4 position : POSITION) : SV_POSITION
11038 return position;
11040 #endif
11041 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
11042 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11043 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11044 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
11045 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
11046 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
11047 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11050 static const DWORD ps_code[] =
11052 #if 0
11053 Texture2D t0, t1;
11054 SamplerState s;
11056 float4 main(float4 position : SV_POSITION) : SV_Target
11058 float2 p;
11060 p.x = 0.5;
11061 p.y = 0.5;
11062 if (position.x < 320)
11063 return t0.Sample(s, p);
11064 return t1.Sample(s, p);
11066 #endif
11067 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
11068 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11069 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
11070 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11071 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
11072 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
11073 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
11074 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
11075 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
11076 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
11077 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
11078 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
11079 0x00000000, 0x0100003e,
11081 static const struct vec2 quad[] =
11083 {-1.0f, -1.0f},
11084 {-1.0f, 1.0f},
11085 { 1.0f, -1.0f},
11086 { 1.0f, 1.0f},
11088 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
11089 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
11090 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
11092 if (!(device = create_device(NULL)))
11094 skip("Failed to create device, skipping tests.\n");
11095 return;
11097 SetRect(&rect, 0, 0, 640, 480);
11098 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
11099 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11100 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
11101 desc.buffer_count = 3;
11102 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
11103 desc.windowed = TRUE;
11104 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
11105 swapchain = create_swapchain(device, window, &desc);
11107 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
11108 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
11109 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
11110 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
11111 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
11112 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
11114 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
11115 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11116 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
11117 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11118 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
11119 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11121 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
11122 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
11123 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
11124 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
11125 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
11127 ID3D11Texture2D_GetDesc(backbuffer_1, &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 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
11134 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11135 if (SUCCEEDED(hr))
11136 ID3D11RenderTargetView_Release(offscreen_rtv);
11138 ID3D11Device_GetImmediateContext(device, &context);
11140 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
11141 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
11143 texture_desc.Width = 640;
11144 texture_desc.Height = 480;
11145 texture_desc.MipLevels = 1;
11146 texture_desc.ArraySize = 1;
11147 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11148 texture_desc.SampleDesc.Count = 1;
11149 texture_desc.SampleDesc.Quality = 0;
11150 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11151 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11152 texture_desc.CPUAccessFlags = 0;
11153 texture_desc.MiscFlags = 0;
11154 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
11155 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
11156 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
11157 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11158 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
11159 vp.TopLeftX = 0;
11160 vp.TopLeftY = 0;
11161 vp.Width = 640;
11162 vp.Height = 480;
11163 vp.MinDepth = 0.0f;
11164 vp.MaxDepth = 1.0f;
11165 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11167 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11169 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11170 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11171 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11172 vs_code, sizeof(vs_code), &input_layout);
11173 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11174 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
11175 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11176 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11177 stride = sizeof(*quad);
11178 offset = 0;
11179 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
11181 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11182 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11183 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11185 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
11187 ID3D11DeviceContext_Draw(context, 4, 0);
11188 color = get_texture_color(offscreen, 120, 240);
11189 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11191 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
11192 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
11193 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
11195 * What is this good for? I don't know. Ad-hoc tests suggest that
11196 * Present() always waits for the next V-sync interval, even if there are
11197 * still untouched buffers. Buffer 0 is the buffer that is shown on the
11198 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
11199 * rendering finishes before the V-sync interval is over. I haven't found
11200 * any productive use for more than one buffer. */
11201 IDXGISwapChain_Present(swapchain, 0, 0);
11203 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
11205 ID3D11DeviceContext_Draw(context, 4, 0);
11206 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
11207 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11208 /* Buffer 1 is still untouched. */
11210 color = get_texture_color(backbuffer_0, 320, 240); /* green */
11211 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11212 color = get_texture_color(backbuffer_2, 320, 240); /* red */
11213 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11215 IDXGISwapChain_Present(swapchain, 0, 0);
11217 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
11219 ID3D11DeviceContext_Draw(context, 4, 0);
11220 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
11221 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
11222 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
11223 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11225 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
11226 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
11227 color = get_texture_color(backbuffer_1, 320, 240); /* red */
11228 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11229 color = get_texture_color(backbuffer_2, 320, 240); /* green */
11230 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11232 ID3D11VertexShader_Release(vs);
11233 ID3D11PixelShader_Release(ps);
11234 ID3D11Buffer_Release(vb);
11235 ID3D11InputLayout_Release(input_layout);
11236 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
11237 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
11238 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
11239 ID3D11RenderTargetView_Release(offscreen_rtv);
11240 ID3D11Texture2D_Release(offscreen);
11241 ID3D11Texture2D_Release(backbuffer_0);
11242 ID3D11Texture2D_Release(backbuffer_1);
11243 ID3D11Texture2D_Release(backbuffer_2);
11244 IDXGISwapChain_Release(swapchain);
11246 ID3D11DeviceContext_Release(context);
11247 refcount = ID3D11Device_Release(device);
11248 ok(!refcount, "Device has %u references left.\n", refcount);
11249 DestroyWindow(window);
11252 static void test_clear_render_target_view(void)
11254 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
11255 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
11256 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
11258 ID3D11Texture2D *texture, *srgb_texture;
11259 struct d3d11_test_context test_context;
11260 ID3D11RenderTargetView *rtv, *srgb_rtv;
11261 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
11262 D3D11_TEXTURE2D_DESC texture_desc;
11263 ID3D11DeviceContext *context;
11264 struct resource_readback rb;
11265 ID3D11Device *device;
11266 unsigned int i, j;
11267 HRESULT hr;
11269 if (!init_test_context(&test_context, NULL))
11270 return;
11272 device = test_context.device;
11273 context = test_context.immediate_context;
11275 texture_desc.Width = 640;
11276 texture_desc.Height = 480;
11277 texture_desc.MipLevels = 1;
11278 texture_desc.ArraySize = 1;
11279 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11280 texture_desc.SampleDesc.Count = 1;
11281 texture_desc.SampleDesc.Quality = 0;
11282 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11283 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11284 texture_desc.CPUAccessFlags = 0;
11285 texture_desc.MiscFlags = 0;
11286 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11287 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11289 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11290 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
11291 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11293 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11294 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11296 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
11297 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11299 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
11300 check_texture_color(test_context.backbuffer, expected_color, 1);
11302 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
11303 check_texture_color(texture, expected_color, 1);
11305 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
11306 check_texture_color(texture, expected_color, 1);
11308 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
11309 check_texture_color(srgb_texture, expected_srgb_color, 1);
11311 ID3D11RenderTargetView_Release(srgb_rtv);
11312 ID3D11RenderTargetView_Release(rtv);
11313 ID3D11Texture2D_Release(srgb_texture);
11314 ID3D11Texture2D_Release(texture);
11316 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
11317 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11318 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11320 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11321 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
11322 U(rtv_desc).Texture2D.MipSlice = 0;
11323 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
11324 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11326 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11327 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
11328 U(rtv_desc).Texture2D.MipSlice = 0;
11329 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11330 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11332 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
11333 check_texture_color(texture, expected_color, 1);
11335 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
11336 get_texture_readback(texture, 0, &rb);
11337 for (i = 0; i < 4; ++i)
11339 for (j = 0; j < 4; ++j)
11341 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
11342 DWORD color = get_readback_color(&rb, 80 + i * 160, 60 + j * 120);
11343 ok(compare_color(color, expected_srgb_color, 1)
11344 || broken(compare_color(color, expected_color, 1) && broken_device),
11345 "Got unexpected color 0x%08x.\n", color);
11348 release_resource_readback(&rb);
11350 ID3D11RenderTargetView_Release(srgb_rtv);
11351 ID3D11RenderTargetView_Release(rtv);
11352 ID3D11Texture2D_Release(texture);
11353 release_test_context(&test_context);
11356 static void test_clear_depth_stencil_view(void)
11358 D3D11_TEXTURE2D_DESC texture_desc;
11359 ID3D11Texture2D *depth_texture;
11360 ID3D11DeviceContext *context;
11361 ID3D11DepthStencilView *dsv;
11362 ID3D11Device *device;
11363 ULONG refcount;
11364 HRESULT hr;
11366 if (!(device = create_device(NULL)))
11368 skip("Failed to create device.\n");
11369 return;
11372 ID3D11Device_GetImmediateContext(device, &context);
11374 texture_desc.Width = 640;
11375 texture_desc.Height = 480;
11376 texture_desc.MipLevels = 1;
11377 texture_desc.ArraySize = 1;
11378 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11379 texture_desc.SampleDesc.Count = 1;
11380 texture_desc.SampleDesc.Quality = 0;
11381 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11382 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
11383 texture_desc.CPUAccessFlags = 0;
11384 texture_desc.MiscFlags = 0;
11385 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
11386 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11388 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
11389 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11391 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11392 check_texture_float(depth_texture, 1.0f, 0);
11394 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
11395 check_texture_float(depth_texture, 0.25f, 0);
11397 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
11398 check_texture_float(depth_texture, 0.25f, 0);
11400 ID3D11Texture2D_Release(depth_texture);
11401 ID3D11DepthStencilView_Release(dsv);
11403 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
11404 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
11405 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11407 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
11408 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11410 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
11411 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
11413 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
11414 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
11416 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
11417 check_texture_color(depth_texture, 0xffffffff, 0);
11419 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
11420 check_texture_color(depth_texture, 0x00000000, 0);
11422 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
11423 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
11425 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
11426 check_texture_color(depth_texture, 0xffffffff, 0);
11428 ID3D11Texture2D_Release(depth_texture);
11429 ID3D11DepthStencilView_Release(dsv);
11431 ID3D11DeviceContext_Release(context);
11433 refcount = ID3D11Device_Release(device);
11434 ok(!refcount, "Device has %u references left.\n", refcount);
11437 static unsigned int to_sint8(unsigned int x)
11439 union
11441 signed int s;
11442 unsigned int u;
11443 } bits;
11444 bits.u = x;
11445 return min(max(bits.s, -128), 127) & 0xff;
11448 #define check_rgba_sint8(data, uvec) check_rgba_sint8_(__LINE__, data, uvec)
11449 static void check_rgba_sint8_(unsigned int line, DWORD data, const struct uvec4 *v)
11451 unsigned int x = to_sint8(v->x);
11452 unsigned int y = to_sint8(v->y);
11453 unsigned int z = to_sint8(v->z);
11454 unsigned int w = to_sint8(v->w);
11455 DWORD expected[] =
11457 /* Windows 7 - Nvidia, WARP */
11458 (v->x & 0xff) | (v->y & 0xff) << 8 | (v->z & 0xff) << 16 | (v->w & 0xff) << 24,
11459 /* Windows 10 - AMD */
11460 x | y << 8 | z << 16 | w << 24,
11461 /* Windows 10 - Intel */
11462 x | x << 8 | x << 16 | x << 24,
11465 ok_(__FILE__, line)(data == expected[0] || data == expected[1] || broken(data == expected[2]),
11466 "Got %#x, expected %#x or %#x at %u, uvec4 %#x, %#x, %#x, %#x.\n",
11467 data, expected[0], expected[1], x, v->x, v->y, v->z, v->w);
11470 static void test_clear_buffer_unordered_access_view(void)
11472 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
11473 ID3D11UnorderedAccessView *uav, *uav2;
11474 struct device_desc device_desc;
11475 D3D11_BUFFER_DESC buffer_desc;
11476 ID3D11DeviceContext *context;
11477 struct resource_readback rb;
11478 ID3D11Buffer *buffer;
11479 ID3D11Device *device;
11480 struct uvec4 uvec4;
11481 unsigned int i, x;
11482 ULONG refcount;
11483 HRESULT hr;
11485 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11486 static const struct uvec4 fe_uvec4 = {0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe};
11487 static const struct uvec4 uvec4_data[] =
11489 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
11491 {0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
11492 {0xffffffff, 0x00000000, 0x00000000, 0x00000000},
11493 {0x00000000, 0xffffffff, 0x00000000, 0x00000000},
11494 {0x00000000, 0x00000000, 0xffffffff, 0x00000000},
11495 {0x00000000, 0x00000000, 0x00000000, 0xffffffff},
11497 {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff},
11498 {0x80000000, 0x80000000, 0x80000000, 0x80000000},
11499 {0x000000ff, 0x00000080, 0x80000080, 0x00000080},
11500 {0x000000ff, 0x0000007f, 0x000000ef, 0x000000fe},
11501 {0x800000ff, 0x8000007f, 0x800000ef, 0x800000fe},
11502 {0xfefefefe, 0xf0f0f0f0, 0xefefefef, 0x0f0f0f0f},
11503 {0xaaaaaaaa, 0xdeadbeef, 0xdeadbabe, 0xdeadf00d},
11505 {0x00000001, 0x00000002, 0x00000003, 0x00000004},
11506 {0x000000ff, 0x000000fe, 0x000000fd, 0x000000fc},
11507 {0x000000f2, 0x000000f1, 0x000000f0, 0x000000ef},
11508 {0x0000000a, 0x0000000d, 0x0000000e, 0x0000000f},
11509 {0x0000001a, 0x0000002d, 0x0000003e, 0x0000004f},
11510 {0x00000050, 0x00000060, 0x00000070, 0x00000080},
11511 {0x00000090, 0x000000a0, 0x000000b0, 0x000000c0},
11512 {0x000000d0, 0x000000e0, 0x000000f0, 0x000000ff},
11513 {0x00000073, 0x00000077, 0x0000007a, 0x0000007b},
11514 {0x0000007c, 0x0000007d, 0x0000007e, 0x0000007f},
11516 {0x80000001, 0x80000002, 0x80000003, 0x80000004},
11517 {0x800000ff, 0x800000fe, 0x800000fd, 0x800000fc},
11518 {0x800000f2, 0x800000f1, 0x800000f0, 0x800000ef},
11519 {0x8000000a, 0x0000000d, 0x8000000e, 0x8000000f},
11520 {0x8000001a, 0x8000002d, 0x8000003e, 0x8000004f},
11521 {0x80000050, 0x80000060, 0x80000070, 0x00000080},
11522 {0x80000090, 0x800000a0, 0x800000b0, 0x800000c0},
11523 {0x800000d0, 0x800000e0, 0x800000f0, 0x800000ff},
11524 {0x80000073, 0x80000077, 0x8000007a, 0x8000007b},
11525 {0x8000007c, 0x8000007d, 0x8000007e, 0x8000007f},
11527 {0x7fffff01, 0x7fffff02, 0x7fffff03, 0x7fffff04},
11528 {0x7fffffff, 0x7ffffffe, 0x7ffffffd, 0x7ffffffc},
11529 {0x7ffffff2, 0x7ffffff1, 0x7ffffff0, 0x7fffffef},
11530 {0x7fffff0a, 0x7fffff0d, 0x7fffff0e, 0x7fffff0f},
11531 {0x7fffff1a, 0x7fffff2d, 0x7fffff3e, 0x7fffff4f},
11532 {0x7fffff50, 0x7fffff60, 0x7fffff70, 0x7fffff80},
11533 {0x8fffff90, 0x7fffffa0, 0x7fffffb0, 0x7fffffc0},
11534 {0x7fffffd0, 0x7fffffe0, 0x7ffffff0, 0x7fffffff},
11535 {0x7fffff73, 0x7fffff77, 0x7fffff7a, 0x7fffff7b},
11536 {0x7fffff7c, 0x7fffff7d, 0x7fffff7e, 0x7fffff7f},
11538 {0xffffff01, 0xffffff02, 0xffffff03, 0xffffff04},
11539 {0xffffffff, 0xfffffffe, 0xfffffffd, 0xfffffffc},
11540 {0xfffffff2, 0xfffffff1, 0xfffffff0, 0xffffffef},
11541 {0xffffff0a, 0xffffff0d, 0xffffff0e, 0xffffff0f},
11542 {0xffffff1a, 0xffffff2d, 0xffffff3e, 0xffffff4f},
11543 {0xffffff50, 0xffffff60, 0xffffff70, 0xffffff80},
11544 {0xffffff90, 0xffffffa0, 0xffffffb0, 0xffffffc0},
11545 {0xffffffd0, 0xffffffe0, 0xfffffff0, 0xffffffff},
11546 {0xffffff73, 0xffffff77, 0xffffff7a, 0xffffff7b},
11547 {0xffffff7c, 0xffffff7d, 0xffffff7e, 0xffffff7f},
11550 device_desc.feature_level = &feature_level;
11551 device_desc.flags = 0;
11552 if (!(device = create_device(&device_desc)))
11554 skip("Failed to create device for feature level %#x.\n", feature_level);
11555 return;
11558 ID3D11Device_GetImmediateContext(device, &context);
11560 /* Structured buffer views */
11561 buffer_desc.ByteWidth = 64;
11562 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
11563 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
11564 buffer_desc.CPUAccessFlags = 0;
11565 buffer_desc.MiscFlags = 0;
11566 buffer_desc.StructureByteStride = 0;
11567 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
11568 buffer_desc.StructureByteStride = 4;
11569 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11570 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11572 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
11573 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11575 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
11576 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11577 U(uav_desc).Buffer.FirstElement = 0;
11578 U(uav_desc).Buffer.NumElements = 4;
11579 U(uav_desc).Buffer.Flags = 0;
11580 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11581 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11583 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11585 uvec4 = uvec4_data[i];
11586 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11587 get_buffer_readback(buffer, &rb);
11588 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11590 DWORD data = get_readback_color(&rb, x, 0);
11591 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11593 release_resource_readback(&rb);
11595 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11596 get_buffer_readback(buffer, &rb);
11597 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11599 DWORD data = get_readback_color(&rb, x, 0);
11600 uvec4 = x < U(uav_desc).Buffer.NumElements ? fe_uvec4 : uvec4_data[i];
11601 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11603 release_resource_readback(&rb);
11606 ID3D11Buffer_Release(buffer);
11607 ID3D11UnorderedAccessView_Release(uav);
11608 ID3D11UnorderedAccessView_Release(uav2);
11610 /* Raw buffer views */
11611 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
11612 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11613 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11615 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
11616 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11617 U(uav_desc).Buffer.FirstElement = 0;
11618 U(uav_desc).Buffer.NumElements = 16;
11619 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
11620 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11621 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11622 U(uav_desc).Buffer.FirstElement = 8;
11623 U(uav_desc).Buffer.NumElements = 8;
11624 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11625 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11627 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11629 uvec4 = uvec4_data[i];
11630 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11631 get_buffer_readback(buffer, &rb);
11632 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11634 DWORD data = get_readback_color(&rb, x, 0);
11635 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11637 release_resource_readback(&rb);
11639 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11640 get_buffer_readback(buffer, &rb);
11641 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11643 DWORD data = get_readback_color(&rb, x, 0);
11644 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11645 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11647 release_resource_readback(&rb);
11650 ID3D11Buffer_Release(buffer);
11651 ID3D11UnorderedAccessView_Release(uav);
11652 ID3D11UnorderedAccessView_Release(uav2);
11654 /* Typed buffer views */
11655 buffer_desc.MiscFlags = 0;
11656 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11657 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11659 uav_desc.Format = DXGI_FORMAT_R32_SINT;
11660 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11661 U(uav_desc).Buffer.FirstElement = 0;
11662 U(uav_desc).Buffer.NumElements = 16;
11663 U(uav_desc).Buffer.Flags = 0;
11664 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11665 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11666 U(uav_desc).Buffer.FirstElement = 9;
11667 U(uav_desc).Buffer.NumElements = 7;
11668 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11669 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11671 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11673 uvec4 = uvec4_data[i];
11674 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11675 get_buffer_readback(buffer, &rb);
11676 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11678 DWORD data = get_readback_color(&rb, x, 0);
11679 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11681 release_resource_readback(&rb);
11683 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11684 get_buffer_readback(buffer, &rb);
11685 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11687 DWORD data = get_readback_color(&rb, x, 0);
11688 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11689 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11691 release_resource_readback(&rb);
11694 ID3D11UnorderedAccessView_Release(uav);
11695 ID3D11UnorderedAccessView_Release(uav2);
11697 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
11698 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11699 U(uav_desc).Buffer.FirstElement = 0;
11700 U(uav_desc).Buffer.NumElements = 4;
11701 U(uav_desc).Buffer.Flags = 0;
11702 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11703 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11704 U(uav_desc).Buffer.FirstElement = 2;
11705 U(uav_desc).Buffer.NumElements = 2;
11706 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11707 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11709 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11711 uvec4 = uvec4_data[i];
11712 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11713 get_buffer_readback(buffer, &rb);
11714 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
11716 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
11717 const struct uvec4 broken_result = {uvec4.x, uvec4.x, uvec4.x, uvec4.x}; /* Intel */
11718 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
11719 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
11720 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
11722 release_resource_readback(&rb);
11724 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11725 get_buffer_readback(buffer, &rb);
11726 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
11728 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
11729 struct uvec4 broken_result;
11730 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11731 broken_result.x = broken_result.y = broken_result.z = broken_result.w = uvec4.x;
11732 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
11733 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
11734 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
11736 release_resource_readback(&rb);
11739 uvec4.x = uvec4.y = uvec4.z = uvec4.w = 0xdeadbeef;
11740 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11741 ID3D11UnorderedAccessView_Release(uav);
11742 ID3D11UnorderedAccessView_Release(uav2);
11744 uav_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT;
11745 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11746 U(uav_desc).Buffer.FirstElement = 0;
11747 U(uav_desc).Buffer.NumElements = 16;
11748 U(uav_desc).Buffer.Flags = 0;
11749 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11750 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11751 U(uav_desc).Buffer.FirstElement = 8;
11752 U(uav_desc).Buffer.NumElements = 8;
11753 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11754 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11756 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11758 uvec4 = uvec4_data[i];
11759 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11760 get_buffer_readback(buffer, &rb);
11761 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11762 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0), &uvec4);
11763 release_resource_readback(&rb);
11765 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11766 get_buffer_readback(buffer, &rb);
11767 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11769 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11770 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0), &uvec4);
11772 release_resource_readback(&rb);
11775 ID3D11UnorderedAccessView_Release(uav);
11776 ID3D11UnorderedAccessView_Release(uav2);
11778 ID3D11Buffer_Release(buffer);
11780 ID3D11DeviceContext_Release(context);
11781 refcount = ID3D11Device_Release(device);
11782 ok(!refcount, "Device has %u references left.\n", refcount);
11785 static void test_draw_depth_only(void)
11787 ID3D11DepthStencilState *depth_stencil_state;
11788 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
11789 struct d3d11_test_context test_context;
11790 ID3D11PixelShader *ps_color, *ps_depth;
11791 D3D11_TEXTURE2D_DESC texture_desc;
11792 ID3D11DeviceContext *context;
11793 ID3D11DepthStencilView *dsv;
11794 struct resource_readback rb;
11795 ID3D11Texture2D *texture;
11796 ID3D11Device *device;
11797 unsigned int i, j;
11798 D3D11_VIEWPORT vp;
11799 struct vec4 depth;
11800 ID3D11Buffer *cb;
11801 HRESULT hr;
11803 static const DWORD ps_color_code[] =
11805 #if 0
11806 float4 main(float4 position : SV_POSITION) : SV_Target
11808 return float4(0.0, 1.0, 0.0, 1.0);
11810 #endif
11811 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
11812 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11813 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
11814 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11815 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
11816 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
11817 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
11819 static const DWORD ps_depth_code[] =
11821 #if 0
11822 float depth;
11824 float main() : SV_Depth
11826 return depth;
11828 #endif
11829 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
11830 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11831 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
11832 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11833 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
11834 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
11837 if (!init_test_context(&test_context, NULL))
11838 return;
11840 device = test_context.device;
11841 context = test_context.immediate_context;
11843 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
11845 texture_desc.Width = 640;
11846 texture_desc.Height = 480;
11847 texture_desc.MipLevels = 1;
11848 texture_desc.ArraySize = 1;
11849 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11850 texture_desc.SampleDesc.Count = 1;
11851 texture_desc.SampleDesc.Quality = 0;
11852 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11853 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
11854 texture_desc.CPUAccessFlags = 0;
11855 texture_desc.MiscFlags = 0;
11857 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11858 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11860 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
11861 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11863 depth_stencil_desc.DepthEnable = TRUE;
11864 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
11865 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS;
11866 depth_stencil_desc.StencilEnable = FALSE;
11868 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
11869 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
11871 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
11872 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11873 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
11874 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11876 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11877 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
11878 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
11879 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
11881 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11882 check_texture_float(texture, 1.0f, 1);
11883 draw_quad(&test_context);
11884 check_texture_float(texture, 0.0f, 1);
11886 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
11888 depth.x = 0.7f;
11889 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11890 draw_quad(&test_context);
11891 check_texture_float(texture, 0.0f, 1);
11892 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11893 check_texture_float(texture, 1.0f, 1);
11894 draw_quad(&test_context);
11895 check_texture_float(texture, 0.7f, 1);
11896 depth.x = 0.8f;
11897 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11898 draw_quad(&test_context);
11899 check_texture_float(texture, 0.7f, 1);
11900 depth.x = 0.5f;
11901 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11902 draw_quad(&test_context);
11903 check_texture_float(texture, 0.5f, 1);
11905 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11906 for (i = 0; i < 4; ++i)
11908 for (j = 0; j < 4; ++j)
11910 depth.x = 1.0f / 16.0f * (j + 4 * i);
11911 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11913 vp.TopLeftX = 160.0f * j;
11914 vp.TopLeftY = 120.0f * i;
11915 vp.Width = 160.0f;
11916 vp.Height = 120.0f;
11917 vp.MinDepth = 0.0f;
11918 vp.MaxDepth = 1.0f;
11919 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11921 draw_quad(&test_context);
11924 get_texture_readback(texture, 0, &rb);
11925 for (i = 0; i < 4; ++i)
11927 for (j = 0; j < 4; ++j)
11929 float obtained_depth, expected_depth;
11931 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
11932 expected_depth = 1.0f / 16.0f * (j + 4 * i);
11933 ok(compare_float(obtained_depth, expected_depth, 1),
11934 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
11935 obtained_depth, j, i, expected_depth);
11938 release_resource_readback(&rb);
11940 ID3D11Buffer_Release(cb);
11941 ID3D11PixelShader_Release(ps_color);
11942 ID3D11PixelShader_Release(ps_depth);
11943 ID3D11DepthStencilView_Release(dsv);
11944 ID3D11DepthStencilState_Release(depth_stencil_state);
11945 ID3D11Texture2D_Release(texture);
11946 release_test_context(&test_context);
11949 static void test_draw_uav_only(void)
11951 struct d3d11_test_context test_context;
11952 D3D11_TEXTURE2D_DESC texture_desc;
11953 ID3D11UnorderedAccessView *uav;
11954 ID3D11DeviceContext *context;
11955 ID3D11Texture2D *texture;
11956 ID3D11PixelShader *ps;
11957 ID3D11Device *device;
11958 D3D11_VIEWPORT vp;
11959 HRESULT hr;
11961 static const DWORD ps_code[] =
11963 #if 0
11964 RWTexture2D<int> u;
11966 void main()
11968 InterlockedAdd(u[uint2(0, 0)], 1);
11970 #endif
11971 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
11972 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11973 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
11974 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
11975 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
11977 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11978 static const UINT values[4] = {0};
11980 if (!init_test_context(&test_context, &feature_level))
11981 return;
11983 device = test_context.device;
11984 context = test_context.immediate_context;
11986 texture_desc.Width = 1;
11987 texture_desc.Height = 1;
11988 texture_desc.MipLevels = 1;
11989 texture_desc.ArraySize = 1;
11990 texture_desc.Format = DXGI_FORMAT_R32_SINT;
11991 texture_desc.SampleDesc.Count = 1;
11992 texture_desc.SampleDesc.Quality = 0;
11993 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11994 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
11995 texture_desc.CPUAccessFlags = 0;
11996 texture_desc.MiscFlags = 0;
11998 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11999 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12001 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
12002 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12004 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12005 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12007 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12008 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
12009 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &test_context.backbuffer_rtv, NULL,
12010 0, 1, &uav, NULL);
12012 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
12013 memset(&vp, 0, sizeof(vp));
12014 vp.Width = 1.0f;
12015 vp.Height = 100.0f;
12016 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
12017 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
12018 draw_quad(&test_context);
12019 check_texture_color(texture, 100, 1);
12021 draw_quad(&test_context);
12022 draw_quad(&test_context);
12023 draw_quad(&test_context);
12024 draw_quad(&test_context);
12025 check_texture_color(texture, 500, 1);
12027 ID3D11PixelShader_Release(ps);
12028 ID3D11Texture2D_Release(texture);
12029 ID3D11UnorderedAccessView_Release(uav);
12030 release_test_context(&test_context);
12033 static void test_cb_relative_addressing(void)
12035 struct d3d11_test_context test_context;
12036 ID3D11Buffer *colors_cb, *index_cb;
12037 unsigned int i, index[4] = {0};
12038 ID3D11DeviceContext *context;
12039 ID3D11PixelShader *ps;
12040 ID3D11Device *device;
12041 HRESULT hr;
12043 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12045 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12047 static const DWORD vs_code[] =
12049 #if 0
12050 int color_index;
12052 cbuffer colors
12054 float4 colors[8];
12057 struct vs_in
12059 float4 position : POSITION;
12062 struct vs_out
12064 float4 position : SV_POSITION;
12065 float4 color : COLOR;
12068 vs_out main(const vs_in v)
12070 vs_out o;
12072 o.position = v.position;
12073 o.color = colors[color_index];
12075 return o;
12077 #endif
12078 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
12079 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12080 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
12081 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12082 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12083 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
12084 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
12085 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
12086 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
12087 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
12088 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
12089 0x0100003e,
12091 static const DWORD ps_code[] =
12093 #if 0
12094 struct ps_in
12096 float4 position : SV_POSITION;
12097 float4 color : COLOR;
12100 float4 main(const ps_in v) : SV_TARGET
12102 return v.color;
12104 #endif
12105 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
12106 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12107 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12108 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12109 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12110 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
12111 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
12112 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12114 static const struct vec2 quad[] =
12116 {-1.0f, -1.0f},
12117 {-1.0f, 1.0f},
12118 { 1.0f, -1.0f},
12119 { 1.0f, 1.0f},
12121 static const struct
12123 float color[4];
12125 colors[10] =
12127 {{0.0f, 0.0f, 0.0f, 1.0f}},
12128 {{0.0f, 0.0f, 1.0f, 0.0f}},
12129 {{0.0f, 0.0f, 1.0f, 1.0f}},
12130 {{0.0f, 1.0f, 0.0f, 0.0f}},
12131 {{0.0f, 1.0f, 0.0f, 1.0f}},
12132 {{0.0f, 1.0f, 1.0f, 0.0f}},
12133 {{0.0f, 1.0f, 1.0f, 1.0f}},
12134 {{1.0f, 0.0f, 0.0f, 0.0f}},
12135 {{1.0f, 0.0f, 0.0f, 1.0f}},
12136 {{1.0f, 0.0f, 1.0f, 0.0f}},
12138 static const struct
12140 unsigned int index;
12141 DWORD expected;
12143 test_data[] =
12145 {0, 0xff000000},
12146 {1, 0x00ff0000},
12147 {2, 0xffff0000},
12148 {3, 0x0000ff00},
12149 {4, 0xff00ff00},
12150 {5, 0x00ffff00},
12151 {6, 0xffffff00},
12152 {7, 0x000000ff},
12154 {8, 0xff0000ff},
12155 {9, 0x00ff00ff},
12157 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
12158 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12160 if (!init_test_context(&test_context, &feature_level))
12161 return;
12163 device = test_context.device;
12164 context = test_context.immediate_context;
12166 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12167 vs_code, sizeof(vs_code), &test_context.input_layout);
12168 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12170 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
12171 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
12172 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
12174 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
12175 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12176 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12177 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12179 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
12180 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
12181 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12183 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
12185 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
12187 index[0] = test_data[i].index;
12188 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
12190 draw_quad(&test_context);
12191 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
12194 ID3D11Buffer_Release(index_cb);
12195 ID3D11Buffer_Release(colors_cb);
12196 ID3D11PixelShader_Release(ps);
12198 release_test_context(&test_context);
12201 static void test_getdc(void)
12203 static const struct
12205 const char *name;
12206 DXGI_FORMAT format;
12207 BOOL getdc_supported;
12209 testdata[] =
12211 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
12212 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
12213 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
12214 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
12215 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
12216 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
12218 struct device_desc device_desc;
12219 D3D11_TEXTURE2D_DESC desc;
12220 ID3D11Texture2D *texture;
12221 IDXGISurface1 *surface;
12222 ID3D11Device *device;
12223 unsigned int i;
12224 ULONG refcount;
12225 HRESULT hr;
12226 HDC dc;
12228 device_desc.feature_level = NULL;
12229 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
12230 if (!(device = create_device(&device_desc)))
12232 skip("Failed to create device.\n");
12233 return;
12236 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
12237 desc.Width = 512;
12238 desc.Height = 512;
12239 desc.MipLevels = 1;
12240 desc.ArraySize = 1;
12241 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
12242 desc.SampleDesc.Count = 1;
12243 desc.SampleDesc.Quality = 0;
12244 desc.Usage = D3D11_USAGE_DEFAULT;
12245 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12246 desc.CPUAccessFlags = 0;
12247 desc.MiscFlags = 0;
12248 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12249 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12251 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
12252 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
12254 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
12255 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
12257 IDXGISurface1_Release(surface);
12258 ID3D11Texture2D_Release(texture);
12260 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
12261 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12262 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12264 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
12265 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
12267 hr = IDXGISurface1_ReleaseDC(surface, NULL);
12268 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
12270 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
12271 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
12273 hr = IDXGISurface1_ReleaseDC(surface, NULL);
12274 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
12276 IDXGISurface1_Release(surface);
12277 ID3D11Texture2D_Release(texture);
12279 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
12281 static const unsigned int bit_count = 32;
12282 unsigned int width_bytes;
12283 DIBSECTION dib;
12284 HBITMAP bitmap;
12285 DWORD type;
12286 int size;
12288 desc.Width = 64;
12289 desc.Height = 64;
12290 desc.MipLevels = 1;
12291 desc.ArraySize = 1;
12292 desc.Format = testdata[i].format;
12293 desc.SampleDesc.Count = 1;
12294 desc.SampleDesc.Quality = 0;
12295 desc.Usage = D3D11_USAGE_STAGING;
12296 desc.BindFlags = 0;
12297 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
12298 desc.MiscFlags = 0;
12300 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12301 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12302 ID3D11Texture2D_Release(texture);
12304 /* STAGING usage, requesting GDI compatibility mode. */
12305 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
12306 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12307 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
12309 desc.Usage = D3D11_USAGE_DEFAULT;
12310 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12311 desc.CPUAccessFlags = 0;
12312 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12313 if (testdata[i].getdc_supported)
12314 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
12315 else
12316 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
12318 if (FAILED(hr))
12319 continue;
12321 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
12322 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
12324 dc = (void *)0x1234;
12325 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
12326 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
12328 if (FAILED(hr))
12330 IDXGISurface1_Release(surface);
12331 ID3D11Texture2D_Release(texture);
12332 continue;
12335 type = GetObjectType(dc);
12336 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
12337 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
12338 type = GetObjectType(bitmap);
12339 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
12341 size = GetObjectA(bitmap, sizeof(dib), &dib);
12342 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
12343 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
12345 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
12346 dib.dsBm.bmType, testdata[i].name);
12347 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
12348 dib.dsBm.bmWidth, testdata[i].name);
12349 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
12350 dib.dsBm.bmHeight, testdata[i].name);
12351 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
12352 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
12353 dib.dsBm.bmWidthBytes, testdata[i].name);
12354 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
12355 dib.dsBm.bmPlanes, testdata[i].name);
12356 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
12357 dib.dsBm.bmBitsPixel, testdata[i].name);
12359 if (size == sizeof(dib))
12360 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
12361 dib.dsBm.bmBits, testdata[i].name);
12362 else
12363 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
12364 dib.dsBm.bmBits, testdata[i].name);
12366 if (size == sizeof(dib))
12368 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
12369 dib.dsBmih.biSize, testdata[i].name);
12370 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
12371 dib.dsBmih.biHeight, testdata[i].name);
12372 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
12373 dib.dsBmih.biHeight, testdata[i].name);
12374 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
12375 dib.dsBmih.biPlanes, testdata[i].name);
12376 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
12377 dib.dsBmih.biBitCount, testdata[i].name);
12378 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
12379 dib.dsBmih.biCompression, testdata[i].name);
12380 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
12381 dib.dsBmih.biSizeImage, testdata[i].name);
12382 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
12383 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
12384 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
12385 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
12386 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
12387 dib.dsBmih.biClrUsed, testdata[i].name);
12388 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
12389 dib.dsBmih.biClrImportant, testdata[i].name);
12390 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
12391 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
12392 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
12393 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
12394 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
12397 hr = IDXGISurface1_ReleaseDC(surface, NULL);
12398 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
12400 IDXGISurface1_Release(surface);
12401 ID3D11Texture2D_Release(texture);
12404 refcount = ID3D11Device_Release(device);
12405 ok(!refcount, "Device has %u references left.\n", refcount);
12408 static void test_shader_stage_input_output_matching(void)
12410 struct d3d11_test_context test_context;
12411 D3D11_TEXTURE2D_DESC texture_desc;
12412 ID3D11Texture2D *render_target;
12413 ID3D11RenderTargetView *rtv[2];
12414 ID3D11DeviceContext *context;
12415 ID3D11VertexShader *vs;
12416 ID3D11PixelShader *ps;
12417 ID3D11Device *device;
12418 HRESULT hr;
12420 static const DWORD vs_code[] =
12422 #if 0
12423 struct output
12425 float4 position : SV_PoSiTion;
12426 float4 color0 : COLOR0;
12427 float4 color1 : COLOR1;
12430 void main(uint id : SV_VertexID, out output o)
12432 float2 coords = float2((id << 1) & 2, id & 2);
12433 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
12434 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
12435 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
12437 #endif
12438 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
12439 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12440 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
12441 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
12442 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12443 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
12444 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
12445 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
12446 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
12447 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
12448 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
12449 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
12450 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
12451 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
12452 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
12453 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
12454 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
12455 0x0100003e,
12457 static const DWORD ps_code[] =
12459 #if 0
12460 struct input
12462 float4 position : SV_PoSiTiOn;
12463 float4 color1 : COLOR1;
12464 float4 color0 : COLOR0;
12467 struct output
12469 float4 target0 : SV_Target0;
12470 float4 target1 : SV_Target1;
12473 void main(const in input i, out output o)
12475 o.target0 = i.color0;
12476 o.target1 = i.color1;
12478 #endif
12479 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
12480 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
12481 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
12482 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
12483 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
12484 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
12485 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
12486 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
12487 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
12488 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
12489 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
12492 if (!init_test_context(&test_context, NULL))
12493 return;
12495 device = test_context.device;
12496 context = test_context.immediate_context;
12498 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12499 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12500 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12501 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12503 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12504 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
12505 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12507 rtv[0] = test_context.backbuffer_rtv;
12508 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
12509 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12511 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12512 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12513 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
12514 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
12515 ID3D11DeviceContext_Draw(context, 3, 0);
12517 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12518 check_texture_color(render_target, 0xff0000ff, 0);
12520 ID3D11RenderTargetView_Release(rtv[1]);
12521 ID3D11Texture2D_Release(render_target);
12522 ID3D11PixelShader_Release(ps);
12523 ID3D11VertexShader_Release(vs);
12524 release_test_context(&test_context);
12527 static void test_shader_interstage_interface(void)
12529 struct d3d11_test_context test_context;
12530 D3D11_TEXTURE2D_DESC texture_desc;
12531 ID3D11InputLayout *input_layout;
12532 ID3D11Texture2D *render_target;
12533 ID3D11DeviceContext *context;
12534 ID3D11RenderTargetView *rtv;
12535 ID3D11VertexShader *vs;
12536 ID3D11PixelShader *ps;
12537 ID3D11Device *device;
12538 UINT stride, offset;
12539 ID3D11Buffer *vb;
12540 HRESULT hr;
12542 static const DWORD vs_code[] =
12544 #if 0
12545 struct vertex
12547 float4 position : SV_Position;
12548 float2 t0 : TEXCOORD0;
12549 nointerpolation float t1 : TEXCOORD1;
12550 uint t2 : TEXCOORD2;
12551 uint t3 : TEXCOORD3;
12552 float t4 : TEXCOORD4;
12555 void main(in vertex vin, out vertex vout)
12557 vout = vin;
12559 #endif
12560 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
12561 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
12562 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
12563 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
12564 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
12565 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
12566 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
12567 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
12568 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
12569 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
12570 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
12571 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
12572 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
12573 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
12574 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
12575 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
12576 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
12577 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
12578 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
12579 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
12580 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
12581 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
12583 static const DWORD ps_code[] =
12585 #if 0
12586 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
12587 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
12588 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
12590 o.x = t0.y + t1;
12591 o.y = t2 + t3;
12592 o.z = t4;
12593 o.w = t0.x;
12595 #endif
12596 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
12597 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
12598 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
12599 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
12600 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
12601 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
12602 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
12603 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
12604 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
12605 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
12606 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
12607 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
12608 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
12609 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
12610 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
12612 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12614 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12615 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
12616 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
12617 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
12618 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
12619 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
12621 static const struct
12623 struct vec2 position;
12624 struct vec2 t0;
12625 float t1;
12626 unsigned int t2;
12627 unsigned int t3;
12628 float t4;
12630 quad[] =
12632 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12633 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12634 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12635 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12637 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12638 static const struct vec4 expected_result = {10.0f, 8.0f, 7.0f, 3.0f};
12640 if (!init_test_context(&test_context, NULL))
12641 return;
12643 device = test_context.device;
12644 context = test_context.immediate_context;
12646 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12647 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12648 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12649 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12651 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12652 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12653 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
12654 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12656 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
12657 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12659 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12660 vs_code, sizeof(vs_code), &input_layout);
12661 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12663 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
12665 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
12667 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
12669 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12670 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12671 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12672 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12673 offset = 0;
12674 stride = sizeof(*quad);
12675 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
12676 ID3D11DeviceContext_Draw(context, 4, 0);
12677 check_texture_vec4(render_target, &expected_result, 0);
12679 ID3D11InputLayout_Release(input_layout);
12680 ID3D11RenderTargetView_Release(rtv);
12681 ID3D11Texture2D_Release(render_target);
12682 ID3D11PixelShader_Release(ps);
12683 ID3D11VertexShader_Release(vs);
12684 ID3D11Buffer_Release(vb);
12685 release_test_context(&test_context);
12688 static void test_sm4_if_instruction(void)
12690 struct d3d11_test_context test_context;
12691 ID3D11PixelShader *ps_if_nz, *ps_if_z;
12692 ID3D11DeviceContext *context;
12693 ID3D11Device *device;
12694 unsigned int bits[4];
12695 DWORD expected_color;
12696 ID3D11Buffer *cb;
12697 unsigned int i;
12698 HRESULT hr;
12700 static const DWORD ps_if_nz_code[] =
12702 #if 0
12703 uint bits;
12705 float4 main() : SV_TARGET
12707 if (bits)
12708 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12709 else
12710 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12712 #endif
12713 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
12714 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12715 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12716 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
12717 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
12718 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12719 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12720 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12722 static const DWORD ps_if_z_code[] =
12724 #if 0
12725 uint bits;
12727 float4 main() : SV_TARGET
12729 if (!bits)
12730 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12731 else
12732 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12734 #endif
12735 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
12736 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12737 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12738 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
12739 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
12740 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12741 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12742 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12744 static unsigned int bit_patterns[] =
12746 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
12749 if (!init_test_context(&test_context, NULL))
12750 return;
12752 device = test_context.device;
12753 context = test_context.immediate_context;
12755 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
12756 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
12757 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
12758 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
12760 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
12761 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
12763 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
12765 *bits = bit_patterns[i];
12766 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
12768 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
12769 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
12770 draw_quad(&test_context);
12771 check_texture_color(test_context.backbuffer, expected_color, 0);
12773 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
12774 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
12775 draw_quad(&test_context);
12776 check_texture_color(test_context.backbuffer, expected_color, 0);
12779 ID3D11Buffer_Release(cb);
12780 ID3D11PixelShader_Release(ps_if_z);
12781 ID3D11PixelShader_Release(ps_if_nz);
12782 release_test_context(&test_context);
12785 static void test_sm4_breakc_instruction(void)
12787 struct d3d11_test_context test_context;
12788 ID3D11DeviceContext *context;
12789 ID3D11PixelShader *ps;
12790 ID3D11Device *device;
12791 HRESULT hr;
12793 static const DWORD ps_breakc_nz_code[] =
12795 #if 0
12796 float4 main() : SV_TARGET
12798 uint counter = 0;
12800 for (uint i = 0; i < 255; ++i)
12801 ++counter;
12803 if (counter == 255)
12804 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12805 else
12806 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12808 #endif
12809 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
12810 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12811 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12812 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
12813 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
12814 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
12815 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12816 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
12817 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
12818 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
12819 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
12820 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12821 0x01000015, 0x0100003e,
12823 static const DWORD ps_breakc_z_code[] =
12825 #if 0
12826 float4 main() : SV_TARGET
12828 uint counter = 0;
12830 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
12831 ++counter;
12833 if (counter == 255)
12834 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12835 else
12836 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12838 #endif
12839 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
12840 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12841 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12842 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
12843 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
12844 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
12845 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
12846 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
12847 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
12848 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
12849 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
12850 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12851 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12852 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12855 if (!init_test_context(&test_context, NULL))
12856 return;
12858 device = test_context.device;
12859 context = test_context.immediate_context;
12861 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
12862 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
12863 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12864 draw_quad(&test_context);
12865 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12866 ID3D11PixelShader_Release(ps);
12868 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
12869 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
12870 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12871 draw_quad(&test_context);
12872 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12873 ID3D11PixelShader_Release(ps);
12875 release_test_context(&test_context);
12878 static void test_sm4_continuec_instruction(void)
12880 struct d3d11_test_context test_context;
12881 ID3D11DeviceContext *context;
12882 ID3D11PixelShader *ps;
12883 ID3D11Device *device;
12884 HRESULT hr;
12886 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
12887 * with a normal continue inside, the shaders have been compiled with
12888 * the /Gfa flag. */
12889 static const DWORD ps_continuec_nz_code[] =
12891 #if 0
12892 float4 main() : SV_TARGET
12894 uint counter = 0;
12895 int i = -1;
12897 while (i < 255) {
12898 ++i;
12900 if (i != 0)
12901 continue;
12903 ++counter;
12906 if (counter == 1)
12907 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12908 else
12909 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12911 #endif
12912 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
12913 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12914 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12915 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
12916 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
12917 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12918 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12919 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
12920 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
12921 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
12922 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
12923 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
12924 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
12925 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
12926 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
12927 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
12928 0x3f800000, 0x0100003e,
12931 static const DWORD ps_continuec_z_code[] =
12933 #if 0
12934 float4 main() : SV_TARGET
12936 uint counter = 0;
12937 int i = -1;
12939 while (i < 255) {
12940 ++i;
12942 if (i == 0)
12943 continue;
12945 ++counter;
12948 if (counter == 255)
12949 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12950 else
12951 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12953 #endif
12954 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
12955 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12956 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12957 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
12958 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
12959 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12960 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12961 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
12962 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
12963 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
12964 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
12965 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
12966 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
12967 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
12968 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12971 if (!init_test_context(&test_context, NULL))
12972 return;
12974 device = test_context.device;
12975 context = test_context.immediate_context;
12977 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), NULL, &ps);
12978 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
12979 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12980 draw_quad(&test_context);
12981 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12982 ID3D11PixelShader_Release(ps);
12984 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), NULL, &ps);
12985 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
12986 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12987 draw_quad(&test_context);
12988 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12989 ID3D11PixelShader_Release(ps);
12991 release_test_context(&test_context);
12994 static void test_sm4_discard_instruction(void)
12996 ID3D11PixelShader *ps_discard_nz, *ps_discard_z;
12997 struct d3d11_test_context test_context;
12998 ID3D11DeviceContext *context;
12999 ID3D11Device *device;
13000 ID3D11Buffer *cb;
13001 unsigned int i;
13002 HRESULT hr;
13004 static const DWORD ps_discard_nz_code[] =
13006 #if 0
13007 uint data;
13009 float4 main() : SV_Target
13011 if (data)
13012 discard;
13013 return float4(0.0f, 0.5f, 0.0f, 1.0f);
13015 #endif
13016 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
13017 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13018 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13019 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
13020 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
13021 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
13022 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
13024 static const DWORD ps_discard_z_code[] =
13026 #if 0
13027 uint data;
13029 float4 main() : SV_Target
13031 if (!data)
13032 discard;
13033 return float4(0.0f, 1.0f, 0.0f, 1.0f);
13035 #endif
13036 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
13037 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13038 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13039 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
13040 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
13041 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
13042 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
13044 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13045 static const struct uvec4 values[] =
13047 {0x0000000},
13048 {0x0000001},
13049 {0x8000000},
13050 {0xfffffff},
13053 if (!init_test_context(&test_context, NULL))
13054 return;
13056 device = test_context.device;
13057 context = test_context.immediate_context;
13059 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
13060 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13062 hr = ID3D11Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code),
13063 NULL, &ps_discard_nz);
13064 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
13065 hr = ID3D11Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code),
13066 NULL, &ps_discard_z);
13067 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
13069 for (i = 0; i < ARRAY_SIZE(values); ++i)
13071 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &values[i], 0, 0);
13073 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
13074 ID3D11DeviceContext_PSSetShader(context, ps_discard_nz, NULL, 0);
13075 draw_quad(&test_context);
13076 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
13078 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
13079 ID3D11DeviceContext_PSSetShader(context, ps_discard_z, NULL, 0);
13080 draw_quad(&test_context);
13081 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
13084 ID3D11Buffer_Release(cb);
13085 ID3D11PixelShader_Release(ps_discard_nz);
13086 ID3D11PixelShader_Release(ps_discard_z);
13087 release_test_context(&test_context);
13090 static void test_sm5_swapc_instruction(void)
13092 struct input
13094 struct uvec4 src0;
13095 struct uvec4 src1;
13096 struct uvec4 src2;
13099 struct d3d11_test_context test_context;
13100 D3D11_TEXTURE2D_DESC texture_desc;
13101 ID3D11DeviceContext *context;
13102 ID3D11RenderTargetView *rtv;
13103 ID3D11Texture2D *texture;
13104 ID3D11PixelShader *ps[6];
13105 ID3D11Device *device;
13106 ID3D11Buffer *cb;
13107 unsigned int i;
13108 HRESULT hr;
13110 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13111 static const DWORD ps_swapc0_code[] =
13113 #if 0
13114 ps_5_0
13115 dcl_globalFlags refactoringAllowed
13116 dcl_constantbuffer cb0[3], immediateIndexed
13117 dcl_output o0.xyzw
13118 dcl_temps 2
13119 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
13120 mov o0.xyzw, r0.xyzw
13122 #endif
13123 0x43425844, 0x9e089246, 0x9f8b5cbe, 0xbac66faf, 0xaef23488, 0x00000001, 0x000000f8, 0x00000003,
13124 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13125 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13126 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
13127 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13128 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
13129 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
13130 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
13132 static const DWORD ps_swapc1_code[] =
13134 #if 0
13135 ps_5_0
13136 dcl_globalFlags refactoringAllowed
13137 dcl_constantbuffer cb0[3], immediateIndexed
13138 dcl_output o0.xyzw
13139 dcl_temps 2
13140 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
13141 mov o0.xyzw, r1.xyzw
13143 #endif
13144 0x43425844, 0xf2daed61, 0xede211f7, 0x7300dbea, 0x573ed49f, 0x00000001, 0x000000f8, 0x00000003,
13145 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13146 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13147 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
13148 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13149 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
13150 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
13151 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
13153 static const DWORD ps_swapc2_code[] =
13155 #if 0
13156 ps_5_0
13157 dcl_globalFlags refactoringAllowed
13158 dcl_constantbuffer cb0[3], immediateIndexed
13159 dcl_output o0.xyzw
13160 dcl_temps 2
13161 mov r0.xyzw, cb0[1].xyzw
13162 mov r1.xyzw, cb0[2].xyzw
13163 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
13164 mov o0.xyzw, r0.xyzw
13166 #endif
13167 0x43425844, 0x230fcb22, 0x70d99148, 0x65814d89, 0x97473498, 0x00000001, 0x00000120, 0x00000003,
13168 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13169 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13170 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
13171 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13172 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
13173 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
13174 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
13175 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
13177 static const DWORD ps_swapc3_code[] =
13179 #if 0
13180 ps_5_0
13181 dcl_globalFlags refactoringAllowed
13182 dcl_constantbuffer cb0[3], immediateIndexed
13183 dcl_output o0.xyzw
13184 dcl_temps 2
13185 mov r0.xyzw, cb0[1].xyzw
13186 mov r1.xyzw, cb0[2].xyzw
13187 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
13188 mov o0.xyzw, r1.xyzw
13190 #endif
13191 0x43425844, 0xce595d62, 0x98305541, 0xb04e74c8, 0xfc010f3a, 0x00000001, 0x00000120, 0x00000003,
13192 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13193 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13194 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
13195 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13196 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
13197 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
13198 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
13199 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
13201 static const DWORD ps_swapc4_code[] =
13203 #if 0
13204 ps_5_0
13205 dcl_globalFlags refactoringAllowed
13206 dcl_constantbuffer cb0[3], immediateIndexed
13207 dcl_output o0.xyzw
13208 dcl_temps 2
13209 mov r0.xyzw, cb0[0].xyzw
13210 swapc r0.xyzw, r1.xyzw, r0.xyzw, cb0[1].xyzw, cb0[2].xyzw
13211 mov o0.xyzw, r0.xyzw
13213 #endif
13214 0x43425844, 0x72067c48, 0xb53572a0, 0x9dd9e0fd, 0x903e37e3, 0x00000001, 0x0000010c, 0x00000003,
13215 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13216 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13217 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
13218 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13219 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
13220 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000000, 0x00208e46,
13221 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
13222 0x00100e46, 0x00000000, 0x0100003e,
13224 static const DWORD ps_swapc5_code[] =
13226 #if 0
13227 ps_5_0
13228 dcl_globalFlags refactoringAllowed
13229 dcl_constantbuffer cb0[3], immediateIndexed
13230 dcl_output o0.xyzw
13231 dcl_temps 2
13232 mov r1.xyzw, cb0[0].xyzw
13233 swapc r0.xyzw, r1.xyzw, r1.xyzw, cb0[1].xyzw, cb0[2].xyzw
13234 mov o0.xyzw, r1.xyzw
13236 #endif
13237 0x43425844, 0x7078fb08, 0xdd24cd44, 0x469d3258, 0x9e33a0bc, 0x00000001, 0x0000010c, 0x00000003,
13238 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13239 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13240 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
13241 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13242 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000,
13243 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001, 0x00208e46,
13244 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
13245 0x00100e46, 0x00000001, 0x0100003e,
13247 static const struct
13249 struct input input;
13250 struct uvec4 dst0;
13251 struct uvec4 dst1;
13253 tests[] =
13256 {{0, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13257 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}
13260 {{1, 1, 1, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13261 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
13264 {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
13265 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13266 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
13269 {{1, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13270 {0xaaaa, 0xc0de, 0xcccc, 0xeeee}, {0xdead, 0xbbbb, 0xffff, 0xdddd},
13273 {{1, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13274 {0xaaaa, 0xc0de, 0xffff, 0xdddd}, {0xdead, 0xbbbb, 0xcccc, 0xeeee},
13277 {{1, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13278 {0xaaaa, 0xc0de, 0xffff, 0xeeee}, {0xdead, 0xbbbb, 0xcccc, 0xdddd}
13281 {{0, 1, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13282 {0xdead, 0xbbbb, 0xffff, 0xeeee}, {0xaaaa, 0xc0de, 0xcccc, 0xdddd}
13285 {{0, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13286 {0xdead, 0xc0de, 0xcccc, 0xeeee}, {0xaaaa, 0xbbbb, 0xffff, 0xdddd}
13289 {{0, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13290 {0xdead, 0xc0de, 0xffff, 0xdddd}, {0xaaaa, 0xbbbb, 0xcccc, 0xeeee},
13294 if (!init_test_context(&test_context, &feature_level))
13295 return;
13297 device = test_context.device;
13298 context = test_context.immediate_context;
13300 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13301 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
13302 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13303 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13305 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13306 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13308 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13310 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct input), NULL);
13311 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13313 hr = ID3D11Device_CreatePixelShader(device, ps_swapc0_code, sizeof(ps_swapc0_code), NULL, &ps[0]);
13314 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13315 hr = ID3D11Device_CreatePixelShader(device, ps_swapc1_code, sizeof(ps_swapc1_code), NULL, &ps[1]);
13316 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13317 hr = ID3D11Device_CreatePixelShader(device, ps_swapc2_code, sizeof(ps_swapc2_code), NULL, &ps[2]);
13318 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13319 hr = ID3D11Device_CreatePixelShader(device, ps_swapc3_code, sizeof(ps_swapc3_code), NULL, &ps[3]);
13320 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13321 hr = ID3D11Device_CreatePixelShader(device, ps_swapc4_code, sizeof(ps_swapc4_code), NULL, &ps[4]);
13322 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13323 hr = ID3D11Device_CreatePixelShader(device, ps_swapc5_code, sizeof(ps_swapc5_code), NULL, &ps[5]);
13324 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13326 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13328 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &tests[i].input, 0, 0);
13330 ID3D11DeviceContext_PSSetShader(context, ps[0], NULL, 0);
13331 draw_quad(&test_context);
13332 check_texture_uvec4(texture, &tests[i].dst0);
13334 ID3D11DeviceContext_PSSetShader(context, ps[1], NULL, 0);
13335 draw_quad(&test_context);
13336 check_texture_uvec4(texture, &tests[i].dst1);
13338 ID3D11DeviceContext_PSSetShader(context, ps[2], NULL, 0);
13339 draw_quad(&test_context);
13340 check_texture_uvec4(texture, &tests[i].dst0);
13342 ID3D11DeviceContext_PSSetShader(context, ps[3], NULL, 0);
13343 draw_quad(&test_context);
13344 check_texture_uvec4(texture, &tests[i].dst1);
13346 ID3D11DeviceContext_PSSetShader(context, ps[4], NULL, 0);
13347 draw_quad(&test_context);
13348 check_texture_uvec4(texture, &tests[i].dst0);
13350 ID3D11DeviceContext_PSSetShader(context, ps[5], NULL, 0);
13351 draw_quad(&test_context);
13352 check_texture_uvec4(texture, &tests[i].dst1);
13355 for (i = 0; i < ARRAY_SIZE(ps); ++i)
13356 ID3D11PixelShader_Release(ps[i]);
13357 ID3D11RenderTargetView_Release(rtv);
13358 ID3D11Texture2D_Release(texture);
13359 ID3D11Buffer_Release(cb);
13360 release_test_context(&test_context);
13363 static void test_create_input_layout(void)
13365 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13367 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13369 ULONG refcount, expected_refcount;
13370 ID3D11InputLayout *input_layout;
13371 ID3D11Device *device;
13372 unsigned int i;
13373 HRESULT hr;
13375 static const DWORD vs_code[] =
13377 #if 0
13378 float4 main(float4 position : POSITION) : SV_POSITION
13380 return position;
13382 #endif
13383 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
13384 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13385 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
13386 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
13387 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
13388 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
13389 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
13391 static const DXGI_FORMAT vertex_formats[] =
13393 DXGI_FORMAT_R32G32_FLOAT,
13394 DXGI_FORMAT_R32G32_UINT,
13395 DXGI_FORMAT_R32G32_SINT,
13396 DXGI_FORMAT_R16G16_FLOAT,
13397 DXGI_FORMAT_R16G16_UINT,
13398 DXGI_FORMAT_R16G16_SINT,
13399 DXGI_FORMAT_R32_FLOAT,
13400 DXGI_FORMAT_R32_UINT,
13401 DXGI_FORMAT_R32_SINT,
13402 DXGI_FORMAT_R16_UINT,
13403 DXGI_FORMAT_R16_SINT,
13404 DXGI_FORMAT_R8_UINT,
13405 DXGI_FORMAT_R8_SINT,
13408 if (!(device = create_device(NULL)))
13410 skip("Failed to create device.\n");
13411 return;
13414 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
13416 expected_refcount = get_refcount(device) + 1;
13417 layout_desc->Format = vertex_formats[i];
13418 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13419 vs_code, sizeof(vs_code), &input_layout);
13420 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
13421 vertex_formats[i], hr);
13422 refcount = get_refcount(device);
13423 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
13424 refcount, expected_refcount);
13425 ID3D11InputLayout_Release(input_layout);
13428 refcount = ID3D11Device_Release(device);
13429 ok(!refcount, "Device has %u references left.\n", refcount);
13432 static void test_input_assembler(void)
13434 enum layout_id
13436 LAYOUT_FLOAT32,
13437 LAYOUT_UINT16,
13438 LAYOUT_SINT16,
13439 LAYOUT_UNORM16,
13440 LAYOUT_SNORM16,
13441 LAYOUT_UINT8,
13442 LAYOUT_SINT8,
13443 LAYOUT_UNORM8,
13444 LAYOUT_SNORM8,
13445 LAYOUT_UNORM10_2,
13446 LAYOUT_UINT10_2,
13448 LAYOUT_COUNT,
13451 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
13453 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13454 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13456 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
13457 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
13458 ID3D11Buffer *vb_position, *vb_attribute;
13459 struct d3d11_test_context test_context;
13460 D3D11_TEXTURE2D_DESC texture_desc;
13461 unsigned int i, j, stride, offset;
13462 ID3D11Texture2D *render_target;
13463 ID3D11DeviceContext *context;
13464 ID3D11RenderTargetView *rtv;
13465 ID3D11PixelShader *ps;
13466 ID3D11Device *device;
13467 HRESULT hr;
13469 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
13471 DXGI_FORMAT_R32G32B32A32_FLOAT,
13472 DXGI_FORMAT_R16G16B16A16_UINT,
13473 DXGI_FORMAT_R16G16B16A16_SINT,
13474 DXGI_FORMAT_R16G16B16A16_UNORM,
13475 DXGI_FORMAT_R16G16B16A16_SNORM,
13476 DXGI_FORMAT_R8G8B8A8_UINT,
13477 DXGI_FORMAT_R8G8B8A8_SINT,
13478 DXGI_FORMAT_R8G8B8A8_UNORM,
13479 DXGI_FORMAT_R8G8B8A8_SNORM,
13480 DXGI_FORMAT_R10G10B10A2_UNORM,
13481 DXGI_FORMAT_R10G10B10A2_UINT,
13483 static const struct vec2 quad[] =
13485 {-1.0f, -1.0f},
13486 {-1.0f, 1.0f},
13487 { 1.0f, -1.0f},
13488 { 1.0f, 1.0f},
13490 static const DWORD ps_code[] =
13492 #if 0
13493 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
13495 return color;
13497 #endif
13498 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
13499 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
13500 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
13501 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
13502 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13503 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
13504 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
13505 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
13507 static const DWORD vs_float_code[] =
13509 #if 0
13510 struct output
13512 float4 position : SV_Position;
13513 float4 color : COLOR;
13516 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
13518 o.position = position;
13519 o.color = color;
13521 #endif
13522 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
13523 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13524 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
13525 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
13526 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13527 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13528 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13529 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13530 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13531 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13532 0x0100003e,
13534 static const DWORD vs_uint_code[] =
13536 #if 0
13537 struct output
13539 float4 position : SV_Position;
13540 float4 color : COLOR;
13543 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
13545 o.position = position;
13546 o.color = color;
13548 #endif
13549 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
13550 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13551 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
13552 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
13553 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13554 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13555 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13556 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13557 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13558 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13559 0x0100003e,
13561 static const DWORD vs_sint_code[] =
13563 #if 0
13564 struct output
13566 float4 position : SV_Position;
13567 float4 color : COLOR;
13570 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
13572 o.position = position;
13573 o.color = color;
13575 #endif
13576 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
13577 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13578 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
13579 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
13580 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13581 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13582 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13583 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13584 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13585 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13586 0x0100003e,
13588 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
13589 static const unsigned short uint16_data[] = {6, 8, 55, 777};
13590 static const short sint16_data[] = {-1, 33, 8, -77};
13591 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
13592 static const short snorm16_data[] = {-32768, 0, 32767, 0};
13593 static const unsigned char uint8_data[] = {0, 64, 128, 255};
13594 static const signed char sint8_data[] = {-128, 0, 127, 64};
13595 static const unsigned int uint32_zero = 0;
13596 static const unsigned int uint32_max = 0xffffffff;
13597 static const unsigned int unorm10_2_data= 0xa00003ff;
13598 static const unsigned int g10_data = 0x000ffc00;
13599 static const unsigned int a2_data = 0xc0000000;
13600 static const struct
13602 enum layout_id layout_id;
13603 unsigned int stride;
13604 const void *data;
13605 struct vec4 expected_color;
13606 BOOL todo;
13608 tests[] =
13610 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
13611 {1.0f, 2.0f, 3.0f, 4.0f}},
13612 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
13613 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
13614 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
13615 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
13616 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
13617 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
13618 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
13619 {-1.0f, 0.0f, 1.0f, 0.0f}},
13620 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
13621 {0.0f, 0.0f, 0.0f, 0.0f}},
13622 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
13623 {255.0f, 255.0f, 255.0f, 255.0f}},
13624 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
13625 {0.0f, 64.0f, 128.0f, 255.0f}},
13626 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
13627 {0.0f, 0.0f, 0.0f, 0.0f}},
13628 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
13629 {-1.0f, -1.0f, -1.0f, -1.0f}},
13630 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
13631 {-128.0f, 0.0f, 127.0f, 64.0f}},
13632 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
13633 {0.0f, 0.0f, 0.0f, 0.0f}},
13634 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
13635 {1.0f, 1.0f, 1.0f, 1.0f}},
13636 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
13637 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
13638 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
13639 {0.0f, 0.0f, 0.0f, 0.0f}},
13640 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
13641 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
13642 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
13643 {0.0f, 0.0f, 0.0f, 0.0f}},
13644 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
13645 {1.0f, 1.0f, 1.0f, 1.0f}},
13646 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
13647 {0.0f, 1.0f, 0.0f, 0.0f}},
13648 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
13649 {0.0f, 0.0f, 0.0f, 1.0f}},
13650 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
13651 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
13652 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
13653 {0.0f, 0.0f, 0.0f, 0.0f}},
13654 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
13655 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
13656 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
13657 {0.0f, 1023.0f, 0.0f, 0.0f}},
13658 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
13659 {0.0f, 0.0f, 0.0f, 3.0f}},
13660 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
13661 {1023.0f, 0.0f, 512.0f, 2.0f}},
13664 if (!init_test_context(&test_context, NULL))
13665 return;
13667 device = test_context.device;
13668 context = test_context.immediate_context;
13670 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13671 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13673 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
13674 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
13675 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
13676 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
13677 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
13678 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
13680 for (i = 0; i < LAYOUT_COUNT; ++i)
13682 input_layout_desc[1].Format = layout_formats[i];
13683 input_layout[i] = NULL;
13684 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
13685 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
13686 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
13687 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
13690 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
13691 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
13693 texture_desc.Width = 640;
13694 texture_desc.Height = 480;
13695 texture_desc.MipLevels = 1;
13696 texture_desc.ArraySize = 1;
13697 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
13698 texture_desc.SampleDesc.Count = 1;
13699 texture_desc.SampleDesc.Quality = 0;
13700 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13701 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
13702 texture_desc.CPUAccessFlags = 0;
13703 texture_desc.MiscFlags = 0;
13705 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
13706 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
13708 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
13709 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13711 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13712 offset = 0;
13713 stride = sizeof(*quad);
13714 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
13715 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13716 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13718 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13720 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
13722 if (tests[i].layout_id == LAYOUT_UINT10_2)
13723 continue;
13725 assert(tests[i].layout_id < LAYOUT_COUNT);
13726 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
13728 assert(4 * tests[i].stride <= 1024);
13729 box.right = tests[i].stride;
13730 for (j = 0; j < 4; ++j)
13732 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
13733 &box, tests[i].data, 0, 0);
13734 box.left += tests[i].stride;
13735 box.right += tests[i].stride;
13738 stride = tests[i].stride;
13739 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
13741 switch (layout_formats[tests[i].layout_id])
13743 case DXGI_FORMAT_R16G16B16A16_UINT:
13744 case DXGI_FORMAT_R10G10B10A2_UINT:
13745 case DXGI_FORMAT_R8G8B8A8_UINT:
13746 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
13747 break;
13748 case DXGI_FORMAT_R16G16B16A16_SINT:
13749 case DXGI_FORMAT_R8G8B8A8_SINT:
13750 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
13751 break;
13753 default:
13754 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
13755 /* Fall through. */
13756 case DXGI_FORMAT_R32G32B32A32_FLOAT:
13757 case DXGI_FORMAT_R16G16B16A16_UNORM:
13758 case DXGI_FORMAT_R16G16B16A16_SNORM:
13759 case DXGI_FORMAT_R10G10B10A2_UNORM:
13760 case DXGI_FORMAT_R8G8B8A8_UNORM:
13761 case DXGI_FORMAT_R8G8B8A8_SNORM:
13762 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
13763 break;
13766 ID3D11DeviceContext_Draw(context, 4, 0);
13767 check_texture_vec4(render_target, &tests[i].expected_color, 2);
13770 ID3D11Texture2D_Release(render_target);
13771 ID3D11RenderTargetView_Release(rtv);
13772 ID3D11Buffer_Release(vb_attribute);
13773 ID3D11Buffer_Release(vb_position);
13774 for (i = 0; i < LAYOUT_COUNT; ++i)
13776 if (input_layout[i])
13777 ID3D11InputLayout_Release(input_layout[i]);
13779 ID3D11PixelShader_Release(ps);
13780 ID3D11VertexShader_Release(vs_float);
13781 ID3D11VertexShader_Release(vs_uint);
13782 ID3D11VertexShader_Release(vs_sint);
13783 release_test_context(&test_context);
13786 static void test_null_sampler(void)
13788 struct d3d11_test_context test_context;
13789 D3D11_TEXTURE2D_DESC texture_desc;
13790 ID3D11ShaderResourceView *srv;
13791 ID3D11DeviceContext *context;
13792 ID3D11RenderTargetView *rtv;
13793 ID3D11SamplerState *sampler;
13794 ID3D11Texture2D *texture;
13795 ID3D11PixelShader *ps;
13796 ID3D11Device *device;
13797 HRESULT hr;
13799 static const DWORD ps_code[] =
13801 #if 0
13802 Texture2D t;
13803 SamplerState s;
13805 float4 main(float4 position : SV_POSITION) : SV_Target
13807 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
13809 #endif
13810 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13811 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13812 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13813 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13814 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13815 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13816 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13817 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13818 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13819 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13821 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
13823 if (!init_test_context(&test_context, NULL))
13824 return;
13826 device = test_context.device;
13827 context = test_context.immediate_context;
13829 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13830 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13832 texture_desc.Width = 64;
13833 texture_desc.Height = 64;
13834 texture_desc.MipLevels = 1;
13835 texture_desc.ArraySize = 1;
13836 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13837 texture_desc.SampleDesc.Count = 1;
13838 texture_desc.SampleDesc.Quality = 0;
13839 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13840 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
13841 texture_desc.CPUAccessFlags = 0;
13842 texture_desc.MiscFlags = 0;
13844 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13845 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13847 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13848 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13850 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
13851 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13853 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
13855 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13856 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
13857 sampler = NULL;
13858 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
13859 draw_quad(&test_context);
13860 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
13862 ID3D11ShaderResourceView_Release(srv);
13863 ID3D11RenderTargetView_Release(rtv);
13864 ID3D11Texture2D_Release(texture);
13865 ID3D11PixelShader_Release(ps);
13866 release_test_context(&test_context);
13869 static void test_check_feature_support(void)
13871 D3D11_FEATURE_DATA_THREADING threading[2];
13872 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
13873 ID3D11Device *device;
13874 ULONG refcount;
13875 HRESULT hr;
13877 if (!(device = create_device(NULL)))
13879 skip("Failed to create device.\n");
13880 return;
13883 memset(threading, 0xef, sizeof(threading));
13885 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
13886 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13887 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
13888 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13889 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
13890 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13891 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
13892 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13893 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
13894 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13895 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
13896 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13898 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
13899 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
13900 ok(threading[0].DriverCommandLists == 0xefefefef,
13901 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
13902 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
13903 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
13904 ok(threading[1].DriverCommandLists == 0xefefefef,
13905 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
13907 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
13908 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
13909 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
13910 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
13911 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
13912 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
13914 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
13915 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13916 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
13917 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13918 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
13919 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13920 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
13921 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13922 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
13923 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13924 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
13925 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13927 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
13928 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
13929 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
13931 refcount = ID3D11Device_Release(device);
13932 ok(!refcount, "Device has %u references left.\n", refcount);
13935 static void test_create_unordered_access_view(void)
13937 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13938 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
13939 D3D11_TEXTURE3D_DESC texture3d_desc;
13940 D3D11_TEXTURE2D_DESC texture2d_desc;
13941 ULONG refcount, expected_refcount;
13942 D3D11_SUBRESOURCE_DATA data = {0};
13943 ID3D11UnorderedAccessView *uav;
13944 struct device_desc device_desc;
13945 D3D11_BUFFER_DESC buffer_desc;
13946 ID3D11Device *device, *tmp;
13947 ID3D11Texture3D *texture3d;
13948 ID3D11Texture2D *texture2d;
13949 ID3D11Resource *texture;
13950 ID3D11Buffer *buffer;
13951 unsigned int i;
13952 HRESULT hr;
13954 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
13955 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
13956 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
13957 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
13958 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
13959 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
13960 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
13961 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
13962 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
13963 static const struct
13965 struct
13967 unsigned int miplevel_count;
13968 unsigned int depth_or_array_size;
13969 DXGI_FORMAT format;
13970 } texture;
13971 struct uav_desc uav_desc;
13972 struct uav_desc expected_uav_desc;
13974 tests[] =
13976 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
13977 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
13978 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
13979 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
13980 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
13981 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
13982 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
13983 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
13984 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
13985 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
13986 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
13987 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
13988 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
13989 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
13990 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
13991 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
13992 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
13993 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
13994 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
13995 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
13996 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
13997 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
13998 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
13999 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
14000 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
14001 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
14002 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
14003 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
14004 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
14005 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
14006 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
14007 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
14008 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
14009 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
14011 static const struct
14013 struct
14015 D3D11_UAV_DIMENSION dimension;
14016 unsigned int miplevel_count;
14017 unsigned int depth_or_array_size;
14018 DXGI_FORMAT format;
14019 } texture;
14020 struct uav_desc uav_desc;
14022 invalid_desc_tests[] =
14024 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
14025 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
14026 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
14027 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
14028 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
14029 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
14030 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
14031 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
14032 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
14033 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
14034 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
14035 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
14036 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
14037 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
14038 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
14039 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
14040 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
14041 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
14042 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
14043 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
14044 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
14045 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
14046 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
14047 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
14048 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
14049 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
14050 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
14051 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
14052 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
14053 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
14054 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
14055 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
14056 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
14058 #undef FMT_UNKNOWN
14059 #undef RGBA8_UNORM
14060 #undef RGBA8_TL
14061 #undef DIM_UNKNOWN
14062 #undef TEX_1D
14063 #undef TEX_1D_ARRAY
14064 #undef TEX_2D
14065 #undef TEX_2D_ARRAY
14066 #undef TEX_3D
14068 device_desc.feature_level = &feature_level;
14069 device_desc.flags = 0;
14070 if (!(device = create_device(&device_desc)))
14072 skip("Failed to create device.\n");
14073 return;
14076 buffer_desc.ByteWidth = 1024;
14077 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
14078 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14079 buffer_desc.CPUAccessFlags = 0;
14080 buffer_desc.MiscFlags = 0;
14081 buffer_desc.StructureByteStride = 0;
14083 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
14084 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14086 expected_refcount = get_refcount(device) + 1;
14087 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14088 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
14089 refcount = get_refcount(device);
14090 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
14091 tmp = NULL;
14092 expected_refcount = refcount + 1;
14093 ID3D11Buffer_GetDevice(buffer, &tmp);
14094 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
14095 refcount = get_refcount(device);
14096 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
14097 ID3D11Device_Release(tmp);
14099 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14100 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
14101 U(uav_desc).Buffer.FirstElement = 0;
14102 U(uav_desc).Buffer.NumElements = 64;
14103 U(uav_desc).Buffer.Flags = 0;
14105 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
14106 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14108 expected_refcount = get_refcount(device) + 1;
14109 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
14110 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
14111 refcount = get_refcount(device);
14112 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
14113 tmp = NULL;
14114 expected_refcount = refcount + 1;
14115 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
14116 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
14117 refcount = get_refcount(device);
14118 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
14119 ID3D11Device_Release(tmp);
14121 ID3D11UnorderedAccessView_Release(uav);
14122 ID3D11Buffer_Release(buffer);
14124 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
14125 buffer_desc.StructureByteStride = 4;
14127 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14128 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
14130 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
14131 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
14133 memset(&uav_desc, 0, sizeof(uav_desc));
14134 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
14136 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
14137 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
14138 uav_desc.ViewDimension);
14139 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
14140 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
14141 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
14143 ID3D11UnorderedAccessView_Release(uav);
14144 ID3D11Buffer_Release(buffer);
14146 texture2d_desc.Width = 512;
14147 texture2d_desc.Height = 512;
14148 texture2d_desc.SampleDesc.Count = 1;
14149 texture2d_desc.SampleDesc.Quality = 0;
14150 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
14151 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14152 texture2d_desc.CPUAccessFlags = 0;
14153 texture2d_desc.MiscFlags = 0;
14155 texture3d_desc.Width = 64;
14156 texture3d_desc.Height = 64;
14157 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
14158 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14159 texture3d_desc.CPUAccessFlags = 0;
14160 texture3d_desc.MiscFlags = 0;
14162 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14164 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
14166 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
14168 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
14169 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
14170 texture2d_desc.Format = tests[i].texture.format;
14172 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14173 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
14174 texture = (ID3D11Resource *)texture2d;
14176 else
14178 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
14179 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
14180 texture3d_desc.Format = tests[i].texture.format;
14182 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
14183 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
14184 texture = (ID3D11Resource *)texture3d;
14187 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
14189 current_desc = NULL;
14191 else
14193 current_desc = &uav_desc;
14194 get_uav_desc(current_desc, &tests[i].uav_desc);
14197 expected_refcount = get_refcount(texture);
14198 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
14199 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
14200 refcount = get_refcount(texture);
14201 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
14203 memset(&uav_desc, 0, sizeof(uav_desc));
14204 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
14205 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
14207 ID3D11UnorderedAccessView_Release(uav);
14208 ID3D11Resource_Release(texture);
14211 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
14213 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
14214 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
14216 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
14218 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
14219 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
14220 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
14222 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14223 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
14224 texture = (ID3D11Resource *)texture2d;
14226 else
14228 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
14229 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
14230 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
14232 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
14233 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
14234 texture = (ID3D11Resource *)texture3d;
14237 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
14238 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
14239 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
14241 ID3D11Resource_Release(texture);
14244 refcount = ID3D11Device_Release(device);
14245 ok(!refcount, "Device has %u references left.\n", refcount);
14248 static void test_immediate_constant_buffer(void)
14250 struct d3d11_test_context test_context;
14251 D3D11_TEXTURE2D_DESC texture_desc;
14252 ID3D11DeviceContext *context;
14253 ID3D11RenderTargetView *rtv;
14254 unsigned int index[4] = {0};
14255 ID3D11Texture2D *texture;
14256 ID3D11PixelShader *ps;
14257 ID3D11Device *device;
14258 ID3D11Buffer *cb;
14259 unsigned int i;
14260 HRESULT hr;
14262 static const DWORD ps_code[] =
14264 #if 0
14265 uint index;
14267 static const int int_array[6] =
14269 310, 111, 212, -513, -318, 0,
14272 static const uint uint_array[6] =
14274 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
14277 static const float float_array[6] =
14279 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
14282 float4 main() : SV_Target
14284 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
14286 #endif
14287 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
14288 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14289 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14290 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
14291 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
14292 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
14293 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
14294 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
14295 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
14296 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
14297 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
14298 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
14299 0x0100003e,
14301 static struct vec4 expected_result[] =
14303 { 310.0f, 2.0f, 76.00f, 1.0f},
14304 { 111.0f, 7.0f, 83.50f, 1.0f},
14305 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
14306 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
14307 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
14308 { 0.0f, 0.0f, 0.0f, 1.0f},
14311 if (!init_test_context(&test_context, NULL))
14312 return;
14314 device = test_context.device;
14315 context = test_context.immediate_context;
14317 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14318 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14319 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14321 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
14322 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14324 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14325 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14326 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14327 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14329 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14330 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14331 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14333 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
14335 *index = i;
14336 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
14338 draw_quad(&test_context);
14339 check_texture_vec4(texture, &expected_result[i], 0);
14342 ID3D11Buffer_Release(cb);
14343 ID3D11PixelShader_Release(ps);
14344 ID3D11Texture2D_Release(texture);
14345 ID3D11RenderTargetView_Release(rtv);
14346 release_test_context(&test_context);
14349 static void test_fp_specials(void)
14351 struct d3d11_test_context test_context;
14352 D3D11_TEXTURE2D_DESC texture_desc;
14353 ID3D11DeviceContext *context;
14354 ID3D11RenderTargetView *rtv;
14355 ID3D11Texture2D *texture;
14356 ID3D11PixelShader *ps;
14357 ID3D11Device *device;
14358 HRESULT hr;
14360 static const DWORD ps_code[] =
14362 #if 0
14363 float4 main() : SV_Target
14365 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
14367 #endif
14368 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
14369 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14370 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14371 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
14372 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
14373 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
14375 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
14377 if (!init_test_context(&test_context, NULL))
14378 return;
14380 device = test_context.device;
14381 context = test_context.immediate_context;
14383 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14384 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14385 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14387 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14388 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14389 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14390 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14392 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14393 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14395 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14397 draw_quad(&test_context);
14398 check_texture_uvec4(texture, &expected_result);
14400 ID3D11PixelShader_Release(ps);
14401 ID3D11Texture2D_Release(texture);
14402 ID3D11RenderTargetView_Release(rtv);
14403 release_test_context(&test_context);
14406 static void test_uint_shader_instructions(void)
14408 struct shader
14410 const DWORD *code;
14411 size_t size;
14412 D3D_FEATURE_LEVEL required_feature_level;
14415 struct d3d11_test_context test_context;
14416 D3D11_TEXTURE2D_DESC texture_desc;
14417 D3D_FEATURE_LEVEL feature_level;
14418 ID3D11DeviceContext *context;
14419 ID3D11RenderTargetView *rtv;
14420 ID3D11Texture2D *texture;
14421 ID3D11PixelShader *ps;
14422 ID3D11Device *device;
14423 ID3D11Buffer *cb;
14424 unsigned int i;
14425 HRESULT hr;
14427 static const DWORD ps_bfi_code[] =
14429 #if 0
14430 uint bits, offset, insert, base;
14432 uint4 main() : SV_Target
14434 uint mask = ((1 << bits) - 1) << offset;
14435 return ((insert << offset) & mask) | (base & ~mask);
14437 #endif
14438 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
14439 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14440 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14441 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
14442 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14443 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
14444 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
14446 static const DWORD ps_bfi2_code[] =
14448 #if 0
14449 ps_5_0
14450 dcl_globalFlags refactoringAllowed
14451 dcl_constantbuffer cb0[1], immediateIndexed
14452 dcl_output o0.xyzw
14453 dcl_temps 1
14454 mov r0.xyzw, cb0[0].xyzw
14455 bfi r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz, r0.wwww
14456 mov o0.xyzw, r0.xyzw
14458 #endif
14459 0x43425844, 0x900f86b6, 0x73f4dabf, 0xea1b1106, 0x591ac790, 0x00000001, 0x00000104, 0x00000003,
14460 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14461 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14462 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000008c, 0x00000050, 0x00000023,
14463 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14464 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14465 0x0b00008c, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
14466 0x00000000, 0x00100ff6, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
14467 0x0100003e,
14469 static const DWORD ps_ibfe_code[] =
14471 #if 0
14472 ps_5_0
14473 dcl_globalFlags refactoringAllowed
14474 dcl_constantbuffer cb0[1], immediateIndexed
14475 dcl_output o0.xyzw
14476 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
14478 #endif
14479 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
14480 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14481 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14482 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
14483 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14484 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
14485 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
14487 static const DWORD ps_ibfe2_code[] =
14489 #if 0
14490 ps_5_0
14491 dcl_globalFlags refactoringAllowed
14492 dcl_constantbuffer cb0[1], immediateIndexed
14493 dcl_output o0.xyzw
14494 dcl_temps 1
14495 mov r0.xyzw, cb0[0].xyzw
14496 ibfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
14497 mov o0.xyzw, r0.xyzw
14499 #endif
14500 0x43425844, 0x347a9c0e, 0x3eff39a4, 0x3dd41cc5, 0xff87ec8d, 0x00000001, 0x000000fc, 0x00000003,
14501 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14502 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14503 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
14504 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14505 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14506 0x0900008b, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
14507 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
14509 static const DWORD ps_ubfe_code[] =
14511 #if 0
14512 uint u;
14514 uint4 main() : SV_Target
14516 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
14518 #endif
14519 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
14520 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14521 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14522 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
14523 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14524 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
14525 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
14526 0x0100003e,
14528 static const DWORD ps_ubfe2_code[] =
14530 #if 0
14531 ps_5_0
14532 dcl_globalFlags refactoringAllowed
14533 dcl_constantbuffer cb0[1], immediateIndexed
14534 dcl_output o0.xyzw
14535 dcl_temps 1
14536 mov r0.xyzw, cb0[0].xyzw
14537 ubfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
14538 mov o0.xyzw, r0.xyzw
14540 #endif
14541 0x43425844, 0xf377b7fc, 0x1e4cb9e7, 0xb9b1020d, 0xde484388, 0x00000001, 0x000000fc, 0x00000003,
14542 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14543 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14544 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
14545 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14546 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14547 0x0900008a, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
14548 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
14550 static const DWORD ps_bfrev_code[] =
14552 #if 0
14553 uint bits;
14555 uint4 main() : SV_Target
14557 return uint4(reversebits(bits), reversebits(reversebits(bits)),
14558 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
14560 #endif
14561 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
14562 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14563 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14564 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
14565 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14566 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
14567 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
14568 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
14569 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
14570 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
14571 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
14573 static const DWORD ps_bits_code[] =
14575 #if 0
14576 uint u;
14577 int i;
14579 uint4 main() : SV_Target
14581 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
14583 #endif
14584 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
14585 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14586 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14587 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
14588 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14589 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
14590 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
14591 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
14592 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
14593 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
14594 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
14595 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
14596 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
14597 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
14599 static const DWORD ps_ftou_code[] =
14601 #if 0
14602 float f;
14604 uint4 main() : SV_Target
14606 return uint4(f, -f, 0, 0);
14608 #endif
14609 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
14610 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14611 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14612 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
14613 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
14614 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
14615 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
14616 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
14618 static const DWORD ps_f16tof32_code[] =
14620 #if 0
14621 uint4 hf;
14623 uint4 main() : SV_Target
14625 return f16tof32(hf);
14627 #endif
14628 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
14629 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14630 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14631 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
14632 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14633 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14634 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
14636 static const DWORD ps_f32tof16_code[] =
14638 #if 0
14639 float4 f;
14641 uint4 main() : SV_Target
14643 return f32tof16(f);
14645 #endif
14646 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
14647 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14648 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14649 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
14650 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14651 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
14653 static const DWORD ps_not_code[] =
14655 #if 0
14656 uint2 bits;
14658 uint4 main() : SV_Target
14660 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
14662 #endif
14663 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
14664 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14665 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14666 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
14667 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14668 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
14669 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
14670 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
14672 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
14673 static const struct shader ps_bfi2 = {ps_bfi2_code, sizeof(ps_bfi2_code), D3D_FEATURE_LEVEL_11_0};
14674 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
14675 static const struct shader ps_ibfe2 = {ps_ibfe2_code, sizeof(ps_ibfe2_code), D3D_FEATURE_LEVEL_11_0};
14676 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
14677 static const struct shader ps_ubfe2 = {ps_ubfe2_code, sizeof(ps_ubfe2_code), D3D_FEATURE_LEVEL_11_0};
14678 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
14679 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
14680 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
14681 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
14682 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
14683 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
14684 static const struct
14686 const struct shader *ps;
14687 unsigned int bits[4];
14688 struct uvec4 expected_result;
14690 tests[] =
14692 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
14693 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
14694 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14695 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14696 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14697 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14698 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
14699 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
14700 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
14701 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
14702 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
14703 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
14704 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
14705 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
14706 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
14707 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
14708 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
14709 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
14710 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
14712 {&ps_bfi2, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14713 {&ps_bfi2, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14714 {&ps_bfi2, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14715 {&ps_bfi2, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14717 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14718 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14719 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14720 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14721 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
14722 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
14723 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14724 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14725 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
14726 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14727 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14728 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14729 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14730 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14731 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14732 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14733 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14734 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14735 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
14736 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
14737 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14738 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14739 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14740 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14741 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14742 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14744 {&ps_ibfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14746 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14747 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
14748 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
14749 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
14750 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
14751 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14752 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
14754 {&ps_ubfe2, { 4, 4, 0x7fffffff}, {0x0000000f, 0x0000000f, 0x0000000f, 0x0000000f}},
14755 {&ps_ubfe2, {23, 8, 0xffffffff}, {0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff}},
14756 {&ps_ubfe2, {30, 1, 0xffffffff}, {0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff}},
14757 {&ps_ubfe2, {15, 15, 0x7fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14758 {&ps_ubfe2, {15, 15, 0xffff00ff}, {0x00007ffe, 0x00007ffe, 0x00007ffe, 0x00007ffe}},
14759 {&ps_ubfe2, {16, 15, 0xffffffff}, {0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff}},
14760 {&ps_ubfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14761 {&ps_ubfe2, {20, 15, 0xffffffff}, {0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff}},
14762 {&ps_ubfe2, {31, 31, 0xffffffff}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
14763 {&ps_ubfe2, {31, 31, 0x80000000}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
14764 {&ps_ubfe2, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14766 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
14767 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
14768 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
14770 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
14771 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
14772 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
14773 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
14774 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
14775 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
14776 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
14777 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
14778 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
14779 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
14780 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
14781 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
14783 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
14784 {&ps_ftou, {BITS_NAN}, { 0, 0}},
14785 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
14786 {&ps_ftou, {BITS_INF}, {~0u, 0}},
14787 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
14788 {&ps_ftou, {BITS_1_0}, { 1, 0}},
14790 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
14791 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
14792 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
14793 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
14795 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
14797 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
14798 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
14801 if (!init_test_context(&test_context, NULL))
14802 return;
14804 device = test_context.device;
14805 context = test_context.immediate_context;
14806 feature_level = ID3D11Device_GetFeatureLevel(device);
14808 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
14809 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14811 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14812 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
14813 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14814 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14816 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14817 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14819 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14821 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14823 if (feature_level < tests[i].ps->required_feature_level)
14824 continue;
14826 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
14827 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14828 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14830 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
14832 draw_quad(&test_context);
14833 check_texture_uvec4(texture, &tests[i].expected_result);
14835 ID3D11PixelShader_Release(ps);
14838 ID3D11Buffer_Release(cb);
14839 ID3D11Texture2D_Release(texture);
14840 ID3D11RenderTargetView_Release(rtv);
14841 release_test_context(&test_context);
14844 static void test_index_buffer_offset(void)
14846 ID3D11Buffer *vb, *ib, *so_buffer, *args_buffer;
14847 struct d3d11_test_context test_context;
14848 ID3D11InputLayout *input_layout;
14849 ID3D11DeviceContext *context;
14850 struct resource_readback rb;
14851 ID3D11GeometryShader *gs;
14852 const struct vec4 *data;
14853 ID3D11VertexShader *vs;
14854 ID3D11Device *device;
14855 UINT stride, offset;
14856 unsigned int i;
14857 HRESULT hr;
14859 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
14860 static const DWORD vs_code[] =
14862 #if 0
14863 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
14864 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
14866 out_position = position;
14867 out_attrib = attrib;
14869 #endif
14870 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
14871 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14872 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
14873 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
14874 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
14875 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
14876 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
14877 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
14878 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
14879 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
14880 0x0100003e,
14882 static const DWORD gs_code[] =
14884 #if 0
14885 struct vertex
14887 float4 position : SV_POSITION;
14888 float4 attrib : ATTRIB;
14891 [maxvertexcount(1)]
14892 void main(point vertex input[1], inout PointStream<vertex> output)
14894 output.Append(input[0]);
14895 output.RestartStrip();
14897 #endif
14898 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
14899 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14900 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
14901 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
14902 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
14903 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
14904 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
14905 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
14906 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
14907 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
14908 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
14909 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
14911 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
14913 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
14914 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
14916 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
14918 {0, "SV_Position", 0, 0, 4, 0},
14919 {0, "ATTRIB", 0, 0, 4, 0},
14921 static const struct
14923 struct vec4 position;
14924 struct vec4 attrib;
14926 vertices[] =
14928 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
14929 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
14930 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
14931 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
14933 static const unsigned int indices[] =
14935 0, 1, 2, 3,
14936 3, 2, 1, 0,
14937 1, 3, 2, 0,
14939 static const struct vec4 expected_data[] =
14941 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
14942 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
14943 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
14944 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
14946 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
14947 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
14948 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
14949 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
14951 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
14952 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
14953 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
14954 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
14956 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
14957 static const D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS argument_data[] =
14959 {4, 1, 0, 0, 0},
14962 if (!init_test_context(&test_context, &feature_level))
14963 return;
14965 device = test_context.device;
14966 context = test_context.immediate_context;
14968 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
14969 vs_code, sizeof(vs_code), &input_layout);
14970 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
14972 stride = 32;
14973 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
14974 so_declaration, ARRAY_SIZE(so_declaration),
14975 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
14976 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
14978 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
14979 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
14981 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
14982 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
14983 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
14985 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
14986 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
14988 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
14989 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
14990 stride = sizeof(*vertices);
14991 offset = 0;
14992 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
14994 offset = 0;
14995 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
14997 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
14998 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
15000 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
15001 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
15003 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
15004 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
15006 get_buffer_readback(so_buffer, &rb);
15007 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
15009 data = get_readback_vec4(&rb, i, 0);
15010 ok(compare_vec4(data, &expected_data[i], 0)
15011 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
15012 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
15013 data->x, data->y, data->z, data->w, i);
15015 release_resource_readback(&rb);
15017 /* indirect draws */
15018 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
15019 sizeof(argument_data), argument_data);
15021 offset = 0;
15022 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
15024 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
15025 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
15027 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
15028 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
15030 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
15031 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
15033 get_buffer_readback(so_buffer, &rb);
15034 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
15036 data = get_readback_vec4(&rb, i, 0);
15037 todo_wine_if(i >= 8 && i != 20 && i != 21)
15038 ok(compare_vec4(data, &expected_data[i], 0)
15039 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
15040 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
15041 data->x, data->y, data->z, data->w, i);
15043 release_resource_readback(&rb);
15045 ID3D11Buffer_Release(so_buffer);
15046 ID3D11Buffer_Release(args_buffer);
15047 ID3D11Buffer_Release(ib);
15048 ID3D11Buffer_Release(vb);
15049 ID3D11VertexShader_Release(vs);
15050 ID3D11GeometryShader_Release(gs);
15051 ID3D11InputLayout_Release(input_layout);
15052 release_test_context(&test_context);
15055 static void test_face_culling(void)
15057 struct d3d11_test_context test_context;
15058 D3D11_RASTERIZER_DESC rasterizer_desc;
15059 ID3D11RasterizerState *state;
15060 ID3D11DeviceContext *context;
15061 ID3D11Buffer *cw_vb, *ccw_vb;
15062 ID3D11Device *device;
15063 BOOL broken_warp;
15064 unsigned int i;
15065 HRESULT hr;
15067 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
15068 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
15069 static const DWORD ps_code[] =
15071 #if 0
15072 float4 main(uint front : SV_IsFrontFace) : SV_Target
15074 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
15076 #endif
15077 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
15078 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
15079 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
15080 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
15081 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
15082 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
15083 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
15084 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
15085 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
15086 0x3f800000, 0x0100003e,
15088 static const struct vec2 ccw_quad[] =
15090 {-1.0f, 1.0f},
15091 {-1.0f, -1.0f},
15092 { 1.0f, 1.0f},
15093 { 1.0f, -1.0f},
15095 static const struct
15097 D3D11_CULL_MODE cull_mode;
15098 BOOL front_ccw;
15099 BOOL expected_cw;
15100 BOOL expected_ccw;
15102 tests[] =
15104 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
15105 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
15106 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
15107 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
15108 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
15109 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
15112 if (!init_test_context(&test_context, NULL))
15113 return;
15115 device = test_context.device;
15116 context = test_context.immediate_context;
15118 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15119 draw_color_quad(&test_context, &green);
15120 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15122 cw_vb = test_context.vb;
15123 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
15125 test_context.vb = ccw_vb;
15126 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15127 draw_color_quad(&test_context, &green);
15128 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15130 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
15131 rasterizer_desc.CullMode = D3D11_CULL_BACK;
15132 rasterizer_desc.FrontCounterClockwise = FALSE;
15133 rasterizer_desc.DepthBias = 0;
15134 rasterizer_desc.DepthBiasClamp = 0.0f;
15135 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
15136 rasterizer_desc.DepthClipEnable = TRUE;
15137 rasterizer_desc.ScissorEnable = FALSE;
15138 rasterizer_desc.MultisampleEnable = FALSE;
15139 rasterizer_desc.AntialiasedLineEnable = FALSE;
15141 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15143 rasterizer_desc.CullMode = tests[i].cull_mode;
15144 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
15145 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
15146 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
15148 ID3D11DeviceContext_RSSetState(context, state);
15150 test_context.vb = cw_vb;
15151 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15152 draw_color_quad(&test_context, &green);
15153 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
15155 test_context.vb = ccw_vb;
15156 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15157 draw_color_quad(&test_context, &green);
15158 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
15160 ID3D11RasterizerState_Release(state);
15163 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0;
15165 /* Test SV_IsFrontFace. */
15166 ID3D11PixelShader_Release(test_context.ps);
15167 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
15168 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15170 rasterizer_desc.CullMode = D3D11_CULL_NONE;
15171 rasterizer_desc.FrontCounterClockwise = FALSE;
15172 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
15173 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15174 ID3D11DeviceContext_RSSetState(context, state);
15176 test_context.vb = cw_vb;
15177 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15178 draw_color_quad(&test_context, &green);
15179 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15180 test_context.vb = ccw_vb;
15181 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15182 draw_color_quad(&test_context, &green);
15183 if (!broken_warp)
15184 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
15185 else
15186 win_skip("Broken WARP.\n");
15188 ID3D11RasterizerState_Release(state);
15190 rasterizer_desc.CullMode = D3D11_CULL_NONE;
15191 rasterizer_desc.FrontCounterClockwise = TRUE;
15192 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
15193 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15194 ID3D11DeviceContext_RSSetState(context, state);
15196 test_context.vb = cw_vb;
15197 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15198 draw_color_quad(&test_context, &green);
15199 if (!broken_warp)
15200 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
15201 else
15202 win_skip("Broken WARP.\n");
15203 test_context.vb = ccw_vb;
15204 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15205 draw_color_quad(&test_context, &green);
15206 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15208 ID3D11RasterizerState_Release(state);
15210 test_context.vb = cw_vb;
15211 ID3D11Buffer_Release(ccw_vb);
15212 release_test_context(&test_context);
15215 static void test_line_antialiasing_blending(void)
15217 ID3D11RasterizerState *rasterizer_state;
15218 struct d3d11_test_context test_context;
15219 D3D11_RASTERIZER_DESC rasterizer_desc;
15220 ID3D11BlendState *blend_state;
15221 ID3D11DeviceContext *context;
15222 D3D11_BLEND_DESC blend_desc;
15223 ID3D11Device *device;
15224 HRESULT hr;
15226 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
15227 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
15229 if (!init_test_context(&test_context, NULL))
15230 return;
15232 device = test_context.device;
15233 context = test_context.immediate_context;
15235 memset(&blend_desc, 0, sizeof(blend_desc));
15236 blend_desc.AlphaToCoverageEnable = FALSE;
15237 blend_desc.IndependentBlendEnable = FALSE;
15238 blend_desc.RenderTarget[0].BlendEnable = TRUE;
15239 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
15240 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
15241 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
15242 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
15243 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
15244 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
15245 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
15247 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
15248 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
15249 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
15251 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15252 draw_color_quad(&test_context, &green);
15253 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
15255 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
15256 draw_color_quad(&test_context, &red);
15257 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
15259 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
15260 ID3D11BlendState_Release(blend_state);
15262 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15263 draw_color_quad(&test_context, &green);
15264 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
15266 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
15267 draw_color_quad(&test_context, &red);
15268 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
15270 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
15271 rasterizer_desc.CullMode = D3D11_CULL_BACK;
15272 rasterizer_desc.FrontCounterClockwise = FALSE;
15273 rasterizer_desc.DepthBias = 0;
15274 rasterizer_desc.DepthBiasClamp = 0.0f;
15275 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
15276 rasterizer_desc.DepthClipEnable = TRUE;
15277 rasterizer_desc.ScissorEnable = FALSE;
15278 rasterizer_desc.MultisampleEnable = FALSE;
15279 rasterizer_desc.AntialiasedLineEnable = TRUE;
15281 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
15282 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15283 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
15285 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15286 draw_color_quad(&test_context, &green);
15287 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
15289 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
15290 draw_color_quad(&test_context, &red);
15291 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
15293 ID3D11RasterizerState_Release(rasterizer_state);
15294 release_test_context(&test_context);
15297 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
15298 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
15299 const char *feature_name)
15301 unsigned int i;
15303 for (i = 0; i < format_count; ++i)
15305 DXGI_FORMAT format = formats[i].format;
15306 unsigned int supported = format_support[format] & feature_flag;
15308 if (formats[i].fl_required <= feature_level)
15310 todo_wine ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
15311 format, feature_name, feature_level, format_support[format]);
15312 continue;
15315 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
15317 if (supported)
15318 trace("Optional format %#x - %s supported, feature level %#x.\n",
15319 format, feature_name, feature_level);
15320 continue;
15323 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
15324 format, feature_name, feature_level, format_support[format]);
15328 static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
15330 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
15331 struct device_desc device_desc;
15332 ID3D11Device *device;
15333 DXGI_FORMAT format;
15334 ULONG refcount;
15335 UINT support;
15336 HRESULT hr;
15338 static const struct format_support index_buffers[] =
15340 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
15341 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
15344 device_desc.feature_level = &feature_level;
15345 device_desc.flags = 0;
15346 if (!(device = create_device(&device_desc)))
15348 skip("Failed to create device for feature level %#x.\n", feature_level);
15349 return;
15352 support = 0xdeadbeef;
15353 hr = ID3D11Device_CheckFormatSupport(device, ~0u, &support);
15354 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15355 ok(!support, "Got unexpected format support %#x.\n", support);
15357 memset(format_support, 0, sizeof(format_support));
15358 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
15360 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
15361 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
15362 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
15363 format, hr, format_support[format]);
15366 check_format_support(format_support, feature_level,
15367 index_buffers, ARRAY_SIZE(index_buffers),
15368 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
15370 check_format_support(format_support, feature_level,
15371 display_format_support, ARRAY_SIZE(display_format_support),
15372 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
15374 refcount = ID3D11Device_Release(device);
15375 ok(!refcount, "Device has %u references left.\n", refcount);
15378 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
15380 struct d3d11_test_context test_context;
15381 D3D11_SUBRESOURCE_DATA resource_data;
15382 D3D11_TEXTURE2D_DESC texture_desc;
15383 ID3D11ShaderResourceView *srv;
15384 ID3D11DeviceContext *context;
15385 ID3D11Texture2D *texture;
15386 ID3D11PixelShader *ps;
15387 ID3D11Device *device;
15388 HRESULT hr;
15390 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
15391 static const DWORD ps_code[] =
15393 #if 0
15394 float4 main() : SV_TARGET
15396 return float4(1.0f, 0.0f, 0.0f, 0.5f);
15398 #endif
15399 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
15400 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
15401 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
15402 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
15403 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
15404 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
15405 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
15406 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
15407 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
15408 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
15409 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
15410 0x45475241, 0xabab0054,
15412 static const DWORD ps_texture_code[] =
15414 #if 0
15415 Texture2D t;
15416 SamplerState s;
15418 float4 main() : SV_TARGET
15420 return t.Sample(s, (float2)0);
15422 #endif
15423 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
15424 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
15425 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
15426 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
15427 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
15428 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
15429 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
15430 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
15431 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
15432 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
15433 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
15434 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
15435 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
15436 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15437 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
15439 static const DWORD texture_data[] = {0xffffff00};
15441 if (!init_test_context(&test_context, &feature_level))
15442 return;
15444 device = test_context.device;
15445 context = test_context.immediate_context;
15447 texture_desc.Width = 1;
15448 texture_desc.Height = 1;
15449 texture_desc.MipLevels = 0;
15450 texture_desc.ArraySize = 1;
15451 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15452 texture_desc.SampleDesc.Count = 1;
15453 texture_desc.SampleDesc.Quality = 0;
15454 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15455 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15456 texture_desc.CPUAccessFlags = 0;
15457 texture_desc.MiscFlags = 0;
15458 resource_data.pSysMem = texture_data;
15459 resource_data.SysMemPitch = sizeof(texture_data);
15460 resource_data.SysMemSlicePitch = 0;
15461 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
15462 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
15463 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
15464 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15466 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15467 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
15468 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15469 draw_quad(&test_context);
15470 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
15471 ID3D11PixelShader_Release(ps);
15473 draw_color_quad(&test_context, &color);
15474 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
15476 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
15477 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
15478 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15479 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
15480 draw_quad(&test_context);
15481 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
15482 ID3D11PixelShader_Release(ps);
15484 ID3D11ShaderResourceView_Release(srv);
15485 ID3D11Texture2D_Release(texture);
15486 release_test_context(&test_context);
15489 static void run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
15490 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
15492 static const D3D_FEATURE_LEVEL feature_levels[] =
15494 D3D_FEATURE_LEVEL_11_1,
15495 D3D_FEATURE_LEVEL_11_0,
15496 D3D_FEATURE_LEVEL_10_1,
15497 D3D_FEATURE_LEVEL_10_0,
15498 D3D_FEATURE_LEVEL_9_3,
15499 D3D_FEATURE_LEVEL_9_2,
15500 D3D_FEATURE_LEVEL_9_1
15502 unsigned int i;
15504 assert(begin <= end);
15505 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
15507 if (begin <= feature_levels[i] && feature_levels[i] <= end)
15508 test_func(feature_levels[i]);
15512 static void run_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
15514 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
15515 D3D_FEATURE_LEVEL_11_1, test_func);
15518 static void run_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
15520 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
15521 D3D_FEATURE_LEVEL_9_3, test_func);
15524 static void test_ddy(void)
15526 static const struct
15528 struct vec4 position;
15529 unsigned int color;
15531 quad[] =
15533 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
15534 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
15535 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
15536 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
15538 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
15540 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15541 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
15543 #if 0
15544 struct vs_data
15546 float4 pos : SV_POSITION;
15547 float4 color : COLOR;
15550 void main(in struct vs_data vs_input, out struct vs_data vs_output)
15552 vs_output.pos = vs_input.pos;
15553 vs_output.color = vs_input.color;
15555 #endif
15556 static const DWORD vs_code[] =
15558 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
15559 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15560 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
15561 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15562 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15563 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15564 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
15565 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
15566 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
15567 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
15568 0x0100003e,
15570 #if 0
15571 struct ps_data
15573 float4 pos : SV_POSITION;
15574 float4 color : COLOR;
15577 float4 main(struct ps_data ps_input) : SV_Target
15579 return ddy(ps_input.color) * 240.0 + 0.5;
15581 #endif
15582 static const DWORD ps_code_ddy[] =
15584 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
15585 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15586 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15587 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15588 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15589 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
15590 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
15591 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
15592 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
15593 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
15595 #if 0
15596 struct ps_data
15598 float4 pos : SV_POSITION;
15599 float4 color : COLOR;
15602 float4 main(struct ps_data ps_input) : SV_Target
15604 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
15606 #endif
15607 static const DWORD ps_code_ddy_coarse[] =
15609 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
15610 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15611 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15612 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15613 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15614 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
15615 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
15616 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
15617 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
15618 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
15620 #if 0
15621 struct ps_data
15623 float4 pos : SV_POSITION;
15624 float4 color : COLOR;
15627 float4 main(struct ps_data ps_input) : SV_Target
15629 return ddy_fine(ps_input.color) * 240.0 + 0.5;
15631 #endif
15632 static const DWORD ps_code_ddy_fine[] =
15634 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
15635 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15636 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15637 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15638 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15639 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
15640 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
15641 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
15642 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
15643 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
15645 static const struct
15647 D3D_FEATURE_LEVEL min_feature_level;
15648 const DWORD *ps_code;
15649 unsigned int ps_code_size;
15651 tests[] =
15653 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
15654 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
15655 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
15657 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
15658 struct d3d11_test_context test_context;
15659 D3D11_TEXTURE2D_DESC texture_desc;
15660 D3D_FEATURE_LEVEL feature_level;
15661 ID3D11InputLayout *input_layout;
15662 ID3D11DeviceContext *context;
15663 unsigned int stride, offset;
15664 struct resource_readback rb;
15665 ID3D11RenderTargetView *rtv;
15666 ID3D11Texture2D *texture;
15667 ID3D11VertexShader *vs;
15668 ID3D11PixelShader *ps;
15669 ID3D11Device *device;
15670 ID3D11Buffer *vb;
15671 unsigned int i;
15672 DWORD color;
15673 HRESULT hr;
15675 if (!init_test_context(&test_context, NULL))
15676 return;
15678 device = test_context.device;
15679 context = test_context.immediate_context;
15680 feature_level = ID3D11Device_GetFeatureLevel(device);
15682 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
15683 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15684 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15686 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15687 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15689 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15690 vs_code, sizeof(vs_code), &input_layout);
15691 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15693 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
15695 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15696 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15698 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
15699 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
15700 stride = sizeof(*quad);
15701 offset = 0;
15702 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
15703 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15705 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15707 if (feature_level < tests[i].min_feature_level)
15709 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
15710 feature_level, tests[i].min_feature_level);
15711 continue;
15714 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
15715 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15717 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15719 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15720 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
15721 ID3D11DeviceContext_Draw(context, 4, 0);
15723 get_texture_readback(texture, 0, &rb);
15724 color = get_readback_color(&rb, 320, 190);
15725 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15726 color = get_readback_color(&rb, 255, 240);
15727 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15728 color = get_readback_color(&rb, 320, 240);
15729 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15730 color = get_readback_color(&rb, 385, 240);
15731 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15732 color = get_readback_color(&rb, 320, 290);
15733 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15734 release_resource_readback(&rb);
15736 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
15737 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
15738 ID3D11DeviceContext_Draw(context, 4, 0);
15740 get_texture_readback(test_context.backbuffer, 0, &rb);
15741 color = get_readback_color(&rb, 320, 190);
15742 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15743 color = get_readback_color(&rb, 255, 240);
15744 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15745 color = get_readback_color(&rb, 320, 240);
15746 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15747 color = get_readback_color(&rb, 385, 240);
15748 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15749 color = get_readback_color(&rb, 320, 290);
15750 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15751 release_resource_readback(&rb);
15753 ID3D11PixelShader_Release(ps);
15756 ID3D11VertexShader_Release(vs);
15757 ID3D11Buffer_Release(vb);
15758 ID3D11InputLayout_Release(input_layout);
15759 ID3D11Texture2D_Release(texture);
15760 ID3D11RenderTargetView_Release(rtv);
15761 release_test_context(&test_context);
15764 static void test_shader_input_registers_limits(void)
15766 struct d3d11_test_context test_context;
15767 D3D11_SUBRESOURCE_DATA resource_data;
15768 D3D11_TEXTURE2D_DESC texture_desc;
15769 D3D11_SAMPLER_DESC sampler_desc;
15770 ID3D11ShaderResourceView *srv;
15771 ID3D11DeviceContext *context;
15772 ID3D11SamplerState *sampler;
15773 ID3D11Texture2D *texture;
15774 ID3D11PixelShader *ps;
15775 ID3D11Device *device;
15776 HRESULT hr;
15778 static const DWORD ps_last_register_code[] =
15780 #if 0
15781 Texture2D t : register(t127);
15782 SamplerState s : register(s15);
15784 void main(out float4 target : SV_Target)
15786 target = t.Sample(s, float2(0, 0));
15788 #endif
15789 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
15790 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15791 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15792 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
15793 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
15794 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
15795 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
15797 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
15798 static const DWORD texture_data[] = {0xff00ff00};
15800 if (!init_test_context(&test_context, NULL))
15801 return;
15803 device = test_context.device;
15804 context = test_context.immediate_context;
15806 texture_desc.Width = 1;
15807 texture_desc.Height = 1;
15808 texture_desc.MipLevels = 0;
15809 texture_desc.ArraySize = 1;
15810 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15811 texture_desc.SampleDesc.Count = 1;
15812 texture_desc.SampleDesc.Quality = 0;
15813 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15814 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15815 texture_desc.CPUAccessFlags = 0;
15816 texture_desc.MiscFlags = 0;
15818 resource_data.pSysMem = texture_data;
15819 resource_data.SysMemPitch = sizeof(texture_data);
15820 resource_data.SysMemSlicePitch = 0;
15822 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
15823 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
15825 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
15826 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15828 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
15829 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
15830 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
15831 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
15832 sampler_desc.MipLODBias = 0.0f;
15833 sampler_desc.MaxAnisotropy = 0;
15834 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
15835 sampler_desc.BorderColor[0] = 0.0f;
15836 sampler_desc.BorderColor[1] = 0.0f;
15837 sampler_desc.BorderColor[2] = 0.0f;
15838 sampler_desc.BorderColor[3] = 0.0f;
15839 sampler_desc.MinLOD = 0.0f;
15840 sampler_desc.MaxLOD = 0.0f;
15842 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
15843 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
15845 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
15846 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15847 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15849 ID3D11DeviceContext_PSSetShaderResources(context,
15850 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
15851 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
15852 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
15853 draw_quad(&test_context);
15854 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
15856 ID3D11PixelShader_Release(ps);
15857 ID3D11SamplerState_Release(sampler);
15858 ID3D11ShaderResourceView_Release(srv);
15859 ID3D11Texture2D_Release(texture);
15860 release_test_context(&test_context);
15863 static void test_unbind_shader_resource_view(void)
15865 struct d3d11_test_context test_context;
15866 D3D11_SUBRESOURCE_DATA resource_data;
15867 ID3D11ShaderResourceView *srv, *srv2;
15868 D3D11_TEXTURE2D_DESC texture_desc;
15869 ID3D11DeviceContext *context;
15870 ID3D11Texture2D *texture;
15871 ID3D11PixelShader *ps;
15872 ID3D11Device *device;
15873 HRESULT hr;
15875 static const DWORD ps_code[] =
15877 #if 0
15878 Texture2D t0;
15879 Texture2D t1;
15880 SamplerState s;
15882 float4 main() : SV_Target
15884 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
15886 #endif
15887 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
15888 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15889 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15890 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
15891 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
15892 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
15893 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
15894 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
15895 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
15896 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
15897 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
15898 0x3f800000, 0x0100003e,
15900 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
15901 static const DWORD texture_data[] = {0xff00ff00};
15903 if (!init_test_context(&test_context, NULL))
15904 return;
15906 device = test_context.device;
15907 context = test_context.immediate_context;
15909 texture_desc.Width = 1;
15910 texture_desc.Height = 1;
15911 texture_desc.MipLevels = 0;
15912 texture_desc.ArraySize = 1;
15913 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15914 texture_desc.SampleDesc.Count = 1;
15915 texture_desc.SampleDesc.Quality = 0;
15916 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15917 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15918 texture_desc.CPUAccessFlags = 0;
15919 texture_desc.MiscFlags = 0;
15921 resource_data.pSysMem = texture_data;
15922 resource_data.SysMemPitch = sizeof(texture_data);
15923 resource_data.SysMemSlicePitch = 0;
15925 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
15926 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
15927 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
15928 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15929 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15930 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15931 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15933 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
15934 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
15935 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
15936 draw_quad(&test_context);
15937 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
15939 srv2 = NULL;
15940 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
15941 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
15942 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
15943 draw_quad(&test_context);
15944 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
15946 ID3D11PixelShader_Release(ps);
15947 ID3D11ShaderResourceView_Release(srv);
15948 ID3D11Texture2D_Release(texture);
15949 release_test_context(&test_context);
15952 static void test_stencil_separate(void)
15954 struct d3d11_test_context test_context;
15955 D3D11_TEXTURE2D_DESC texture_desc;
15956 D3D11_DEPTH_STENCIL_DESC ds_desc;
15957 ID3D11DepthStencilState *ds_state;
15958 ID3D11DepthStencilView *ds_view;
15959 D3D11_RASTERIZER_DESC rs_desc;
15960 ID3D11DeviceContext *context;
15961 ID3D11RasterizerState *rs;
15962 ID3D11Texture2D *texture;
15963 ID3D11Device *device;
15964 HRESULT hr;
15966 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
15967 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
15968 static const struct vec2 ccw_quad[] =
15970 {-1.0f, -1.0f},
15971 { 1.0f, -1.0f},
15972 {-1.0f, 1.0f},
15973 { 1.0f, 1.0f},
15976 if (!init_test_context(&test_context, NULL))
15977 return;
15979 device = test_context.device;
15980 context = test_context.immediate_context;
15982 texture_desc.Width = 640;
15983 texture_desc.Height = 480;
15984 texture_desc.MipLevels = 1;
15985 texture_desc.ArraySize = 1;
15986 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
15987 texture_desc.SampleDesc.Count = 1;
15988 texture_desc.SampleDesc.Quality = 0;
15989 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15990 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
15991 texture_desc.CPUAccessFlags = 0;
15992 texture_desc.MiscFlags = 0;
15993 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15994 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15995 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
15996 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
15998 ds_desc.DepthEnable = TRUE;
15999 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
16000 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
16001 ds_desc.StencilEnable = TRUE;
16002 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
16003 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
16004 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
16005 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
16006 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
16007 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
16008 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
16009 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
16010 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
16011 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
16012 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
16013 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
16015 rs_desc.FillMode = D3D11_FILL_SOLID;
16016 rs_desc.CullMode = D3D11_CULL_NONE;
16017 rs_desc.FrontCounterClockwise = FALSE;
16018 rs_desc.DepthBias = 0;
16019 rs_desc.DepthBiasClamp = 0.0f;
16020 rs_desc.SlopeScaledDepthBias = 0.0f;
16021 rs_desc.DepthClipEnable = TRUE;
16022 rs_desc.ScissorEnable = FALSE;
16023 rs_desc.MultisampleEnable = FALSE;
16024 rs_desc.AntialiasedLineEnable = FALSE;
16025 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
16026 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
16028 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
16029 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
16030 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
16031 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
16032 ID3D11DeviceContext_RSSetState(context, rs);
16034 draw_color_quad(&test_context, &green);
16035 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
16037 ID3D11Buffer_Release(test_context.vb);
16038 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
16040 draw_color_quad(&test_context, &green);
16041 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16043 ID3D11RasterizerState_Release(rs);
16044 rs_desc.FrontCounterClockwise = TRUE;
16045 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
16046 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
16047 ID3D11DeviceContext_RSSetState(context, rs);
16049 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
16050 draw_color_quad(&test_context, &green);
16051 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
16053 ID3D11DepthStencilState_Release(ds_state);
16054 ID3D11DepthStencilView_Release(ds_view);
16055 ID3D11RasterizerState_Release(rs);
16056 ID3D11Texture2D_Release(texture);
16057 release_test_context(&test_context);
16060 static void test_uav_load(void)
16062 struct shader
16064 const DWORD *code;
16065 size_t size;
16067 struct texture
16069 UINT width;
16070 UINT height;
16071 UINT miplevel_count;
16072 UINT array_size;
16073 DXGI_FORMAT format;
16074 D3D11_SUBRESOURCE_DATA data[3];
16077 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
16078 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16079 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
16080 struct d3d11_test_context test_context;
16081 const struct texture *current_texture;
16082 ID3D11Texture2D *texture, *rt_texture;
16083 D3D11_TEXTURE2D_DESC texture_desc;
16084 const struct shader *current_ps;
16085 ID3D11UnorderedAccessView *uav;
16086 ID3D11DeviceContext *context;
16087 struct resource_readback rb;
16088 ID3D11PixelShader *ps;
16089 ID3D11Device *device;
16090 unsigned int i, x, y;
16091 ID3D11Buffer *cb;
16092 HRESULT hr;
16094 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16095 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16096 static const DWORD ps_ld_2d_float_code[] =
16098 #if 0
16099 RWTexture2D<float> u;
16101 float main(float4 position : SV_Position) : SV_Target
16103 float2 s;
16104 u.GetDimensions(s.x, s.y);
16105 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
16107 #endif
16108 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
16109 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16110 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16111 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16112 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
16113 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
16114 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
16115 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
16116 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
16117 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
16118 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
16119 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
16120 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16122 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
16123 static const DWORD ps_ld_2d_uint_code[] =
16125 #if 0
16126 RWTexture2D<uint> u;
16128 uint main(float4 position : SV_Position) : SV_Target
16130 float2 s;
16131 u.GetDimensions(s.x, s.y);
16132 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
16134 #endif
16135 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
16136 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16137 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16138 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
16139 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
16140 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
16141 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
16142 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
16143 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
16144 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
16145 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
16146 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
16147 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16149 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
16150 static const DWORD ps_ld_2d_int_code[] =
16152 #if 0
16153 RWTexture2D<int> u;
16155 int main(float4 position : SV_Position) : SV_Target
16157 float2 s;
16158 u.GetDimensions(s.x, s.y);
16159 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
16161 #endif
16162 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
16163 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16164 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16165 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
16166 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
16167 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
16168 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
16169 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
16170 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
16171 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
16172 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
16173 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
16174 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16176 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
16177 static const DWORD ps_ld_2d_uint_arr_code[] =
16179 #if 0
16180 RWTexture2DArray<uint> u;
16182 uint layer;
16184 uint main(float4 position : SV_Position) : SV_Target
16186 float3 s;
16187 u.GetDimensions(s.x, s.y, s.z);
16188 s.z = layer;
16189 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
16191 #endif
16192 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
16193 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16194 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16195 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
16196 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
16197 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
16198 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
16199 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
16200 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
16201 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
16202 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
16203 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
16204 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
16205 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16207 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
16208 static const float float_data[] =
16210 0.50f, 0.25f, 1.00f, 0.00f,
16211 -1.00f, -2.00f, -3.00f, -4.00f,
16212 -0.50f, -0.25f, -1.00f, -0.00f,
16213 1.00f, 2.00f, 3.00f, 4.00f,
16215 static const unsigned int uint_data[] =
16217 0x00, 0x10, 0x20, 0x30,
16218 0x40, 0x50, 0x60, 0x70,
16219 0x80, 0x90, 0xa0, 0xb0,
16220 0xc0, 0xd0, 0xe0, 0xf0,
16222 static const unsigned int uint_data2[] =
16224 0xffff, 0xffff, 0xffff, 0xffff,
16225 0xffff, 0xc000, 0xc000, 0xffff,
16226 0xffff, 0xc000, 0xc000, 0xffff,
16227 0xffff, 0xffff, 0xffff, 0xffff,
16229 static const unsigned int uint_data3[] =
16231 0xaa, 0xaa, 0xcc, 0xcc,
16232 0xaa, 0xaa, 0xdd, 0xdd,
16233 0xbb, 0xbb, 0xee, 0xee,
16234 0xbb, 0xbb, 0xff, 0xff,
16236 static const int int_data[] =
16238 -1, 0x10, 0x20, 0x30,
16239 0x40, 0x50, 0x60, -777,
16240 -666, 0x90, -555, 0xb0,
16241 0xc0, 0xd0, 0xe0, -101,
16243 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
16244 {{float_data, 4 * sizeof(*float_data), 0}}};
16245 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
16246 {{uint_data, 4 * sizeof(*uint_data), 0}}};
16247 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
16248 {{uint_data, 4 * sizeof(*uint_data), 0},
16249 {uint_data2, 4 * sizeof(*uint_data2), 0},
16250 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
16251 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
16252 {{int_data, 4 * sizeof(*int_data), 0}}};
16254 static const struct test
16256 const struct shader *ps;
16257 const struct texture *texture;
16258 struct uav_desc uav_desc;
16259 struct uvec4 constant;
16260 const DWORD *expected_colors;
16262 tests[] =
16264 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
16265 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
16266 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
16267 #define R32_UINT DXGI_FORMAT_R32_UINT
16268 #define R32_SINT DXGI_FORMAT_R32_SINT
16269 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {}, (const DWORD *)float_data},
16270 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {}, (const DWORD *)uint_data},
16271 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {}, (const DWORD *)int_data},
16272 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
16273 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
16274 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
16275 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
16276 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
16277 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
16278 #undef TEX_2D
16279 #undef TEX_2D_ARRAY
16280 #undef R32_FLOAT
16281 #undef R32_UINT
16282 #undef R32_SINT
16285 if (!init_test_context(&test_context, &feature_level))
16286 return;
16288 device = test_context.device;
16289 context = test_context.immediate_context;
16291 texture_desc.Width = 640;
16292 texture_desc.Height = 480;
16293 texture_desc.MipLevels = 1;
16294 texture_desc.ArraySize = 1;
16295 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
16296 texture_desc.SampleDesc.Count = 1;
16297 texture_desc.SampleDesc.Quality = 0;
16298 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16299 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16300 texture_desc.CPUAccessFlags = 0;
16301 texture_desc.MiscFlags = 0;
16302 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
16303 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16305 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
16306 U(rtv_desc).Texture2D.MipSlice = 0;
16308 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
16309 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
16310 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16312 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
16313 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
16314 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16316 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
16317 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
16318 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16320 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16322 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
16323 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16325 ps = NULL;
16326 uav = NULL;
16327 texture = NULL;
16328 current_ps = NULL;
16329 current_texture = NULL;
16330 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16332 const struct test *test = &tests[i];
16333 ID3D11RenderTargetView *current_rtv;
16335 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
16336 NULL, &test->constant, 0, 0);
16338 if (current_ps != test->ps)
16340 if (ps)
16341 ID3D11PixelShader_Release(ps);
16343 current_ps = test->ps;
16345 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
16346 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
16348 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16351 if (current_texture != test->texture)
16353 if (texture)
16354 ID3D11Texture2D_Release(texture);
16356 current_texture = test->texture;
16358 texture_desc.Width = current_texture->width;
16359 texture_desc.Height = current_texture->height;
16360 texture_desc.MipLevels = current_texture->miplevel_count;
16361 texture_desc.ArraySize = current_texture->array_size;
16362 texture_desc.Format = current_texture->format;
16364 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
16365 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
16368 if (uav)
16369 ID3D11UnorderedAccessView_Release(uav);
16371 get_uav_desc(&uav_desc, &test->uav_desc);
16372 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
16373 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
16375 switch (uav_desc.Format)
16377 case DXGI_FORMAT_R32_FLOAT:
16378 current_rtv = rtv_float;
16379 break;
16380 case DXGI_FORMAT_R32_UINT:
16381 current_rtv = rtv_uint;
16382 break;
16383 case DXGI_FORMAT_R32_SINT:
16384 current_rtv = rtv_sint;
16385 break;
16386 default:
16387 trace("Unhandled format %#x.\n", uav_desc.Format);
16388 current_rtv = NULL;
16389 break;
16392 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
16394 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
16395 1, 1, &uav, NULL);
16397 draw_quad(&test_context);
16399 get_texture_readback(rt_texture, 0, &rb);
16400 for (y = 0; y < 4; ++y)
16402 for (x = 0; x < 4; ++x)
16404 DWORD expected = test->expected_colors[y * 4 + x];
16405 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
16406 ok(compare_color(color, expected, 0),
16407 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
16408 i, color, expected, x, y);
16411 release_resource_readback(&rb);
16413 ID3D11PixelShader_Release(ps);
16414 ID3D11Texture2D_Release(texture);
16415 ID3D11UnorderedAccessView_Release(uav);
16417 ID3D11Buffer_Release(cb);
16418 ID3D11RenderTargetView_Release(rtv_float);
16419 ID3D11RenderTargetView_Release(rtv_sint);
16420 ID3D11RenderTargetView_Release(rtv_uint);
16421 ID3D11Texture2D_Release(rt_texture);
16422 release_test_context(&test_context);
16425 static void test_cs_uav_store(void)
16427 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16428 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16429 static const float zero[4] = {0.0f};
16430 D3D11_TEXTURE2D_DESC texture_desc;
16431 ID3D11UnorderedAccessView *uav;
16432 struct device_desc device_desc;
16433 ID3D11DeviceContext *context;
16434 struct vec4 input = {1.0f};
16435 ID3D11Texture2D *texture;
16436 ID3D11ComputeShader *cs;
16437 ID3D11Device *device;
16438 ID3D11Buffer *cb;
16439 ULONG refcount;
16440 HRESULT hr;
16441 RECT rect;
16443 static const DWORD cs_1_thread_code[] =
16445 #if 0
16446 RWTexture2D<float> u;
16448 float value;
16450 [numthreads(1, 1, 1)]
16451 void main()
16453 uint x, y, width, height;
16454 u.GetDimensions(width, height);
16455 for (y = 0; y < height; ++y)
16457 for (x = 0; x < width; ++x)
16458 u[uint2(x, y)] = value;
16461 #endif
16462 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
16463 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16464 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
16465 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16466 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
16467 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
16468 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
16469 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
16470 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
16471 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
16472 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
16473 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
16474 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
16475 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
16476 0x01000016, 0x0100003e,
16478 static const DWORD cs_1_group_code[] =
16480 #if 0
16481 RWTexture2D<float> u;
16483 float value;
16485 [numthreads(16, 16, 1)]
16486 void main(uint3 threadID : SV_GroupThreadID)
16488 uint2 count, size ;
16489 u.GetDimensions(size.x, size.y);
16490 count = size / (uint2)16;
16491 for (uint y = 0; y < count.y; ++y)
16492 for (uint x = 0; x < count.x; ++x)
16493 u[count * threadID.xy + uint2(x, y)] = value;
16495 #endif
16496 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
16497 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16498 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
16499 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16500 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
16501 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
16502 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
16503 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
16504 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
16505 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
16506 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
16507 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
16508 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
16509 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
16510 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
16511 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
16512 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
16514 static const DWORD cs_1_store_code[] =
16516 #if 0
16517 RWTexture2D<float> u;
16519 float value;
16521 [numthreads(1, 1, 1)]
16522 void main(uint3 groupID : SV_GroupID)
16524 u[groupID.xy] = value;
16526 #endif
16527 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
16528 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16529 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16530 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16531 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
16532 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
16534 static const DWORD cs_dispatch_id_code[] =
16536 #if 0
16537 RWTexture2D<float> u;
16539 float value;
16541 [numthreads(4, 4, 1)]
16542 void main(uint3 id : SV_DispatchThreadID)
16544 u[id.xy] = value;
16546 #endif
16547 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
16548 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16549 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16550 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16551 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
16552 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
16554 static const DWORD cs_group_index_code[] =
16556 #if 0
16557 RWTexture2D<float> u;
16559 float value;
16561 [numthreads(32, 1, 1)]
16562 void main(uint index : SV_GroupIndex)
16564 uint2 size;
16565 u.GetDimensions(size.x, size.y);
16566 uint count = size.x * size.y / 32;
16567 index *= count;
16568 for (uint i = 0; i < count; ++i, ++index)
16569 u[uint2(index % size.x, index / size.x)] = value;
16571 #endif
16572 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
16573 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16574 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
16575 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16576 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
16577 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
16578 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
16579 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
16580 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
16581 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
16582 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
16583 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
16584 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
16585 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
16586 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
16587 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
16590 device_desc.feature_level = &feature_level;
16591 device_desc.flags = 0;
16592 if (!(device = create_device(&device_desc)))
16594 skip("Failed to create device for feature level %#x.\n", feature_level);
16595 return;
16598 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
16600 texture_desc.Width = 64;
16601 texture_desc.Height = 64;
16602 texture_desc.MipLevels = 1;
16603 texture_desc.ArraySize = 1;
16604 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
16605 texture_desc.SampleDesc.Count = 1;
16606 texture_desc.SampleDesc.Quality = 0;
16607 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16608 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16609 texture_desc.CPUAccessFlags = 0;
16610 texture_desc.MiscFlags = 0;
16612 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16613 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16615 uav_desc.Format = texture_desc.Format;
16616 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
16617 U(uav_desc).Texture2D.MipSlice = 0;
16619 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
16620 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16622 ID3D11Device_GetImmediateContext(device, &context);
16624 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
16625 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16627 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
16628 check_texture_float(texture, 0.0f, 2);
16630 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
16631 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16632 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16634 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16635 check_texture_float(texture, 1.0f, 2);
16637 input.x = 0.5f;
16638 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16639 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16640 check_texture_float(texture, 0.5f, 2);
16642 ID3D11ComputeShader_Release(cs);
16644 input.x = 2.0f;
16645 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16646 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
16647 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16648 check_texture_float(texture, 0.5f, 2);
16650 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
16651 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16652 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16654 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16655 check_texture_float(texture, 2.0f, 2);
16657 input.x = 4.0f;
16658 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16659 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16660 check_texture_float(texture, 4.0f, 2);
16662 ID3D11ComputeShader_Release(cs);
16664 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
16665 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16666 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16668 input.x = 1.0f;
16669 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16670 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
16671 check_texture_float(texture, 1.0f, 2);
16673 input.x = 0.5f;
16674 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16675 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
16676 SetRect(&rect, 0, 0, 16, 32);
16677 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
16678 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
16679 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16680 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
16681 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16683 ID3D11ComputeShader_Release(cs);
16685 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
16686 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16687 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16689 input.x = 0.6f;
16690 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16691 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
16692 SetRect(&rect, 0, 0, 60, 60);
16693 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
16694 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
16695 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16696 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
16697 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16699 input.x = 0.7f;
16700 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16701 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
16702 check_texture_float(texture, 0.7f, 2);
16704 ID3D11ComputeShader_Release(cs);
16706 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
16707 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16708 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16710 input.x = 0.3f;
16711 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16712 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16713 check_texture_float(texture, 0.3f, 2);
16715 input.x = 0.1f;
16716 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16717 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
16718 check_texture_float(texture, 0.1f, 2);
16720 ID3D11ComputeShader_Release(cs);
16722 ID3D11Buffer_Release(cb);
16723 ID3D11Texture2D_Release(texture);
16724 ID3D11UnorderedAccessView_Release(uav);
16725 ID3D11DeviceContext_Release(context);
16726 refcount = ID3D11Device_Release(device);
16727 ok(!refcount, "Device has %u references left.\n", refcount);
16730 static void test_uav_store_immediate_constant(void)
16732 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16733 struct d3d11_test_context test_context;
16734 ID3D11UnorderedAccessView *uav;
16735 ID3D11DeviceContext *context;
16736 struct resource_readback rb;
16737 ID3D11ComputeShader *cs;
16738 ID3D11Device *device;
16739 ID3D11Buffer *buffer;
16740 float float_data;
16741 int int_data;
16742 HRESULT hr;
16744 static const DWORD cs_store_int_code[] =
16746 #if 0
16747 RWBuffer<int> u;
16749 [numthreads(1, 1, 1)]
16750 void main()
16752 u[0] = 42;
16754 #endif
16755 0x43425844, 0x7246d785, 0x3f4ccbd6, 0x6a7cdbc0, 0xe2b58c72, 0x00000001, 0x000000b8, 0x00000003,
16756 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16757 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16758 0x0400089c, 0x0011e000, 0x00000000, 0x00003333, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
16759 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
16760 0x00004002, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, 0x0100003e,
16762 static const DWORD cs_store_float_code[] =
16764 #if 0
16765 RWBuffer<float> u;
16767 [numthreads(1, 1, 1)]
16768 void main()
16770 u[0] = 1.0;
16772 #endif
16773 0x43425844, 0x525eea68, 0xc4cd5716, 0xc588f9c4, 0x0da27c5a, 0x00000001, 0x000000b8, 0x00000003,
16774 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16775 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16776 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
16777 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
16778 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e,
16780 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16781 static const unsigned int zero[4] = {0};
16783 if (!init_test_context(&test_context, &feature_level))
16784 return;
16786 device = test_context.device;
16787 context = test_context.immediate_context;
16789 buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
16791 uav_desc.Format = DXGI_FORMAT_R32_SINT;
16792 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16793 U(uav_desc).Buffer.FirstElement = 0;
16794 U(uav_desc).Buffer.NumElements = 1;
16795 U(uav_desc).Buffer.Flags = 0;
16796 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16797 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16798 hr = ID3D11Device_CreateComputeShader(device, cs_store_int_code, sizeof(cs_store_int_code), NULL, &cs);
16799 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16801 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
16802 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16803 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16804 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16805 get_buffer_readback(buffer, &rb);
16806 int_data = get_readback_color(&rb, 0, 0);
16807 ok(int_data == 42, "Got unexpected value %u.\n", int_data);
16808 release_resource_readback(&rb);
16810 ID3D11ComputeShader_Release(cs);
16811 ID3D11UnorderedAccessView_Release(uav);
16812 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
16813 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16814 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16815 hr = ID3D11Device_CreateComputeShader(device, cs_store_float_code, sizeof(cs_store_float_code), NULL, &cs);
16816 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16818 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
16819 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16820 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16821 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16822 get_buffer_readback(buffer, &rb);
16823 float_data = get_readback_float(&rb, 0, 0);
16824 ok(float_data == 1.0f, "Got unexpected value %.8e.\n", float_data);
16825 release_resource_readback(&rb);
16827 ID3D11Buffer_Release(buffer);
16828 ID3D11ComputeShader_Release(cs);
16829 ID3D11UnorderedAccessView_Release(uav);
16830 release_test_context(&test_context);
16833 static void test_ps_cs_uav_binding(void)
16835 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16836 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
16837 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16838 ID3D11Texture2D *cs_texture, *ps_texture;
16839 struct d3d11_test_context test_context;
16840 static const float zero[4] = {0.0f};
16841 D3D11_TEXTURE2D_DESC texture_desc;
16842 ID3D11DeviceContext *context;
16843 ID3D11Buffer *cs_cb, *ps_cb;
16844 struct vec4 input = {1.0f};
16845 ID3D11ComputeShader *cs;
16846 ID3D11PixelShader *ps;
16847 ID3D11Device *device;
16848 HRESULT hr;
16850 static const DWORD cs_code[] =
16852 #if 0
16853 RWTexture2D<float> u;
16855 float value;
16857 [numthreads(1, 1, 1)]
16858 void main()
16860 uint x, y, width, height;
16861 u.GetDimensions(width, height);
16862 for (y = 0; y < height; ++y)
16864 for (x = 0; x < width; ++x)
16865 u[uint2(x, y)] = value;
16868 #endif
16869 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
16870 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16871 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
16872 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16873 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
16874 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
16875 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
16876 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
16877 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
16878 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
16879 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
16880 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
16881 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
16882 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
16883 0x01000016, 0x0100003e,
16885 static const DWORD ps_code[] =
16887 #if 0
16888 RWTexture2D<float> u : register(u1);
16890 float value;
16892 void main()
16894 uint x, y, width, height;
16895 u.GetDimensions(width, height);
16896 for (y = 0; y < height; ++y)
16898 for (x = 0; x < width; ++x)
16899 u[uint2(x, y)] = value;
16902 #endif
16903 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
16904 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16905 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
16906 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
16907 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
16908 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
16909 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
16910 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
16911 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
16912 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
16913 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
16914 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
16915 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
16916 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
16919 if (!init_test_context(&test_context, &feature_level))
16920 return;
16922 device = test_context.device;
16923 context = test_context.immediate_context;
16925 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
16926 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
16928 texture_desc.Width = 64;
16929 texture_desc.Height = 64;
16930 texture_desc.MipLevels = 1;
16931 texture_desc.ArraySize = 1;
16932 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
16933 texture_desc.SampleDesc.Count = 1;
16934 texture_desc.SampleDesc.Quality = 0;
16935 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16936 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16937 texture_desc.CPUAccessFlags = 0;
16938 texture_desc.MiscFlags = 0;
16939 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
16940 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16941 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
16942 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16944 uav_desc.Format = texture_desc.Format;
16945 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
16946 U(uav_desc).Texture2D.MipSlice = 0;
16947 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
16948 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16949 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
16950 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16952 ID3D11Device_GetImmediateContext(device, &context);
16954 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
16955 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
16956 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
16957 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
16958 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
16959 1, &test_context.backbuffer_rtv, NULL, 1, 1, &ps_uav, NULL);
16961 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
16962 check_texture_float(cs_texture, 0.0f, 2);
16963 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
16964 check_texture_float(ps_texture, 0.0f, 2);
16966 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
16967 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16968 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16969 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16970 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16971 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16973 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16974 check_texture_float(cs_texture, 1.0f, 2);
16975 check_texture_float(ps_texture, 0.0f, 2);
16976 draw_quad(&test_context);
16977 check_texture_float(cs_texture, 1.0f, 2);
16978 check_texture_float(ps_texture, 1.0f, 2);
16980 input.x = 0.5f;
16981 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
16982 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16983 check_texture_float(cs_texture, 0.5f, 2);
16984 check_texture_float(ps_texture, 1.0f, 2);
16985 input.x = 2.0f;
16986 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
16987 draw_quad(&test_context);
16988 check_texture_float(cs_texture, 0.5f, 2);
16989 check_texture_float(ps_texture, 2.0f, 2);
16991 input.x = 8.0f;
16992 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
16993 input.x = 4.0f;
16994 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
16995 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16996 check_texture_float(cs_texture, 8.0f, 2);
16997 check_texture_float(ps_texture, 2.0f, 2);
16998 draw_quad(&test_context);
16999 check_texture_float(cs_texture, 8.0f, 2);
17000 check_texture_float(ps_texture, 4.0f, 2);
17002 ID3D11ComputeShader_Release(cs);
17003 ID3D11PixelShader_Release(ps);
17004 ID3D11Buffer_Release(cs_cb);
17005 ID3D11Buffer_Release(ps_cb);
17006 ID3D11Texture2D_Release(cs_texture);
17007 ID3D11Texture2D_Release(ps_texture);
17008 ID3D11UnorderedAccessView_Release(cs_uav);
17009 ID3D11UnorderedAccessView_Release(ps_uav);
17010 ID3D11DeviceContext_Release(context);
17011 release_test_context(&test_context);
17014 static void test_atomic_instructions(void)
17016 ID3D11UnorderedAccessView *in_uav, *out_uav;
17017 ID3D11Buffer *cb, *in_buffer, *out_buffer;
17018 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
17019 struct d3d11_test_context test_context;
17020 struct resource_readback rb, out_rb;
17021 D3D11_TEXTURE2D_DESC texture_desc;
17022 D3D11_BUFFER_DESC buffer_desc;
17023 ID3D11DeviceContext *context;
17024 ID3D11RenderTargetView *rtv;
17025 ID3D11Texture2D *texture;
17026 ID3D11ComputeShader *cs;
17027 ID3D11PixelShader *ps;
17028 ID3D11Device *device;
17029 D3D11_VIEWPORT vp;
17030 unsigned int i, j;
17031 HRESULT hr;
17033 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17034 static const unsigned int zero[4] = {0, 0, 0, 0};
17035 static const DWORD ps_atomics_code[] =
17037 #if 0
17038 RWByteAddressBuffer u;
17040 uint4 v;
17041 int4 i;
17043 void main()
17045 u.InterlockedAnd(0 * 4, v.x);
17046 u.InterlockedCompareStore(1 * 4, v.y, v.x);
17047 u.InterlockedAdd(2 * 4, v.x);
17048 u.InterlockedOr(3 * 4, v.x);
17049 u.InterlockedMax(4 * 4, i.x);
17050 u.InterlockedMin(5 * 4, i.x);
17051 u.InterlockedMax(6 * 4, v.x);
17052 u.InterlockedMin(7 * 4, v.x);
17053 u.InterlockedXor(8 * 4, v.x);
17055 #endif
17056 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
17057 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17058 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
17059 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
17060 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
17061 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
17062 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
17063 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
17064 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
17065 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
17066 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
17067 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
17068 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
17069 0x00000000, 0x00000000, 0x0100003e,
17071 static const DWORD cs_atomics_code[] =
17073 #if 0
17074 RWByteAddressBuffer u;
17075 RWByteAddressBuffer u2;
17077 uint4 v;
17078 int4 i;
17080 [numthreads(1, 1, 1)]
17081 void main()
17083 uint r;
17084 u.InterlockedAnd(0 * 4, v.x, r);
17085 u2.Store(0 * 4, r);
17086 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
17087 u2.Store(1 * 4, r);
17088 u.InterlockedAdd(2 * 4, v.x, r);
17089 u2.Store(2 * 4, r);
17090 u.InterlockedOr(3 * 4, v.x, r);
17091 u2.Store(3 * 4, r);
17092 u.InterlockedMax(4 * 4, i.x, r);
17093 u2.Store(4 * 4, r);
17094 u.InterlockedMin(5 * 4, i.x, r);
17095 u2.Store(5 * 4, r);
17096 u.InterlockedMax(6 * 4, v.x, r);
17097 u2.Store(6 * 4, r);
17098 u.InterlockedMin(7 * 4, v.x, r);
17099 u2.Store(7 * 4, r);
17100 u.InterlockedXor(8 * 4, v.x, r);
17101 u2.Store(8 * 4, r);
17103 #endif
17104 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
17105 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17106 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
17107 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
17108 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
17109 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
17110 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
17111 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
17112 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
17113 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
17114 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
17115 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
17116 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
17117 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
17118 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
17119 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
17120 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
17121 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
17122 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
17123 0x0010000a, 0x00000000, 0x0100003e,
17126 static const char * const instructions[] =
17128 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
17129 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
17131 static const char * const imm_instructions[] =
17133 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
17134 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
17136 static const struct test
17138 struct uvec4 v;
17139 struct ivec4 i;
17140 unsigned int input[ARRAY_SIZE(instructions)];
17141 unsigned int expected_result[ARRAY_SIZE(instructions)];
17143 tests[] =
17145 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
17146 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
17149 if (!init_test_context(&test_context, &feature_level))
17150 return;
17152 device = test_context.device;
17153 context = test_context.immediate_context;
17155 texture_desc.Width = 1;
17156 texture_desc.Height = 1;
17157 texture_desc.MipLevels = 1;
17158 texture_desc.ArraySize = 1;
17159 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
17160 texture_desc.SampleDesc.Count = 1;
17161 texture_desc.SampleDesc.Quality = 0;
17162 texture_desc.Usage = D3D11_USAGE_DEFAULT;
17163 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
17164 texture_desc.CPUAccessFlags = 0;
17165 texture_desc.MiscFlags = 0;
17166 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17167 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17168 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
17169 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17171 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
17172 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17173 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
17175 buffer_desc.ByteWidth = sizeof(tests->input);
17176 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17177 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17178 buffer_desc.CPUAccessFlags = 0;
17179 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
17180 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
17181 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17182 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
17183 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17185 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
17186 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
17187 U(uav_desc).Buffer.FirstElement = 0;
17188 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
17189 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
17190 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
17191 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17192 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
17193 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17195 vp.TopLeftX = 0.0f;
17196 vp.TopLeftY = 0.0f;
17197 vp.Width = texture_desc.Width;
17198 vp.Height = texture_desc.Height;
17199 vp.MinDepth = 0.0f;
17200 vp.MaxDepth = 1.0f;
17201 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
17203 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
17204 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17205 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17207 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
17208 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17209 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
17211 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17213 const struct test *test = &tests[i];
17215 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17216 NULL, &test->v, 0, 0);
17218 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
17219 NULL, test->input, 0, 0);
17221 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
17222 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
17223 0, 1, &in_uav, NULL);
17225 draw_quad(&test_context);
17226 get_buffer_readback(in_buffer, &rb);
17227 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
17229 unsigned int value = get_readback_color(&rb, j, 0);
17230 unsigned int expected = test->expected_result[j];
17232 todo_wine_if(expected != test->input[j]
17233 && (!strcmp(instructions[j], "atomic_imax")
17234 || !strcmp(instructions[j], "atomic_imin")))
17235 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
17236 "with inputs (%u, %u), (%d), %#x (%d).\n",
17237 i, value, value, expected, expected, instructions[j],
17238 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
17240 release_resource_readback(&rb);
17242 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
17243 NULL, test->input, 0, 0);
17244 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
17246 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
17247 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
17249 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17250 get_buffer_readback(in_buffer, &rb);
17251 get_buffer_readback(out_buffer, &out_rb);
17252 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
17254 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
17255 || !strcmp(imm_instructions[j], "imm_atomic_imin");
17256 unsigned int out_value = get_readback_color(&out_rb, j, 0);
17257 unsigned int value = get_readback_color(&rb, j, 0);
17258 unsigned int expected = test->expected_result[j];
17260 todo_wine_if(expected != test->input[j] && todo_instruction)
17261 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
17262 "with inputs (%u, %u), (%d), %#x (%d).\n",
17263 i, value, value, expected, expected, imm_instructions[j],
17264 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
17266 todo_wine_if(todo_instruction && out_value != test->input[j])
17267 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
17268 out_value, test->input[j], imm_instructions[j]);
17270 release_resource_readback(&out_rb);
17271 release_resource_readback(&rb);
17274 ID3D11Buffer_Release(cb);
17275 ID3D11Buffer_Release(in_buffer);
17276 ID3D11Buffer_Release(out_buffer);
17277 ID3D11ComputeShader_Release(cs);
17278 ID3D11PixelShader_Release(ps);
17279 ID3D11RenderTargetView_Release(rtv);
17280 ID3D11Texture2D_Release(texture);
17281 ID3D11UnorderedAccessView_Release(in_uav);
17282 ID3D11UnorderedAccessView_Release(out_uav);
17283 release_test_context(&test_context);
17286 static void test_sm4_ret_instruction(void)
17288 struct d3d11_test_context test_context;
17289 ID3D11DeviceContext *context;
17290 ID3D11PixelShader *ps;
17291 struct uvec4 constant;
17292 ID3D11Device *device;
17293 ID3D11Buffer *cb;
17294 HRESULT hr;
17296 static const DWORD ps_code[] =
17298 #if 0
17299 uint c;
17301 float4 main() : SV_TARGET
17303 if (c == 1)
17304 return float4(1, 0, 0, 1);
17305 if (c == 2)
17306 return float4(0, 1, 0, 1);
17307 if (c == 3)
17308 return float4(0, 0, 1, 1);
17309 return float4(1, 1, 1, 1);
17311 #endif
17312 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
17313 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17314 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17315 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
17316 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
17317 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
17318 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
17319 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
17320 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
17321 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
17322 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
17323 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
17324 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
17325 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
17326 0x0100003e,
17329 if (!init_test_context(&test_context, NULL))
17330 return;
17332 device = test_context.device;
17333 context = test_context.immediate_context;
17335 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17336 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
17337 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17338 memset(&constant, 0, sizeof(constant));
17339 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
17340 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17342 draw_quad(&test_context);
17343 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
17345 constant.x = 1;
17346 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17347 draw_quad(&test_context);
17348 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
17350 constant.x = 2;
17351 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17352 draw_quad(&test_context);
17353 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17355 constant.x = 3;
17356 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17357 draw_quad(&test_context);
17358 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
17360 constant.x = 4;
17361 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17362 draw_quad(&test_context);
17363 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
17365 ID3D11Buffer_Release(cb);
17366 ID3D11PixelShader_Release(ps);
17367 release_test_context(&test_context);
17370 static void test_primitive_restart(void)
17372 struct d3d11_test_context test_context;
17373 ID3D11Buffer *ib32, *ib16, *vb;
17374 ID3D11DeviceContext *context;
17375 unsigned int stride, offset;
17376 ID3D11InputLayout *layout;
17377 ID3D11VertexShader *vs;
17378 ID3D11PixelShader *ps;
17379 ID3D11Device *device;
17380 unsigned int i;
17381 HRESULT hr;
17382 RECT rect;
17384 static const DWORD ps_code[] =
17386 #if 0
17387 struct vs_out
17389 float4 position : SV_Position;
17390 float4 color : color;
17393 float4 main(vs_out input) : SV_TARGET
17395 return input.color;
17397 #endif
17398 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
17399 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17400 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17401 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
17402 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17403 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
17404 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
17405 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
17407 static const DWORD vs_code[] =
17409 #if 0
17410 struct vs_out
17412 float4 position : SV_Position;
17413 float4 color : color;
17416 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
17418 output.position = position;
17419 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
17421 #endif
17422 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
17423 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
17424 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
17425 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
17426 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
17427 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
17428 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
17429 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
17430 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
17431 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
17432 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
17433 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
17434 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
17436 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17438 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17440 static const struct vec2 vertices[] =
17442 {-1.00f, -1.0f},
17443 {-1.00f, 1.0f},
17444 {-0.25f, -1.0f},
17445 {-0.25f, 1.0f},
17446 { 0.25f, -1.0f},
17447 { 0.25f, 1.0f},
17448 { 1.00f, -1.0f},
17449 { 1.00f, 1.0f},
17451 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
17452 static const unsigned short indices16[] =
17454 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
17456 static const unsigned int indices32[] =
17458 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
17461 if (!init_test_context(&test_context, NULL))
17462 return;
17464 device = test_context.device;
17465 context = test_context.immediate_context;
17467 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17468 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17469 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17470 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
17472 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
17473 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
17475 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17476 vs_code, sizeof(vs_code), &layout);
17477 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17479 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
17481 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17482 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17484 ID3D11DeviceContext_IASetInputLayout(context, layout);
17485 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
17486 stride = sizeof(*vertices);
17487 offset = 0;
17488 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
17490 for (i = 0; i < 2; ++i)
17492 if (!i)
17493 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
17494 else
17495 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
17497 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17498 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
17499 SetRect(&rect, 0, 0, 240, 480);
17500 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
17501 SetRect(&rect, 240, 0, 400, 480);
17502 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
17503 SetRect(&rect, 400, 0, 640, 480);
17504 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
17507 ID3D11Buffer_Release(ib16);
17508 ID3D11Buffer_Release(ib32);
17509 ID3D11Buffer_Release(vb);
17510 ID3D11InputLayout_Release(layout);
17511 ID3D11PixelShader_Release(ps);
17512 ID3D11VertexShader_Release(vs);
17513 release_test_context(&test_context);
17516 static void test_resinfo_instruction(void)
17518 struct shader
17520 const DWORD *code;
17521 size_t size;
17524 struct d3d11_test_context test_context;
17525 D3D11_TEXTURE3D_DESC texture3d_desc;
17526 D3D11_TEXTURE2D_DESC texture_desc;
17527 const struct shader *current_ps;
17528 D3D_FEATURE_LEVEL feature_level;
17529 ID3D11ShaderResourceView *srv;
17530 ID3D11DeviceContext *context;
17531 ID3D11Texture2D *rtv_texture;
17532 ID3D11RenderTargetView *rtv;
17533 ID3D11Resource *texture;
17534 struct uvec4 constant;
17535 ID3D11PixelShader *ps;
17536 ID3D11Device *device;
17537 unsigned int i, type;
17538 ID3D11Buffer *cb;
17539 HRESULT hr;
17541 static const DWORD ps_2d_code[] =
17543 #if 0
17544 Texture2D t;
17546 uint type;
17547 uint level;
17549 float4 main() : SV_TARGET
17551 if (!type)
17553 float width, height, miplevels;
17554 t.GetDimensions(level, width, height, miplevels);
17555 return float4(width, height, miplevels, 0);
17557 else
17559 uint width, height, miplevels;
17560 t.GetDimensions(level, width, height, miplevels);
17561 return float4(width, height, miplevels, 0);
17564 #endif
17565 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
17566 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17567 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17568 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
17569 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
17570 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17571 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17572 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
17573 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
17574 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
17575 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
17576 0x01000015, 0x0100003e,
17578 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
17579 static const DWORD ps_2d_array_code[] =
17581 #if 0
17582 Texture2DArray t;
17584 uint type;
17585 uint level;
17587 float4 main() : SV_TARGET
17589 if (!type)
17591 float width, height, elements, miplevels;
17592 t.GetDimensions(level, width, height, elements, miplevels);
17593 return float4(width, height, elements, miplevels);
17595 else
17597 uint width, height, elements, miplevels;
17598 t.GetDimensions(level, width, height, elements, miplevels);
17599 return float4(width, height, elements, miplevels);
17602 #endif
17603 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
17604 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17605 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17606 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
17607 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
17608 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17609 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17610 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
17611 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
17612 0x0100003e, 0x01000015, 0x0100003e,
17614 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
17615 static const DWORD ps_3d_code[] =
17617 #if 0
17618 Texture3D t;
17620 uint type;
17621 uint level;
17623 float4 main() : SV_TARGET
17625 if (!type)
17627 float width, height, depth, miplevels;
17628 t.GetDimensions(level, width, height, depth, miplevels);
17629 return float4(width, height, depth, miplevels);
17631 else
17633 uint width, height, depth, miplevels;
17634 t.GetDimensions(level, width, height, depth, miplevels);
17635 return float4(width, height, depth, miplevels);
17638 #endif
17639 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
17640 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17641 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17642 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
17643 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
17644 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17645 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17646 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
17647 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
17648 0x0100003e, 0x01000015, 0x0100003e,
17650 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
17651 static const DWORD ps_cube_code[] =
17653 #if 0
17654 TextureCube t;
17656 uint type;
17657 uint level;
17659 float4 main() : SV_TARGET
17661 if (!type)
17663 float width, height, miplevels;
17664 t.GetDimensions(level, width, height, miplevels);
17665 return float4(width, height, miplevels, 0);
17667 else
17669 uint width, height, miplevels;
17670 t.GetDimensions(level, width, height, miplevels);
17671 return float4(width, height, miplevels, 0);
17674 #endif
17675 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
17676 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17677 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17678 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
17679 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
17680 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17681 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17682 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
17683 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
17684 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
17685 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
17686 0x01000015, 0x0100003e,
17688 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
17689 static const DWORD ps_cube_array_code[] =
17691 #if 0
17692 TextureCubeArray t;
17694 uint type;
17695 uint level;
17697 float4 main() : SV_TARGET
17699 if (!type)
17701 float width, height, elements, miplevels;
17702 t.GetDimensions(level, width, height, elements, miplevels);
17703 return float4(width, height, miplevels, 0);
17705 else
17707 uint width, height, elements, miplevels;
17708 t.GetDimensions(level, width, height, elements, miplevels);
17709 return float4(width, height, miplevels, 0);
17712 #endif
17713 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
17714 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17715 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17716 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
17717 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
17718 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
17719 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
17720 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
17721 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
17722 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
17723 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
17724 0x0100003e, 0x01000015, 0x0100003e,
17726 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
17727 static const struct ps_test
17729 const struct shader *ps;
17730 struct
17732 unsigned int width;
17733 unsigned int height;
17734 unsigned int depth;
17735 unsigned int miplevel_count;
17736 unsigned int array_size;
17737 unsigned int cube_count;
17738 } texture_desc;
17739 unsigned int miplevel;
17740 struct vec4 expected_result;
17742 ps_tests[] =
17744 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
17745 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
17746 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
17747 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
17749 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
17750 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
17751 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
17752 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
17754 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
17755 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
17756 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
17757 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
17758 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
17759 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
17760 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
17761 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
17762 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
17764 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
17765 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
17766 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
17767 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
17768 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
17770 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
17771 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
17772 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
17775 if (!init_test_context(&test_context, NULL))
17776 return;
17778 device = test_context.device;
17779 context = test_context.immediate_context;
17780 feature_level = ID3D11Device_GetFeatureLevel(device);
17782 texture_desc.Width = 64;
17783 texture_desc.Height = 64;
17784 texture_desc.MipLevels = 1;
17785 texture_desc.ArraySize = 1;
17786 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17787 texture_desc.SampleDesc.Count = 1;
17788 texture_desc.SampleDesc.Quality = 0;
17789 texture_desc.Usage = D3D11_USAGE_DEFAULT;
17790 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
17791 texture_desc.CPUAccessFlags = 0;
17792 texture_desc.MiscFlags = 0;
17793 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
17794 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17795 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
17796 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17798 memset(&constant, 0, sizeof(constant));
17799 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
17801 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17802 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17804 ps = NULL;
17805 current_ps = NULL;
17806 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
17808 const struct ps_test *test = &ps_tests[i];
17810 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
17812 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
17813 continue;
17816 if (current_ps != test->ps)
17818 if (ps)
17819 ID3D11PixelShader_Release(ps);
17821 current_ps = test->ps;
17823 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
17824 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
17825 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17828 if (test->texture_desc.depth != 1)
17830 texture3d_desc.Width = test->texture_desc.width;
17831 texture3d_desc.Height = test->texture_desc.height;
17832 texture3d_desc.Depth = test->texture_desc.depth;
17833 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
17834 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
17835 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
17836 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
17837 texture3d_desc.CPUAccessFlags = 0;
17838 texture3d_desc.MiscFlags = 0;
17839 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
17840 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
17842 else
17844 texture_desc.Width = test->texture_desc.width;
17845 texture_desc.Height = test->texture_desc.height;
17846 texture_desc.MipLevels = test->texture_desc.miplevel_count;
17847 texture_desc.ArraySize = test->texture_desc.array_size;
17848 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
17849 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
17850 texture_desc.MiscFlags = 0;
17851 if (test->texture_desc.cube_count)
17852 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
17853 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
17854 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
17857 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
17858 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
17859 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
17861 for (type = 0; type < 2; ++type)
17863 constant.x = type;
17864 constant.y = test->miplevel;
17865 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17867 draw_quad(&test_context);
17868 check_texture_vec4(rtv_texture, &test->expected_result, 0);
17871 ID3D11Resource_Release(texture);
17872 ID3D11ShaderResourceView_Release(srv);
17874 ID3D11PixelShader_Release(ps);
17876 ID3D11Buffer_Release(cb);
17877 ID3D11RenderTargetView_Release(rtv);
17878 ID3D11Texture2D_Release(rtv_texture);
17879 release_test_context(&test_context);
17882 static void test_sm5_bufinfo_instruction(void)
17884 struct shader
17886 const DWORD *code;
17887 size_t size;
17890 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
17891 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
17892 struct d3d11_test_context test_context;
17893 D3D11_TEXTURE2D_DESC texture_desc;
17894 const struct shader *current_ps;
17895 ID3D11UnorderedAccessView *uav;
17896 ID3D11ShaderResourceView *srv;
17897 D3D11_BUFFER_DESC buffer_desc;
17898 ID3D11DeviceContext *context;
17899 ID3D11RenderTargetView *rtv;
17900 ID3D11Texture2D *texture;
17901 ID3D11PixelShader *ps;
17902 ID3D11Buffer *buffer;
17903 ID3D11Device *device;
17904 unsigned int i;
17905 HRESULT hr;
17907 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17908 static const DWORD ps_uav_structured_code[] =
17910 #if 0
17911 struct s
17913 uint4 u;
17914 bool b;
17917 RWStructuredBuffer<s> b;
17919 uint4 main(void) : SV_Target
17921 uint count, stride;
17922 b.GetDimensions(count, stride);
17923 return uint4(count, stride, 0, 1);
17925 #endif
17926 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
17927 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17928 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17929 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
17930 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
17931 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
17932 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
17933 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
17935 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
17936 static const DWORD ps_uav_structured32_code[] =
17938 #if 0
17939 struct s
17941 uint4 u;
17942 bool4 b;
17945 RWStructuredBuffer<s> b;
17947 uint4 main(void) : SV_Target
17949 uint count, stride;
17950 b.GetDimensions(count, stride);
17951 return uint4(count, stride, 0, 1);
17953 #endif
17954 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
17955 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17956 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17957 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
17958 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
17959 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
17960 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
17961 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
17963 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
17964 static const DWORD ps_srv_structured_code[] =
17966 #if 0
17967 StructuredBuffer<bool> b;
17969 uint4 main(void) : SV_Target
17971 uint count, stride;
17972 b.GetDimensions(count, stride);
17973 return uint4(count, stride, 0, 1);
17975 #endif
17976 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
17977 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17978 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17979 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
17980 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
17981 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
17982 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
17983 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
17985 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
17986 static const DWORD ps_uav_raw_code[] =
17988 #if 0
17989 RWByteAddressBuffer b;
17991 uint4 main(void) : SV_Target
17993 uint width;
17994 b.GetDimensions(width);
17995 return width;
17997 #endif
17998 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
17999 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18000 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18001 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
18002 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
18003 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
18004 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18006 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
18007 static const DWORD ps_srv_raw_code[] =
18009 #if 0
18010 ByteAddressBuffer b;
18012 uint4 main(void) : SV_Target
18014 uint width;
18015 b.GetDimensions(width);
18016 return width;
18018 #endif
18019 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
18020 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18021 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18022 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
18023 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
18024 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
18025 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18027 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
18028 static const DWORD ps_uav_typed_code[] =
18030 #if 0
18031 RWBuffer<float> b;
18033 uint4 main(void) : SV_Target
18035 uint width;
18036 b.GetDimensions(width);
18037 return width;
18039 #endif
18040 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
18041 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18042 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18043 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
18044 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
18045 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
18046 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18048 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
18049 static const DWORD ps_srv_typed_code[] =
18051 #if 0
18052 Buffer<float> b;
18054 uint4 main(void) : SV_Target
18056 uint width;
18057 b.GetDimensions(width);
18058 return width;
18060 #endif
18061 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
18062 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18063 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18064 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
18065 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
18066 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
18067 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18069 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
18070 static const struct test
18072 const struct shader *ps;
18073 BOOL uav;
18074 unsigned int buffer_size;
18075 unsigned int buffer_misc_flags;
18076 unsigned int buffer_structure_byte_stride;
18077 DXGI_FORMAT view_format;
18078 unsigned int view_element_idx;
18079 unsigned int view_element_count;
18080 struct uvec4 expected_result;
18082 tests[] =
18084 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
18085 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
18086 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
18087 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
18088 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
18089 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
18090 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
18091 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
18092 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
18093 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
18094 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
18095 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
18096 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
18097 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
18098 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
18099 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
18100 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
18101 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
18102 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
18103 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
18104 #undef RAW
18105 #undef STRUCTURED
18108 if (!init_test_context(&test_context, &feature_level))
18109 return;
18111 device = test_context.device;
18112 context = test_context.immediate_context;
18114 texture_desc.Width = 64;
18115 texture_desc.Height = 64;
18116 texture_desc.MipLevels = 1;
18117 texture_desc.ArraySize = 1;
18118 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
18119 texture_desc.SampleDesc.Count = 1;
18120 texture_desc.SampleDesc.Quality = 0;
18121 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18122 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
18123 texture_desc.CPUAccessFlags = 0;
18124 texture_desc.MiscFlags = 0;
18125 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18126 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18127 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18128 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18130 ps = NULL;
18131 current_ps = NULL;
18132 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18134 const struct test *test = &tests[i];
18136 if (current_ps != test->ps)
18138 if (ps)
18139 ID3D11PixelShader_Release(ps);
18141 current_ps = test->ps;
18143 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
18144 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
18145 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18148 buffer_desc.ByteWidth = test->buffer_size;
18149 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18150 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
18151 buffer_desc.CPUAccessFlags = 0;
18152 buffer_desc.MiscFlags = test->buffer_misc_flags;
18153 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
18154 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18155 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
18157 if (test->uav)
18159 uav_desc.Format = test->view_format;
18160 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
18161 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
18162 U(uav_desc).Buffer.NumElements = test->view_element_count;
18163 U(uav_desc).Buffer.Flags = 0;
18164 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
18165 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
18166 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
18167 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
18168 srv = NULL;
18170 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
18171 1, 1, &uav, NULL);
18173 else
18175 srv_desc.Format = test->view_format;
18176 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
18177 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
18178 U(srv_desc).BufferEx.NumElements = test->view_element_count;
18179 U(srv_desc).BufferEx.Flags = 0;
18180 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
18181 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
18182 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
18183 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
18184 uav = NULL;
18186 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18187 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18190 draw_quad(&test_context);
18191 check_texture_uvec4(texture, &test->expected_result);
18193 if (srv)
18194 ID3D11ShaderResourceView_Release(srv);
18195 if (uav)
18196 ID3D11UnorderedAccessView_Release(uav);
18197 ID3D11Buffer_Release(buffer);
18199 ID3D11PixelShader_Release(ps);
18201 ID3D11RenderTargetView_Release(rtv);
18202 ID3D11Texture2D_Release(texture);
18203 release_test_context(&test_context);
18206 static void test_render_target_device_mismatch(void)
18208 struct d3d11_test_context test_context;
18209 struct device_desc device_desc = {0};
18210 ID3D11DeviceContext *context;
18211 ID3D11RenderTargetView *rtv;
18212 ID3D11Device *device;
18213 ULONG refcount;
18215 if (!init_test_context(&test_context, NULL))
18216 return;
18218 device = create_device(&device_desc);
18219 ok(!!device, "Failed to create device.\n");
18221 ID3D11Device_GetImmediateContext(device, &context);
18223 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
18224 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
18225 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
18226 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
18227 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
18228 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
18229 ID3D11RenderTargetView_Release(rtv);
18231 rtv = NULL;
18232 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18234 ID3D11DeviceContext_Release(context);
18235 refcount = ID3D11Device_Release(device);
18236 ok(!refcount, "Device has %u references left.\n", refcount);
18237 release_test_context(&test_context);
18240 static void test_buffer_srv(void)
18242 struct shader
18244 const DWORD *code;
18245 size_t size;
18246 BOOL requires_raw_and_structured_buffers;
18248 struct buffer
18250 unsigned int byte_count;
18251 unsigned int data_offset;
18252 const void *data;
18253 unsigned int structure_byte_stride;
18256 BOOL raw_and_structured_buffers_supported;
18257 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
18258 struct d3d11_test_context test_context;
18259 D3D11_SUBRESOURCE_DATA resource_data;
18260 const struct buffer *current_buffer;
18261 const struct shader *current_shader;
18262 ID3D11ShaderResourceView *srv;
18263 D3D11_BUFFER_DESC buffer_desc;
18264 ID3D11DeviceContext *context;
18265 DWORD color, expected_color;
18266 struct resource_readback rb;
18267 ID3D11Buffer *cb, *buffer;
18268 ID3D11PixelShader *ps;
18269 ID3D11Device *device;
18270 unsigned int i, x, y;
18271 struct vec4 cb_size;
18272 HRESULT hr;
18274 static const DWORD ps_float4_code[] =
18276 #if 0
18277 Buffer<float4> b;
18279 float2 size;
18281 float4 main(float4 position : SV_POSITION) : SV_Target
18283 float2 p;
18284 int2 coords;
18285 p.x = position.x / 640.0f;
18286 p.y = position.y / 480.0f;
18287 coords = int2(p.x * size.x, p.y * size.y);
18288 return b.Load(coords.y * size.x + coords.x);
18290 #endif
18291 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
18292 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18293 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
18294 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18295 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
18296 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
18297 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
18298 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
18299 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
18300 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
18301 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
18302 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
18303 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
18305 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
18306 static const DWORD ps_structured_code[] =
18308 #if 0
18309 StructuredBuffer<float4> b;
18311 float2 size;
18313 float4 main(float4 position : SV_POSITION) : SV_Target
18315 float2 p;
18316 int2 coords;
18317 p.x = position.x / 640.0f;
18318 p.y = position.y / 480.0f;
18319 coords = int2(p.x * size.x, p.y * size.y);
18320 return b[coords.y * size.x + coords.x];
18322 #endif
18323 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
18324 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
18325 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
18326 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
18327 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
18328 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
18329 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
18330 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
18331 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
18332 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
18333 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
18334 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
18335 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
18336 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
18338 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
18339 static const DWORD rgba16[] =
18341 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
18342 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
18343 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
18344 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
18346 static const DWORD rgba4[] =
18348 0xffffffff, 0xff0000ff,
18349 0xff000000, 0xff00ff00,
18351 static const BYTE r4[] =
18353 0xde, 0xad,
18354 0xba, 0xbe,
18356 static const struct vec4 rgba_float[] =
18358 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
18359 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
18361 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
18362 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
18363 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
18364 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
18365 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
18366 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
18367 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
18368 &rgba_float, sizeof(*rgba_float)};
18369 static const DWORD rgba16_colors2x2[] =
18371 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
18372 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
18373 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
18374 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
18376 static const DWORD rgba16_colors1x1[] =
18378 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18379 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18380 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18381 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18383 static const DWORD rgba4_colors[] =
18385 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
18386 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
18387 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
18388 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
18390 static const DWORD r4_colors[] =
18392 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
18393 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
18394 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
18395 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
18397 static const DWORD zero_colors[16] = {0};
18398 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
18400 static const struct test
18402 const struct shader *shader;
18403 const struct buffer *buffer;
18404 DXGI_FORMAT srv_format;
18405 unsigned int srv_first_element;
18406 unsigned int srv_element_count;
18407 struct vec2 size;
18408 const DWORD *expected_colors;
18410 tests[] =
18412 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
18413 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
18414 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
18415 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
18416 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
18417 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
18418 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
18419 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
18420 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
18421 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
18422 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
18425 if (!init_test_context(&test_context, NULL))
18426 return;
18428 device = test_context.device;
18429 context = test_context.immediate_context;
18430 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
18431 || check_compute_shaders_via_sm4_support(device);
18433 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
18434 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18436 buffer_desc.ByteWidth = 256;
18437 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18438 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18439 buffer_desc.CPUAccessFlags = 0;
18440 buffer_desc.MiscFlags = 0;
18441 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18442 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18443 srv_desc.Format = DXGI_FORMAT_R8_UNORM;
18444 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
18445 U(srv_desc).Buffer.FirstElement = 0;
18446 U(srv_desc).Buffer.NumElements = 0;
18447 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
18448 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18449 ID3D11Buffer_Release(buffer);
18451 ps = NULL;
18452 srv = NULL;
18453 buffer = NULL;
18454 current_shader = NULL;
18455 current_buffer = NULL;
18456 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18458 const struct test *test = &tests[i];
18460 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
18462 skip("Test %u: Raw and structured buffers are not supported.\n", i);
18463 continue;
18465 /* Structured buffer views with an offset don't seem to work on WARP. */
18466 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
18467 && is_warp_device(device))
18469 skip("Test %u: Broken WARP.\n", i);
18470 continue;
18473 if (current_shader != test->shader)
18475 if (ps)
18476 ID3D11PixelShader_Release(ps);
18478 current_shader = test->shader;
18480 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
18481 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
18482 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18485 if (current_buffer != test->buffer)
18487 if (buffer)
18488 ID3D11Buffer_Release(buffer);
18490 current_buffer = test->buffer;
18491 if (current_buffer)
18493 BYTE *data = NULL;
18495 buffer_desc.ByteWidth = current_buffer->byte_count;
18496 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18497 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18498 buffer_desc.CPUAccessFlags = 0;
18499 buffer_desc.MiscFlags = 0;
18500 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
18501 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
18502 resource_data.SysMemPitch = 0;
18503 resource_data.SysMemSlicePitch = 0;
18504 if (current_buffer->data_offset)
18506 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, current_buffer->byte_count);
18507 ok(!!data, "Failed to allocate memory.\n");
18508 memcpy(data + current_buffer->data_offset, current_buffer->data,
18509 current_buffer->byte_count - current_buffer->data_offset);
18510 resource_data.pSysMem = data;
18512 else
18514 resource_data.pSysMem = current_buffer->data;
18516 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
18517 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
18518 HeapFree(GetProcessHeap(), 0, data);
18520 else
18522 buffer = NULL;
18526 if (srv)
18527 ID3D11ShaderResourceView_Release(srv);
18528 if (current_buffer)
18530 srv_desc.Format = test->srv_format;
18531 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
18532 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
18533 U(srv_desc).Buffer.NumElements = test->srv_element_count;
18534 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
18535 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
18537 else
18539 srv = NULL;
18541 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18543 cb_size.x = test->size.x;
18544 cb_size.y = test->size.y;
18545 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
18547 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
18548 draw_quad(&test_context);
18550 get_texture_readback(test_context.backbuffer, 0, &rb);
18551 for (y = 0; y < 4; ++y)
18553 for (x = 0; x < 4; ++x)
18555 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
18556 expected_color = test->expected_colors[y * 4 + x];
18557 ok(compare_color(color, expected_color, 1),
18558 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
18559 i, color, expected_color, x, y);
18562 release_resource_readback(&rb);
18564 if (srv)
18565 ID3D11ShaderResourceView_Release(srv);
18566 if (buffer)
18567 ID3D11Buffer_Release(buffer);
18569 ID3D11Buffer_Release(cb);
18570 ID3D11PixelShader_Release(ps);
18571 release_test_context(&test_context);
18574 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
18576 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18577 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
18578 struct d3d11_test_context test_context;
18579 D3D11_SUBRESOURCE_DATA resource_data;
18580 D3D11_TEXTURE2D_DESC texture_desc;
18581 ID3D11UnorderedAccessView *uav;
18582 ID3D11ShaderResourceView *srv;
18583 D3D11_BUFFER_DESC buffer_desc;
18584 ID3D11Buffer *cb, *raw_buffer;
18585 ID3D11DeviceContext *context;
18586 struct resource_readback rb;
18587 ID3D11RenderTargetView *rtv;
18588 ID3D11Texture2D *texture;
18589 ID3D11ComputeShader *cs;
18590 ID3D11PixelShader *ps;
18591 ID3D11Device *device;
18592 unsigned int i, data;
18593 struct uvec4 offset;
18594 HRESULT hr;
18596 static const unsigned int buffer_data[] =
18598 0xffffffff, 0x00000000,
18600 static const DWORD ps_code[] =
18602 #if 0
18603 ByteAddressBuffer buffer;
18605 uint offset;
18607 uint main() : SV_Target0
18609 return buffer.Load(offset);
18611 #endif
18612 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
18613 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
18614 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
18615 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
18616 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
18617 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
18618 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
18619 0x00000000,
18621 static const DWORD cs_code[] =
18623 #if 0
18624 RWByteAddressBuffer buffer;
18626 uint2 input;
18628 [numthreads(1, 1, 1)]
18629 void main()
18631 buffer.Store(input.x, input.y);
18633 #endif
18634 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
18635 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18636 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
18637 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
18638 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
18639 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
18641 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
18643 if (!init_test_context(&test_context, &feature_level))
18644 return;
18646 device = test_context.device;
18647 context = test_context.immediate_context;
18649 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
18651 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18652 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18653 if (SUCCEEDED(hr))
18654 ID3D11PixelShader_Release(ps);
18655 skip("Raw buffers are not supported.\n");
18656 release_test_context(&test_context);
18657 return;
18660 if (is_intel_device(device))
18662 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
18663 * This test checks what happens when offsets are not properly aligned.
18664 * The behavior seems to be undefined on Intel hardware. */
18665 win_skip("Skipping the test on Intel hardware.\n");
18666 release_test_context(&test_context);
18667 return;
18670 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18671 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18673 memset(&offset, 0, sizeof(offset));
18674 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
18676 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18677 texture_desc.Format = DXGI_FORMAT_R32_UINT;
18678 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18679 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18680 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18681 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18683 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18685 buffer_desc.ByteWidth = sizeof(buffer_data);
18686 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18687 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18688 buffer_desc.CPUAccessFlags = 0;
18689 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
18690 resource_data.pSysMem = buffer_data;
18691 resource_data.SysMemPitch = 0;
18692 resource_data.SysMemSlicePitch = 0;
18693 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
18694 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18696 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
18697 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
18698 U(srv_desc).BufferEx.FirstElement = 0;
18699 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
18700 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
18701 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
18702 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
18704 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18705 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18706 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18708 offset.x = 0;
18709 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18710 NULL, &offset, 0, 0);
18711 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18712 draw_quad(&test_context);
18713 check_texture_color(texture, buffer_data[0], 0);
18714 offset.x = 1;
18715 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18716 NULL, &offset, 0, 0);
18717 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18718 draw_quad(&test_context);
18719 check_texture_color(texture, buffer_data[0], 0);
18720 offset.x = 2;
18721 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18722 NULL, &offset, 0, 0);
18723 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18724 draw_quad(&test_context);
18725 check_texture_color(texture, buffer_data[0], 0);
18726 offset.x = 3;
18727 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18728 NULL, &offset, 0, 0);
18729 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18730 draw_quad(&test_context);
18731 check_texture_color(texture, buffer_data[0], 0);
18733 offset.x = 4;
18734 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18735 NULL, &offset, 0, 0);
18736 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18737 draw_quad(&test_context);
18738 check_texture_color(texture, buffer_data[1], 0);
18739 offset.x = 7;
18740 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18741 NULL, &offset, 0, 0);
18742 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18743 draw_quad(&test_context);
18744 check_texture_color(texture, buffer_data[1], 0);
18746 if (feature_level < D3D_FEATURE_LEVEL_11_0)
18748 skip("Feature level 11_0 required for unaligned UAV test.\n");
18749 goto done;
18752 ID3D11Buffer_Release(raw_buffer);
18753 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
18754 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
18755 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18757 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
18758 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
18759 U(uav_desc).Buffer.FirstElement = 0;
18760 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
18761 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
18762 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
18763 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18765 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
18766 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18768 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18769 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
18770 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
18772 offset.x = 0;
18773 offset.y = 0xffffffff;
18774 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18775 NULL, &offset, 0, 0);
18776 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18777 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18778 get_buffer_readback(raw_buffer, &rb);
18779 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18781 data = get_readback_color(&rb, i, 0);
18782 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18784 release_resource_readback(&rb);
18786 offset.x = 1;
18787 offset.y = 0xffffffff;
18788 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18789 NULL, &offset, 0, 0);
18790 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18791 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18792 get_buffer_readback(raw_buffer, &rb);
18793 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18795 data = get_readback_color(&rb, i, 0);
18796 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18798 release_resource_readback(&rb);
18800 offset.x = 2;
18801 offset.y = 0xffffffff;
18802 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18803 NULL, &offset, 0, 0);
18804 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18805 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18806 get_buffer_readback(raw_buffer, &rb);
18807 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18809 data = get_readback_color(&rb, i, 0);
18810 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18812 release_resource_readback(&rb);
18814 offset.x = 3;
18815 offset.y = 0xffffffff;
18816 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18817 NULL, &offset, 0, 0);
18818 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18819 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18820 get_buffer_readback(raw_buffer, &rb);
18821 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18823 data = get_readback_color(&rb, i, 0);
18824 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18826 release_resource_readback(&rb);
18828 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18829 offset.x = 3;
18830 offset.y = 0xffff;
18831 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18832 NULL, &offset, 0, 0);
18833 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18834 offset.x = 4;
18835 offset.y = 0xa;
18836 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18837 NULL, &offset, 0, 0);
18838 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18839 get_buffer_readback(raw_buffer, &rb);
18840 data = get_readback_color(&rb, 0, 0);
18841 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
18842 data = get_readback_color(&rb, 1, 0);
18843 ok(data == 0xa, "Got unexpected result %#x.\n", data);
18844 release_resource_readback(&rb);
18846 ID3D11ComputeShader_Release(cs);
18847 ID3D11UnorderedAccessView_Release(uav);
18849 done:
18850 ID3D11Buffer_Release(cb);
18851 ID3D11Buffer_Release(raw_buffer);
18852 ID3D11PixelShader_Release(ps);
18853 ID3D11RenderTargetView_Release(rtv);
18854 ID3D11ShaderResourceView_Release(srv);
18855 ID3D11Texture2D_Release(texture);
18856 release_test_context(&test_context);
18859 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
18860 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
18862 D3D11_MAPPED_SUBRESOURCE map_desc;
18863 unsigned int counter;
18865 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
18867 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
18868 D3D11_MAP_READ, 0, &map_desc)))
18869 return 0xdeadbeef;
18870 counter = *(unsigned int *)map_desc.pData;
18871 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
18872 return counter;
18875 static int compare_id(const void *a, const void *b)
18877 return *(int *)a - *(int *)b;
18880 static void test_uav_counters(void)
18882 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
18883 ID3D11ComputeShader *cs_producer, *cs_consumer;
18884 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18885 struct d3d11_test_context test_context;
18886 ID3D11UnorderedAccessView *uav, *uav2;
18887 unsigned int data, id[128], i;
18888 D3D11_BUFFER_DESC buffer_desc;
18889 ID3D11DeviceContext *context;
18890 struct resource_readback rb;
18891 ID3D11Device *device;
18892 D3D11_BOX box;
18893 HRESULT hr;
18895 static const DWORD cs_producer_code[] =
18897 #if 0
18898 RWStructuredBuffer<uint> u;
18900 [numthreads(4, 1, 1)]
18901 void main(uint3 dispatch_id : SV_DispatchThreadID)
18903 uint counter = u.IncrementCounter();
18904 u[counter] = dispatch_id.x;
18906 #endif
18907 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
18908 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18909 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
18910 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
18911 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
18912 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
18913 0x0002000a, 0x0100003e,
18915 static const DWORD cs_consumer_code[] =
18917 #if 0
18918 RWStructuredBuffer<uint> u;
18919 RWStructuredBuffer<uint> u2;
18921 [numthreads(4, 1, 1)]
18922 void main()
18924 uint counter = u.DecrementCounter();
18925 u2[counter] = u[counter];
18927 #endif
18928 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
18929 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18930 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
18931 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
18932 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
18933 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
18934 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
18935 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
18937 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18939 if (!init_test_context(&test_context, &feature_level))
18940 return;
18942 device = test_context.device;
18943 context = test_context.immediate_context;
18945 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
18946 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18947 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
18948 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18950 memset(&buffer_desc, 0, sizeof(buffer_desc));
18951 buffer_desc.ByteWidth = sizeof(unsigned int);
18952 buffer_desc.Usage = D3D11_USAGE_STAGING;
18953 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
18954 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
18955 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
18957 buffer_desc.ByteWidth = 1024;
18958 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18959 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
18960 buffer_desc.CPUAccessFlags = 0;
18961 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
18962 buffer_desc.StructureByteStride = sizeof(unsigned int);
18963 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18964 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
18965 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
18966 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
18967 U(uav_desc).Buffer.FirstElement = 0;
18968 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
18969 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
18970 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
18971 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18972 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
18973 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
18974 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
18975 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18977 data = read_uav_counter(context, staging_buffer, uav);
18978 ok(!data, "Got unexpected initial value %u.\n", data);
18979 data = 8;
18980 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
18981 data = read_uav_counter(context, staging_buffer, uav);
18982 ok(data == 8, "Got unexpected value %u.\n", data);
18983 data = ~0u;
18984 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
18985 data = read_uav_counter(context, staging_buffer, uav);
18986 ok(data == 8, "Got unexpected value %u.\n", data);
18987 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
18988 data = read_uav_counter(context, staging_buffer, uav);
18989 ok(data == 8, "Got unexpected value %u.\n", data);
18991 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
18992 data = 0;
18993 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
18994 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
18995 data = read_uav_counter(context, staging_buffer, uav);
18996 ok(!data, "Got unexpected value %u.\n", data);
18998 /* produce */
18999 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
19000 data = read_uav_counter(context, staging_buffer, uav);
19001 ok(data == 64, "Got unexpected value %u.\n", data);
19002 get_buffer_readback(buffer, &rb);
19003 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
19004 release_resource_readback(&rb);
19005 qsort(id, 64, sizeof(*id), compare_id);
19006 for (i = 0; i < 64; ++i)
19008 if (id[i] != i)
19009 break;
19011 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
19013 /* consume */
19014 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
19015 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
19016 data = read_uav_counter(context, staging_buffer, uav);
19017 ok(!data, "Got unexpected value %u.\n", data);
19018 get_buffer_readback(buffer2, &rb);
19019 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
19020 release_resource_readback(&rb);
19021 qsort(id, 64, sizeof(*id), compare_id);
19022 for (i = 0; i < 64; ++i)
19024 if (id[i] != i)
19025 break;
19027 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
19029 /* produce on CPU */
19030 for (i = 0; i < 8; ++i)
19031 id[i] = 0xdeadbeef;
19032 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
19033 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
19034 data = 8;
19035 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19036 data = read_uav_counter(context, staging_buffer, uav);
19037 ok(data == 8, "Got unexpected value %u.\n", data);
19039 /* consume */
19040 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19041 data = read_uav_counter(context, staging_buffer, uav);
19042 ok(data == 4, "Got unexpected value %u.\n", data);
19043 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19044 data = read_uav_counter(context, staging_buffer, uav);
19045 ok(!data, "Got unexpected value %u.\n", data);
19046 get_buffer_readback(buffer2, &rb);
19047 for (i = 0; i < 8; ++i)
19049 data = get_readback_color(&rb, i, 0);
19050 ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
19052 release_resource_readback(&rb);
19054 ID3D11Buffer_Release(buffer);
19055 ID3D11Buffer_Release(buffer2);
19056 ID3D11Buffer_Release(staging_buffer);
19057 ID3D11ComputeShader_Release(cs_producer);
19058 ID3D11ComputeShader_Release(cs_consumer);
19059 ID3D11UnorderedAccessView_Release(uav);
19060 ID3D11UnorderedAccessView_Release(uav2);
19061 release_test_context(&test_context);
19064 static void test_dispatch_indirect(void)
19066 struct stats
19068 unsigned int dispatch_count;
19069 unsigned int thread_count;
19070 unsigned int max_x;
19071 unsigned int max_y;
19072 unsigned int max_z;
19075 ID3D11Buffer *append_buffer, *stats_buffer, *args_buffer, *staging_buffer;
19076 ID3D11UnorderedAccessView *uav, *stats_uav;
19077 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19078 ID3D11ComputeShader *cs_append, *cs_stats;
19079 struct d3d11_test_context test_context;
19080 D3D11_BUFFER_DESC buffer_desc;
19081 ID3D11DeviceContext *context;
19082 struct resource_readback rb;
19083 ID3D11Device *device;
19084 unsigned int data, i;
19085 struct stats *stats;
19086 HRESULT hr;
19088 static const DWORD cs_append_code[] =
19090 #if 0
19091 struct dispatch_args
19093 uint x, y, z;
19096 AppendStructuredBuffer<dispatch_args> u;
19098 [numthreads(1, 1, 1)]
19099 void main()
19101 dispatch_args args = {4, 2, 1};
19102 u.Append(args);
19103 args.y = 1;
19104 u.Append(args);
19105 args.x = 3;
19106 u.Append(args);
19108 #endif
19109 0x43425844, 0x954de75a, 0x8bb1b78b, 0x84ded464, 0x9d9532b7, 0x00000001, 0x00000158, 0x00000003,
19110 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19111 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000104, 0x00050050, 0x00000041, 0x0100086a,
19112 0x0400009e, 0x0011e000, 0x00000000, 0x0000000c, 0x02000068, 0x00000001, 0x0400009b, 0x00000001,
19113 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x0c0000a8,
19114 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002, 0x00000004,
19115 0x00000002, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000,
19116 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002,
19117 0x00000004, 0x00000001, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
19118 0x00000000, 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
19119 0x00004002, 0x00000003, 0x00000001, 0x00000001, 0x00000000, 0x0100003e,
19121 static const DWORD cs_stats_code[] =
19123 #if 0
19124 struct stats
19126 uint dispatch_count;
19127 uint thread_count;
19128 uint max_x;
19129 uint max_y;
19130 uint max_z;
19133 RWStructuredBuffer<stats> u;
19135 [numthreads(1, 1, 1)]
19136 void main(uint3 id : SV_DispatchThreadID)
19138 if (all(!id))
19139 InterlockedAdd(u[0].dispatch_count, 1);
19140 InterlockedAdd(u[0].thread_count, 1);
19141 InterlockedMax(u[0].max_x, id.x);
19142 InterlockedMax(u[0].max_y, id.y);
19143 InterlockedMax(u[0].max_z, id.z);
19145 #endif
19146 0x43425844, 0xbd3f2e4e, 0xb0f61ff7, 0xa8e10584, 0x2f61aec9, 0x00000001, 0x000001bc, 0x00000003,
19147 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19148 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000168, 0x00050050, 0x0000005a, 0x0100086a,
19149 0x0400009e, 0x0011e000, 0x00000000, 0x00000014, 0x0200005f, 0x00020072, 0x02000068, 0x00000001,
19150 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x09000020, 0x00100072, 0x00000000, 0x00020246,
19151 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000001, 0x00100012, 0x00000000,
19152 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00100012, 0x00000000, 0x0010002a,
19153 0x00000000, 0x0010000a, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x0a0000ad, 0x0011e000,
19154 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001,
19155 0x01000015, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000,
19156 0x00000000, 0x00004001, 0x00000001, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002, 0x00000000,
19157 0x00000008, 0x00000000, 0x00000000, 0x0002000a, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002,
19158 0x00000000, 0x0000000c, 0x00000000, 0x00000000, 0x0002001a, 0x090000b0, 0x0011e000, 0x00000000,
19159 0x00004002, 0x00000000, 0x00000010, 0x00000000, 0x00000000, 0x0002002a, 0x0100003e,
19161 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19162 static const unsigned int zero[4] = {0, 0, 0, 0};
19164 if (!init_test_context(&test_context, &feature_level))
19165 return;
19167 device = test_context.device;
19168 context = test_context.immediate_context;
19170 hr = ID3D11Device_CreateComputeShader(device, cs_append_code, sizeof(cs_append_code), NULL, &cs_append);
19171 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19172 hr = ID3D11Device_CreateComputeShader(device, cs_stats_code, sizeof(cs_stats_code), NULL, &cs_stats);
19173 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19175 memset(&buffer_desc, 0, sizeof(buffer_desc));
19176 buffer_desc.ByteWidth = sizeof(unsigned int);
19177 buffer_desc.Usage = D3D11_USAGE_STAGING;
19178 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
19179 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
19180 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19182 buffer_desc.ByteWidth = 60;
19183 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19184 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19185 buffer_desc.CPUAccessFlags = 0;
19186 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19187 buffer_desc.StructureByteStride = 3 * sizeof(unsigned int);
19188 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &append_buffer);
19189 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19190 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
19191 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19192 U(uav_desc).Buffer.FirstElement = 0;
19193 U(uav_desc).Buffer.NumElements = 5;
19194 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
19195 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)append_buffer, &uav_desc, &uav);
19196 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19198 /* We use a separate buffer because D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
19199 * and D3D11_RESOURCE_MISC_BUFFER_STRUCTURED are mutually exclusive flags.
19201 buffer_desc.BindFlags = 0;
19202 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
19203 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &args_buffer);
19204 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19206 buffer_desc.ByteWidth = sizeof(*stats);
19207 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19208 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19209 buffer_desc.StructureByteStride = sizeof(*stats);
19210 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &stats_buffer);
19211 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19212 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)stats_buffer, NULL, &stats_uav);
19213 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19215 data = read_uav_counter(context, staging_buffer, uav);
19216 ok(!data, "Got unexpected initial value %u.\n", data);
19217 data = 8;
19218 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19219 data = read_uav_counter(context, staging_buffer, uav);
19220 ok(data == 8, "Got unexpected value %u.\n", data);
19222 ID3D11DeviceContext_CSSetShader(context, cs_append, NULL, 0);
19223 data = 0;
19224 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19225 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19226 data = read_uav_counter(context, staging_buffer, uav);
19227 ok(data == 3, "Got unexpected value %u.\n", data);
19228 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)args_buffer, (ID3D11Resource *)append_buffer);
19230 ID3D11DeviceContext_CSSetShader(context, cs_stats, NULL, 0);
19231 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, stats_uav, zero);
19232 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &stats_uav, NULL);
19233 data = read_uav_counter(context, staging_buffer, uav);
19234 for (i = 0; i < data; ++i)
19235 ID3D11DeviceContext_DispatchIndirect(context, args_buffer, i * 3 * sizeof(unsigned int));
19236 get_buffer_readback(stats_buffer, &rb);
19237 stats = rb.map_desc.pData;
19238 ok(stats->dispatch_count == 3, "Got unexpected dispatch count %u.\n", stats->dispatch_count);
19239 ok(stats->thread_count == 15, "Got unexpected thread count %u.\n", stats->thread_count);
19240 ok(stats->max_x == 3, "Got unexpected max x %u.\n", stats->max_x);
19241 ok(stats->max_y == 1, "Got unexpected max y %u.\n", stats->max_y);
19242 ok(stats->max_z == 0, "Got unexpected max z %u.\n", stats->max_z);
19243 release_resource_readback(&rb);
19245 ID3D11Buffer_Release(append_buffer);
19246 ID3D11Buffer_Release(args_buffer);
19247 ID3D11Buffer_Release(staging_buffer);
19248 ID3D11Buffer_Release(stats_buffer);
19249 ID3D11ComputeShader_Release(cs_append);
19250 ID3D11ComputeShader_Release(cs_stats);
19251 ID3D11UnorderedAccessView_Release(uav);
19252 ID3D11UnorderedAccessView_Release(stats_uav);
19253 release_test_context(&test_context);
19256 static void test_compute_shader_registers(void)
19258 struct data
19260 unsigned int group_id[3];
19261 unsigned int group_index;
19262 unsigned int dispatch_id[3];
19263 unsigned int thread_id[3];
19266 struct d3d11_test_context test_context;
19267 unsigned int i, x, y, group_x, group_y;
19268 ID3D11UnorderedAccessView *uav;
19269 D3D11_BUFFER_DESC buffer_desc;
19270 ID3D11DeviceContext *context;
19271 struct resource_readback rb;
19272 ID3D11Buffer *cb, *buffer;
19273 struct uvec4 dimensions;
19274 ID3D11ComputeShader *cs;
19275 const struct data *data;
19276 ID3D11Device *device;
19277 HRESULT hr;
19279 static const DWORD cs_code[] =
19281 #if 0
19282 struct data
19284 uint3 group_id;
19285 uint group_index;
19286 uint3 dispatch_id;
19287 uint3 group_thread_id;
19290 RWStructuredBuffer<data> u;
19292 uint2 dim;
19294 [numthreads(3, 2, 1)]
19295 void main(uint3 group_id : SV_GroupID,
19296 uint group_index : SV_GroupIndex,
19297 uint3 dispatch_id : SV_DispatchThreadID,
19298 uint3 group_thread_id : SV_GroupThreadID)
19300 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
19301 u[i].group_id = group_id;
19302 u[i].group_index = group_index;
19303 u[i].dispatch_id = dispatch_id;
19304 u[i].group_thread_id = group_thread_id;
19306 #endif
19307 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
19308 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19309 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
19310 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
19311 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
19312 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
19313 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
19314 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
19315 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
19316 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
19317 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
19318 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
19319 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
19320 0x0100003e,
19322 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19324 if (!init_test_context(&test_context, &feature_level))
19325 return;
19327 device = test_context.device;
19328 context = test_context.immediate_context;
19330 buffer_desc.ByteWidth = 10240;
19331 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19332 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19333 buffer_desc.CPUAccessFlags = 0;
19334 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19335 buffer_desc.StructureByteStride = 40;
19336 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
19337 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19338 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19339 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19340 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19342 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
19344 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
19345 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19347 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19348 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
19349 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19351 dimensions.x = 2;
19352 dimensions.y = 3;
19353 dimensions.z = 1;
19354 dimensions.w = 0;
19355 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
19356 NULL, &dimensions, 0, 0);
19357 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
19359 get_buffer_readback(buffer, &rb);
19360 i = 0;
19361 data = rb.map_desc.pData;
19362 for (y = 0; y < dimensions.y; ++y)
19364 for (group_y = 0; group_y < 2; ++group_y)
19366 for (x = 0; x < dimensions.x; ++x)
19368 for (group_x = 0; group_x < 3; ++group_x)
19370 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
19371 const unsigned int group_index = group_y * 3 + group_x;
19372 const struct data *d = &data[i];
19374 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
19375 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
19376 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
19377 i, x, y, group_x, group_y);
19378 ok(d->group_index == group_index,
19379 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
19380 d->group_index, group_index, i, x, y, group_x, group_y);
19381 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
19382 && !d->dispatch_id[2],
19383 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
19384 "at %u (%u, %u, %u, %u).\n",
19385 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
19386 dispatch_id[0], dispatch_id[1], 0,
19387 i, x, y, group_x, group_y);
19388 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
19389 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
19390 "at %u (%u, %u, %u, %u).\n",
19391 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
19392 i, x, y, group_x, group_y);
19393 ++i;
19398 release_resource_readback(&rb);
19400 ID3D11Buffer_Release(cb);
19401 ID3D11Buffer_Release(buffer);
19402 ID3D11ComputeShader_Release(cs);
19403 ID3D11UnorderedAccessView_Release(uav);
19404 release_test_context(&test_context);
19407 static void test_tgsm(void)
19409 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19410 struct d3d11_test_context test_context;
19411 ID3D11UnorderedAccessView *uav, *uav2;
19412 struct resource_readback rb, rb2;
19413 unsigned int i, data, expected;
19414 ID3D11Buffer *buffer, *buffer2;
19415 D3D11_BUFFER_DESC buffer_desc;
19416 ID3D11DeviceContext *context;
19417 ID3D11ComputeShader *cs;
19418 ID3D11Device *device;
19419 float float_data;
19420 HRESULT hr;
19422 static const DWORD raw_tgsm_code[] =
19424 #if 0
19425 RWByteAddressBuffer u;
19426 groupshared uint m;
19428 [numthreads(32, 1, 1)]
19429 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
19431 if (!local_idx)
19432 m = group_id.x;
19433 GroupMemoryBarrierWithGroupSync();
19434 InterlockedAdd(m, group_id.x);
19435 GroupMemoryBarrierWithGroupSync();
19436 if (!local_idx)
19437 u.Store(4 * group_id.x, m);
19439 #endif
19440 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
19441 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19442 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
19443 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
19444 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
19445 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
19446 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
19447 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
19448 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
19449 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
19450 0x01000015, 0x0100003e,
19452 static const DWORD structured_tgsm_code[] =
19454 #if 0
19455 #define GROUP_SIZE 32
19457 RWByteAddressBuffer u;
19458 RWByteAddressBuffer u2;
19459 groupshared uint m[GROUP_SIZE];
19461 [numthreads(GROUP_SIZE, 1, 1)]
19462 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
19464 uint sum, original, i;
19466 if (!local_idx)
19468 for (i = 0; i < GROUP_SIZE; ++i)
19469 m[i] = 2 * group_id.x;
19471 GroupMemoryBarrierWithGroupSync();
19472 InterlockedAdd(m[local_idx], 1);
19473 GroupMemoryBarrierWithGroupSync();
19474 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
19475 u.InterlockedExchange(4 * group_id.x, sum, original);
19476 u2.Store(4 * group_id.x, original);
19478 #endif
19479 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
19480 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19481 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
19482 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
19483 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
19484 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
19485 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
19486 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
19487 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
19488 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
19489 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
19490 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
19491 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
19492 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
19493 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
19494 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
19495 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
19496 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
19497 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
19498 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
19499 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
19500 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
19502 static const DWORD structured_tgsm_float_code[] =
19504 #if 0
19505 #define GROUP_SIZE 32
19507 struct data
19509 float f;
19510 uint u;
19513 RWBuffer<float> u;
19514 RWBuffer<uint> u2;
19515 groupshared data m[GROUP_SIZE];
19517 [numthreads(GROUP_SIZE, 1, 1)]
19518 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
19519 uint thread_id : SV_DispatchThreadID)
19521 uint i;
19522 if (!local_idx)
19524 for (i = 0; i < GROUP_SIZE; ++i)
19526 m[i].f = group_id.x;
19527 m[i].u = group_id.x;
19530 GroupMemoryBarrierWithGroupSync();
19531 for (i = 0; i < local_idx; ++i)
19533 m[local_idx].f += group_id.x;
19534 m[local_idx].u += group_id.x;
19536 u[thread_id.x] = m[local_idx].f;
19537 u2[thread_id.x] = m[local_idx].u;
19539 #endif
19540 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
19541 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19542 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
19543 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
19544 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
19545 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
19546 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
19547 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
19548 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
19549 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
19550 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
19551 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
19552 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
19553 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
19554 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
19555 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
19556 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
19557 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
19558 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
19559 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
19560 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
19561 0x00100556, 0x00000000, 0x0100003e,
19563 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19564 static const unsigned int zero[4] = {0};
19566 if (!init_test_context(&test_context, &feature_level))
19567 return;
19569 device = test_context.device;
19570 context = test_context.immediate_context;
19572 buffer_desc.ByteWidth = 1024;
19573 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19574 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19575 buffer_desc.CPUAccessFlags = 0;
19576 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
19577 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19578 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19580 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
19581 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19582 U(uav_desc).Buffer.FirstElement = 0;
19583 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
19584 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
19585 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19586 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19588 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
19589 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19591 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19592 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19594 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19595 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
19596 get_buffer_readback(buffer, &rb);
19597 for (i = 0; i < 64; ++i)
19599 data = get_readback_color(&rb, i, 0);
19600 expected = 33 * i;
19601 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
19603 release_resource_readback(&rb);
19605 ID3D11Buffer_Release(buffer);
19606 ID3D11ComputeShader_Release(cs);
19607 ID3D11UnorderedAccessView_Release(uav);
19609 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19610 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19611 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19612 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19613 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
19614 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19615 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
19616 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19617 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
19618 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19620 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19621 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19622 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
19624 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19625 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
19626 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
19627 get_buffer_readback(buffer, &rb);
19628 get_buffer_readback(buffer2, &rb2);
19629 for (i = 0; i < 32; ++i)
19631 expected = 64 * i + 32;
19632 data = get_readback_color(&rb, i, 0);
19633 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
19634 data = get_readback_color(&rb2, i, 0);
19635 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
19637 release_resource_readback(&rb);
19638 release_resource_readback(&rb2);
19640 ID3D11Buffer_Release(buffer);
19641 ID3D11Buffer_Release(buffer2);
19642 ID3D11ComputeShader_Release(cs);
19643 ID3D11UnorderedAccessView_Release(uav);
19644 ID3D11UnorderedAccessView_Release(uav2);
19646 buffer_desc.MiscFlags = 0;
19647 U(uav_desc).Buffer.Flags = 0;
19648 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19649 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19650 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
19651 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19652 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19653 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
19654 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19655 uav_desc.Format = DXGI_FORMAT_R32_UINT;
19656 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
19657 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19658 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
19659 sizeof(structured_tgsm_float_code), NULL, &cs);
19660 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19662 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19663 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19664 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
19666 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19667 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
19668 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
19669 get_buffer_readback(buffer, &rb);
19670 get_buffer_readback(buffer2, &rb2);
19671 for (i = 0; i < 96; ++i)
19673 expected = (i % 32 + 1) * (i / 32);
19674 float_data = get_readback_float(&rb, i, 0);
19675 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
19676 data = get_readback_color(&rb2, i, 0);
19677 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
19679 release_resource_readback(&rb);
19680 release_resource_readback(&rb2);
19682 ID3D11Buffer_Release(buffer);
19683 ID3D11Buffer_Release(buffer2);
19684 ID3D11ComputeShader_Release(cs);
19685 ID3D11UnorderedAccessView_Release(uav);
19686 ID3D11UnorderedAccessView_Release(uav2);
19687 release_test_context(&test_context);
19690 static void test_geometry_shader(void)
19692 static const struct
19694 struct vec4 position;
19695 unsigned int color;
19697 vertex[] =
19699 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
19701 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
19703 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
19704 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
19706 #if 0
19707 struct vs_data
19709 float4 pos : SV_POSITION;
19710 float4 color : COLOR;
19713 void main(in struct vs_data vs_input, out struct vs_data vs_output)
19715 vs_output.pos = vs_input.pos;
19716 vs_output.color = vs_input.color;
19718 #endif
19719 static const DWORD vs_code[] =
19721 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
19722 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19723 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19724 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19725 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19726 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19727 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
19728 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
19729 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
19730 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
19731 0x0100003e,
19733 #if 0
19734 struct gs_data
19736 float4 pos : SV_POSITION;
19737 float4 color : COLOR;
19740 [maxvertexcount(4)]
19741 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
19743 float offset = 0.2 * vin[0].pos.w;
19744 gs_data v;
19746 v.color = vin[0].color;
19748 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
19749 vout.Append(v);
19750 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
19751 vout.Append(v);
19752 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
19753 vout.Append(v);
19754 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
19755 vout.Append(v);
19757 #endif
19758 static const DWORD gs_code[] =
19760 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
19761 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19762 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19763 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19764 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19765 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19766 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
19767 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
19768 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
19769 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
19770 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
19771 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
19772 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
19773 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
19774 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
19775 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
19776 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
19777 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
19778 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
19779 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
19780 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
19781 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
19782 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
19783 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
19784 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
19785 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
19786 0x00000001, 0x01000013, 0x0100003e,
19788 static const DWORD gs_5_0_code[] =
19790 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
19791 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19792 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19793 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19794 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
19795 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
19796 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
19797 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
19798 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
19799 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
19800 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
19801 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
19802 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
19803 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
19804 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
19805 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
19806 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
19807 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
19808 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
19809 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
19810 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
19811 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
19812 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
19813 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
19814 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
19815 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
19816 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
19817 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
19818 0x0100003e,
19820 #if 0
19821 struct ps_data
19823 float4 pos : SV_POSITION;
19824 float4 color : COLOR;
19827 float4 main(struct ps_data ps_input) : SV_Target
19829 return ps_input.color;
19831 #endif
19832 static const DWORD ps_code[] =
19834 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
19835 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19836 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
19837 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19838 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19839 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
19840 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
19841 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
19843 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
19844 struct d3d11_test_context test_context;
19845 ID3D11InputLayout *input_layout;
19846 ID3D11DeviceContext *context;
19847 unsigned int stride, offset;
19848 struct resource_readback rb;
19849 ID3D11GeometryShader *gs;
19850 ID3D11VertexShader *vs;
19851 ID3D11PixelShader *ps;
19852 ID3D11Device *device;
19853 ID3D11Buffer *vb;
19854 DWORD color;
19855 HRESULT hr;
19857 if (!init_test_context(&test_context, NULL))
19858 return;
19860 device = test_context.device;
19861 context = test_context.immediate_context;
19863 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
19864 vs_code, sizeof(vs_code), &input_layout);
19865 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
19867 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
19869 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
19870 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
19871 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
19872 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
19873 else
19874 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
19875 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
19876 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19877 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19879 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
19880 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
19881 stride = sizeof(*vertex);
19882 offset = 0;
19883 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
19884 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
19885 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
19886 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19888 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
19889 ID3D11DeviceContext_Draw(context, 1, 0);
19891 get_texture_readback(test_context.backbuffer, 0, &rb);
19892 color = get_readback_color(&rb, 320, 190);
19893 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
19894 color = get_readback_color(&rb, 255, 240);
19895 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
19896 color = get_readback_color(&rb, 320, 240);
19897 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
19898 color = get_readback_color(&rb, 385, 240);
19899 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
19900 color = get_readback_color(&rb, 320, 290);
19901 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
19902 release_resource_readback(&rb);
19904 ID3D11PixelShader_Release(ps);
19905 ID3D11GeometryShader_Release(gs);
19906 ID3D11VertexShader_Release(vs);
19907 ID3D11Buffer_Release(vb);
19908 ID3D11InputLayout_Release(input_layout);
19909 release_test_context(&test_context);
19912 struct triangle
19914 struct vec4 v[3];
19917 #define check_triangles(buffer, triangles, count) check_triangles_(__LINE__, buffer, triangles, count)
19918 static void check_triangles_(unsigned int line, ID3D11Buffer *buffer,
19919 const struct triangle *triangles, unsigned int triangle_count)
19921 const struct triangle *current, *expected;
19922 struct resource_readback rb;
19923 unsigned int i, j, offset;
19924 BOOL all_match = TRUE;
19926 get_buffer_readback(buffer, &rb);
19928 for (i = 0; i < triangle_count; ++i)
19930 current = get_readback_data(&rb, i, 0, sizeof(*current));
19931 expected = &triangles[i];
19933 offset = ~0u;
19934 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
19936 if (compare_vec4(&current->v[0], &expected->v[j], 0))
19938 offset = j;
19939 break;
19943 if (offset == ~0u)
19945 all_match = FALSE;
19946 break;
19949 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
19951 if (!compare_vec4(&current->v[j], &expected->v[(j + offset) % 3], 0))
19953 all_match = FALSE;
19954 break;
19957 if (!all_match)
19958 break;
19961 ok_(__FILE__, line)(all_match, "Triangle %u vertices {%.8e, %.8e, %.8e, %.8e}, "
19962 "{%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e} "
19963 "do not match {%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e}, "
19964 "{%.8e, %.8e, %.8e, %.8e}.\n", i,
19965 current->v[0].x, current->v[0].y, current->v[0].z, current->v[0].w,
19966 current->v[1].x, current->v[1].y, current->v[1].z, current->v[1].w,
19967 current->v[2].x, current->v[2].y, current->v[2].z, current->v[2].w,
19968 expected->v[0].x, expected->v[0].y, expected->v[0].z, expected->v[0].w,
19969 expected->v[1].x, expected->v[1].y, expected->v[1].z, expected->v[1].w,
19970 expected->v[2].x, expected->v[2].y, expected->v[2].z, expected->v[2].w);
19972 release_resource_readback(&rb);
19975 static void test_quad_tessellation(void)
19977 #if 0
19978 struct point_data
19980 float4 position : SV_POSITION;
19983 struct patch_constant_data
19985 float edges[4] : SV_TessFactor;
19986 float inside[2] : SV_InsideTessFactor;
19989 float4 tess_factors;
19990 float2 inside_tess_factors;
19992 patch_constant_data patch_constant(InputPatch<point_data, 4> input)
19994 patch_constant_data output;
19996 output.edges[0] = tess_factors.x;
19997 output.edges[1] = tess_factors.y;
19998 output.edges[2] = tess_factors.z;
19999 output.edges[3] = tess_factors.w;
20000 output.inside[0] = inside_tess_factors.x;
20001 output.inside[1] = inside_tess_factors.y;
20003 return output;
20006 [domain("quad")]
20007 [outputcontrolpoints(4)]
20008 [outputtopology("triangle_ccw")]
20009 [partitioning("integer")]
20010 [patchconstantfunc("patch_constant")]
20011 point_data hs_main(InputPatch<point_data, 4> input,
20012 uint i : SV_OutputControlPointID)
20014 return input[i];
20017 [domain("quad")]
20018 point_data ds_main(patch_constant_data input,
20019 float2 tess_coord : SV_DomainLocation,
20020 const OutputPatch<point_data, 4> patch)
20022 point_data output;
20024 float4 a = lerp(patch[0].position, patch[1].position, tess_coord.x);
20025 float4 b = lerp(patch[2].position, patch[3].position, tess_coord.x);
20026 output.position = lerp(a, b, tess_coord.y);
20028 return output;
20030 #endif
20031 static const DWORD hs_quad_ccw_code[] =
20033 0x43425844, 0xdf8df700, 0x58b08fb1, 0xbd23d2c3, 0xcf884094, 0x00000001, 0x000002b8, 0x00000004,
20034 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
20035 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
20036 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20037 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
20038 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
20039 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
20040 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
20041 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
20042 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
20043 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
20044 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
20045 0x01002097, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
20046 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
20047 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
20048 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20049 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
20050 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
20051 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20052 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
20053 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
20054 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
20056 static const DWORD ds_quad_code[] =
20058 0x43425844, 0xeb6b7631, 0x07f5469e, 0xed0cbf4a, 0x7158b3a6, 0x00000001, 0x00000284, 0x00000004,
20059 0x00000030, 0x00000064, 0x00000128, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
20060 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
20061 0x004e4f49, 0x47534350, 0x000000bc, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b,
20062 0x00000003, 0x00000000, 0x00000001, 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001,
20063 0x00000001, 0x00000098, 0x00000002, 0x0000000b, 0x00000003, 0x00000002, 0x00000001, 0x00000098,
20064 0x00000003, 0x0000000b, 0x00000003, 0x00000003, 0x00000001, 0x000000a6, 0x00000000, 0x0000000c,
20065 0x00000003, 0x00000004, 0x00000001, 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005,
20066 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365,
20067 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
20068 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853,
20069 0x00000120, 0x00040050, 0x00000048, 0x01002093, 0x01001895, 0x0100086a, 0x0200005f, 0x0001c032,
20070 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20071 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, 0x80219e46, 0x00000041, 0x00000002,
20072 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, 0x001000f2, 0x00000000, 0x0001c006,
20073 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, 0x0a000000, 0x001000f2, 0x00000001,
20074 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, 0x00000001, 0x00000000, 0x09000032,
20075 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, 0x00219e46, 0x00000000, 0x00000000,
20076 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x80100e46, 0x00000041, 0x00000001,
20077 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
20078 0x0100003e,
20080 #if 0
20082 [outputtopology("triangle_cw")]
20084 #endif
20085 static const DWORD hs_quad_cw_code[] =
20087 0x43425844, 0x1ab30cc8, 0x94174771, 0x61f4cdd0, 0xa287f62c, 0x00000001, 0x000002b8, 0x00000004,
20088 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
20089 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
20090 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20091 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
20092 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
20093 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
20094 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
20095 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
20096 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
20097 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
20098 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
20099 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
20100 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
20101 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
20102 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20103 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
20104 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
20105 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20106 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
20107 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
20108 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
20110 #if 0
20111 struct point_data
20113 float4 pos : SV_POSITION;
20116 [maxvertexcount(3)]
20117 void main(triangle point_data vin[3], inout TriangleStream<point_data> vout)
20119 for (uint i = 0; i < 3; ++i)
20120 vout.Append(vin[i]);
20122 #endif
20123 static const DWORD gs_code[] =
20125 0x43425844, 0x8e49d18d, 0x6d08d6e5, 0xb7015628, 0xf9351fdd, 0x00000001, 0x00000164, 0x00000003,
20126 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
20127 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
20128 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
20129 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000000c8, 0x00020040,
20130 0x00000032, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068, 0x00000001,
20131 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000003,
20132 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
20133 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010001a, 0x00000000,
20134 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x01000013,
20135 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016,
20136 0x0100003e,
20138 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
20140 {0, "SV_POSITION", 0, 0, 4, 0},
20142 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20143 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
20144 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
20145 static const BYTE zero_data[1024];
20146 static const struct triangle expected_quad_ccw[] =
20148 {{{-1.0f, -1.0f, 0.0f, 1.0f},
20149 { 1.0f, -1.0f, 0.0f, 1.0f},
20150 {-1.0f, 1.0f, 0.0f, 1.0f}}},
20151 {{{-1.0f, 1.0f, 0.0f, 1.0f},
20152 { 1.0f, -1.0f, 0.0f, 1.0f},
20153 { 1.0f, 1.0f, 0.0f, 1.0f}}},
20154 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
20155 { 0.0f, 0.0f, 0.0f, 0.0f},
20156 { 0.0f, 0.0f, 0.0f, 0.0f}}},
20158 static const struct triangle expected_quad_cw[] =
20160 {{{-1.0f, -1.0f, 0.0f, 1.0f},
20161 {-1.0f, 1.0f, 0.0f, 1.0f},
20162 { 1.0f, -1.0f, 0.0f, 1.0f}}},
20163 {{{-1.0f, 1.0f, 0.0f, 1.0f},
20164 { 1.0f, 1.0f, 0.0f, 1.0f},
20165 { 1.0f, -1.0f, 0.0f, 1.0f}}},
20166 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
20167 { 0.0f, 0.0f, 0.0f, 0.0f},
20168 { 0.0f, 0.0f, 0.0f, 0.0f}}},
20170 struct
20172 float tess_factors[4];
20173 float inside_tess_factors[2];
20174 DWORD padding[2];
20175 } constant;
20177 D3D11_QUERY_DATA_SO_STATISTICS so_statistics;
20178 struct d3d11_test_context test_context;
20179 ID3D11DeviceContext *context;
20180 ID3D11Buffer *cb, *so_buffer;
20181 D3D11_QUERY_DESC query_desc;
20182 ID3D11Asynchronous *query;
20183 ID3D11GeometryShader *gs;
20184 ID3D11DomainShader *ds;
20185 const UINT offset = 0;
20186 ID3D11HullShader *hs;
20187 ID3D11Device *device;
20188 unsigned int i;
20189 HRESULT hr;
20191 if (!init_test_context(&test_context, &feature_level))
20192 return;
20194 device = test_context.device;
20195 context = test_context.immediate_context;
20197 draw_color_quad(&test_context, &white);
20198 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20200 set_quad_color(&test_context, &green);
20201 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
20203 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
20204 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
20205 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0, NULL, &gs);
20206 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
20207 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
20209 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
20210 constant.tess_factors[i] = 1.0f;
20211 for (i = 0; i < ARRAY_SIZE(constant.inside_tess_factors); ++i)
20212 constant.inside_tess_factors[i] = 1.0f;
20213 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
20214 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb);
20215 hr = ID3D11Device_CreateHullShader(device, hs_quad_ccw_code, sizeof(hs_quad_ccw_code), NULL, &hs);
20216 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
20217 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
20218 hr = ID3D11Device_CreateDomainShader(device, ds_quad_code, sizeof(ds_quad_code), NULL, &ds);
20219 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
20220 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
20222 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20223 ID3D11DeviceContext_Draw(context, 4, 0);
20224 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20225 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
20226 check_triangles(so_buffer, expected_quad_ccw, ARRAY_SIZE(expected_quad_ccw));
20228 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
20230 ID3D11HullShader_Release(hs);
20231 hr = ID3D11Device_CreateHullShader(device, hs_quad_cw_code, sizeof(hs_quad_cw_code), NULL, &hs);
20232 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
20233 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
20235 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20236 ID3D11DeviceContext_Draw(context, 4, 0);
20237 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20238 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
20239 check_triangles(so_buffer, expected_quad_cw, ARRAY_SIZE(expected_quad_cw));
20241 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
20243 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20244 query_desc.Query = D3D11_QUERY_SO_STATISTICS_STREAM0;
20245 query_desc.MiscFlags = 0;
20246 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
20247 ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
20248 ID3D11DeviceContext_Begin(context, query);
20250 set_quad_color(&test_context, &white);
20251 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
20252 constant.tess_factors[i] = 2.0f;
20253 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20254 ID3D11DeviceContext_Draw(context, 4, 0);
20255 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20257 set_quad_color(&test_context, &green);
20258 constant.tess_factors[0] = 0.0f; /* A patch is discarded. */
20259 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20260 ID3D11DeviceContext_Draw(context, 4, 0);
20261 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20263 ID3D11DeviceContext_End(context, query);
20264 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
20265 ok(so_statistics.NumPrimitivesWritten == 8, "Got unexpected primitives written %u.\n",
20266 (unsigned int)so_statistics.NumPrimitivesWritten);
20267 ok(so_statistics.PrimitivesStorageNeeded == 8, "Got unexpected primitives storage needed %u.\n",
20268 (unsigned int)so_statistics.PrimitivesStorageNeeded);
20269 ID3D11DeviceContext_Begin(context, query);
20271 constant.tess_factors[0] = 5.0f;
20272 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20273 ID3D11DeviceContext_Draw(context, 4, 0);
20274 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20276 ID3D11DeviceContext_End(context, query);
20277 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
20278 ok(so_statistics.NumPrimitivesWritten == 11, "Got unexpected primitives written %u.\n",
20279 (unsigned int)so_statistics.NumPrimitivesWritten);
20280 ok(so_statistics.PrimitivesStorageNeeded == 11, "Got unexpected primitives storage needed %u.\n",
20281 (unsigned int)so_statistics.PrimitivesStorageNeeded);
20282 ID3D11Asynchronous_Release(query);
20284 ID3D11Buffer_Release(so_buffer);
20285 ID3D11GeometryShader_Release(gs);
20286 ID3D11DomainShader_Release(ds);
20287 ID3D11HullShader_Release(hs);
20288 ID3D11Buffer_Release(cb);
20289 release_test_context(&test_context);
20292 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
20293 static void check_so_desc_(unsigned int line, ID3D11Device *device,
20294 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
20295 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
20296 unsigned int rasterizer_stream)
20298 ID3D11GeometryShader *gs;
20299 HRESULT hr;
20301 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
20302 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
20303 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
20304 if (SUCCEEDED(hr))
20305 ID3D11GeometryShader_Release(gs);
20308 #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)
20309 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
20310 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
20311 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
20312 unsigned int rasterizer_stream)
20314 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
20315 HRESULT hr;
20317 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
20318 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
20319 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
20320 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
20321 if (SUCCEEDED(hr))
20322 ID3D11GeometryShader_Release(gs);
20325 static void test_stream_output(void)
20327 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
20328 struct d3d11_test_context test_context;
20329 unsigned int i, count;
20330 ID3D11Device *device;
20332 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20333 static const DWORD vs_code[] =
20335 #if 0
20336 struct data
20338 float4 position : SV_Position;
20339 float4 attrib1 : ATTRIB1;
20340 float3 attrib2 : attrib2;
20341 float2 attrib3 : ATTriB3;
20342 float attrib4 : ATTRIB4;
20345 void main(in data i, out data o)
20347 o = i;
20349 #endif
20350 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
20351 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20352 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20353 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20354 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20355 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
20356 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20357 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20358 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20359 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20360 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20361 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20362 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
20363 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
20364 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20365 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20366 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
20367 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
20368 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
20369 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
20371 static const DWORD gs_code[] =
20373 #if 0
20374 struct data
20376 float4 position : SV_Position;
20377 float4 attrib1 : ATTRIB1;
20378 float3 attrib2 : attrib2;
20379 float2 attrib3 : ATTriB3;
20380 float attrib4 : ATTRIB4;
20383 [maxvertexcount(1)]
20384 void main(point data i[1], inout PointStream<data> o)
20386 o.Append(i[0]);
20388 #endif
20389 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
20390 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20391 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20392 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20393 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20394 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
20395 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20396 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20397 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20398 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20399 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20400 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20401 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
20402 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
20403 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
20404 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20405 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20406 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
20407 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
20408 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
20409 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
20411 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
20413 {0, "SV_Position", 0, 0, 4, 0},
20415 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
20417 {0, "SV_Position", 0, 0, 4, 0},
20418 {0, NULL, 0, 0, 0, 0},
20420 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
20422 /* SemanticName and SemanticIndex */
20424 {0, "sv_position", 0, 0, 4, 0},
20425 {0, "attrib", 1, 0, 4, 0},
20428 {0, "sv_position", 0, 0, 4, 0},
20429 {0, "ATTRIB", 1, 0, 4, 0},
20431 /* Gaps */
20433 {0, "SV_POSITION", 0, 0, 4, 0},
20434 {0, NULL, 0, 0, 8, 0},
20435 {0, "ATTRIB", 1, 0, 4, 0},
20438 {0, "SV_POSITION", 0, 0, 4, 0},
20439 {0, NULL, 0, 0, 4, 0},
20440 {0, NULL, 0, 0, 4, 0},
20441 {0, "ATTRIB", 1, 0, 4, 0},
20443 /* ComponentCount */
20445 {0, "ATTRIB", 1, 0, 4, 0},
20448 {0, "ATTRIB", 2, 0, 3, 0},
20451 {0, "ATTRIB", 3, 0, 2, 0},
20454 {0, "ATTRIB", 4, 0, 1, 0},
20456 /* ComponentIndex */
20458 {0, "ATTRIB", 1, 1, 3, 0},
20461 {0, "ATTRIB", 1, 2, 2, 0},
20464 {0, "ATTRIB", 1, 3, 1, 0},
20467 {0, "ATTRIB", 3, 1, 1, 0},
20469 /* OutputSlot */
20471 {0, "attrib", 1, 0, 4, 0},
20474 {0, "attrib", 1, 0, 4, 1},
20477 {0, "attrib", 1, 0, 4, 2},
20480 {0, "attrib", 1, 0, 4, 3},
20483 {0, "attrib", 1, 0, 4, 0},
20484 {0, "attrib", 2, 0, 3, 1},
20485 {0, NULL, 0, 0, 1, 1},
20486 {0, "attrib", 3, 0, 2, 2},
20487 {0, NULL, 0, 0, 2, 2},
20488 {0, "attrib", 4, 0, 1, 3},
20489 {0, NULL, 0, 0, 7, 3},
20492 {0, "attrib", 1, 0, 4, 0},
20493 {0, "attrib", 2, 0, 3, 1},
20494 {0, NULL, 0, 0, 1, 1},
20495 {0, "attrib", 3, 0, 2, 2},
20496 {0, NULL, 0, 0, 1, 2},
20497 {0, NULL, 0, 0, 1, 2},
20498 {0, "attrib", 4, 0, 1, 3},
20499 {0, NULL, 0, 0, 3, 3},
20500 {0, NULL, 0, 0, 1, 3},
20501 {0, NULL, 0, 0, 1, 3},
20502 {0, NULL, 0, 0, 1, 3},
20503 {0, NULL, 0, 0, 1, 3},
20506 {0, "attrib", 1, 0, 4, 0},
20507 {0, "attrib", 2, 0, 3, 0},
20508 {0, "attrib", 3, 0, 2, 0},
20509 {0, NULL, 0, 0, 1, 0},
20510 {0, "attrib", 4, 0, 1, 0},
20513 {0, "attrib", 1, 0, 4, 0},
20514 {0, "attrib", 2, 0, 3, 0},
20515 {0, "attrib", 3, 0, 2, 3},
20516 {0, NULL, 0, 0, 1, 3},
20517 {0, "attrib", 4, 0, 1, 3},
20519 /* Multiple occurrences of the same output */
20521 {0, "ATTRIB", 1, 0, 2, 0},
20522 {0, "ATTRIB", 1, 2, 2, 1},
20525 {0, "ATTRIB", 1, 0, 1, 0},
20526 {0, "ATTRIB", 1, 1, 3, 0},
20529 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
20531 /* SemanticName and SemanticIndex */
20533 {0, "SV_Position", 0, 0, 4, 0},
20534 {0, "ATTRIB", 0, 0, 4, 0},
20537 {0, "sv_position", 0, 0, 4, 0},
20538 {0, "ATTRIB_", 1, 0, 4, 0},
20540 /* Gaps */
20542 {0, "SV_POSITION", 0, 0, 4, 0},
20543 {0, NULL, 0, 1, 8, 0},
20544 {0, "ATTRIB", 1, 0, 4, 0},
20547 {0, "SV_POSITION", 0, 0, 4, 0},
20548 {0, NULL, 1, 0, 8, 0},
20549 {0, "ATTRIB", 1, 0, 4, 0},
20551 /* Buffer stride */
20553 {0, "SV_POSITION", 0, 0, 4, 0},
20554 {0, NULL, 0, 0, 8, 0},
20555 {0, NULL, 0, 0, 8, 0},
20556 {0, "ATTRIB", 1, 0, 4, 0},
20558 /* ComponentCount */
20560 {0, "ATTRIB", 2, 0, 5, 0},
20563 {0, "ATTRIB", 2, 0, 4, 0},
20566 {0, "ATTRIB", 3, 0, 3, 0},
20569 {0, "ATTRIB", 4, 0, 2, 0},
20571 /* ComponentIndex */
20573 {0, "ATTRIB", 1, 1, 4, 0},
20576 {0, "ATTRIB", 1, 2, 3, 0},
20579 {0, "ATTRIB", 1, 3, 2, 0},
20582 {0, "ATTRIB", 1, 4, 0, 0},
20585 {0, "ATTRIB", 1, 4, 1, 0},
20588 {0, "ATTRIB", 3, 2, 1, 0},
20591 {0, "ATTRIB", 3, 2, 0, 0},
20593 /* OutputSlot */
20595 {0, "attrib", 1, 0, 4, 4},
20598 {0, "attrib", 1, 0, 4, 4},
20601 {0, "attrib", 1, 0, 4, 4},
20604 {0, "attrib", 1, 0, 4, 4},
20607 {0, "attrib", 1, 0, 4, 0},
20608 {0, "attrib", 2, 0, 3, 1},
20609 {0, NULL, 0, 0, 1, 1},
20610 {0, "attrib", 3, 0, 2, 2},
20611 {0, NULL, 0, 0, 2, 2},
20612 {0, "attrib", 4, 0, 1, 3},
20613 {0, NULL, 0, 0, 3, 4},
20616 {0, "attrib", 1, 0, 4, 0},
20617 {0, "attrib", 2, 0, 3, 0},
20618 {0, "attrib", 3, 0, 2, 0},
20619 {0, NULL, 0, 0, 1, 0},
20620 {0, "attrib", 4, 0, 1, 0},
20621 {0, NULL, 0, 0, 3, 3},
20622 {0, NULL, 0, 0, 1, 3},
20623 {0, NULL, 0, 0, 1, 3},
20624 {0, NULL, 0, 0, 1, 3},
20625 {0, NULL, 0, 0, 1, 3},
20628 {0, "attrib", 1, 0, 4, 0},
20629 {0, NULL, 0, 0, 3, 1},
20630 {0, NULL, 0, 0, 1, 1},
20631 {0, NULL, 0, 0, 1, 2},
20632 {0, "attrib", 2, 0, 3, 3},
20633 {0, NULL, 0, 0, 1, 3},
20636 {0, "attrib", 2, 0, 3, 3},
20637 {0, NULL, 0, 0, 3, 1},
20638 {0, NULL, 0, 0, 1, 3},
20639 {0, "attrib", 1, 0, 4, 0},
20640 {0, NULL, 0, 0, 1, 2},
20641 {0, NULL, 0, 0, 1, 1},
20643 /* Stream */
20645 {1, "attrib", 1, 0, 4, 0},
20648 {4, "attrib", 1, 0, 4, 0},
20650 /* Multiple occurrences of the same output */
20652 {0, "ATTRIB", 1, 0, 4, 0},
20653 {0, "ATTRIB", 1, 0, 4, 1},
20656 {0, "ATTRIB", 1, 0, 4, 0},
20657 {0, "ATTRIB", 1, 0, 3, 0},
20661 if (!init_test_context(&test_context, &feature_level))
20662 return;
20664 device = test_context.device;
20666 for (i = 0; i < ARRAY_SIZE(stride); ++i)
20667 stride[i] = 64;
20669 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20670 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20671 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20672 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20673 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20674 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20676 todo_wine
20677 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
20678 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20679 todo_wine
20680 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
20681 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20683 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
20684 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20685 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
20686 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
20687 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20689 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
20690 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20691 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
20692 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20694 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
20696 unsigned int max_output_slot = 0;
20697 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
20699 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
20700 max_output_slot = max(max_output_slot, e->OutputSlot);
20701 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
20702 break;
20705 /* Buffer strides are required for all buffers. */
20706 if (!max_output_slot)
20708 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20709 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20710 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20711 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20712 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20713 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20714 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20715 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
20716 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20717 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
20719 else
20721 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20722 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20723 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20724 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
20728 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
20730 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
20732 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
20733 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
20734 break;
20737 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20738 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20739 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20740 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20741 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20742 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
20743 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20744 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
20747 /* Buffer strides */
20748 stride[1] = 63;
20749 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20750 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
20751 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20752 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20753 stride[1] = 1;
20754 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20755 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20756 stride[0] = 0;
20757 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20758 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20760 /* Rasterizer stream */
20761 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
20762 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
20763 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20764 NULL, 0, D3D11_SO_STREAM_COUNT);
20766 release_test_context(&test_context);
20769 static void test_fl10_stream_output_desc(void)
20771 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
20772 struct d3d11_test_context test_context;
20773 unsigned int i, count;
20774 ID3D11Device *device;
20776 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
20777 static const DWORD vs_code[] =
20779 #if 0
20780 struct data
20782 float4 position : SV_Position;
20783 float4 attrib1 : ATTRIB1;
20784 float3 attrib2 : attrib2;
20785 float2 attrib3 : ATTriB3;
20786 float attrib4 : ATTRIB4;
20789 void main(in data i, out data o)
20791 o = i;
20793 #endif
20794 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
20795 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20796 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20797 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20798 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20799 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
20800 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20801 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20802 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20803 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20804 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20805 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20806 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
20807 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
20808 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20809 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20810 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
20811 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
20812 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
20813 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
20815 static const DWORD gs_code[] =
20817 #if 0
20818 struct data
20820 float4 position : SV_Position;
20821 float4 attrib1 : ATTRIB1;
20822 float3 attrib2 : attrib2;
20823 float2 attrib3 : ATTriB3;
20824 float attrib4 : ATTRIB4;
20827 [maxvertexcount(1)]
20828 void main(point data i[1], inout PointStream<data> o)
20830 o.Append(i[0]);
20832 #endif
20833 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
20834 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20835 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20836 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20837 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20838 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
20839 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20840 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20841 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20842 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20843 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20844 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20845 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
20846 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
20847 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
20848 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20849 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20850 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
20851 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
20852 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
20853 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
20855 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
20857 {0, "SV_Position", 0, 0, 4, 0},
20859 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
20861 {0, "SV_Position", 0, 0, 4, 0},
20862 {0, NULL, 0, 0, 0, 0},
20864 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
20866 /* Gaps */
20868 {0, "SV_POSITION", 0, 0, 4, 0},
20869 {0, NULL, 0, 0, 8, 0},
20870 {0, "ATTRIB", 1, 0, 4, 0},
20873 {0, "SV_POSITION", 0, 0, 4, 0},
20874 {0, NULL, 0, 0, 4, 0},
20875 {0, NULL, 0, 0, 4, 0},
20876 {0, "ATTRIB", 1, 0, 4, 0},
20878 /* OutputSlot */
20880 {0, "attrib", 1, 0, 4, 0},
20881 {0, "attrib", 2, 0, 3, 0},
20882 {0, "attrib", 3, 0, 2, 0},
20883 {0, "attrib", 4, 0, 1, 0},
20886 {0, "attrib", 1, 0, 4, 0},
20887 {0, "attrib", 2, 0, 3, 1},
20888 {0, "attrib", 3, 0, 2, 2},
20889 {0, "attrib", 4, 0, 1, 3},
20892 {0, "attrib", 1, 0, 4, 0},
20893 {0, "attrib", 2, 0, 3, 3},
20896 {0, "attrib", 1, 0, 4, 0},
20897 {0, "attrib", 2, 0, 3, 0},
20898 {0, "attrib", 3, 0, 2, 0},
20899 {0, NULL, 0, 0, 1, 0},
20900 {0, "attrib", 4, 0, 1, 0},
20902 /* Multiple occurrences of the same output */
20904 {0, "ATTRIB", 1, 0, 2, 0},
20905 {0, "ATTRIB", 1, 2, 2, 1},
20908 {0, "ATTRIB", 1, 0, 1, 0},
20909 {0, "ATTRIB", 1, 1, 3, 0},
20912 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
20914 /* OutputSlot */
20916 {0, "attrib", 1, 0, 4, 0},
20917 {0, NULL, 0, 0, 4, 0},
20918 {0, "attrib", 4, 0, 1, 3},
20921 {0, "attrib", 1, 0, 4, 0},
20922 {0, NULL, 0, 0, 4, 0},
20923 {0, NULL, 0, 0, 4, 0},
20924 {0, "attrib", 4, 0, 1, 3},
20927 {0, "attrib", 1, 0, 4, 0},
20928 {0, "attrib", 2, 0, 3, 0},
20929 {0, "attrib", 3, 0, 2, 0},
20930 {0, "attrib", 4, 0, 1, 1},
20933 {0, "attrib", 1, 0, 4, 0},
20934 {0, "attrib", 2, 0, 3, 0},
20935 {0, "attrib", 3, 0, 2, 3},
20936 {0, NULL, 0, 0, 1, 3},
20937 {0, "attrib", 4, 0, 1, 3},
20940 {0, "attrib", 1, 0, 4, 0},
20941 {0, "attrib", 1, 0, 3, 1},
20942 {0, "attrib", 1, 0, 2, 2},
20943 {0, "attrib", 1, 0, 1, 3},
20944 {0, NULL, 0, 0, 3, 3},
20948 if (!init_test_context(&test_context, &feature_level))
20949 return;
20951 device = test_context.device;
20953 for (i = 0; i < ARRAY_SIZE(stride); ++i)
20954 stride[i] = 64;
20956 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
20957 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
20958 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
20959 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
20961 todo_wine
20962 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
20963 todo_wine
20964 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
20966 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
20967 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
20968 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
20969 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
20970 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
20972 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
20973 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
20975 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
20977 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
20979 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
20980 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
20981 break;
20984 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
20987 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
20989 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
20991 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
20992 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
20993 break;
20996 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20997 stride, 1, 0);
20998 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20999 stride, 2, 0);
21000 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
21001 stride, 3, 0);
21002 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
21003 stride, 4, 0);
21006 /* Buffer strides */
21007 stride[1] = 63;
21008 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21009 &stride[1], 1, 0);
21010 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21011 stride, 2, 0);
21012 stride[0] = 0;
21013 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21014 stride, 1, 0);
21016 /* Rasterizer stream */
21017 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21018 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
21019 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
21020 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21021 NULL, 0, i);
21022 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
21024 release_test_context(&test_context);
21027 static void test_stream_output_resume(void)
21029 struct d3d11_test_context test_context;
21030 ID3D11Buffer *cb, *so_buffer, *buffer;
21031 unsigned int i, j, idx, offset;
21032 ID3D11DeviceContext *context;
21033 struct resource_readback rb;
21034 ID3D11GeometryShader *gs;
21035 const struct vec4 *data;
21036 ID3D11Device *device;
21037 HRESULT hr;
21039 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21040 static const DWORD gs_code[] =
21042 #if 0
21043 float4 constant;
21045 struct vertex
21047 float4 position : SV_POSITION;
21050 struct element
21052 float4 position : SV_POSITION;
21053 float4 so_output : so_output;
21056 [maxvertexcount(3)]
21057 void main(triangle vertex input[3], inout PointStream<element> output)
21059 element o;
21060 o.so_output = constant;
21061 o.position = input[0].position;
21062 output.Append(o);
21063 o.position = input[1].position;
21064 output.Append(o);
21065 o.position = input[2].position;
21066 output.Append(o);
21068 #endif
21069 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
21070 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21071 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
21072 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
21073 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
21074 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
21075 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
21076 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
21077 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
21078 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
21079 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
21080 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
21081 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
21082 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
21084 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
21086 {0, "so_output", 0, 0, 4, 0},
21088 static const struct vec4 constants[] =
21090 {0.5f, 0.250f, 0.0f, 0.0f},
21091 {0.0f, 0.125f, 0.0f, 1.0f},
21092 {1.0f, 1.000f, 1.0f, 0.0f}
21094 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
21095 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
21096 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
21098 if (!init_test_context(&test_context, &feature_level))
21099 return;
21101 device = test_context.device;
21102 context = test_context.immediate_context;
21104 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
21105 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
21106 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
21108 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
21109 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
21111 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21112 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
21114 offset = 0;
21115 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
21117 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
21118 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
21120 draw_color_quad(&test_context, &red);
21121 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
21123 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21124 draw_color_quad(&test_context, &green);
21125 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
21127 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
21128 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21129 draw_color_quad(&test_context, &red);
21130 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
21132 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21133 draw_color_quad(&test_context, &red);
21134 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
21136 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
21137 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21138 draw_color_quad(&test_context, &white);
21139 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
21141 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21142 draw_color_quad(&test_context, &green);
21143 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
21145 buffer = NULL;
21146 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
21147 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21148 draw_color_quad(&test_context, &white);
21149 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
21151 idx = 0;
21152 get_buffer_readback(so_buffer, &rb);
21153 for (i = 0; i < ARRAY_SIZE(constants); ++i)
21155 for (j = 0; j < 6; ++j) /* 2 triangles */
21157 data = get_readback_vec4(&rb, idx++, 0);
21158 ok(compare_vec4(data, &constants[i], 0),
21159 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
21160 data->x, data->y, data->z, data->w, idx, i, j);
21163 release_resource_readback(&rb);
21165 ID3D11Buffer_Release(cb);
21166 ID3D11Buffer_Release(so_buffer);
21167 ID3D11GeometryShader_Release(gs);
21168 release_test_context(&test_context);
21171 static void test_stream_output_components(void)
21173 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
21174 struct d3d11_test_context test_context;
21175 ID3D11InputLayout *input_layout[2];
21176 ID3D11Buffer *vb[2], *so_buffer;
21177 ID3D11DeviceContext *context;
21178 struct resource_readback rb;
21179 unsigned int stride, offset;
21180 ID3D11GeometryShader *gs;
21181 ID3D11VertexShader *vs;
21182 ID3D11PixelShader *ps;
21183 ID3D11Device *device;
21184 const float *result;
21185 unsigned int i, j;
21186 HRESULT hr;
21188 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21189 static const DWORD vs_code[] =
21191 #if 0
21192 struct vertex
21194 float4 position : POSITION;
21195 float4 color : COLOR;
21196 float4 color2 : COLOR2;
21199 void main(in vertex i, out vertex o)
21201 o = i;
21203 #endif
21204 0x43425844, 0x95991b76, 0x4898640b, 0xe36ad9d6, 0xfbfe78b4, 0x00000001, 0x00000194, 0x00000003,
21205 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
21206 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
21207 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
21208 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
21209 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
21210 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
21211 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
21212 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
21213 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
21214 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
21215 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
21216 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
21218 static const DWORD gs_code[] =
21220 #if 0
21221 struct vertex
21223 float4 position : POSITION;
21224 float4 color : COLOR;
21225 float4 color2 : COLOR2;
21228 [maxvertexcount(1)]
21229 void main(point vertex input[1], inout PointStream<vertex> output)
21231 output.Append(input[0]);
21233 #endif
21234 0x43425844, 0x218f7d27, 0x555fa7f1, 0x282c545f, 0x3989c843, 0x00000001, 0x000001c0, 0x00000003,
21235 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
21236 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
21237 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
21238 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
21239 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
21240 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
21241 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
21242 0x000000bc, 0x00020040, 0x0000002f, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x0400005f,
21243 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000002, 0x0100085d,
21244 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x03000065,
21245 0x001020f2, 0x00000002, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
21246 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001,
21247 0x06000036, 0x001020f2, 0x00000002, 0x00201e46, 0x00000000, 0x00000002, 0x01000013, 0x0100003e,
21249 static const DWORD ps_code[] =
21251 #if 0
21252 float4 main(float4 position : SV_Position,
21253 float2 texcoord : TEXCOORD) : SV_Target
21255 return float4(position.xy, texcoord);
21257 #endif
21258 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
21259 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
21260 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
21261 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
21262 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
21263 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
21264 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
21265 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
21266 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
21268 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
21270 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
21271 {"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
21272 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
21274 static const D3D11_INPUT_ELEMENT_DESC layout_desc2[] =
21276 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
21277 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
21278 {"COLOR", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
21280 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
21282 {0, "POSITION", 0, 0, 4, 0},
21283 {0, "COLOR", 0, 0, 3, 0},
21284 {0, "COLOR", 2, 0, 2, 0},
21286 static const D3D11_SO_DECLARATION_ENTRY so_declaration2[] =
21288 {0, "POSITION", 0, 0, 1, 0},
21289 {0, "POSITION", 0, 1, 1, 0},
21290 {0, "POSITION", 0, 2, 1, 0},
21291 {0, "POSITION", 0, 3, 1, 0},
21292 {0, "COLOR", 0, 0, 1, 0},
21293 {0, "COLOR", 0, 1, 1, 0},
21294 {0, "COLOR", 0, 2, 1, 0},
21295 {0, "COLOR", 2, 0, 1, 0},
21296 {0, "COLOR", 2, 1, 1, 0},
21298 static const D3D11_SO_DECLARATION_ENTRY so_declaration3[] =
21300 {0, "COLOR", 0, 2, 2, 0},
21301 {0, "COLOR", 2, 3, 1, 0},
21303 static const struct
21305 struct vec4 position;
21306 struct vec3 color;
21307 struct vec2 color2;
21309 vb_data[] =
21311 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.5f, 1.0f}},
21312 {{-1.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
21313 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f}, {0.5f, 0.4f}},
21314 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.1f, 0.6f}},
21316 static const struct
21318 struct vec4 position;
21319 struct vec4 color;
21320 struct vec4 color2;
21322 vb_data2[] =
21324 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
21325 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
21326 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
21327 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
21329 static const unsigned int vb_stride[] = {sizeof(*vb_data), sizeof(*vb_data2)};
21330 static const float expected_data[] =
21332 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f,
21333 -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
21334 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, 0.4f,
21335 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.1f, 0.6f,
21337 static const float expected_data2[] =
21339 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
21340 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
21341 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
21342 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
21344 static const float expected_data3[] =
21346 3.0f, 4.0f, 8.0f, 1.2f, 1.3f, 1.7f, 2.0f, 2.1f, 2.5f, 2.7f, 2.8f, 3.2f,
21348 static const struct
21350 BOOL with_ps;
21351 unsigned int vb_idx;
21352 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
21353 unsigned int so_entry_count;
21354 const float *expected_data;
21355 unsigned int expected_data_size;
21357 tests[] =
21359 {TRUE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
21360 {TRUE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
21361 {TRUE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
21362 {TRUE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
21363 {TRUE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
21365 {FALSE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
21366 {FALSE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
21367 {FALSE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
21368 {FALSE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
21369 {FALSE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
21372 if (!init_test_context(&test_context, &feature_level))
21373 return;
21375 device = test_context.device;
21376 context = test_context.immediate_context;
21378 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
21379 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data2), vb_data2);
21381 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
21382 vs_code, sizeof(vs_code), &input_layout[0]);
21383 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
21384 hr = ID3D11Device_CreateInputLayout(device, layout_desc2, ARRAY_SIZE(layout_desc2),
21385 vs_code, sizeof(vs_code), &input_layout[1]);
21386 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
21388 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
21389 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
21390 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
21391 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21393 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
21394 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
21396 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
21398 gs = NULL;
21399 current_so_declaration = NULL;
21400 for (i = 0; i < ARRAY_SIZE(tests); ++i)
21402 ID3D11DeviceContext_PSSetShader(context, tests[i].with_ps ? ps : NULL, NULL, 0);
21404 if (current_so_declaration != tests[i].so_declaration)
21406 if (gs)
21407 ID3D11GeometryShader_Release(gs);
21409 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
21410 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
21411 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
21412 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
21413 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21414 current_so_declaration = tests[i].so_declaration;
21417 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].vb_idx]);
21418 stride = vb_stride[tests[i].vb_idx];
21419 offset = 0;
21420 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[tests[i].vb_idx], &stride, &offset);
21422 offset = 0;
21423 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
21425 ID3D11DeviceContext_Draw(context, 4, 0);
21427 get_buffer_readback(so_buffer, &rb);
21428 result = rb.map_desc.pData;
21429 for (j = 0; j < tests[i].expected_data_size; ++j)
21431 float expected_value = tests[i].expected_data[j];
21432 ok(compare_float(result[j], expected_value, 2),
21433 "Test %u: Got %.8e, expected %.8e at %u.\n",
21434 i, result[j], expected_value, j);
21436 release_resource_readback(&rb);
21439 for (i = 0; i < ARRAY_SIZE(vb); ++i)
21440 ID3D11Buffer_Release(vb[i]);
21441 ID3D11Buffer_Release(so_buffer);
21442 ID3D11VertexShader_Release(vs);
21443 ID3D11GeometryShader_Release(gs);
21444 ID3D11PixelShader_Release(ps);
21445 for (i = 0; i < ARRAY_SIZE(input_layout); ++i)
21446 ID3D11InputLayout_Release(input_layout[i]);
21447 release_test_context(&test_context);
21450 static void test_gather(void)
21452 struct
21454 int width, height;
21455 int offset_x, offset_y;
21456 } constant;
21457 struct d3d11_test_context test_context;
21458 D3D11_TEXTURE2D_DESC texture_desc;
21459 ID3D11ShaderResourceView *srv;
21460 ID3D11Texture2D *texture, *rt;
21461 ID3D11DeviceContext *context;
21462 ID3D11RenderTargetView *rtv;
21463 struct resource_readback rb;
21464 ID3D11PixelShader *ps;
21465 ID3D11Device *device;
21466 unsigned int x, y;
21467 ID3D11Buffer *cb;
21468 HRESULT hr;
21470 static const DWORD gather4_code[] =
21472 #if 0
21473 SamplerState s;
21474 Texture2D<float4> t;
21476 int2 size;
21478 float4 main(float4 position : SV_Position) : SV_Target
21480 return t.Gather(s, position.xy / size);
21482 #endif
21483 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
21484 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21485 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21486 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21487 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
21488 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21489 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21490 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21491 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21492 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
21493 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
21495 static const DWORD gather4_offset_code[] =
21497 #if 0
21498 SamplerState s;
21499 Texture2D<float4> t;
21501 int2 size;
21503 float4 main(float4 position : SV_Position) : SV_Target
21505 return t.Gather(s, position.xy / size, int2(1, 1));
21507 #endif
21508 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
21509 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21510 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21511 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21512 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
21513 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21514 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21515 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21516 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21517 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
21518 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
21520 static const DWORD gather4_green_code[] =
21522 #if 0
21523 SamplerState s;
21524 Texture2D<float4> t;
21526 int2 size;
21528 float4 main(float4 position : SV_Position) : SV_Target
21530 return t.GatherGreen(s, position.xy / size);
21532 #endif
21533 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
21534 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21535 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21536 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21537 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
21538 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21539 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21540 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21541 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21542 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21543 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
21545 static const DWORD gather4_po_code[] =
21547 #if 0
21548 SamplerState s;
21549 Texture2D<float4> t;
21551 int2 size;
21552 int2 offset;
21554 float4 main(float4 position : SV_Position) : SV_Target
21556 return t.Gather(s, position.xy / size, offset);
21558 #endif
21559 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
21560 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21561 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21562 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21563 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
21564 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21565 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21566 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21567 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21568 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21569 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
21570 0x00000000, 0x0100003e,
21572 static const struct vec4 texture_data[] =
21574 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
21575 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
21576 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
21577 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
21579 static const struct vec4 expected_gather4[] =
21581 {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},
21582 {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},
21583 {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},
21584 {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},
21586 static const struct vec4 expected_gather4_offset[] =
21588 {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},
21589 {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},
21590 {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},
21591 {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},
21593 static const struct vec4 expected_gather4_green[] =
21595 {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},
21596 {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},
21597 {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},
21598 {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},
21600 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
21601 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
21603 if (!init_test_context(&test_context, NULL))
21604 return;
21606 device = test_context.device;
21607 context = test_context.immediate_context;
21609 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
21611 skip("Shader model 4.1 required for gather4 instruction.\n");
21612 release_test_context(&test_context);
21613 return;
21616 texture_desc.Width = 4;
21617 texture_desc.Height = 4;
21618 texture_desc.MipLevels = 1;
21619 texture_desc.ArraySize = 1;
21620 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
21621 texture_desc.SampleDesc.Count = 1;
21622 texture_desc.SampleDesc.Quality = 0;
21623 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21624 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21625 texture_desc.CPUAccessFlags = 0;
21626 texture_desc.MiscFlags = 0;
21627 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
21628 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21629 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
21630 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
21631 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
21633 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
21634 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
21635 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21636 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
21637 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
21638 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
21640 constant.width = texture_desc.Width;
21641 constant.height = texture_desc.Height;
21642 constant.offset_x = 1;
21643 constant.offset_y = 1;
21644 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
21645 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
21647 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
21648 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21649 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21651 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21652 draw_quad(&test_context);
21653 get_texture_readback(rt, 0, &rb);
21654 for (y = 0; y < texture_desc.Height; ++y)
21656 for (x = 0; x < texture_desc.Width; ++x)
21658 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
21659 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21660 ok(compare_vec4(got, expected, 0),
21661 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21662 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21665 release_resource_readback(&rb);
21667 ID3D11PixelShader_Release(ps);
21668 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
21669 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21670 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21672 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21673 draw_quad(&test_context);
21674 get_texture_readback(rt, 0, &rb);
21675 for (y = 0; y < texture_desc.Height; ++y)
21677 for (x = 0; x < texture_desc.Width; ++x)
21679 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
21680 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21681 ok(compare_vec4(got, expected, 0),
21682 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21683 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21686 release_resource_readback(&rb);
21688 ID3D11PixelShader_Release(ps);
21690 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
21692 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
21693 goto done;
21696 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
21697 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21698 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21700 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21701 draw_quad(&test_context);
21702 get_texture_readback(rt, 0, &rb);
21703 for (y = 0; y < texture_desc.Height; ++y)
21705 for (x = 0; x < texture_desc.Width; ++x)
21707 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
21708 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21709 ok(compare_vec4(got, expected, 0),
21710 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21711 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21714 release_resource_readback(&rb);
21716 ID3D11PixelShader_Release(ps);
21717 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
21718 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21719 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21721 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21722 draw_quad(&test_context);
21723 get_texture_readback(rt, 0, &rb);
21724 for (y = 0; y < texture_desc.Height; ++y)
21726 for (x = 0; x < texture_desc.Width; ++x)
21728 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
21729 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21730 ok(compare_vec4(got, expected, 0),
21731 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21732 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21735 release_resource_readback(&rb);
21737 constant.offset_x = 0;
21738 constant.offset_y = 0;
21739 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
21740 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21741 draw_quad(&test_context);
21742 get_texture_readback(rt, 0, &rb);
21743 for (y = 0; y < texture_desc.Height; ++y)
21745 for (x = 0; x < texture_desc.Width; ++x)
21747 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
21748 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21749 ok(compare_vec4(got, expected, 0),
21750 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21751 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21754 release_resource_readback(&rb);
21756 ID3D11PixelShader_Release(ps);
21758 done:
21759 ID3D11Buffer_Release(cb);
21760 ID3D11Texture2D_Release(rt);
21761 ID3D11Texture2D_Release(texture);
21762 ID3D11RenderTargetView_Release(rtv);
21763 ID3D11ShaderResourceView_Release(srv);
21764 release_test_context(&test_context);
21767 static void test_gather_c(void)
21769 struct
21771 int width, height;
21772 int offset_x, offset_y;
21773 float compare_value;
21774 int padding[3];
21775 } constant;
21776 struct d3d11_test_context test_context;
21777 D3D11_TEXTURE2D_DESC texture_desc;
21778 D3D11_SAMPLER_DESC sampler_desc;
21779 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
21780 ID3D11ShaderResourceView *srv;
21781 ID3D11Texture2D *texture, *rt;
21782 ID3D11DeviceContext *context;
21783 ID3D11SamplerState *sampler;
21784 ID3D11RenderTargetView *rtv;
21785 struct resource_readback rb;
21786 ID3D11PixelShader *ps;
21787 ID3D11Device *device;
21788 unsigned int x, y;
21789 ID3D11Buffer *cb;
21790 HRESULT hr;
21792 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21793 static const DWORD gather4_c_code[] =
21795 #if 0
21796 SamplerComparisonState s;
21797 Texture2D<float4> t;
21799 int2 size;
21800 int2 offset;
21801 float compare;
21803 float4 main(float4 position : SV_Position) : SV_Target
21805 return t.GatherCmp(s, position.xy / size, compare);
21807 #endif
21808 0x43425844, 0xd3d04479, 0x901e9208, 0x7074fd0c, 0xbcadb2da, 0x00000001, 0x00000168, 0x00000003,
21809 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21810 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21811 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21812 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
21813 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
21814 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21815 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21816 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21817 0x00000000, 0x00100046, 0x00000000, 0x8e00007e, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21818 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0020800a, 0x00000000,
21819 0x00000001, 0x0100003e,
21821 static const DWORD gather4_po_c_code[] =
21823 #if 0
21824 SamplerComparisonState s;
21825 Texture2D<float4> t;
21827 int2 size;
21828 int2 offset;
21829 float compare;
21831 float4 main(float4 position : SV_Position) : SV_Target
21833 return t.GatherCmp(s, position.xy / size, compare, offset);
21835 #endif
21836 0x43425844, 0x501de13e, 0x472d2d20, 0x6df0fee4, 0xef27d9e6, 0x00000001, 0x00000174, 0x00000003,
21837 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21838 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21839 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21840 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d8, 0x00000050,
21841 0x00000036, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
21842 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21843 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21844 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21845 0x00000000, 0x00100046, 0x00000000, 0x91000080, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21846 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
21847 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
21849 static const float texture_data[] =
21851 0.00f, 0.10f, 0.20f, 0.30f,
21852 0.40f, 0.50f, 0.60f, 0.70f,
21853 0.80f, 0.90f, 0.05f, 0.15f,
21854 0.25f, 0.35f, 0.45f, 0.55f,
21856 static const struct vec4 expected_gather4_c[] =
21858 {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},
21859 {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},
21860 {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},
21861 {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},
21863 static const struct vec4 expected_gather4_po_c[] =
21865 {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},
21866 {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},
21867 {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},
21868 {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},
21870 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
21871 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
21873 if (!init_test_context(&test_context, &feature_level))
21874 return;
21876 device = test_context.device;
21877 context = test_context.immediate_context;
21879 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
21880 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
21881 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
21882 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
21883 sampler_desc.MipLODBias = 0.0f;
21884 sampler_desc.MaxAnisotropy = 0;
21885 sampler_desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
21886 sampler_desc.BorderColor[0] = 0.0f;
21887 sampler_desc.BorderColor[1] = 0.0f;
21888 sampler_desc.BorderColor[2] = 0.0f;
21889 sampler_desc.BorderColor[3] = 0.0f;
21890 sampler_desc.MinLOD = 0.0f;
21891 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
21893 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
21894 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
21895 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
21897 texture_desc.Width = 4;
21898 texture_desc.Height = 4;
21899 texture_desc.MipLevels = 1;
21900 texture_desc.ArraySize = 1;
21901 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
21902 texture_desc.SampleDesc.Count = 1;
21903 texture_desc.SampleDesc.Quality = 0;
21904 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21905 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21906 texture_desc.CPUAccessFlags = 0;
21907 texture_desc.MiscFlags = 0;
21908 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
21909 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21910 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
21911 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
21912 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
21914 constant.width = texture_desc.Width;
21915 constant.height = texture_desc.Height;
21916 constant.offset_x = 1;
21917 constant.offset_y = 1;
21918 constant.compare_value = 0.5f;
21919 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
21920 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
21922 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
21923 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
21924 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
21925 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21927 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
21928 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
21929 U(srv_desc).Texture2D.MostDetailedMip = 0;
21930 U(srv_desc).Texture2D.MipLevels = 1;
21931 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
21932 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
21933 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
21935 hr = ID3D11Device_CreatePixelShader(device, gather4_c_code, sizeof(gather4_c_code), NULL, &ps);
21936 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21937 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21939 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21940 draw_quad(&test_context);
21941 get_texture_readback(rt, 0, &rb);
21942 for (y = 0; y < texture_desc.Height; ++y)
21944 for (x = 0; x < texture_desc.Width; ++x)
21946 const struct vec4 *expected = &expected_gather4_c[y * texture_desc.Width + x];
21947 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21948 ok(compare_vec4(got, expected, 0),
21949 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21950 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21953 release_resource_readback(&rb);
21954 ID3D11PixelShader_Release(ps);
21956 hr = ID3D11Device_CreatePixelShader(device, gather4_po_c_code, sizeof(gather4_po_c_code), NULL, &ps);
21957 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21958 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21960 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21961 draw_quad(&test_context);
21962 get_texture_readback(rt, 0, &rb);
21963 for (y = 0; y < texture_desc.Height; ++y)
21965 for (x = 0; x < texture_desc.Width; ++x)
21967 const struct vec4 *expected = &expected_gather4_po_c[y * texture_desc.Width + x];
21968 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21969 ok(compare_vec4(got, expected, 0),
21970 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21971 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21974 release_resource_readback(&rb);
21975 ID3D11PixelShader_Release(ps);
21977 ID3D11ShaderResourceView_Release(srv);
21978 ID3D11Texture2D_Release(texture);
21980 ID3D11Buffer_Release(cb);
21981 ID3D11Texture2D_Release(rt);
21982 ID3D11RenderTargetView_Release(rtv);
21983 ID3D11SamplerState_Release(sampler);
21984 release_test_context(&test_context);
21987 static void test_fractional_viewports(void)
21989 struct d3d11_test_context test_context;
21990 D3D11_TEXTURE2D_DESC texture_desc;
21991 ID3D11InputLayout *input_layout;
21992 ID3D11DeviceContext *context;
21993 struct resource_readback rb;
21994 ID3D11RenderTargetView *rtv;
21995 ID3D11VertexShader *vs;
21996 ID3D11PixelShader *ps;
21997 unsigned int i, x, y;
21998 ID3D11Device *device;
21999 ID3D11Texture2D *rt;
22000 UINT offset, stride;
22001 D3D11_VIEWPORT vp;
22002 ID3D11Buffer *vb;
22003 HRESULT hr;
22005 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22006 static const DWORD vs_code[] =
22008 #if 0
22009 void main(in float4 in_position : POSITION,
22010 in float2 in_texcoord : TEXCOORD,
22011 out float4 position : SV_Position,
22012 out float2 texcoord : TEXCOORD)
22014 position = in_position;
22015 texcoord = in_texcoord;
22017 #endif
22018 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
22019 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
22020 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
22021 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
22022 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
22023 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
22024 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
22025 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
22026 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
22027 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
22028 0x00000001, 0x0100003e,
22030 static const DWORD ps_code[] =
22032 #if 0
22033 float4 main(float4 position : SV_Position,
22034 float2 texcoord : TEXCOORD) : SV_Target
22036 return float4(position.xy, texcoord);
22038 #endif
22039 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
22040 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
22041 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
22042 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
22043 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
22044 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
22045 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
22046 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
22047 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
22049 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
22051 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
22052 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
22054 static const struct
22056 struct vec2 position;
22057 struct vec2 texcoord;
22059 quad[] =
22061 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
22062 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
22063 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
22064 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
22066 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
22067 static const float viewport_offsets[] =
22069 0.0f, 0.5f, 0.25f, 0.125f, 0.0625f, 0.03125f, 0.015625f, 0.0078125f, 0.00390625f,
22070 1.0f / 128.0f, 63.0f / 128.0f,
22073 if (!init_test_context(&test_context, &feature_level))
22074 return;
22075 device = test_context.device;
22076 context = test_context.immediate_context;
22078 texture_desc.Width = 4;
22079 texture_desc.Height = 4;
22080 texture_desc.MipLevels = 1;
22081 texture_desc.ArraySize = 1;
22082 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
22083 texture_desc.SampleDesc.Count = 1;
22084 texture_desc.SampleDesc.Quality = 0;
22085 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22086 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
22087 texture_desc.CPUAccessFlags = 0;
22088 texture_desc.MiscFlags = 0;
22089 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
22090 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22091 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
22092 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
22093 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
22095 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
22096 vs_code, sizeof(vs_code), &input_layout);
22097 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
22098 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
22100 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
22101 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
22102 stride = sizeof(*quad);
22103 offset = 0;
22104 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
22106 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
22107 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
22108 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
22110 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22111 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22112 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22114 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
22116 vp.TopLeftX = viewport_offsets[i];
22117 vp.TopLeftY = viewport_offsets[i];
22118 vp.Width = texture_desc.Width;
22119 vp.Height = texture_desc.Height;
22120 vp.MinDepth = 0.0f;
22121 vp.MaxDepth = 1.0f;
22122 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
22123 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
22124 ID3D11DeviceContext_Draw(context, 4, 0);
22125 get_texture_readback(rt, 0, &rb);
22126 for (y = 0; y < texture_desc.Height; ++y)
22128 for (x = 0; x < texture_desc.Width; ++x)
22130 const struct vec4 *v = get_readback_vec4(&rb, x, y);
22131 struct vec4 expected = {x + 0.5f, y + 0.5f,
22132 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
22133 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
22134 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
22135 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
22136 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
22137 todo_wine
22138 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
22139 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
22140 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
22143 release_resource_readback(&rb);
22146 ID3D11InputLayout_Release(input_layout);
22147 ID3D11Buffer_Release(vb);
22148 ID3D11VertexShader_Release(vs);
22149 ID3D11PixelShader_Release(ps);
22150 ID3D11RenderTargetView_Release(rtv);
22151 ID3D11Texture2D_Release(rt);
22152 release_test_context(&test_context);
22155 static void test_early_depth_stencil(void)
22157 ID3D11DepthStencilState *depth_stencil_state;
22158 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
22159 ID3D11Texture2D *texture, *depth_texture;
22160 struct d3d11_test_context test_context;
22161 D3D11_TEXTURE2D_DESC texture_desc;
22162 ID3D11UnorderedAccessView *uav;
22163 ID3D11DeviceContext *context;
22164 ID3D11DepthStencilView *dsv;
22165 ID3D11PixelShader *ps;
22166 ID3D11Device *device;
22167 D3D11_VIEWPORT vp;
22168 HRESULT hr;
22170 static const DWORD ps_code[] =
22172 #if 0
22173 RWTexture2D<int> u;
22175 [earlydepthstencil]
22176 float4 main() : SV_Target
22178 InterlockedAdd(u[uint2(0, 0)], 1);
22179 return float4(1.0f, 1.0f, 1.0f, 1.0f);
22181 #endif
22182 0x43425844, 0xda4325ad, 0xc01d3815, 0xfd610cc9, 0x8ed1e351, 0x00000001, 0x000000ec, 0x00000003,
22183 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22184 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22185 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000074, 0x00000050, 0x0000001d,
22186 0x0100286a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x03000065, 0x001020f2, 0x00000000,
22187 0x0a0000ad, 0x0011e000, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
22188 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
22189 0x3f800000, 0x3f800000, 0x0100003e,
22191 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22192 static const UINT values[4] = {0};
22194 if (!init_test_context(&test_context, &feature_level))
22195 return;
22197 device = test_context.device;
22198 context = test_context.immediate_context;
22200 depth_stencil_desc.DepthEnable = TRUE;
22201 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
22202 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
22203 depth_stencil_desc.StencilEnable = FALSE;
22204 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
22205 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
22207 texture_desc.Width = 1;
22208 texture_desc.Height = 1;
22209 texture_desc.MipLevels = 1;
22210 texture_desc.ArraySize = 1;
22211 texture_desc.Format = DXGI_FORMAT_R32_SINT;
22212 texture_desc.SampleDesc.Count = 1;
22213 texture_desc.SampleDesc.Quality = 0;
22214 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22215 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22216 texture_desc.CPUAccessFlags = 0;
22217 texture_desc.MiscFlags = 0;
22218 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22219 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22220 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
22221 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22223 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
22224 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
22225 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22226 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
22227 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
22228 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22229 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
22230 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
22232 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22233 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22234 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22236 memset(&vp, 0, sizeof(vp));
22237 vp.Width = 1.0f;
22238 vp.Height = 100.0f;
22239 vp.MinDepth = 0.5f;
22240 vp.MaxDepth = 0.5f;
22241 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
22242 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
22243 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
22244 1, &test_context.backbuffer_rtv, dsv, 1, 1, &uav, NULL);
22246 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
22248 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
22249 draw_quad(&test_context);
22250 check_texture_color(texture, 100, 1);
22251 draw_quad(&test_context);
22252 check_texture_color(texture, 200, 1);
22253 check_texture_float(depth_texture, 0.6f, 1);
22255 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.3f, 0);
22256 draw_quad(&test_context);
22257 draw_quad(&test_context);
22258 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.55f, 0);
22259 draw_quad(&test_context);
22260 check_texture_color(texture, 300, 1);
22262 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
22263 draw_quad(&test_context);
22264 check_texture_color(texture, 400, 1);
22265 check_texture_float(depth_texture, 0.5f, 1);
22267 ID3D11Texture2D_Release(depth_texture);
22268 ID3D11DepthStencilView_Release(dsv);
22269 ID3D11DepthStencilState_Release(depth_stencil_state);
22270 ID3D11PixelShader_Release(ps);
22271 ID3D11Texture2D_Release(texture);
22272 ID3D11UnorderedAccessView_Release(uav);
22273 release_test_context(&test_context);
22276 static void test_conservative_depth_output(void)
22278 struct shader
22280 const DWORD *code;
22281 size_t size;
22284 ID3D11DepthStencilState *depth_stencil_state;
22285 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
22286 struct d3d11_test_context test_context;
22287 const struct shader *current_shader;
22288 D3D11_TEXTURE2D_DESC texture_desc;
22289 ID3D11DeviceContext *context;
22290 ID3D11DepthStencilView *dsv;
22291 ID3D11Texture2D *texture;
22292 ID3D11PixelShader *ps;
22293 DWORD expected_color;
22294 float expected_depth;
22295 ID3D11Device *device;
22296 struct vec4 ps_depth;
22297 ID3D11Buffer *cb;
22298 unsigned int i;
22299 HRESULT hr;
22301 static const DWORD ps_depth_le_code[] =
22303 #if 0
22304 float depth;
22306 float4 main(out float out_depth : SV_DepthLessEqual) : SV_Target0
22308 out_depth = depth;
22309 return float4(0.0f, 1.0f, 0.f, 1.0f);
22311 #endif
22312 0x43425844, 0x045c8d00, 0xc49e2ebe, 0x76f6022a, 0xf6996ecc, 0x00000001, 0x00000108, 0x00000003,
22313 0x0000002c, 0x0000003c, 0x00000098, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22314 0x00000054, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22315 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
22316 0x65677261, 0x56530074, 0x7065445f, 0x654c6874, 0x71457373, 0x006c6175, 0x58454853, 0x00000068,
22317 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065,
22318 0x001020f2, 0x00000000, 0x02000065, 0x00027001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
22319 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00027001, 0x0020800a, 0x00000000,
22320 0x00000000, 0x0100003e,
22322 static const struct shader ps_depth_le = {ps_depth_le_code, sizeof(ps_depth_le_code)};
22323 static const DWORD ps_depth_ge_code[] =
22325 #if 0
22326 float depth;
22328 float4 main(out float out_depth : SV_DepthGreaterEqual) : SV_Target0
22330 out_depth = depth;
22331 return float4(0.0f, 1.0f, 0.f, 1.0f);
22333 #endif
22334 0x43425844, 0xd17af83e, 0xa32c01cc, 0x0d8e9665, 0xe6dc17c2, 0x00000001, 0x0000010c, 0x00000003,
22335 0x0000002c, 0x0000003c, 0x0000009c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22336 0x00000058, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22337 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
22338 0x65677261, 0x56530074, 0x7065445f, 0x72476874, 0x65746165, 0x75714572, 0xab006c61, 0x58454853,
22339 0x00000068, 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
22340 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x00026001, 0x08000036, 0x001020f2, 0x00000000,
22341 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00026001, 0x0020800a,
22342 0x00000000, 0x00000000, 0x0100003e,
22344 static const struct shader ps_depth_ge = {ps_depth_ge_code, sizeof(ps_depth_ge_code)};
22345 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22346 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
22347 static const struct
22349 const struct shader *ps;
22350 float vs_depth;
22351 float ps_depth;
22352 BOOL passes_depth_test;
22354 tests[] =
22356 {&ps_depth_le, 0.7f, 0.7f, TRUE},
22357 {&ps_depth_le, 0.7f, 0.4f, FALSE},
22358 {&ps_depth_le, 0.4f, 0.4f, FALSE},
22359 /* {&ps_depth_le, 0.4f, 0.6f, FALSE}, undefined result */
22360 {&ps_depth_ge, 0.7f, 0.7f, TRUE},
22361 /* {&ps_depth_ge, 0.7f, 0.4f, TRUE}, undefined result */
22362 {&ps_depth_ge, 0.4f, 0.4f, FALSE},
22363 {&ps_depth_ge, 0.4f, 0.6f, TRUE},
22366 if (!init_test_context(&test_context, &feature_level))
22367 return;
22369 device = test_context.device;
22370 context = test_context.immediate_context;
22372 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_depth), NULL);
22374 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
22375 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
22376 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22377 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
22378 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22379 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22380 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
22381 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
22383 depth_stencil_desc.DepthEnable = TRUE;
22384 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
22385 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_GREATER_EQUAL;
22386 depth_stencil_desc.StencilEnable = FALSE;
22387 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
22388 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
22390 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22391 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
22392 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
22394 ps = NULL;
22395 current_shader = NULL;
22396 for (i = 0; i < ARRAY_SIZE(tests); ++i)
22398 if (current_shader != tests[i].ps)
22400 if (ps)
22401 ID3D11PixelShader_Release(ps);
22403 current_shader = tests[i].ps;
22404 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
22405 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22406 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22409 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
22410 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
22411 ps_depth.x = tests[i].ps_depth;
22412 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_depth, 0, 0);
22413 draw_quad_z(&test_context, tests[i].vs_depth);
22415 expected_color = tests[i].passes_depth_test ? 0xff00ff00 : 0xffffffff;
22416 expected_depth = tests[i].passes_depth_test ? max(tests[i].vs_depth, tests[i].ps_depth) : 0.5f;
22417 check_texture_color(test_context.backbuffer, expected_color, 0);
22418 check_texture_float(texture, expected_depth, 1);
22421 ID3D11Buffer_Release(cb);
22422 ID3D11PixelShader_Release(ps);
22423 ID3D11DepthStencilView_Release(dsv);
22424 ID3D11DepthStencilState_Release(depth_stencil_state);
22425 ID3D11Texture2D_Release(texture);
22426 release_test_context(&test_context);
22429 static void test_format_compatibility(void)
22431 ID3D11Texture2D *dst_texture, *src_texture;
22432 D3D11_SUBRESOURCE_DATA resource_data;
22433 D3D11_TEXTURE2D_DESC texture_desc;
22434 ID3D11DeviceContext *context;
22435 struct resource_readback rb;
22436 DWORD colour, expected;
22437 ID3D11Device *device;
22438 unsigned int i, j;
22439 ULONG refcount;
22440 HRESULT hr;
22442 static const struct
22444 DXGI_FORMAT src_format;
22445 DXGI_FORMAT dst_format;
22446 size_t texel_size;
22447 BOOL success;
22449 test_data[] =
22451 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
22452 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
22453 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
22454 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
22455 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
22456 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
22457 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
22458 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
22459 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
22460 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
22461 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
22462 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
22463 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
22464 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
22465 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
22466 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
22467 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
22468 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
22469 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
22471 static const DWORD initial_data[16] = {0};
22472 static const DWORD bitmap_data[] =
22474 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
22475 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
22476 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
22477 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
22480 if (!(device = create_device(NULL)))
22482 skip("Failed to create device.\n");
22483 return;
22485 ID3D11Device_GetImmediateContext(device, &context);
22487 texture_desc.Height = 4;
22488 texture_desc.MipLevels = 1;
22489 texture_desc.ArraySize = 1;
22490 texture_desc.SampleDesc.Count = 1;
22491 texture_desc.SampleDesc.Quality = 0;
22492 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
22493 texture_desc.CPUAccessFlags = 0;
22494 texture_desc.MiscFlags = 0;
22496 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
22498 unsigned int x, y, texel_dwords;
22499 D3D11_BOX box;
22501 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
22502 texture_desc.Format = test_data[i].src_format;
22503 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
22505 resource_data.pSysMem = bitmap_data;
22506 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
22507 resource_data.SysMemSlicePitch = 0;
22509 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
22510 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
22512 texture_desc.Format = test_data[i].dst_format;
22513 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22515 resource_data.pSysMem = initial_data;
22517 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
22518 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
22520 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
22521 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0, 1, 1, 0,
22522 (ID3D11Resource *)src_texture, 0, &box);
22524 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
22525 get_texture_readback(dst_texture, 0, &rb);
22526 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
22528 x = j % 4;
22529 y = j / 4;
22530 colour = get_readback_color(&rb, x, y);
22531 expected = test_data[i].success && x >= texel_dwords && y
22532 ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
22533 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
22534 i, colour, x, y, expected);
22536 release_resource_readback(&rb);
22538 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
22540 get_texture_readback(dst_texture, 0, &rb);
22541 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
22543 x = j % 4;
22544 y = j / 4;
22545 colour = get_readback_color(&rb, x, y);
22546 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
22547 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
22548 i, colour, x, y, expected);
22550 release_resource_readback(&rb);
22552 ID3D11Texture2D_Release(dst_texture);
22553 ID3D11Texture2D_Release(src_texture);
22556 ID3D11DeviceContext_Release(context);
22557 refcount = ID3D11Device_Release(device);
22558 ok(!refcount, "Device has %u references left.\n", refcount);
22561 START_TEST(d3d11)
22563 test_create_device();
22564 run_for_each_feature_level(test_device_interfaces);
22565 test_get_immediate_context();
22566 test_create_texture2d();
22567 test_texture2d_interfaces();
22568 test_create_texture3d();
22569 test_texture3d_interfaces();
22570 test_create_buffer();
22571 test_create_depthstencil_view();
22572 test_depthstencil_view_interfaces();
22573 test_create_rendertarget_view();
22574 test_create_shader_resource_view();
22575 run_for_each_feature_level(test_create_shader);
22576 test_create_sampler_state();
22577 test_create_blend_state();
22578 test_create_depthstencil_state();
22579 test_create_rasterizer_state();
22580 test_create_query();
22581 test_occlusion_query();
22582 test_pipeline_statistics_query();
22583 test_timestamp_query();
22584 test_device_removed_reason();
22585 test_private_data();
22586 run_for_each_feature_level(test_state_refcounting);
22587 test_device_context_state();
22588 test_blend();
22589 test_texture();
22590 test_cube_maps();
22591 test_depth_stencil_sampling();
22592 test_sample_c_lz();
22593 test_multiple_render_targets();
22594 test_render_target_views();
22595 test_layered_rendering();
22596 test_scissor();
22597 test_clear_state();
22598 test_il_append_aligned();
22599 test_instance_id();
22600 test_fragment_coords();
22601 test_update_subresource();
22602 test_copy_subresource_region();
22603 test_resource_map();
22604 test_check_multisample_quality_levels();
22605 run_for_each_feature_level(test_swapchain_formats);
22606 test_swapchain_views();
22607 test_swapchain_flip();
22608 test_clear_render_target_view();
22609 test_clear_depth_stencil_view();
22610 test_clear_buffer_unordered_access_view();
22611 test_draw_depth_only();
22612 test_draw_uav_only();
22613 test_cb_relative_addressing();
22614 test_getdc();
22615 test_shader_stage_input_output_matching();
22616 test_shader_interstage_interface();
22617 test_sm4_if_instruction();
22618 test_sm4_breakc_instruction();
22619 test_sm4_continuec_instruction();
22620 test_sm4_discard_instruction();
22621 test_sm5_swapc_instruction();
22622 test_create_input_layout();
22623 test_input_assembler();
22624 test_null_sampler();
22625 test_check_feature_support();
22626 test_create_unordered_access_view();
22627 test_immediate_constant_buffer();
22628 test_fp_specials();
22629 test_uint_shader_instructions();
22630 test_index_buffer_offset();
22631 test_face_culling();
22632 test_line_antialiasing_blending();
22633 run_for_each_feature_level(test_required_format_support);
22634 run_for_each_9_x_feature_level(test_fl9_draw);
22635 test_ddy();
22636 test_shader_input_registers_limits();
22637 test_unbind_shader_resource_view();
22638 test_stencil_separate();
22639 test_uav_load();
22640 test_cs_uav_store();
22641 test_uav_store_immediate_constant();
22642 test_ps_cs_uav_binding();
22643 test_atomic_instructions();
22644 test_sm4_ret_instruction();
22645 test_primitive_restart();
22646 test_resinfo_instruction();
22647 test_sm5_bufinfo_instruction();
22648 test_render_target_device_mismatch();
22649 test_buffer_srv();
22650 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
22651 test_unaligned_raw_buffer_access);
22652 test_uav_counters();
22653 test_dispatch_indirect();
22654 test_compute_shader_registers();
22655 test_tgsm();
22656 test_geometry_shader();
22657 test_quad_tessellation();
22658 test_stream_output();
22659 test_fl10_stream_output_desc();
22660 test_stream_output_resume();
22661 test_stream_output_components();
22662 test_gather();
22663 test_gather_c();
22664 test_fractional_viewports();
22665 test_early_depth_stencil();
22666 test_conservative_depth_output();
22667 test_format_compatibility();