d3d11/tests: Add basic test for quad tessellation.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob91d5927acb18de90cbb714dd368a8788724f1513
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
3 * Copyright 2015 Józef Kucia for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <assert.h>
21 #include <float.h>
22 #include <stdlib.h>
23 #define COBJMACROS
24 #include "initguid.h"
25 #include "d3d11_1.h"
26 #include "wine/test.h"
27 #include <limits.h>
29 #ifndef ARRAY_SIZE
30 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
31 #endif
33 #define BITS_NNAN 0xffc00000
34 #define BITS_NAN 0x7fc00000
35 #define BITS_NINF 0xff800000
36 #define BITS_INF 0x7f800000
37 #define BITS_N1_0 0xbf800000
38 #define BITS_1_0 0x3f800000
40 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
42 struct format_support
44 DXGI_FORMAT format;
45 D3D_FEATURE_LEVEL fl_required;
46 D3D_FEATURE_LEVEL fl_optional;
49 static const struct format_support display_format_support[] =
51 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
52 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
53 {DXGI_FORMAT_B8G8R8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
54 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
55 {DXGI_FORMAT_R16G16B16A16_FLOAT, D3D_FEATURE_LEVEL_10_0},
56 {DXGI_FORMAT_R10G10B10A2_UNORM, D3D_FEATURE_LEVEL_10_0},
57 {DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0},
60 struct vec2
62 float x, y;
65 struct vec3
67 float x, y, z;
70 struct vec4
72 float x, y, z, w;
75 struct ivec4
77 int x, y, z, w;
80 struct uvec4
82 unsigned int x, y, z, w;
85 struct device_desc
87 const D3D_FEATURE_LEVEL *feature_level;
88 UINT flags;
91 struct swapchain_desc
93 BOOL windowed;
94 UINT buffer_count;
95 DXGI_SWAP_EFFECT swap_effect;
96 DWORD flags;
99 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
101 box->left = left;
102 box->top = top;
103 box->front = front;
104 box->right = right;
105 box->bottom = bottom;
106 box->back = back;
109 static ULONG get_refcount(void *iface)
111 IUnknown *unknown = iface;
112 IUnknown_AddRef(unknown);
113 return IUnknown_Release(unknown);
116 #define check_interface(a, b, c, d) check_interface_(__LINE__, a, b, c, d)
117 static HRESULT check_interface_(unsigned int line, void *iface, REFIID riid, BOOL supported, BOOL is_broken)
119 HRESULT hr, expected_hr, broken_hr;
120 IUnknown *unknown = iface, *out;
122 if (supported)
124 expected_hr = S_OK;
125 broken_hr = E_NOINTERFACE;
127 else
129 expected_hr = E_NOINTERFACE;
130 broken_hr = S_OK;
133 hr = IUnknown_QueryInterface(unknown, riid, (void **)&out);
134 ok_(__FILE__, line)(hr == expected_hr || broken(is_broken && hr == broken_hr),
135 "Got hr %#x, expected %#x.\n", hr, expected_hr);
136 if (SUCCEEDED(hr))
137 IUnknown_Release(out);
138 return hr;
141 static BOOL compare_float(float f, float g, unsigned int ulps)
143 int x = *(int *)&f;
144 int y = *(int *)&g;
146 if (x < 0)
147 x = INT_MIN - x;
148 if (y < 0)
149 y = INT_MIN - y;
151 if (abs(x - y) > ulps)
152 return FALSE;
154 return TRUE;
157 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
159 return compare_float(v1->x, v2->x, ulps)
160 && compare_float(v1->y, v2->y, ulps)
161 && compare_float(v1->z, v2->z, ulps)
162 && compare_float(v1->w, v2->w, ulps);
165 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
167 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
170 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
172 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
173 return FALSE;
174 c1 >>= 8; c2 >>= 8;
175 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
176 return FALSE;
177 c1 >>= 8; c2 >>= 8;
178 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
179 return FALSE;
180 c1 >>= 8; c2 >>= 8;
181 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
182 return FALSE;
183 return TRUE;
186 struct srv_desc
188 DXGI_FORMAT format;
189 D3D11_SRV_DIMENSION dimension;
190 unsigned int miplevel_idx;
191 unsigned int miplevel_count;
192 unsigned int layer_idx;
193 unsigned int layer_count;
196 static void get_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *d3d11_desc, const struct srv_desc *desc)
198 d3d11_desc->Format = desc->format;
199 d3d11_desc->ViewDimension = desc->dimension;
200 if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1D)
202 U(*d3d11_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
203 U(*d3d11_desc).Texture1D.MipLevels = desc->miplevel_count;
205 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1DARRAY)
207 U(*d3d11_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
208 U(*d3d11_desc).Texture1DArray.MipLevels = desc->miplevel_count;
209 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
210 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
212 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
214 U(*d3d11_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
215 U(*d3d11_desc).Texture2D.MipLevels = desc->miplevel_count;
217 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
219 U(*d3d11_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
220 U(*d3d11_desc).Texture2DArray.MipLevels = desc->miplevel_count;
221 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
222 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
224 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
226 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
227 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
229 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE3D)
231 U(*d3d11_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
232 U(*d3d11_desc).Texture3D.MipLevels = desc->miplevel_count;
234 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
236 U(*d3d11_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
237 U(*d3d11_desc).TextureCube.MipLevels = desc->miplevel_count;
239 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
241 U(*d3d11_desc).TextureCubeArray.MostDetailedMip = desc->miplevel_idx;
242 U(*d3d11_desc).TextureCubeArray.MipLevels = desc->miplevel_count;
243 U(*d3d11_desc).TextureCubeArray.First2DArrayFace = desc->layer_idx;
244 U(*d3d11_desc).TextureCubeArray.NumCubes = desc->layer_count;
246 else if (desc->dimension != D3D11_SRV_DIMENSION_UNKNOWN
247 && desc->dimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
249 trace("Unhandled view dimension %#x.\n", desc->dimension);
253 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
254 static void check_srv_desc_(unsigned int line, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc,
255 const struct srv_desc *expected_desc)
257 ok_(__FILE__, line)(desc->Format == expected_desc->format,
258 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
259 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
260 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
262 if (desc->ViewDimension != expected_desc->dimension)
263 return;
265 if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D)
267 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
268 "Got MostDetailedMip %u, expected %u.\n",
269 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
270 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
271 "Got MipLevels %u, expected %u.\n",
272 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
274 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
276 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
277 "Got MostDetailedMip %u, expected %u.\n",
278 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
279 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
280 "Got MipLevels %u, expected %u.\n",
281 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
282 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
283 "Got FirstArraySlice %u, expected %u.\n",
284 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
285 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
286 "Got ArraySize %u, expected %u.\n",
287 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
289 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
291 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
292 "Got FirstArraySlice %u, expected %u.\n",
293 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
294 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
295 "Got ArraySize %u, expected %u.\n",
296 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
298 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D)
300 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
301 "Got MostDetailedMip %u, expected %u.\n",
302 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
303 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
304 "Got MipLevels %u, expected %u.\n",
305 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
307 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
309 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
310 "Got MostDetailedMip %u, expected %u.\n",
311 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
312 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
313 "Got MipLevels %u, expected %u.\n",
314 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
316 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
318 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MostDetailedMip == expected_desc->miplevel_idx,
319 "Got MostDetailedMip %u, expected %u.\n",
320 U(*desc).TextureCubeArray.MostDetailedMip, expected_desc->miplevel_idx);
321 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MipLevels == expected_desc->miplevel_count,
322 "Got MipLevels %u, expected %u.\n",
323 U(*desc).TextureCubeArray.MipLevels, expected_desc->miplevel_count);
324 ok_(__FILE__, line)(U(*desc).TextureCubeArray.First2DArrayFace == expected_desc->layer_idx,
325 "Got First2DArrayFace %u, expected %u.\n",
326 U(*desc).TextureCubeArray.First2DArrayFace, expected_desc->layer_idx);
327 ok_(__FILE__, line)(U(*desc).TextureCubeArray.NumCubes == expected_desc->layer_count,
328 "Got NumCubes %u, expected %u.\n",
329 U(*desc).TextureCubeArray.NumCubes, expected_desc->layer_count);
331 else if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
333 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
337 struct rtv_desc
339 DXGI_FORMAT format;
340 D3D11_RTV_DIMENSION dimension;
341 unsigned int miplevel_idx;
342 unsigned int layer_idx;
343 unsigned int layer_count;
346 static void get_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *d3d11_desc, const struct rtv_desc *desc)
348 d3d11_desc->Format = desc->format;
349 d3d11_desc->ViewDimension = desc->dimension;
350 if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1D)
352 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
354 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1DARRAY)
356 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
357 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
358 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
360 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
362 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
364 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
366 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
367 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
368 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
370 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
372 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
373 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
375 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE3D)
377 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
378 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
379 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
381 else if (desc->dimension != D3D11_RTV_DIMENSION_UNKNOWN
382 && desc->dimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
384 trace("Unhandled view dimension %#x.\n", desc->dimension);
388 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
389 static void check_rtv_desc_(unsigned int line, const D3D11_RENDER_TARGET_VIEW_DESC *desc,
390 const struct rtv_desc *expected_desc)
392 ok_(__FILE__, line)(desc->Format == expected_desc->format,
393 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
394 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
395 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
397 if (desc->ViewDimension != expected_desc->dimension)
398 return;
400 if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D)
402 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
403 "Got MipSlice %u, expected %u.\n",
404 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
406 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
408 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
409 "Got MipSlice %u, expected %u.\n",
410 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
411 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
412 "Got FirstArraySlice %u, expected %u.\n",
413 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
414 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
415 "Got ArraySize %u, expected %u.\n",
416 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
418 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
420 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
421 "Got FirstArraySlice %u, expected %u.\n",
422 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
423 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
424 "Got ArraySize %u, expected %u.\n",
425 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
427 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE3D)
429 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
430 "Got MipSlice %u, expected %u.\n",
431 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
432 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
433 "Got FirstWSlice %u, expected %u.\n",
434 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
435 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
436 "Got WSize %u, expected %u.\n",
437 U(*desc).Texture3D.WSize, expected_desc->layer_count);
439 else if (desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
441 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
445 struct dsv_desc
447 DXGI_FORMAT format;
448 D3D11_DSV_DIMENSION dimension;
449 unsigned int miplevel_idx;
450 unsigned int layer_idx;
451 unsigned int layer_count;
454 static void get_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *d3d11_desc, const struct dsv_desc *desc)
456 d3d11_desc->Format = desc->format;
457 d3d11_desc->ViewDimension = desc->dimension;
458 d3d11_desc->Flags = 0;
459 if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1D)
461 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
463 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1DARRAY)
465 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
466 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
467 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
469 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2D)
471 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
473 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
475 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
476 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
477 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
479 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
481 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
482 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
484 else if (desc->dimension != D3D11_DSV_DIMENSION_UNKNOWN
485 && desc->dimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
487 trace("Unhandled view dimension %#x.\n", desc->dimension);
491 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
492 static void check_dsv_desc_(unsigned int line, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc,
493 const struct dsv_desc *expected_desc)
495 ok_(__FILE__, line)(desc->Format == expected_desc->format,
496 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
497 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
498 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
500 if (desc->ViewDimension != expected_desc->dimension)
501 return;
503 if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D)
505 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
506 "Got MipSlice %u, expected %u.\n",
507 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
509 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
511 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
512 "Got MipSlice %u, expected %u.\n",
513 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
514 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
515 "Got FirstArraySlice %u, expected %u.\n",
516 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
517 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
518 "Got ArraySize %u, expected %u.\n",
519 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
521 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
523 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
524 "Got FirstArraySlice %u, expected %u.\n",
525 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
526 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
527 "Got ArraySize %u, expected %u.\n",
528 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
530 else if (desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
532 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
536 struct uav_desc
538 DXGI_FORMAT format;
539 D3D11_UAV_DIMENSION dimension;
540 unsigned int miplevel_idx;
541 unsigned int layer_idx;
542 unsigned int layer_count;
545 static void get_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC *d3d11_desc, const struct uav_desc *desc)
547 d3d11_desc->Format = desc->format;
548 d3d11_desc->ViewDimension = desc->dimension;
549 if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1D)
551 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
553 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
555 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
556 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
557 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
559 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2D)
561 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
563 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
565 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
566 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
567 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
569 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE3D)
571 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
572 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
573 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
575 else if (desc->dimension != D3D11_UAV_DIMENSION_UNKNOWN)
577 trace("Unhandled view dimension %#x.\n", desc->dimension);
581 #define check_uav_desc(a, b) check_uav_desc_(__LINE__, a, b)
582 static void check_uav_desc_(unsigned int line, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc,
583 const struct uav_desc *expected_desc)
585 ok_(__FILE__, line)(desc->Format == expected_desc->format,
586 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
587 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
588 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
590 if (desc->ViewDimension != expected_desc->dimension)
591 return;
593 if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2D)
595 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
596 "Got MipSlice %u, expected %u.\n",
597 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
599 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
601 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
602 "Got MipSlice %u, expected %u.\n",
603 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
604 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
605 "Got FirstArraySlice %u, expected %u.\n",
606 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
607 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
608 "Got ArraySize %u, expected %u.\n",
609 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
611 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE3D)
613 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
614 "Got MipSlice %u, expected %u.\n",
615 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
616 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
617 "Got FirstWSlice %u, expected %u.\n",
618 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
619 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
620 "Got WSize %u, expected %u.\n",
621 U(*desc).Texture3D.WSize, expected_desc->layer_count);
623 else
625 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
629 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, c, d)
630 static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
631 unsigned int bind_flags, unsigned int size, const void *data)
633 D3D11_SUBRESOURCE_DATA resource_data;
634 D3D11_BUFFER_DESC buffer_desc;
635 ID3D11Buffer *buffer;
636 HRESULT hr;
638 buffer_desc.ByteWidth = size;
639 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
640 buffer_desc.BindFlags = bind_flags;
641 buffer_desc.CPUAccessFlags = 0;
642 buffer_desc.MiscFlags = 0;
643 buffer_desc.StructureByteStride = 0;
645 resource_data.pSysMem = data;
646 resource_data.SysMemPitch = 0;
647 resource_data.SysMemSlicePitch = 0;
649 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
650 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
651 return buffer;
654 struct resource_readback
656 ID3D11Resource *resource;
657 D3D11_MAPPED_SUBRESOURCE map_desc;
658 ID3D11DeviceContext *immediate_context;
659 unsigned int width, height, sub_resource_idx;
662 static void get_buffer_readback(ID3D11Buffer *buffer, struct resource_readback *rb)
664 D3D11_BUFFER_DESC buffer_desc;
665 ID3D11Device *device;
666 HRESULT hr;
668 memset(rb, 0, sizeof(*rb));
670 ID3D11Buffer_GetDevice(buffer, &device);
672 ID3D11Buffer_GetDesc(buffer, &buffer_desc);
673 buffer_desc.Usage = D3D11_USAGE_STAGING;
674 buffer_desc.BindFlags = 0;
675 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
676 buffer_desc.MiscFlags = 0;
677 buffer_desc.StructureByteStride = 0;
678 if (FAILED(hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D11Buffer **)&rb->resource)))
680 trace("Failed to create staging buffer, hr %#x.\n", hr);
681 ID3D11Device_Release(device);
682 return;
685 rb->width = buffer_desc.ByteWidth;
686 rb->height = 1;
687 rb->sub_resource_idx = 0;
689 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
691 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)buffer);
692 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, 0,
693 D3D11_MAP_READ, 0, &rb->map_desc)))
695 trace("Failed to map buffer, hr %#x.\n", hr);
696 ID3D11Resource_Release(rb->resource);
697 rb->resource = NULL;
698 ID3D11DeviceContext_Release(rb->immediate_context);
699 rb->immediate_context = NULL;
702 ID3D11Device_Release(device);
705 static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
706 struct resource_readback *rb)
708 D3D11_TEXTURE2D_DESC texture_desc;
709 unsigned int miplevel;
710 ID3D11Device *device;
711 HRESULT hr;
713 memset(rb, 0, sizeof(*rb));
715 ID3D11Texture2D_GetDevice(texture, &device);
717 ID3D11Texture2D_GetDesc(texture, &texture_desc);
718 texture_desc.Usage = D3D11_USAGE_STAGING;
719 texture_desc.BindFlags = 0;
720 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
721 texture_desc.MiscFlags = 0;
722 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->resource)))
724 trace("Failed to create texture, hr %#x.\n", hr);
725 ID3D11Device_Release(device);
726 return;
729 miplevel = sub_resource_idx % texture_desc.MipLevels;
730 rb->width = max(1, texture_desc.Width >> miplevel);
731 rb->height = max(1, texture_desc.Height >> miplevel);
732 rb->sub_resource_idx = sub_resource_idx;
734 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
736 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)texture);
737 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, sub_resource_idx,
738 D3D11_MAP_READ, 0, &rb->map_desc)))
740 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
741 ID3D11Resource_Release(rb->resource);
742 rb->resource = NULL;
743 ID3D11DeviceContext_Release(rb->immediate_context);
744 rb->immediate_context = NULL;
747 ID3D11Device_Release(device);
750 static void *get_readback_data(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned byte_width)
752 return (BYTE *)rb->map_desc.pData + y * rb->map_desc.RowPitch + x * byte_width;
755 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y)
757 return *(DWORD *)get_readback_data(rb, x, y, sizeof(DWORD));
760 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
762 return *(float *)get_readback_data(rb, x, y, sizeof(float));
765 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
767 return get_readback_data(rb, x, y, sizeof(struct vec4));
770 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
772 return get_readback_data(rb, x, y, sizeof(struct uvec4));
775 static void release_resource_readback(struct resource_readback *rb)
777 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
778 ID3D11Resource_Release(rb->resource);
779 ID3D11DeviceContext_Release(rb->immediate_context);
782 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
784 struct resource_readback rb;
785 DWORD color;
787 get_texture_readback(texture, 0, &rb);
788 color = get_readback_color(&rb, x, y);
789 release_resource_readback(&rb);
791 return color;
794 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
795 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
796 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
798 struct resource_readback rb;
799 unsigned int x = 0, y = 0;
800 BOOL all_match = TRUE;
801 RECT default_rect;
802 DWORD color = 0;
804 get_texture_readback(texture, sub_resource_idx, &rb);
805 if (!rect)
807 SetRect(&default_rect, 0, 0, rb.width, rb.height);
808 rect = &default_rect;
810 for (y = rect->top; y < rect->bottom; ++y)
812 for (x = rect->left; x < rect->right; ++x)
814 color = get_readback_color(&rb, x, y);
815 if (!compare_color(color, expected_color, max_diff))
817 all_match = FALSE;
818 break;
821 if (!all_match)
822 break;
824 release_resource_readback(&rb);
825 ok_(__FILE__, line)(all_match,
826 "Got 0x%08x, expected 0x%08x at (%u, %u), sub-resource %u.\n",
827 color, expected_color, x, y, sub_resource_idx);
830 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
831 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
832 DWORD expected_color, BYTE max_diff)
834 unsigned int sub_resource_idx, sub_resource_count;
835 D3D11_TEXTURE2D_DESC texture_desc;
837 ID3D11Texture2D_GetDesc(texture, &texture_desc);
838 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
839 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
840 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
843 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
844 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
845 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
847 struct resource_readback rb;
848 unsigned int x = 0, y = 0;
849 BOOL all_match = TRUE;
850 float value = 0.0f;
851 RECT default_rect;
853 get_texture_readback(texture, sub_resource_idx, &rb);
854 if (!rect)
856 SetRect(&default_rect, 0, 0, rb.width, rb.height);
857 rect = &default_rect;
859 for (y = rect->top; y < rect->bottom; ++y)
861 for (x = rect->left; x < rect->right; ++x)
863 value = get_readback_float(&rb, x, y);
864 if (!compare_float(value, expected_value, max_diff))
866 all_match = FALSE;
867 break;
870 if (!all_match)
871 break;
873 release_resource_readback(&rb);
874 ok_(__FILE__, line)(all_match,
875 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
876 value, expected_value, x, y, sub_resource_idx);
879 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
880 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
881 float expected_value, BYTE max_diff)
883 unsigned int sub_resource_idx, sub_resource_count;
884 D3D11_TEXTURE2D_DESC texture_desc;
886 ID3D11Texture2D_GetDesc(texture, &texture_desc);
887 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
888 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
889 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
892 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
893 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
894 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
896 struct resource_readback rb;
897 unsigned int x = 0, y = 0;
898 struct vec4 value = {0};
899 BOOL all_match = TRUE;
900 RECT default_rect;
902 get_texture_readback(texture, sub_resource_idx, &rb);
903 if (!rect)
905 SetRect(&default_rect, 0, 0, rb.width, rb.height);
906 rect = &default_rect;
908 for (y = rect->top; y < rect->bottom; ++y)
910 for (x = rect->left; x < rect->right; ++x)
912 value = *get_readback_vec4(&rb, x, y);
913 if (!compare_vec4(&value, expected_value, max_diff))
915 all_match = FALSE;
916 break;
919 if (!all_match)
920 break;
922 release_resource_readback(&rb);
923 ok_(__FILE__, line)(all_match,
924 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
925 value.x, value.y, value.z, value.w,
926 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
927 x, y, sub_resource_idx);
930 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
931 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
932 const struct vec4 *expected_value, BYTE max_diff)
934 unsigned int sub_resource_idx, sub_resource_count;
935 D3D11_TEXTURE2D_DESC texture_desc;
937 ID3D11Texture2D_GetDesc(texture, &texture_desc);
938 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
939 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
940 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
943 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
944 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
945 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
947 struct resource_readback rb;
948 unsigned int x = 0, y = 0;
949 struct uvec4 value = {0};
950 BOOL all_match = TRUE;
951 RECT default_rect;
953 get_texture_readback(texture, sub_resource_idx, &rb);
954 if (!rect)
956 SetRect(&default_rect, 0, 0, rb.width, rb.height);
957 rect = &default_rect;
959 for (y = rect->top; y < rect->bottom; ++y)
961 for (x = rect->left; x < rect->right; ++x)
963 value = *get_readback_uvec4(&rb, x, y);
964 if (!compare_uvec4(&value, expected_value))
966 all_match = FALSE;
967 break;
970 if (!all_match)
971 break;
973 release_resource_readback(&rb);
974 ok_(__FILE__, line)(all_match,
975 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
976 "at (%u, %u), sub-resource %u.\n",
977 value.x, value.y, value.z, value.w,
978 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
979 x, y, sub_resource_idx);
982 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
983 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
984 const struct uvec4 *expected_value)
986 unsigned int sub_resource_idx, sub_resource_count;
987 D3D11_TEXTURE2D_DESC texture_desc;
989 ID3D11Texture2D_GetDesc(texture, &texture_desc);
990 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
991 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
992 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
995 static ID3D11Device *create_device(const struct device_desc *desc)
997 static const D3D_FEATURE_LEVEL default_feature_level[] =
999 D3D_FEATURE_LEVEL_11_0,
1000 D3D_FEATURE_LEVEL_10_0,
1002 const D3D_FEATURE_LEVEL *feature_level;
1003 UINT flags = desc ? desc->flags : 0;
1004 unsigned int feature_level_count;
1005 ID3D11Device *device;
1007 if (desc && desc->feature_level)
1009 feature_level = desc->feature_level;
1010 feature_level_count = 1;
1012 else
1014 feature_level = default_feature_level;
1015 feature_level_count = ARRAY_SIZE(default_feature_level);
1018 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, feature_level, feature_level_count,
1019 D3D11_SDK_VERSION, &device, NULL, NULL)))
1020 return device;
1021 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags, feature_level, feature_level_count,
1022 D3D11_SDK_VERSION, &device, NULL, NULL)))
1023 return device;
1024 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags, feature_level, feature_level_count,
1025 D3D11_SDK_VERSION, &device, NULL, NULL)))
1026 return device;
1028 return NULL;
1031 static void get_device_adapter_desc(ID3D11Device *device, DXGI_ADAPTER_DESC *adapter_desc)
1033 IDXGIDevice *dxgi_device;
1034 IDXGIAdapter *adapter;
1035 HRESULT hr;
1037 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1038 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1039 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1040 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1041 IDXGIDevice_Release(dxgi_device);
1042 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1043 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1044 IDXGIAdapter_Release(adapter);
1047 static BOOL is_warp_device(ID3D11Device *device)
1049 DXGI_ADAPTER_DESC adapter_desc;
1050 get_device_adapter_desc(device, &adapter_desc);
1051 return !adapter_desc.SubSysId && !adapter_desc.Revision
1052 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1053 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1056 static BOOL is_vendor_device(ID3D11Device *device, unsigned int vendor_id)
1058 DXGI_ADAPTER_DESC adapter_desc;
1060 if (!strcmp(winetest_platform, "wine"))
1061 return FALSE;
1063 get_device_adapter_desc(device, &adapter_desc);
1064 return adapter_desc.VendorId == vendor_id;
1067 static BOOL is_amd_device(ID3D11Device *device)
1069 return is_vendor_device(device, 0x1002);
1072 static BOOL is_intel_device(ID3D11Device *device)
1074 return is_vendor_device(device, 0x8086);
1077 static BOOL is_nvidia_device(ID3D11Device *device)
1079 return is_vendor_device(device, 0x10de);
1082 static BOOL check_compute_shaders_via_sm4_support(ID3D11Device *device)
1084 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
1086 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1087 D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(options))))
1088 return FALSE;
1089 return options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x;
1092 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, const struct swapchain_desc *swapchain_desc)
1094 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1095 IDXGISwapChain *swapchain;
1096 IDXGIDevice *dxgi_device;
1097 IDXGIAdapter *adapter;
1098 IDXGIFactory *factory;
1099 HRESULT hr;
1101 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1102 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1103 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1104 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1105 IDXGIDevice_Release(dxgi_device);
1106 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1107 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1108 IDXGIAdapter_Release(adapter);
1110 dxgi_desc.BufferDesc.Width = 640;
1111 dxgi_desc.BufferDesc.Height = 480;
1112 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1113 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1114 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1115 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1116 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1117 dxgi_desc.SampleDesc.Count = 1;
1118 dxgi_desc.SampleDesc.Quality = 0;
1119 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1120 dxgi_desc.BufferCount = 1;
1121 dxgi_desc.OutputWindow = window;
1122 dxgi_desc.Windowed = TRUE;
1123 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1124 dxgi_desc.Flags = 0;
1126 if (swapchain_desc)
1128 dxgi_desc.Windowed = swapchain_desc->windowed;
1129 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1130 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1132 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1133 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1136 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1137 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1138 IDXGIFactory_Release(factory);
1140 return swapchain;
1143 struct d3d11_test_context
1145 ID3D11Device *device;
1146 HWND window;
1147 IDXGISwapChain *swapchain;
1148 ID3D11Texture2D *backbuffer;
1149 ID3D11RenderTargetView *backbuffer_rtv;
1150 ID3D11DeviceContext *immediate_context;
1152 ID3D11InputLayout *input_layout;
1153 ID3D11VertexShader *vs;
1154 ID3D11Buffer *vb;
1156 ID3D11PixelShader *ps;
1157 ID3D11Buffer *ps_cb;
1160 #define init_test_context(c, l) init_test_context_(__LINE__, c, l)
1161 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1162 const D3D_FEATURE_LEVEL *feature_level)
1164 struct device_desc device_desc;
1165 D3D11_VIEWPORT vp;
1166 HRESULT hr;
1167 RECT rect;
1169 memset(context, 0, sizeof(*context));
1171 device_desc.feature_level = feature_level;
1172 device_desc.flags = 0;
1173 if (!(context->device = create_device(&device_desc)))
1175 skip_(__FILE__, line)("Failed to create device.\n");
1176 return FALSE;
1178 SetRect(&rect, 0, 0, 640, 480);
1179 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1180 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1181 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1182 context->swapchain = create_swapchain(context->device, context->window, NULL);
1183 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1184 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1186 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1187 NULL, &context->backbuffer_rtv);
1188 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1190 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1192 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1194 vp.TopLeftX = 0.0f;
1195 vp.TopLeftY = 0.0f;
1196 vp.Width = 640.0f;
1197 vp.Height = 480.0f;
1198 vp.MinDepth = 0.0f;
1199 vp.MaxDepth = 1.0f;
1200 ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp);
1202 return TRUE;
1205 #define release_test_context(c) release_test_context_(__LINE__, c)
1206 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1208 ULONG ref;
1210 if (context->input_layout)
1211 ID3D11InputLayout_Release(context->input_layout);
1212 if (context->vs)
1213 ID3D11VertexShader_Release(context->vs);
1214 if (context->vb)
1215 ID3D11Buffer_Release(context->vb);
1216 if (context->ps)
1217 ID3D11PixelShader_Release(context->ps);
1218 if (context->ps_cb)
1219 ID3D11Buffer_Release(context->ps_cb);
1221 ID3D11DeviceContext_Release(context->immediate_context);
1222 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1223 ID3D11Texture2D_Release(context->backbuffer);
1224 IDXGISwapChain_Release(context->swapchain);
1225 DestroyWindow(context->window);
1227 ref = ID3D11Device_Release(context->device);
1228 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1231 #define draw_quad(c) draw_quad_(__LINE__, c)
1232 static void draw_quad_(unsigned int line, struct d3d11_test_context *context)
1234 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1236 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1238 static const DWORD default_vs_code[] =
1240 #if 0
1241 float4 main(float4 position : POSITION) : SV_POSITION
1243 return position;
1245 #endif
1246 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1247 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1248 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1249 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1250 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1251 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1252 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1253 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1254 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1255 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1256 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1257 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1258 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1259 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1260 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1262 static const struct vec2 quad[] =
1264 {-1.0f, -1.0f},
1265 {-1.0f, 1.0f},
1266 { 1.0f, -1.0f},
1267 { 1.0f, 1.0f},
1270 ID3D11Device *device = context->device;
1271 unsigned int stride, offset;
1272 HRESULT hr;
1274 if (!context->input_layout)
1276 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1277 default_vs_code, sizeof(default_vs_code), &context->input_layout);
1278 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1280 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1282 hr = ID3D11Device_CreateVertexShader(device, default_vs_code, sizeof(default_vs_code), NULL, &context->vs);
1283 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1286 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1287 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1288 stride = sizeof(*quad);
1289 offset = 0;
1290 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1291 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1293 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1296 static void set_quad_color(struct d3d11_test_context *context, const struct vec4 *color)
1298 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1299 (ID3D11Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1302 #define draw_color_quad(c, color) draw_color_quad_(__LINE__, c, color)
1303 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context, const struct vec4 *color)
1305 static const DWORD ps_color_code[] =
1307 #if 0
1308 float4 color;
1310 float4 main() : SV_TARGET
1312 return color;
1314 #endif
1315 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1316 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1317 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1318 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1319 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1320 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1321 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1322 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1323 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1324 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1325 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1328 ID3D11Device *device = context->device;
1329 HRESULT hr;
1331 if (!context->ps)
1333 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1334 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1337 if (!context->ps_cb)
1338 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1340 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1341 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1343 set_quad_color(context, color);
1345 draw_quad_(line, context);
1348 static void test_create_device(void)
1350 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1352 D3D_FEATURE_LEVEL_11_0,
1353 D3D_FEATURE_LEVEL_10_1,
1354 D3D_FEATURE_LEVEL_10_0,
1355 D3D_FEATURE_LEVEL_9_3,
1356 D3D_FEATURE_LEVEL_9_2,
1357 D3D_FEATURE_LEVEL_9_1,
1359 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1360 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1361 ID3D11DeviceContext *immediate_context;
1362 IDXGISwapChain *swapchain;
1363 ID3D11Device *device;
1364 ULONG refcount;
1365 HWND window;
1366 HRESULT hr;
1368 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1369 &device, NULL, NULL)))
1371 skip("Failed to create HAL device.\n");
1372 if ((device = create_device(NULL)))
1374 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
1375 ID3D11Device_Release(device);
1377 return;
1380 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
1381 trace("Feature level %#x.\n", supported_feature_level);
1382 ID3D11Device_Release(device);
1384 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
1385 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1387 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
1388 &feature_level, NULL);
1389 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1390 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1391 feature_level, supported_feature_level);
1393 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
1394 ARRAY_SIZE(default_feature_levels), D3D11_SDK_VERSION, NULL, &feature_level, NULL);
1395 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1396 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1397 feature_level, supported_feature_level);
1399 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
1400 &immediate_context);
1401 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1403 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
1404 refcount = get_refcount(immediate_context);
1405 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1407 ID3D11DeviceContext_GetDevice(immediate_context, &device);
1408 refcount = ID3D11Device_Release(device);
1409 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1411 refcount = ID3D11DeviceContext_Release(immediate_context);
1412 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
1414 device = (ID3D11Device *)0xdeadbeef;
1415 feature_level = 0xdeadbeef;
1416 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1417 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1418 &device, &feature_level, &immediate_context);
1419 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
1420 ok(!device, "Got unexpected device pointer %p.\n", device);
1421 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1422 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1424 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
1426 swapchain_desc.BufferDesc.Width = 800;
1427 swapchain_desc.BufferDesc.Height = 600;
1428 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
1429 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
1430 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1431 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1432 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1433 swapchain_desc.SampleDesc.Count = 1;
1434 swapchain_desc.SampleDesc.Quality = 0;
1435 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1436 swapchain_desc.BufferCount = 1;
1437 swapchain_desc.OutputWindow = window;
1438 swapchain_desc.Windowed = TRUE;
1439 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1440 swapchain_desc.Flags = 0;
1442 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1443 &swapchain_desc, NULL, NULL, NULL, NULL);
1444 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1446 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1447 &swapchain_desc, NULL, NULL, &feature_level, NULL);
1448 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1449 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1450 feature_level, supported_feature_level);
1452 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1453 &swapchain_desc, &swapchain, &device, NULL, NULL);
1454 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1456 memset(&obtained_desc, 0, sizeof(obtained_desc));
1457 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
1458 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
1459 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
1460 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
1461 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
1462 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
1463 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
1464 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
1465 obtained_desc.BufferDesc.RefreshRate.Numerator);
1466 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
1467 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
1468 obtained_desc.BufferDesc.RefreshRate.Denominator);
1469 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
1470 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
1471 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
1472 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
1473 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
1474 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
1475 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
1476 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
1477 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
1478 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
1479 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
1480 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
1481 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
1482 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
1483 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
1484 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
1485 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
1486 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
1487 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
1488 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
1489 ok(obtained_desc.Flags == swapchain_desc.Flags,
1490 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
1492 refcount = IDXGISwapChain_Release(swapchain);
1493 ok(!refcount, "Swapchain has %u references left.\n", refcount);
1495 feature_level = ID3D11Device_GetFeatureLevel(device);
1496 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1497 feature_level, supported_feature_level);
1499 refcount = ID3D11Device_Release(device);
1500 ok(!refcount, "Device has %u references left.\n", refcount);
1502 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1503 NULL, NULL, &device, NULL, NULL);
1504 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1505 ID3D11Device_Release(device);
1507 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1508 NULL, NULL, NULL, NULL, NULL);
1509 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1511 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1512 NULL, NULL, NULL, &feature_level, NULL);
1513 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1514 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1515 feature_level, supported_feature_level);
1517 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1518 NULL, NULL, NULL, NULL, &immediate_context);
1519 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1520 ID3D11DeviceContext_Release(immediate_context);
1522 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1523 &swapchain_desc, NULL, NULL, NULL, NULL);
1524 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1526 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1527 &swapchain_desc, &swapchain, NULL, NULL, NULL);
1528 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1529 IDXGISwapChain_Release(swapchain);
1531 swapchain_desc.OutputWindow = NULL;
1532 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1533 &swapchain_desc, NULL, NULL, NULL, NULL);
1534 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1535 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1536 &swapchain_desc, NULL, &device, NULL, NULL);
1537 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1538 ID3D11Device_Release(device);
1540 swapchain = (IDXGISwapChain *)0xdeadbeef;
1541 device = (ID3D11Device *)0xdeadbeef;
1542 feature_level = 0xdeadbeef;
1543 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1544 swapchain_desc.OutputWindow = NULL;
1545 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1546 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1547 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1548 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1549 ok(!device, "Got unexpected device pointer %p.\n", device);
1550 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1551 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1553 swapchain = (IDXGISwapChain *)0xdeadbeef;
1554 device = (ID3D11Device *)0xdeadbeef;
1555 feature_level = 0xdeadbeef;
1556 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1557 swapchain_desc.OutputWindow = window;
1558 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
1559 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1560 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1561 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1562 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1563 ok(!device, "Got unexpected device pointer %p.\n", device);
1564 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1565 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1567 DestroyWindow(window);
1570 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
1572 struct device_desc device_desc;
1573 IDXGIAdapter *dxgi_adapter;
1574 IDXGIDevice *dxgi_device;
1575 ID3D11Device *device;
1576 IUnknown *iface;
1577 ULONG refcount;
1578 HRESULT hr;
1580 device_desc.feature_level = &feature_level;
1581 device_desc.flags = 0;
1582 if (!(device = create_device(&device_desc)))
1584 skip("Failed to create device for feature level %#x.\n", feature_level);
1585 return;
1588 check_interface(device, &IID_IUnknown, TRUE, FALSE);
1589 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
1590 check_interface(device, &IID_IDXGIDevice, TRUE, FALSE);
1591 check_interface(device, &IID_IDXGIDevice1, TRUE, FALSE);
1592 check_interface(device, &IID_ID3D10Multithread, TRUE, TRUE); /* Not available on all Windows versions. */
1593 todo_wine check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
1594 todo_wine check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
1595 check_interface(device, &IID_ID3D11InfoQueue, FALSE, FALSE); /* Non-debug mode. */
1597 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1598 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1599 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1600 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1601 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1602 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1603 IUnknown_Release(iface);
1604 IDXGIAdapter_Release(dxgi_adapter);
1605 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1606 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1607 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1608 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
1609 IUnknown_Release(iface);
1610 IDXGIAdapter_Release(dxgi_adapter);
1611 IDXGIDevice_Release(dxgi_device);
1613 refcount = ID3D11Device_Release(device);
1614 ok(!refcount, "Device has %u references left.\n", refcount);
1616 device_desc.feature_level = &feature_level;
1617 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
1618 if (!(device = create_device(&device_desc)))
1620 skip("Failed to create debug device for feature level %#x.\n", feature_level);
1621 return;
1624 todo_wine check_interface(device, &IID_ID3D11InfoQueue, TRUE, FALSE);
1626 refcount = ID3D11Device_Release(device);
1627 ok(!refcount, "Device has %u references left.\n", refcount);
1630 static void test_get_immediate_context(void)
1632 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
1633 ULONG expected_refcount, refcount;
1634 ID3D11Device *device;
1636 if (!(device = create_device(NULL)))
1638 skip("Failed to create device.\n");
1639 return;
1642 expected_refcount = get_refcount(device) + 1;
1643 ID3D11Device_GetImmediateContext(device, &immediate_context);
1644 refcount = get_refcount(device);
1645 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1646 previous_immediate_context = immediate_context;
1648 ID3D11Device_GetImmediateContext(device, &immediate_context);
1649 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1650 refcount = get_refcount(device);
1651 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1653 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
1654 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1655 refcount = ID3D11DeviceContext_Release(immediate_context);
1656 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1658 ID3D11Device_GetImmediateContext(device, &immediate_context);
1659 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1660 refcount = ID3D11DeviceContext_Release(immediate_context);
1661 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1663 refcount = ID3D11Device_Release(device);
1664 ok(!refcount, "Device has %u references left.\n", refcount);
1667 static void test_create_texture2d(void)
1669 ULONG refcount, expected_refcount;
1670 D3D11_SUBRESOURCE_DATA data = {0};
1671 D3D_FEATURE_LEVEL feature_level;
1672 ID3D11Device *device, *tmp;
1673 D3D11_TEXTURE2D_DESC desc;
1674 ID3D11Texture2D *texture;
1675 UINT quality_level_count;
1676 unsigned int i;
1677 HRESULT hr;
1679 static const struct
1681 DXGI_FORMAT format;
1682 UINT array_size;
1683 D3D11_BIND_FLAG bind_flags;
1684 UINT misc_flags;
1685 BOOL succeeds;
1686 BOOL todo;
1688 tests[] =
1690 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1691 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1692 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1693 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1694 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1695 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1696 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1697 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1698 FALSE, FALSE},
1699 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1700 FALSE, FALSE},
1701 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1702 FALSE, FALSE},
1703 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1704 TRUE, FALSE},
1705 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1706 TRUE, FALSE},
1707 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1708 TRUE, FALSE},
1709 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1710 TRUE, FALSE},
1711 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1712 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1713 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1714 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1715 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1716 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1717 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1718 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1719 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1720 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1721 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1722 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1723 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1724 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1725 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1726 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1727 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1728 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1729 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1730 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1731 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1732 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1733 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1734 TRUE, FALSE},
1735 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1736 TRUE, FALSE},
1737 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1738 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
1739 FALSE, TRUE},
1740 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1741 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
1742 FALSE, TRUE},
1743 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1744 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1745 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1746 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1747 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1748 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1749 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1750 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1751 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1752 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1753 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1754 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1755 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1756 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1757 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1758 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1759 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1760 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1761 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1762 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1763 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1764 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1765 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1766 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1767 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1768 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1769 FALSE, TRUE},
1770 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1771 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1774 if (!(device = create_device(NULL)))
1776 skip("Failed to create device.\n");
1777 return;
1780 feature_level = ID3D11Device_GetFeatureLevel(device);
1782 desc.Width = 512;
1783 desc.Height = 512;
1784 desc.MipLevels = 1;
1785 desc.ArraySize = 1;
1786 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1787 desc.SampleDesc.Count = 1;
1788 desc.SampleDesc.Quality = 0;
1789 desc.Usage = D3D11_USAGE_DEFAULT;
1790 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1791 desc.CPUAccessFlags = 0;
1792 desc.MiscFlags = 0;
1794 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
1795 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1797 expected_refcount = get_refcount(device) + 1;
1798 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1799 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1800 refcount = get_refcount(device);
1801 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1802 tmp = NULL;
1803 expected_refcount = refcount + 1;
1804 ID3D11Texture2D_GetDevice(texture, &tmp);
1805 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1806 refcount = get_refcount(device);
1807 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1808 ID3D11Device_Release(tmp);
1810 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1811 ID3D11Texture2D_Release(texture);
1813 desc.MipLevels = 0;
1814 expected_refcount = get_refcount(device) + 1;
1815 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1816 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1817 refcount = get_refcount(device);
1818 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1819 tmp = NULL;
1820 expected_refcount = refcount + 1;
1821 ID3D11Texture2D_GetDevice(texture, &tmp);
1822 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1823 refcount = get_refcount(device);
1824 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1825 ID3D11Device_Release(tmp);
1827 ID3D11Texture2D_GetDesc(texture, &desc);
1828 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1829 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1830 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1831 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1832 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1833 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1834 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1835 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1836 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1837 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1838 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1840 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1841 ID3D11Texture2D_Release(texture);
1843 desc.MipLevels = 1;
1844 desc.ArraySize = 2;
1845 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1846 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1848 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1849 ID3D11Texture2D_Release(texture);
1851 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1852 desc.ArraySize = 1;
1853 desc.SampleDesc.Count = 2;
1854 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1855 if (quality_level_count)
1857 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1858 ID3D11Texture2D_Release(texture);
1859 desc.SampleDesc.Quality = quality_level_count;
1860 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1862 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1864 /* We assume 15 samples multisampling is never supported in practice. */
1865 desc.SampleDesc.Count = 15;
1866 desc.SampleDesc.Quality = 0;
1867 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1868 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1870 desc.SampleDesc.Count = 1;
1871 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1873 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
1874 BOOL todo = tests[i].todo;
1876 if (feature_level < D3D_FEATURE_LEVEL_10_1
1877 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
1878 && tests[i].array_size > 6)
1880 expected_hr = E_INVALIDARG;
1881 todo = TRUE;
1884 desc.ArraySize = tests[i].array_size;
1885 desc.Format = tests[i].format;
1886 desc.BindFlags = tests[i].bind_flags;
1887 desc.MiscFlags = tests[i].misc_flags;
1888 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, (ID3D11Texture2D **)&texture);
1890 todo_wine_if(todo)
1891 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
1892 i, hr, desc.Format);
1894 if (SUCCEEDED(hr))
1895 ID3D11Texture2D_Release(texture);
1898 refcount = ID3D11Device_Release(device);
1899 ok(!refcount, "Device has %u references left.\n", refcount);
1902 static void test_texture2d_interfaces(void)
1904 ID3D10Texture2D *d3d10_texture;
1905 D3D11_TEXTURE2D_DESC desc;
1906 ID3D11Texture2D *texture;
1907 ID3D11Device *device;
1908 unsigned int i;
1909 ULONG refcount;
1910 HRESULT hr;
1912 static const struct test
1914 BOOL implements_d3d10_interfaces;
1915 UINT bind_flags;
1916 UINT misc_flags;
1917 UINT expected_bind_flags;
1918 UINT expected_misc_flags;
1920 desc_conversion_tests[] =
1923 TRUE,
1924 D3D11_BIND_SHADER_RESOURCE, 0,
1925 D3D10_BIND_SHADER_RESOURCE, 0
1928 TRUE,
1929 D3D11_BIND_UNORDERED_ACCESS, 0,
1930 D3D11_BIND_UNORDERED_ACCESS, 0
1933 FALSE,
1934 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1935 0, 0
1938 TRUE,
1939 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
1940 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1943 TRUE,
1944 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
1945 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1949 if (!(device = create_device(NULL)))
1951 skip("Failed to create ID3D11Device, skipping tests.\n");
1952 return;
1955 desc.Width = 512;
1956 desc.Height = 512;
1957 desc.MipLevels = 0;
1958 desc.ArraySize = 1;
1959 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1960 desc.SampleDesc.Count = 1;
1961 desc.SampleDesc.Quality = 0;
1962 desc.Usage = D3D11_USAGE_DEFAULT;
1963 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1964 desc.CPUAccessFlags = 0;
1965 desc.MiscFlags = 0;
1967 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1968 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1969 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1970 hr = check_interface(texture, &IID_ID3D10Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
1971 ID3D11Texture2D_Release(texture);
1972 if (FAILED(hr))
1974 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
1975 ID3D11Device_Release(device);
1976 return;
1979 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
1981 const struct test *current = &desc_conversion_tests[i];
1982 D3D10_TEXTURE2D_DESC d3d10_desc;
1983 ID3D10Device *d3d10_device;
1985 desc.Width = 512;
1986 desc.Height = 512;
1987 desc.MipLevels = 1;
1988 desc.ArraySize = 1;
1989 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1990 desc.SampleDesc.Count = 1;
1991 desc.SampleDesc.Quality = 0;
1992 desc.Usage = D3D11_USAGE_DEFAULT;
1993 desc.BindFlags = current->bind_flags;
1994 desc.CPUAccessFlags = 0;
1995 desc.MiscFlags = current->misc_flags;
1997 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1998 /* Shared resources are not supported by REF and WARP devices. */
1999 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2000 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2001 if (FAILED(hr))
2003 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
2004 continue;
2007 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2009 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2010 ID3D11Texture2D_Release(texture);
2012 if (current->implements_d3d10_interfaces)
2014 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2016 else
2018 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2019 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
2020 continue;
2023 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
2025 ok(d3d10_desc.Width == desc.Width,
2026 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2027 ok(d3d10_desc.Height == desc.Height,
2028 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2029 ok(d3d10_desc.MipLevels == desc.MipLevels,
2030 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2031 ok(d3d10_desc.ArraySize == desc.ArraySize,
2032 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2033 ok(d3d10_desc.Format == desc.Format,
2034 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2035 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
2036 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
2037 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2038 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
2039 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2040 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2041 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2042 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2043 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2044 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2045 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2046 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2048 d3d10_device = (ID3D10Device *)0xdeadbeef;
2049 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
2050 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2051 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2053 ID3D10Texture2D_Release(d3d10_texture);
2056 refcount = ID3D11Device_Release(device);
2057 ok(!refcount, "Device has %u references left.\n", refcount);
2060 static void test_create_texture3d(void)
2062 ULONG refcount, expected_refcount;
2063 D3D11_SUBRESOURCE_DATA data = {0};
2064 ID3D11Device *device, *tmp;
2065 D3D11_TEXTURE3D_DESC desc;
2066 ID3D11Texture3D *texture;
2067 unsigned int i;
2068 HRESULT hr;
2070 static const struct
2072 DXGI_FORMAT format;
2073 D3D11_BIND_FLAG bind_flags;
2074 BOOL succeeds;
2075 BOOL todo;
2077 tests[] =
2079 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
2080 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
2081 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2082 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2083 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2084 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2085 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2086 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2087 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2090 if (!(device = create_device(NULL)))
2092 skip("Failed to create ID3D11Device, skipping tests.\n");
2093 return;
2096 desc.Width = 64;
2097 desc.Height = 64;
2098 desc.Depth = 64;
2099 desc.MipLevels = 1;
2100 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2101 desc.Usage = D3D11_USAGE_DEFAULT;
2102 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2103 desc.CPUAccessFlags = 0;
2104 desc.MiscFlags = 0;
2106 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2107 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2109 expected_refcount = get_refcount(device) + 1;
2110 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2111 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2112 refcount = get_refcount(device);
2113 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2114 tmp = NULL;
2115 expected_refcount = refcount + 1;
2116 ID3D11Texture3D_GetDevice(texture, &tmp);
2117 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2118 refcount = get_refcount(device);
2119 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2120 ID3D11Device_Release(tmp);
2122 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2123 ID3D11Texture3D_Release(texture);
2125 desc.MipLevels = 0;
2126 expected_refcount = get_refcount(device) + 1;
2127 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2128 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2129 refcount = get_refcount(device);
2130 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2131 tmp = NULL;
2132 expected_refcount = refcount + 1;
2133 ID3D11Texture3D_GetDevice(texture, &tmp);
2134 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2135 refcount = get_refcount(device);
2136 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2137 ID3D11Device_Release(tmp);
2139 ID3D11Texture3D_GetDesc(texture, &desc);
2140 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2141 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2142 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2143 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2144 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2145 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2146 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2147 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2148 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2150 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2151 ID3D11Texture3D_Release(texture);
2153 desc.MipLevels = 1;
2154 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2156 desc.Format = tests[i].format;
2157 desc.BindFlags = tests[i].bind_flags;
2158 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, (ID3D11Texture3D **)&texture);
2160 todo_wine_if(tests[i].todo)
2161 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2163 if (SUCCEEDED(hr))
2164 ID3D11Texture3D_Release(texture);
2167 refcount = ID3D11Device_Release(device);
2168 ok(!refcount, "Device has %u references left.\n", refcount);
2171 static void test_texture3d_interfaces(void)
2173 ID3D10Texture3D *d3d10_texture;
2174 D3D11_TEXTURE3D_DESC desc;
2175 ID3D11Texture3D *texture;
2176 ID3D11Device *device;
2177 unsigned int i;
2178 ULONG refcount;
2179 HRESULT hr;
2181 static const struct test
2183 BOOL implements_d3d10_interfaces;
2184 UINT bind_flags;
2185 UINT misc_flags;
2186 UINT expected_bind_flags;
2187 UINT expected_misc_flags;
2189 desc_conversion_tests[] =
2192 TRUE,
2193 D3D11_BIND_SHADER_RESOURCE, 0,
2194 D3D10_BIND_SHADER_RESOURCE, 0
2197 TRUE,
2198 D3D11_BIND_UNORDERED_ACCESS, 0,
2199 D3D11_BIND_UNORDERED_ACCESS, 0
2202 FALSE,
2203 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2204 0, 0
2207 TRUE,
2208 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2209 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2213 if (!(device = create_device(NULL)))
2215 skip("Failed to create ID3D11Device.\n");
2216 return;
2219 desc.Width = 64;
2220 desc.Height = 64;
2221 desc.Depth = 64;
2222 desc.MipLevels = 0;
2223 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2224 desc.Usage = D3D11_USAGE_DEFAULT;
2225 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2226 desc.CPUAccessFlags = 0;
2227 desc.MiscFlags = 0;
2229 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2230 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2231 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2232 hr = check_interface(texture, &IID_ID3D10Texture3D, TRUE, TRUE); /* Not available on all Windows versions. */
2233 ID3D11Texture3D_Release(texture);
2234 if (FAILED(hr))
2236 win_skip("3D textures do not implement ID3D10Texture3D.\n");
2237 ID3D11Device_Release(device);
2238 return;
2241 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2243 const struct test *current = &desc_conversion_tests[i];
2244 D3D10_TEXTURE3D_DESC d3d10_desc;
2245 ID3D10Device *d3d10_device;
2247 desc.Width = 64;
2248 desc.Height = 64;
2249 desc.Depth = 64;
2250 desc.MipLevels = 1;
2251 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2252 desc.Usage = D3D11_USAGE_DEFAULT;
2253 desc.BindFlags = current->bind_flags;
2254 desc.CPUAccessFlags = 0;
2255 desc.MiscFlags = current->misc_flags;
2257 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2258 /* Shared resources are not supported by REF and WARP devices. */
2259 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2260 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
2261 if (FAILED(hr))
2263 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
2264 continue;
2267 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2269 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2270 ID3D11Texture3D_Release(texture);
2272 if (current->implements_d3d10_interfaces)
2274 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
2276 else
2278 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
2279 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2280 continue;
2283 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
2285 ok(d3d10_desc.Width == desc.Width,
2286 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2287 ok(d3d10_desc.Height == desc.Height,
2288 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2289 ok(d3d10_desc.Depth == desc.Depth,
2290 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
2291 ok(d3d10_desc.MipLevels == desc.MipLevels,
2292 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2293 ok(d3d10_desc.Format == desc.Format,
2294 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2295 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2296 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2297 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2298 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2299 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2300 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2301 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2302 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2304 d3d10_device = (ID3D10Device *)0xdeadbeef;
2305 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
2306 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2307 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2309 ID3D10Texture3D_Release(d3d10_texture);
2312 refcount = ID3D11Device_Release(device);
2313 ok(!refcount, "Device has %u references left.\n", refcount);
2316 static void test_create_buffer(void)
2318 ID3D10Buffer *d3d10_buffer;
2319 D3D11_BUFFER_DESC desc;
2320 ID3D11Buffer *buffer;
2321 ID3D11Device *device;
2322 unsigned int i;
2323 ULONG refcount;
2324 HRESULT hr;
2326 static const struct test
2328 BOOL succeeds;
2329 BOOL implements_d3d10_interfaces;
2330 UINT bind_flags;
2331 UINT misc_flags;
2332 UINT structure_stride;
2333 UINT expected_bind_flags;
2334 UINT expected_misc_flags;
2336 tests[] =
2339 TRUE, TRUE,
2340 D3D11_BIND_VERTEX_BUFFER, 0, 0,
2341 D3D10_BIND_VERTEX_BUFFER, 0
2344 TRUE, TRUE,
2345 D3D11_BIND_INDEX_BUFFER, 0, 0,
2346 D3D10_BIND_INDEX_BUFFER, 0
2349 TRUE, TRUE,
2350 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
2351 D3D10_BIND_CONSTANT_BUFFER, 0
2354 TRUE, TRUE,
2355 D3D11_BIND_SHADER_RESOURCE, 0, 0,
2356 D3D10_BIND_SHADER_RESOURCE, 0
2359 TRUE, TRUE,
2360 D3D11_BIND_STREAM_OUTPUT, 0, 0,
2361 D3D10_BIND_STREAM_OUTPUT, 0
2364 TRUE, TRUE,
2365 D3D11_BIND_RENDER_TARGET, 0, 0,
2366 D3D10_BIND_RENDER_TARGET, 0
2369 TRUE, TRUE,
2370 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
2371 D3D11_BIND_UNORDERED_ACCESS, 0
2374 TRUE, TRUE,
2375 0, D3D11_RESOURCE_MISC_SHARED, 0,
2376 0, D3D10_RESOURCE_MISC_SHARED
2379 TRUE, TRUE,
2380 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
2381 0, 0
2384 FALSE, FALSE,
2385 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2388 FALSE, FALSE,
2389 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2392 FALSE, FALSE,
2393 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2396 TRUE, TRUE,
2397 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2398 D3D10_BIND_SHADER_RESOURCE, 0
2401 FALSE, FALSE,
2402 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2405 FALSE, FALSE,
2406 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2409 TRUE, TRUE,
2410 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2411 D3D11_BIND_UNORDERED_ACCESS, 0
2414 FALSE, FALSE,
2415 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2417 /* Structured buffers do not implement ID3D10Buffer. */
2419 TRUE, FALSE,
2420 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2423 TRUE, FALSE,
2424 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2427 FALSE, FALSE,
2428 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
2431 FALSE, FALSE,
2432 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
2435 FALSE, FALSE,
2436 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
2439 FALSE, FALSE,
2440 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
2443 FALSE, FALSE,
2444 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
2447 TRUE, FALSE,
2448 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
2451 FALSE, FALSE,
2452 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
2455 TRUE, FALSE,
2456 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
2459 TRUE, FALSE,
2460 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
2463 FALSE, FALSE,
2464 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
2467 TRUE, FALSE,
2468 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
2471 TRUE, TRUE,
2472 0, 0, 513,
2473 0, 0
2476 TRUE, TRUE,
2477 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
2478 D3D10_BIND_CONSTANT_BUFFER, 0
2481 TRUE, TRUE,
2482 D3D11_BIND_SHADER_RESOURCE, 0, 513,
2483 D3D10_BIND_SHADER_RESOURCE, 0
2486 TRUE, TRUE,
2487 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
2488 D3D11_BIND_UNORDERED_ACCESS, 0
2491 FALSE, FALSE,
2492 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2495 FALSE, FALSE,
2496 D3D11_BIND_SHADER_RESOURCE,
2497 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2500 TRUE, TRUE,
2501 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
2502 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2506 if (!(device = create_device(NULL)))
2508 skip("Failed to create ID3D11Device.\n");
2509 return;
2512 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
2513 hr = check_interface(buffer, &IID_ID3D10Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
2514 ID3D11Buffer_Release(buffer);
2515 if (FAILED(hr))
2517 win_skip("Buffers do not implement ID3D10Buffer.\n");
2518 ID3D11Device_Release(device);
2519 return;
2522 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2524 const struct test *current = &tests[i];
2525 D3D11_BUFFER_DESC obtained_desc;
2526 D3D10_BUFFER_DESC d3d10_desc;
2527 ID3D10Device *d3d10_device;
2528 HRESULT expected_hr;
2530 desc.ByteWidth = 1024;
2531 desc.Usage = D3D11_USAGE_DEFAULT;
2532 desc.BindFlags = current->bind_flags;
2533 desc.CPUAccessFlags = 0;
2534 desc.MiscFlags = current->misc_flags;
2535 desc.StructureByteStride = current->structure_stride;
2537 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2538 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
2539 /* Shared resources are not supported by REF and WARP devices. */
2540 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
2541 i, hr, expected_hr);
2542 if (FAILED(hr))
2544 if (hr == E_OUTOFMEMORY)
2545 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2546 continue;
2549 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
2550 desc.StructureByteStride = 0;
2552 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
2554 ok(obtained_desc.ByteWidth == desc.ByteWidth,
2555 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
2556 ok(obtained_desc.Usage == desc.Usage,
2557 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
2558 ok(obtained_desc.BindFlags == desc.BindFlags,
2559 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
2560 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
2561 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
2562 ok(obtained_desc.MiscFlags == desc.MiscFlags,
2563 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
2564 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
2565 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
2567 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2568 ID3D11Buffer_Release(buffer);
2570 if (current->implements_d3d10_interfaces)
2572 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
2574 else
2576 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
2577 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2578 continue;
2581 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
2583 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
2584 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
2585 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2586 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2587 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2588 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2589 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2590 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2591 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2592 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2594 d3d10_device = (ID3D10Device *)0xdeadbeef;
2595 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
2596 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2597 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2599 ID3D10Buffer_Release(d3d10_buffer);
2602 refcount = ID3D11Device_Release(device);
2603 ok(!refcount, "Device has %u references left.\n", refcount);
2606 static void test_create_depthstencil_view(void)
2608 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2609 D3D11_TEXTURE2D_DESC texture_desc;
2610 ULONG refcount, expected_refcount;
2611 ID3D11DepthStencilView *dsview;
2612 ID3D11Device *device, *tmp;
2613 ID3D11Texture2D *texture;
2614 unsigned int i;
2615 HRESULT hr;
2617 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2618 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2619 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2620 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
2621 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
2622 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
2623 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
2624 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
2625 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
2626 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
2627 static const struct
2629 struct
2631 unsigned int miplevel_count;
2632 unsigned int array_size;
2633 DXGI_FORMAT format;
2634 } texture;
2635 struct dsv_desc dsv_desc;
2636 struct dsv_desc expected_dsv_desc;
2638 tests[] =
2640 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2641 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2642 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2643 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2644 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2645 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2646 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2647 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2648 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2649 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2650 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2651 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2652 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2653 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2654 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2655 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2656 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2657 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2658 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2659 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2660 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2661 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2662 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2663 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2664 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2665 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2666 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2668 static const struct
2670 struct
2672 unsigned int miplevel_count;
2673 unsigned int array_size;
2674 DXGI_FORMAT format;
2675 } texture;
2676 struct dsv_desc dsv_desc;
2678 invalid_desc_tests[] =
2680 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2681 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2682 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2683 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2684 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2685 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2686 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2687 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2688 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2689 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2690 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2691 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2692 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2694 #undef FMT_UNKNOWN
2695 #undef D24S8
2696 #undef R24S8_TL
2697 #undef DIM_UNKNOWN
2698 #undef TEX_1D
2699 #undef TEX_1D_ARRAY
2700 #undef TEX_2D
2701 #undef TEX_2D_ARRAY
2702 #undef TEX_2DMS
2703 #undef TEX_2DMS_ARR
2705 if (!(device = create_device(NULL)))
2707 skip("Failed to create device.\n");
2708 return;
2711 texture_desc.Width = 512;
2712 texture_desc.Height = 512;
2713 texture_desc.MipLevels = 1;
2714 texture_desc.ArraySize = 1;
2715 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2716 texture_desc.SampleDesc.Count = 1;
2717 texture_desc.SampleDesc.Quality = 0;
2718 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2719 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2720 texture_desc.CPUAccessFlags = 0;
2721 texture_desc.MiscFlags = 0;
2723 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2724 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2726 expected_refcount = get_refcount(device) + 1;
2727 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
2728 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2729 refcount = get_refcount(device);
2730 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2731 tmp = NULL;
2732 expected_refcount = refcount + 1;
2733 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
2734 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2735 refcount = get_refcount(device);
2736 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2737 ID3D11Device_Release(tmp);
2739 memset(&dsv_desc, 0, sizeof(dsv_desc));
2740 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2741 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2742 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
2743 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2744 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
2745 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2747 ID3D11DepthStencilView_Release(dsview);
2748 ID3D11Texture2D_Release(texture);
2750 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2752 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
2754 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2755 texture_desc.ArraySize = tests[i].texture.array_size;
2756 texture_desc.Format = tests[i].texture.format;
2758 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2759 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2761 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
2763 current_desc = NULL;
2765 else
2767 current_desc = &dsv_desc;
2768 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2771 expected_refcount = get_refcount(texture);
2772 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
2773 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2774 refcount = get_refcount(texture);
2775 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2777 /* Not available on all Windows versions. */
2778 check_interface(dsview, &IID_ID3D10DepthStencilView, TRUE, TRUE);
2780 memset(&dsv_desc, 0, sizeof(dsv_desc));
2781 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2782 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2784 ID3D11DepthStencilView_Release(dsview);
2785 ID3D11Texture2D_Release(texture);
2788 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2790 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2791 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2792 texture_desc.Format = invalid_desc_tests[i].texture.format;
2794 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2795 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2797 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2798 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2799 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2801 ID3D11Texture2D_Release(texture);
2804 refcount = ID3D11Device_Release(device);
2805 ok(!refcount, "Device has %u references left.\n", refcount);
2808 static void test_depthstencil_view_interfaces(void)
2810 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
2811 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2812 ID3D10DepthStencilView *d3d10_dsview;
2813 D3D11_TEXTURE2D_DESC texture_desc;
2814 ID3D11DepthStencilView *dsview;
2815 ID3D11Texture2D *texture;
2816 ID3D11Device *device;
2817 ULONG refcount;
2818 HRESULT hr;
2820 if (!(device = create_device(NULL)))
2822 skip("Failed to create device.\n");
2823 return;
2826 texture_desc.Width = 512;
2827 texture_desc.Height = 512;
2828 texture_desc.MipLevels = 1;
2829 texture_desc.ArraySize = 1;
2830 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2831 texture_desc.SampleDesc.Count = 1;
2832 texture_desc.SampleDesc.Quality = 0;
2833 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2834 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2835 texture_desc.CPUAccessFlags = 0;
2836 texture_desc.MiscFlags = 0;
2838 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2839 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2841 dsv_desc.Format = texture_desc.Format;
2842 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
2843 dsv_desc.Flags = 0;
2844 U(dsv_desc).Texture2D.MipSlice = 0;
2846 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2847 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2849 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
2850 ID3D11DepthStencilView_Release(dsview);
2851 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2852 "Depth stencil view should implement ID3D10DepthStencilView.\n");
2854 if (FAILED(hr))
2856 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
2857 goto done;
2860 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
2861 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
2862 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
2863 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
2864 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2865 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
2867 ID3D10DepthStencilView_Release(d3d10_dsview);
2869 done:
2870 ID3D11Texture2D_Release(texture);
2872 refcount = ID3D11Device_Release(device);
2873 ok(!refcount, "Device has %u references left.\n", refcount);
2876 static void test_create_rendertarget_view(void)
2878 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
2879 D3D11_TEXTURE3D_DESC texture3d_desc;
2880 D3D11_TEXTURE2D_DESC texture2d_desc;
2881 D3D11_SUBRESOURCE_DATA data = {0};
2882 ULONG refcount, expected_refcount;
2883 D3D11_BUFFER_DESC buffer_desc;
2884 ID3D11RenderTargetView *rtview;
2885 ID3D11Device *device, *tmp;
2886 ID3D11Texture3D *texture3d;
2887 ID3D11Texture2D *texture2d;
2888 ID3D11Resource *texture;
2889 ID3D11Buffer *buffer;
2890 unsigned int i;
2891 HRESULT hr;
2893 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2894 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2895 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2896 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
2897 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
2898 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
2899 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
2900 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
2901 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
2902 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
2903 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
2904 static const struct
2906 struct
2908 unsigned int miplevel_count;
2909 unsigned int depth_or_array_size;
2910 DXGI_FORMAT format;
2911 } texture;
2912 struct rtv_desc rtv_desc;
2913 struct rtv_desc expected_rtv_desc;
2915 tests[] =
2917 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2918 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2919 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2920 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2921 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2922 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2923 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2924 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2925 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2926 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2927 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2928 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2929 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2930 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2931 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2932 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2933 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2934 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2935 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2936 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2937 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2938 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2939 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2940 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2941 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2942 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2943 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2944 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2945 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2946 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2947 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2948 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2949 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2950 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2951 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2952 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2953 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2954 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2955 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2956 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2957 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2958 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2959 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2960 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2962 static const struct
2964 struct
2966 D3D11_RTV_DIMENSION dimension;
2967 unsigned int miplevel_count;
2968 unsigned int depth_or_array_size;
2969 DXGI_FORMAT format;
2970 } texture;
2971 struct rtv_desc rtv_desc;
2973 invalid_desc_tests[] =
2975 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2976 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2977 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2978 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2979 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
2980 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
2981 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
2982 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2983 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
2984 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
2985 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
2986 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
2987 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
2988 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
2989 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
2990 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2991 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2992 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2993 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2994 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2995 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2996 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2997 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2998 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
2999 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
3000 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3001 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3002 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
3003 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3004 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3005 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
3006 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
3007 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
3008 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
3009 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
3011 #undef FMT_UNKNOWN
3012 #undef RGBA8_UNORM
3013 #undef RGBA8_TL
3014 #undef DIM_UNKNOWN
3015 #undef TEX_1D
3016 #undef TEX_1D_ARRAY
3017 #undef TEX_2D
3018 #undef TEX_2D_ARRAY
3019 #undef TEX_2DMS
3020 #undef TEX_2DMS_ARR
3021 #undef TEX_3D
3023 if (!(device = create_device(NULL)))
3025 skip("Failed to create device.\n");
3026 return;
3029 buffer_desc.ByteWidth = 1024;
3030 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3031 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3032 buffer_desc.CPUAccessFlags = 0;
3033 buffer_desc.MiscFlags = 0;
3034 buffer_desc.StructureByteStride = 0;
3036 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
3037 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3039 expected_refcount = get_refcount(device) + 1;
3040 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3041 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3042 refcount = get_refcount(device);
3043 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3044 tmp = NULL;
3045 expected_refcount = refcount + 1;
3046 ID3D11Buffer_GetDevice(buffer, &tmp);
3047 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3048 refcount = get_refcount(device);
3049 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3050 ID3D11Device_Release(tmp);
3052 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3053 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
3054 U1(U(rtv_desc).Buffer).ElementOffset = 0;
3055 U2(U(rtv_desc).Buffer).ElementWidth = 64;
3057 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
3058 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3060 expected_refcount = get_refcount(device) + 1;
3061 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
3062 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
3063 refcount = get_refcount(device);
3064 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3065 tmp = NULL;
3066 expected_refcount = refcount + 1;
3067 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
3068 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3069 refcount = get_refcount(device);
3070 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3071 ID3D11Device_Release(tmp);
3073 /* Not available on all Windows versions. */
3074 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3076 ID3D11RenderTargetView_Release(rtview);
3077 ID3D11Buffer_Release(buffer);
3079 texture2d_desc.Width = 512;
3080 texture2d_desc.Height = 512;
3081 texture2d_desc.SampleDesc.Count = 1;
3082 texture2d_desc.SampleDesc.Quality = 0;
3083 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3084 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3085 texture2d_desc.CPUAccessFlags = 0;
3086 texture2d_desc.MiscFlags = 0;
3088 texture3d_desc.Width = 64;
3089 texture3d_desc.Height = 64;
3090 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3091 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3092 texture3d_desc.CPUAccessFlags = 0;
3093 texture3d_desc.MiscFlags = 0;
3095 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3097 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3099 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3101 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3102 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3103 texture2d_desc.Format = tests[i].texture.format;
3105 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3106 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3107 texture = (ID3D11Resource *)texture2d;
3109 else
3111 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3112 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3113 texture3d_desc.Format = tests[i].texture.format;
3115 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3116 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3117 texture = (ID3D11Resource *)texture3d;
3120 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
3122 current_desc = NULL;
3124 else
3126 current_desc = &rtv_desc;
3127 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3130 expected_refcount = get_refcount(texture);
3131 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3132 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3133 refcount = get_refcount(texture);
3134 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3136 /* Not available on all Windows versions. */
3137 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3139 memset(&rtv_desc, 0, sizeof(rtv_desc));
3140 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
3141 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3143 ID3D11RenderTargetView_Release(rtview);
3144 ID3D11Resource_Release(texture);
3147 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3149 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
3150 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
3152 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3154 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3155 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3156 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3158 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3159 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3160 texture = (ID3D11Resource *)texture2d;
3162 else
3164 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3165 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3166 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3168 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3169 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3170 texture = (ID3D11Resource *)texture3d;
3173 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3174 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3175 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3177 ID3D11Resource_Release(texture);
3180 refcount = ID3D11Device_Release(device);
3181 ok(!refcount, "Device has %u references left.\n", refcount);
3184 static void test_create_shader_resource_view(void)
3186 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
3187 D3D11_TEXTURE3D_DESC texture3d_desc;
3188 D3D11_TEXTURE2D_DESC texture2d_desc;
3189 ULONG refcount, expected_refcount;
3190 ID3D11ShaderResourceView *srview;
3191 D3D_FEATURE_LEVEL feature_level;
3192 D3D11_BUFFER_DESC buffer_desc;
3193 ID3D11Device *device, *tmp;
3194 ID3D11Texture3D *texture3d;
3195 ID3D11Texture2D *texture2d;
3196 ID3D11Resource *texture;
3197 ID3D11Buffer *buffer;
3198 unsigned int i;
3199 HRESULT hr;
3201 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3202 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3203 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3204 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
3205 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
3206 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
3207 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
3208 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
3209 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
3210 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
3211 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
3212 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
3213 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3214 static const struct
3216 struct
3218 unsigned int miplevel_count;
3219 unsigned int depth_or_array_size;
3220 DXGI_FORMAT format;
3221 } texture;
3222 struct srv_desc srv_desc;
3223 struct srv_desc expected_srv_desc;
3225 tests[] =
3227 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3228 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3229 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3230 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3231 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3232 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3233 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3234 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3235 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3236 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3237 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3238 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3239 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3240 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3241 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3242 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3243 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3244 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3245 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3246 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3247 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3248 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3249 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3250 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3251 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3252 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3253 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3254 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3255 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3256 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3257 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3258 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3259 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3260 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3261 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3262 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3263 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3264 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3265 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3266 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3267 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3268 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3269 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3270 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3271 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3272 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
3274 static const struct
3276 struct
3278 D3D11_SRV_DIMENSION dimension;
3279 unsigned int miplevel_count;
3280 unsigned int depth_or_array_size;
3281 DXGI_FORMAT format;
3282 } texture;
3283 struct srv_desc srv_desc;
3285 invalid_desc_tests[] =
3287 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3288 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3289 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3290 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3291 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3292 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3293 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3294 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3295 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3296 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3297 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3298 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3299 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3300 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3301 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3302 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3303 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3304 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3305 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3306 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3307 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3308 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3309 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3310 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3311 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
3312 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
3313 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3314 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3315 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3316 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
3317 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
3318 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
3319 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
3320 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
3321 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3322 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3323 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3324 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3325 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3326 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3327 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3328 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3329 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3330 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3331 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3332 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3333 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3334 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3335 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3336 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3337 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3338 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3340 #undef FMT_UNKNOWN
3341 #undef RGBA8_UNORM
3342 #undef DIM_UNKNOWN
3343 #undef TEX_1D
3344 #undef TEX_1D_ARRAY
3345 #undef TEX_2D
3346 #undef TEX_2D_ARRAY
3347 #undef TEX_2DMS
3348 #undef TEX_2DMS_ARR
3349 #undef TEX_3D
3350 #undef TEX_CUBE
3351 #undef CUBE_ARRAY
3353 if (!(device = create_device(NULL)))
3355 skip("Failed to create device.\n");
3356 return;
3358 feature_level = ID3D11Device_GetFeatureLevel(device);
3360 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
3362 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3363 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3365 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3366 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
3367 U1(U(srv_desc).Buffer).ElementOffset = 0;
3368 U2(U(srv_desc).Buffer).ElementWidth = 64;
3370 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
3371 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3373 expected_refcount = get_refcount(device) + 1;
3374 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
3375 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
3376 refcount = get_refcount(device);
3377 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3378 tmp = NULL;
3379 expected_refcount = refcount + 1;
3380 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
3381 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3382 refcount = get_refcount(device);
3383 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3384 ID3D11Device_Release(tmp);
3386 /* Not available on all Windows versions. */
3387 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
3388 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3390 ID3D11ShaderResourceView_Release(srview);
3391 ID3D11Buffer_Release(buffer);
3393 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
3395 buffer_desc.ByteWidth = 1024;
3396 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3397 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3398 buffer_desc.CPUAccessFlags = 0;
3399 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
3400 buffer_desc.StructureByteStride = 4;
3402 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3403 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3405 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3406 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
3408 memset(&srv_desc, 0, sizeof(srv_desc));
3409 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3411 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
3412 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
3413 srv_desc.ViewDimension);
3414 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
3415 U1(U(srv_desc).Buffer).FirstElement);
3416 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
3417 U2(U(srv_desc).Buffer).NumElements);
3419 ID3D11ShaderResourceView_Release(srview);
3420 ID3D11Buffer_Release(buffer);
3422 else
3424 skip("Structured buffers require feature level 11_0.\n");
3427 texture2d_desc.Width = 512;
3428 texture2d_desc.Height = 512;
3429 texture2d_desc.SampleDesc.Count = 1;
3430 texture2d_desc.SampleDesc.Quality = 0;
3431 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3432 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3433 texture2d_desc.CPUAccessFlags = 0;
3435 texture3d_desc.Width = 64;
3436 texture3d_desc.Height = 64;
3437 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3438 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3439 texture3d_desc.CPUAccessFlags = 0;
3440 texture3d_desc.MiscFlags = 0;
3442 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3444 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
3446 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
3448 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3449 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3450 texture2d_desc.Format = tests[i].texture.format;
3451 texture2d_desc.MiscFlags = 0;
3453 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3454 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3455 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3457 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
3458 && (texture2d_desc.ArraySize != 6
3459 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3460 && feature_level < D3D_FEATURE_LEVEL_10_1)
3462 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3463 continue;
3466 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3467 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3468 texture = (ID3D11Resource *)texture2d;
3470 else
3472 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3473 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3474 texture3d_desc.Format = tests[i].texture.format;
3476 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3477 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3478 texture = (ID3D11Resource *)texture3d;
3481 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
3483 current_desc = NULL;
3485 else
3487 current_desc = &srv_desc;
3488 get_srv_desc(current_desc, &tests[i].srv_desc);
3491 expected_refcount = get_refcount(texture);
3492 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3493 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3494 refcount = get_refcount(texture);
3495 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3497 /* Not available on all Windows versions. */
3498 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
3499 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3501 memset(&srv_desc, 0, sizeof(srv_desc));
3502 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3503 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3505 ID3D11ShaderResourceView_Release(srview);
3506 ID3D11Resource_Release(texture);
3509 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3511 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
3512 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
3514 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
3516 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3517 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3518 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3519 texture2d_desc.MiscFlags = 0;
3521 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3522 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3523 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3525 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3526 && feature_level < D3D_FEATURE_LEVEL_10_1)
3528 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3529 continue;
3532 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3533 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3534 texture = (ID3D11Resource *)texture2d;
3536 else
3538 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3539 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3540 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3542 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3543 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3544 texture = (ID3D11Resource *)texture3d;
3547 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3548 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3549 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3551 ID3D11Resource_Release(texture);
3554 refcount = ID3D11Device_Release(device);
3555 ok(!refcount, "Device has %u references left.\n", refcount);
3558 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
3560 #if 0
3561 float4 light;
3562 float4x4 mat;
3564 struct input
3566 float4 position : POSITION;
3567 float3 normal : NORMAL;
3570 struct output
3572 float4 position : POSITION;
3573 float4 diffuse : COLOR;
3576 output main(const input v)
3578 output o;
3580 o.position = mul(v.position, mat);
3581 o.diffuse = dot((float3)light, v.normal);
3583 return o;
3585 #endif
3586 static const DWORD vs_4_1[] =
3588 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
3589 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
3590 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
3591 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
3592 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3593 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
3594 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
3595 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3596 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
3597 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
3598 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
3599 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
3600 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
3601 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
3602 0x0100003e,
3604 static const DWORD vs_4_0[] =
3606 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3607 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3608 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3609 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3610 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3611 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3612 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3613 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3614 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3615 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3616 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3617 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3618 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3619 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3620 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3621 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3623 static const DWORD vs_3_0[] =
3625 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3626 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3627 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3628 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3629 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3630 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3631 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3632 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3633 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3634 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3635 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3636 0x0000ffff,
3638 static const DWORD vs_2_0[] =
3640 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3641 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3642 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3643 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3644 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3645 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3646 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3647 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3648 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3649 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3650 0x90e40001, 0x0000ffff,
3653 #if 0
3654 float4 main(const float4 color : COLOR) : SV_TARGET
3656 float4 o;
3658 o = color;
3660 return o;
3662 #endif
3663 static const DWORD ps_4_1[] =
3665 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
3666 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3667 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3668 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3669 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
3670 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3671 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3673 static const DWORD ps_4_0[] =
3675 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
3676 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3677 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3678 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3679 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3680 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3681 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3683 static const DWORD ps_4_0_level_9_0[] =
3685 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
3686 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
3687 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
3688 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
3689 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
3690 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
3691 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
3692 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
3693 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3694 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
3695 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3696 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3697 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
3698 0xabab0054,
3700 static const DWORD ps_4_0_level_9_1[] =
3702 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
3703 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3704 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3705 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3706 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3707 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3708 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3709 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3710 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3711 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3712 0x45475241, 0xabab0054,
3714 static const DWORD ps_4_0_level_9_3[] =
3716 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
3717 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3718 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3719 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3720 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3721 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3722 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3723 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3724 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3725 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3726 0x45475241, 0xabab0054,
3729 #if 0
3730 struct gs_out
3732 float4 pos : SV_POSITION;
3735 [maxvertexcount(4)]
3736 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3738 float offset = 0.1 * vin[0].w;
3739 gs_out v;
3741 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3742 vout.Append(v);
3743 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3744 vout.Append(v);
3745 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3746 vout.Append(v);
3747 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3748 vout.Append(v);
3750 #endif
3751 static const DWORD gs_4_1[] =
3753 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
3754 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3755 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3756 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3757 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
3758 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
3759 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
3760 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
3761 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
3762 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3763 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
3764 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3765 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
3766 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3767 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
3768 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3769 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
3770 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3772 static const DWORD gs_4_0[] =
3774 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3775 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3776 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3777 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3778 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3779 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3780 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3781 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3782 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3783 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3784 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3785 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3786 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3787 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3788 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3789 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3790 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3791 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3794 ULONG refcount, expected_refcount;
3795 struct device_desc device_desc;
3796 ID3D11Device *device, *tmp;
3797 ID3D11GeometryShader *gs;
3798 ID3D11VertexShader *vs;
3799 ID3D11PixelShader *ps;
3800 HRESULT hr;
3802 device_desc.feature_level = &feature_level;
3803 device_desc.flags = 0;
3804 if (!(device = create_device(&device_desc)))
3806 skip("Failed to create device for feature level %#x.\n", feature_level);
3807 return;
3810 /* level_9 shaders */
3811 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
3812 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3813 ID3D11PixelShader_Release(ps);
3815 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
3816 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3817 ID3D11PixelShader_Release(ps);
3819 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
3820 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3821 ID3D11PixelShader_Release(ps);
3823 /* vertex shader */
3824 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
3825 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3827 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
3828 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3830 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
3831 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
3832 hr, feature_level);
3834 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3835 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
3836 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3837 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3838 else
3839 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3841 refcount = get_refcount(device);
3842 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3843 refcount, expected_refcount);
3844 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3846 tmp = NULL;
3847 expected_refcount = refcount + 1;
3848 ID3D11VertexShader_GetDevice(vs, &tmp);
3849 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3850 refcount = get_refcount(device);
3851 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3852 refcount, expected_refcount);
3853 ID3D11Device_Release(tmp);
3855 /* Not available on all Windows versions. */
3856 check_interface(vs, &IID_ID3D10VertexShader, TRUE, TRUE);
3858 refcount = ID3D11VertexShader_Release(vs);
3859 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3862 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
3863 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3865 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3866 hr, feature_level);
3867 refcount = ID3D11VertexShader_Release(vs);
3868 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3870 else
3872 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3873 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3874 hr, feature_level);
3875 if (SUCCEEDED(hr))
3876 ID3D11VertexShader_Release(vs);
3879 /* pixel shader */
3880 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3881 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
3882 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3883 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3884 else
3885 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3887 refcount = get_refcount(device);
3888 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3889 refcount, expected_refcount);
3890 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3892 tmp = NULL;
3893 expected_refcount = refcount + 1;
3894 ID3D11PixelShader_GetDevice(ps, &tmp);
3895 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3896 refcount = get_refcount(device);
3897 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3898 refcount, expected_refcount);
3899 ID3D11Device_Release(tmp);
3901 /* Not available on all Windows versions. */
3902 check_interface(ps, &IID_ID3D10PixelShader, TRUE, TRUE);
3904 refcount = ID3D11PixelShader_Release(ps);
3905 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3908 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
3909 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3911 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
3912 hr, feature_level);
3913 refcount = ID3D11PixelShader_Release(ps);
3914 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3916 else
3918 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3919 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3920 if (SUCCEEDED(hr))
3921 ID3D11PixelShader_Release(ps);
3924 /* geometry shader */
3925 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3926 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
3927 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3928 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3929 else
3930 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3932 refcount = get_refcount(device);
3933 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3934 refcount, expected_refcount);
3935 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3937 tmp = NULL;
3938 expected_refcount = refcount + 1;
3939 ID3D11GeometryShader_GetDevice(gs, &tmp);
3940 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3941 refcount = get_refcount(device);
3942 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3943 refcount, expected_refcount);
3944 ID3D11Device_Release(tmp);
3946 /* Not available on all Windows versions. */
3947 check_interface(gs, &IID_ID3D10GeometryShader, TRUE, TRUE);
3949 refcount = ID3D11GeometryShader_Release(gs);
3950 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3953 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
3954 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3956 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
3957 hr, feature_level);
3958 refcount = ID3D11GeometryShader_Release(gs);
3959 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3961 else
3963 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3964 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
3965 hr, feature_level);
3966 if (SUCCEEDED(hr))
3967 ID3D11GeometryShader_Release(gs);
3970 refcount = ID3D11Device_Release(device);
3971 ok(!refcount, "Device has %u references left.\n", refcount);
3974 static void test_create_sampler_state(void)
3976 static const struct test
3978 D3D11_FILTER filter;
3979 D3D10_FILTER expected_filter;
3981 desc_conversion_tests[] =
3983 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
3984 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
3985 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
3986 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
3987 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
3988 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
3989 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
3990 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
3991 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
3992 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
3993 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
3995 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
3996 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
3998 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
3999 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
4001 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
4002 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
4004 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
4005 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
4006 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
4009 ID3D11SamplerState *sampler_state1, *sampler_state2;
4010 ID3D10SamplerState *d3d10_sampler_state;
4011 ULONG refcount, expected_refcount;
4012 ID3D11Device *device, *tmp;
4013 D3D11_SAMPLER_DESC desc;
4014 unsigned int i;
4015 HRESULT hr;
4017 if (!(device = create_device(NULL)))
4019 skip("Failed to create device.\n");
4020 return;
4023 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
4024 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4026 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
4027 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4028 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4029 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
4030 desc.MipLODBias = 0.0f;
4031 desc.MaxAnisotropy = 16;
4032 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4033 desc.BorderColor[0] = 0.0f;
4034 desc.BorderColor[1] = 1.0f;
4035 desc.BorderColor[2] = 0.0f;
4036 desc.BorderColor[3] = 1.0f;
4037 desc.MinLOD = 0.0f;
4038 desc.MaxLOD = 16.0f;
4040 expected_refcount = get_refcount(device) + 1;
4041 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4042 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4043 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
4044 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4045 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4046 refcount = get_refcount(device);
4047 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4048 tmp = NULL;
4049 expected_refcount = refcount + 1;
4050 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
4051 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4052 refcount = get_refcount(device);
4053 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4054 ID3D11Device_Release(tmp);
4056 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
4057 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4058 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4059 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4060 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4061 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4062 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4063 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4064 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4065 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4066 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4067 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4068 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4070 refcount = ID3D11SamplerState_Release(sampler_state2);
4071 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4072 refcount = ID3D11SamplerState_Release(sampler_state1);
4073 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4075 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4077 const struct test *current = &desc_conversion_tests[i];
4078 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4080 desc.Filter = current->filter;
4081 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4082 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4083 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4084 desc.MipLODBias = 0.0f;
4085 desc.MaxAnisotropy = 16;
4086 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4087 desc.BorderColor[0] = 0.0f;
4088 desc.BorderColor[1] = 1.0f;
4089 desc.BorderColor[2] = 0.0f;
4090 desc.BorderColor[3] = 1.0f;
4091 desc.MinLOD = 0.0f;
4092 desc.MaxLOD = 16.0f;
4094 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4095 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4097 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
4098 (void **)&d3d10_sampler_state);
4099 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4100 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4101 if (FAILED(hr))
4103 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
4104 ID3D11SamplerState_Release(sampler_state1);
4105 break;
4108 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4109 expected_desc.Filter = current->expected_filter;
4110 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4111 expected_desc.MaxAnisotropy = 0;
4112 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4113 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4115 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
4116 ok(d3d10_desc.Filter == expected_desc.Filter,
4117 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
4118 ok(d3d10_desc.AddressU == expected_desc.AddressU,
4119 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
4120 ok(d3d10_desc.AddressV == expected_desc.AddressV,
4121 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
4122 ok(d3d10_desc.AddressW == expected_desc.AddressW,
4123 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
4124 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
4125 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
4126 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4127 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
4128 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4129 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
4130 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
4131 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
4132 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
4133 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
4134 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4135 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
4136 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
4137 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
4138 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
4139 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
4140 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
4142 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
4143 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4144 refcount = ID3D11SamplerState_Release(sampler_state1);
4145 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4148 refcount = ID3D11Device_Release(device);
4149 ok(!refcount, "Device has %u references left.\n", refcount);
4152 static void test_create_blend_state(void)
4154 static const D3D11_BLEND_DESC desc_conversion_tests[] =
4157 FALSE, FALSE,
4160 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4161 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
4166 FALSE, TRUE,
4169 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4170 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4173 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4174 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
4177 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4178 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4181 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4182 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
4185 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4186 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4189 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4190 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4193 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4194 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4197 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4198 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4203 FALSE, TRUE,
4206 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4207 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4210 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
4211 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4214 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
4215 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4218 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4219 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4222 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
4223 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4226 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
4227 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4230 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4231 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4234 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4235 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4241 ID3D11BlendState *blend_state1, *blend_state2;
4242 D3D11_BLEND_DESC desc, obtained_desc;
4243 ID3D10BlendState *d3d10_blend_state;
4244 D3D10_BLEND_DESC d3d10_blend_desc;
4245 ULONG refcount, expected_refcount;
4246 ID3D11Device *device, *tmp;
4247 unsigned int i, j;
4248 HRESULT hr;
4250 if (!(device = create_device(NULL)))
4252 skip("Failed to create device.\n");
4253 return;
4256 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
4257 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4259 memset(&desc, 0, sizeof(desc));
4260 desc.AlphaToCoverageEnable = FALSE;
4261 desc.IndependentBlendEnable = FALSE;
4262 desc.RenderTarget[0].BlendEnable = FALSE;
4263 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
4264 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
4265 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
4266 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
4267 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
4268 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
4269 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
4271 expected_refcount = get_refcount(device) + 1;
4272 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
4273 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4274 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
4275 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4276 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4277 refcount = get_refcount(device);
4278 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4279 tmp = NULL;
4280 expected_refcount = refcount + 1;
4281 ID3D11BlendState_GetDevice(blend_state1, &tmp);
4282 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4283 refcount = get_refcount(device);
4284 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4285 ID3D11Device_Release(tmp);
4287 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
4288 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
4289 obtained_desc.AlphaToCoverageEnable);
4290 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
4291 obtained_desc.IndependentBlendEnable);
4292 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4294 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
4295 "Got unexpected blend enable %#x for render target %u.\n",
4296 obtained_desc.RenderTarget[i].BlendEnable, i);
4297 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
4298 "Got unexpected src blend %u for render target %u.\n",
4299 obtained_desc.RenderTarget[i].SrcBlend, i);
4300 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
4301 "Got unexpected dest blend %u for render target %u.\n",
4302 obtained_desc.RenderTarget[i].DestBlend, i);
4303 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
4304 "Got unexpected blend op %u for render target %u.\n",
4305 obtained_desc.RenderTarget[i].BlendOp, i);
4306 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
4307 "Got unexpected src blend alpha %u for render target %u.\n",
4308 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
4309 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
4310 "Got unexpected dest blend alpha %u for render target %u.\n",
4311 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
4312 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
4313 "Got unexpected blend op alpha %u for render target %u.\n",
4314 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
4315 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
4316 "Got unexpected render target write mask %#x for render target %u.\n",
4317 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
4320 /* Not available on all Windows versions. */
4321 check_interface(blend_state1, &IID_ID3D10BlendState, TRUE, TRUE);
4322 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
4324 refcount = ID3D11BlendState_Release(blend_state1);
4325 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4326 refcount = ID3D11BlendState_Release(blend_state2);
4327 ok(!refcount, "Blend state has %u references left.\n", refcount);
4329 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4331 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
4333 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
4334 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4336 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
4337 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4338 "Blend state should implement ID3D10BlendState.\n");
4339 if (FAILED(hr))
4341 win_skip("Blend state does not implement ID3D10BlendState.\n");
4342 ID3D11BlendState_Release(blend_state1);
4343 break;
4346 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
4347 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
4348 "Got unexpected alpha to coverage enable %#x for test %u.\n",
4349 d3d10_blend_desc.AlphaToCoverageEnable, i);
4350 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
4351 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
4352 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
4353 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
4354 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
4355 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
4356 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
4357 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
4358 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
4359 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
4360 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
4361 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
4362 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
4364 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
4365 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
4366 "Got unexpected blend enable %#x for test %u, render target %u.\n",
4367 d3d10_blend_desc.BlendEnable[j], i, j);
4368 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
4369 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
4370 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
4373 ID3D10BlendState_Release(d3d10_blend_state);
4375 refcount = ID3D11BlendState_Release(blend_state1);
4376 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4379 refcount = ID3D11Device_Release(device);
4380 ok(!refcount, "Device has %u references left.\n", refcount);
4383 static void test_create_depthstencil_state(void)
4385 ID3D11DepthStencilState *ds_state1, *ds_state2;
4386 ULONG refcount, expected_refcount;
4387 D3D11_DEPTH_STENCIL_DESC ds_desc;
4388 ID3D11Device *device, *tmp;
4389 HRESULT hr;
4391 if (!(device = create_device(NULL)))
4393 skip("Failed to create device.\n");
4394 return;
4397 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
4398 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4400 ds_desc.DepthEnable = TRUE;
4401 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
4402 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
4403 ds_desc.StencilEnable = FALSE;
4404 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
4405 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
4406 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4407 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4408 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4409 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4410 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4411 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4412 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4413 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4415 expected_refcount = get_refcount(device) + 1;
4416 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4417 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4418 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4419 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4420 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4421 refcount = get_refcount(device);
4422 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4423 tmp = NULL;
4424 expected_refcount = refcount + 1;
4425 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
4426 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4427 refcount = get_refcount(device);
4428 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4429 ID3D11Device_Release(tmp);
4431 /* Not available on all Windows versions. */
4432 check_interface(ds_state1, &IID_ID3D10DepthStencilState, TRUE, TRUE);
4434 refcount = ID3D11DepthStencilState_Release(ds_state2);
4435 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4436 refcount = ID3D11DepthStencilState_Release(ds_state1);
4437 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4439 ds_desc.DepthEnable = FALSE;
4440 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
4441 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
4442 ds_desc.StencilEnable = FALSE;
4443 ds_desc.StencilReadMask = 0;
4444 ds_desc.StencilWriteMask = 0;
4445 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
4446 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
4447 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
4448 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
4449 ds_desc.BackFace = ds_desc.FrontFace;
4451 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4452 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4454 memset(&ds_desc, 0, sizeof(ds_desc));
4455 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
4456 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4457 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
4458 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4459 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4460 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4461 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
4462 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4463 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
4464 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4465 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4466 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4467 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4468 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4469 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4470 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4471 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4472 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4473 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4474 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4475 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4476 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4477 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4478 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4479 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4480 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4482 ID3D11DepthStencilState_Release(ds_state1);
4484 refcount = ID3D11Device_Release(device);
4485 ok(!refcount, "Device has %u references left.\n", refcount);
4488 static void test_create_rasterizer_state(void)
4490 ID3D11RasterizerState *rast_state1, *rast_state2;
4491 ID3D10RasterizerState *d3d10_rast_state;
4492 ULONG refcount, expected_refcount;
4493 D3D10_RASTERIZER_DESC d3d10_desc;
4494 D3D11_RASTERIZER_DESC desc;
4495 ID3D11Device *device, *tmp;
4496 HRESULT hr;
4498 if (!(device = create_device(NULL)))
4500 skip("Failed to create device.\n");
4501 return;
4504 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
4505 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4507 desc.FillMode = D3D11_FILL_SOLID;
4508 desc.CullMode = D3D11_CULL_BACK;
4509 desc.FrontCounterClockwise = FALSE;
4510 desc.DepthBias = 0;
4511 desc.DepthBiasClamp = 0.0f;
4512 desc.SlopeScaledDepthBias = 0.0f;
4513 desc.DepthClipEnable = TRUE;
4514 desc.ScissorEnable = FALSE;
4515 desc.MultisampleEnable = FALSE;
4516 desc.AntialiasedLineEnable = FALSE;
4518 expected_refcount = get_refcount(device) + 1;
4519 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
4520 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4521 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
4522 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4523 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4524 refcount = get_refcount(device);
4525 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4526 tmp = NULL;
4527 expected_refcount = refcount + 1;
4528 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
4529 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4530 refcount = get_refcount(device);
4531 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4532 ID3D11Device_Release(tmp);
4534 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
4535 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4536 "Rasterizer state should implement ID3D10RasterizerState.\n");
4537 if (SUCCEEDED(hr))
4539 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
4540 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
4541 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
4542 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
4543 d3d10_desc.FrontCounterClockwise);
4544 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
4545 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
4546 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
4547 d3d10_desc.SlopeScaledDepthBias);
4548 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
4549 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
4550 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
4551 d3d10_desc.MultisampleEnable);
4552 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
4553 d3d10_desc.AntialiasedLineEnable);
4555 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
4556 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4559 refcount = ID3D11RasterizerState_Release(rast_state2);
4560 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4561 refcount = ID3D11RasterizerState_Release(rast_state1);
4562 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4564 refcount = ID3D11Device_Release(device);
4565 ok(!refcount, "Device has %u references left.\n", refcount);
4568 static void test_create_query(void)
4570 static const struct
4572 D3D11_QUERY query;
4573 D3D_FEATURE_LEVEL required_feature_level;
4574 BOOL is_predicate;
4575 BOOL can_use_create_predicate;
4576 BOOL todo;
4578 tests[] =
4580 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4581 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4582 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4583 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4584 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4585 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
4586 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4587 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
4588 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4589 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4590 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4591 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4592 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4593 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4594 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4595 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4598 ULONG refcount, expected_refcount;
4599 D3D_FEATURE_LEVEL feature_level;
4600 D3D11_QUERY_DESC query_desc;
4601 ID3D11Predicate *predicate;
4602 ID3D11Device *device, *tmp;
4603 HRESULT hr, expected_hr;
4604 ID3D11Query *query;
4605 unsigned int i;
4607 if (!(device = create_device(NULL)))
4609 skip("Failed to create device.\n");
4610 return;
4612 feature_level = ID3D11Device_GetFeatureLevel(device);
4614 hr = ID3D11Device_CreateQuery(device, NULL, &query);
4615 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4616 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
4617 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4619 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4621 if (tests[i].required_feature_level > feature_level)
4623 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
4624 continue;
4627 query_desc.Query = tests[i].query;
4628 query_desc.MiscFlags = 0;
4630 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
4631 todo_wine_if(tests[i].todo)
4632 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4634 query_desc.Query = tests[i].query;
4635 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
4636 todo_wine_if(tests[i].todo)
4637 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4638 if (FAILED(hr))
4639 continue;
4641 check_interface(query, &IID_ID3D11Predicate, tests[i].is_predicate, FALSE);
4642 ID3D11Query_Release(query);
4644 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
4645 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
4646 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4648 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
4649 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4650 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4651 if (SUCCEEDED(hr))
4652 ID3D11Predicate_Release(predicate);
4655 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
4656 expected_refcount = get_refcount(device) + 1;
4657 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4658 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4659 refcount = get_refcount(device);
4660 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4661 tmp = NULL;
4662 expected_refcount = refcount + 1;
4663 ID3D11Predicate_GetDevice(predicate, &tmp);
4664 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4665 refcount = get_refcount(device);
4666 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4667 ID3D11Device_Release(tmp);
4668 /* Not available on all Windows versions. */
4669 check_interface(predicate, &IID_ID3D10Predicate, TRUE, TRUE);
4670 ID3D11Predicate_Release(predicate);
4672 refcount = ID3D11Device_Release(device);
4673 ok(!refcount, "Device has %u references left.\n", refcount);
4676 static void test_occlusion_query(void)
4678 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4679 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4681 struct d3d11_test_context test_context;
4682 D3D11_TEXTURE2D_DESC texture_desc;
4683 ID3D11DeviceContext *context;
4684 ID3D11RenderTargetView *rtv;
4685 D3D11_QUERY_DESC query_desc;
4686 ID3D11Asynchronous *query;
4687 unsigned int data_size, i;
4688 ID3D11Texture2D *texture;
4689 ID3D11Device *device;
4690 D3D11_VIEWPORT vp;
4691 union
4693 UINT64 uint;
4694 DWORD dword[2];
4695 } data;
4696 HRESULT hr;
4698 if (!init_test_context(&test_context, NULL))
4699 return;
4701 device = test_context.device;
4702 context = test_context.immediate_context;
4704 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4706 query_desc.Query = D3D11_QUERY_OCCLUSION;
4707 query_desc.MiscFlags = 0;
4708 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4709 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4710 data_size = ID3D11Asynchronous_GetDataSize(query);
4711 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4713 memset(&data, 0xff, sizeof(data));
4714 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4715 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4716 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4717 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4718 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4719 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4721 ID3D11DeviceContext_End(context, query);
4722 ID3D11DeviceContext_Begin(context, query);
4723 ID3D11DeviceContext_Begin(context, query);
4725 memset(&data, 0xff, sizeof(data));
4726 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4727 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4728 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4729 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4730 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4731 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4733 draw_color_quad(&test_context, &red);
4735 ID3D11DeviceContext_End(context, query);
4736 for (i = 0; i < 500; ++i)
4738 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4739 break;
4740 Sleep(10);
4742 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4744 memset(&data, 0xff, sizeof(data));
4745 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4746 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4747 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4749 memset(&data, 0xff, sizeof(data));
4750 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
4751 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4752 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
4753 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4754 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
4755 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4756 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
4757 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4758 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4759 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4761 memset(&data, 0xff, sizeof(data));
4762 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
4763 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4764 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4765 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4767 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
4768 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4769 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
4770 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4772 ID3D11DeviceContext_Begin(context, query);
4773 ID3D11DeviceContext_End(context, query);
4774 ID3D11DeviceContext_End(context, query);
4776 for (i = 0; i < 500; ++i)
4778 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4779 break;
4780 Sleep(10);
4782 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4784 data.dword[0] = 0x12345678;
4785 data.dword[1] = 0x12345678;
4786 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4787 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4788 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4789 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4790 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4792 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4793 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4794 texture_desc.MipLevels = 1;
4795 texture_desc.ArraySize = 1;
4796 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4797 texture_desc.SampleDesc.Count = 1;
4798 texture_desc.SampleDesc.Quality = 0;
4799 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4800 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4801 texture_desc.CPUAccessFlags = 0;
4802 texture_desc.MiscFlags = 0;
4803 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4804 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4805 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
4806 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4808 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
4809 vp.TopLeftX = 0.0f;
4810 vp.TopLeftY = 0.0f;
4811 vp.Width = texture_desc.Width;
4812 vp.Height = texture_desc.Height;
4813 vp.MinDepth = 0.0f;
4814 vp.MaxDepth = 1.0f;
4815 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4817 ID3D11DeviceContext_Begin(context, query);
4818 for (i = 0; i < 100; i++)
4819 draw_color_quad(&test_context, &red);
4820 ID3D11DeviceContext_End(context, query);
4822 for (i = 0; i < 500; ++i)
4824 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4825 break;
4826 Sleep(10);
4828 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4830 memset(&data, 0xff, sizeof(data));
4831 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4832 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4833 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4834 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4835 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4836 || (data.dword[0] == 0xffffffff && !data.dword[1])
4837 || broken(!data.uint),
4838 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4840 ID3D11Asynchronous_Release(query);
4842 /* The following test exercises a code path in wined3d. A wined3d context
4843 * associated with the query is destroyed when the swapchain is released. */
4844 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4845 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4847 vp.Width = 64.0f;
4848 vp.Height = 64.0f;
4849 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4850 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4851 ID3D11DeviceContext_Begin(context, query);
4852 draw_color_quad(&test_context, &red);
4853 ID3D11DeviceContext_End(context, query);
4855 ID3D11RenderTargetView_Release(test_context.backbuffer_rtv);
4856 ID3D11Texture2D_Release(test_context.backbuffer);
4857 IDXGISwapChain_Release(test_context.swapchain);
4858 test_context.swapchain = create_swapchain(device, test_context.window, NULL);
4859 hr = IDXGISwapChain_GetBuffer(test_context.swapchain, 0, &IID_ID3D11Texture2D,
4860 (void **)&test_context.backbuffer);
4861 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
4862 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer,
4863 NULL, &test_context.backbuffer_rtv);
4864 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4865 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
4866 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4868 for (i = 0; i < 500; ++i)
4870 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4871 break;
4872 Sleep(10);
4874 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4875 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4876 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4877 /* This test occasionally succeeds with CSMT enabled because of a race condition. */
4878 if (0)
4879 todo_wine ok(data.dword[0] == 0x1000 && !data.dword[1],
4880 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4882 ID3D11Asynchronous_Release(query);
4883 ID3D11RenderTargetView_Release(rtv);
4884 ID3D11Texture2D_Release(texture);
4885 release_test_context(&test_context);
4888 static void test_timestamp_query(void)
4890 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4892 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
4893 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
4894 struct d3d11_test_context test_context;
4895 ID3D11DeviceContext *context;
4896 D3D11_QUERY_DESC query_desc;
4897 unsigned int data_size, i;
4898 ID3D11Device *device;
4899 UINT64 timestamp;
4900 HRESULT hr;
4902 if (!init_test_context(&test_context, NULL))
4903 return;
4905 device = test_context.device;
4906 context = test_context.immediate_context;
4908 query_desc.Query = D3D11_QUERY_TIMESTAMP;
4909 query_desc.MiscFlags = 0;
4910 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
4911 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4912 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
4913 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
4915 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
4916 query_desc.MiscFlags = 0;
4917 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
4918 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4919 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
4920 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
4922 disjoint.Frequency = 0xdeadbeef;
4923 disjoint.Disjoint = 0xdeadbeef;
4924 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4925 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4926 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4927 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4928 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4929 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
4931 /* Test a TIMESTAMP_DISJOINT query. */
4932 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
4934 disjoint.Frequency = 0xdeadbeef;
4935 disjoint.Disjoint = 0xdeadbeef;
4936 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4937 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4938 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4939 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4940 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4941 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
4943 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
4944 for (i = 0; i < 500; ++i)
4946 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
4947 break;
4948 Sleep(10);
4950 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4952 disjoint.Frequency = 0xdeadbeef;
4953 disjoint.Disjoint = 0xff;
4954 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4955 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4956 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
4957 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4959 prev_disjoint = disjoint;
4961 disjoint.Frequency = 0xdeadbeef;
4962 disjoint.Disjoint = 0xff;
4963 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
4964 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4965 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
4966 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4967 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
4968 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4969 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
4970 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4971 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4972 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
4974 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4975 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4976 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
4977 D3D11_ASYNC_GETDATA_DONOTFLUSH);
4978 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4979 ok(!memcmp(&disjoint, &prev_disjoint, sizeof(disjoint)), "Disjoint data mismatch.\n");
4981 memset(&timestamp, 0xff, sizeof(timestamp));
4982 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
4983 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4984 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4985 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4986 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
4988 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
4989 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
4991 memset(&timestamp, 0xff, sizeof(timestamp));
4992 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4993 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4994 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
4996 draw_color_quad(&test_context, &red);
4998 ID3D11DeviceContext_End(context, timestamp_query);
4999 for (i = 0; i < 500; ++i)
5001 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
5002 break;
5003 Sleep(10);
5005 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5007 timestamp = 0xdeadbeef;
5008 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5009 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5010 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5012 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5013 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5014 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
5016 timestamp = 0xdeadbeef;
5017 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
5018 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5019 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
5020 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5021 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5022 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5023 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
5024 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5025 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5027 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5028 for (i = 0; i < 500; ++i)
5030 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
5031 break;
5032 Sleep(10);
5034 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5036 disjoint.Frequency = 0xdeadbeef;
5037 disjoint.Disjoint = 0xff;
5038 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5039 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5040 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
5041 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5043 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
5044 ID3D11Asynchronous_Release(timestamp_query);
5045 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5046 query_desc.MiscFlags = 0;
5047 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5048 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5050 draw_color_quad(&test_context, &red);
5052 ID3D11DeviceContext_End(context, timestamp_query);
5053 for (i = 0; i < 500; ++i)
5055 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
5056 break;
5057 Sleep(10);
5059 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5060 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5061 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5063 ID3D11Asynchronous_Release(timestamp_query);
5064 ID3D11Asynchronous_Release(timestamp_disjoint_query);
5065 release_test_context(&test_context);
5068 static void test_device_removed_reason(void)
5070 ID3D11Device *device;
5071 ULONG refcount;
5072 HRESULT hr;
5074 if (!(device = create_device(NULL)))
5076 skip("Failed to create device.\n");
5077 return;
5080 hr = ID3D11Device_GetDeviceRemovedReason(device);
5081 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5082 hr = ID3D11Device_GetDeviceRemovedReason(device);
5083 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5085 refcount = ID3D11Device_Release(device);
5086 ok(!refcount, "Device has %u references left.\n", refcount);
5089 static void test_private_data(void)
5091 ULONG refcount, expected_refcount;
5092 D3D11_TEXTURE2D_DESC texture_desc;
5093 ID3D10Texture2D *d3d10_texture;
5094 ID3D11Device *test_object;
5095 ID3D11Texture2D *texture;
5096 IDXGIDevice *dxgi_device;
5097 IDXGISurface *surface;
5098 ID3D11Device *device;
5099 IUnknown *ptr;
5100 HRESULT hr;
5101 UINT size;
5103 static const GUID test_guid =
5104 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
5105 static const GUID test_guid2 =
5106 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
5107 static const DWORD data[] = {1, 2, 3, 4};
5109 if (!(device = create_device(NULL)))
5111 skip("Failed to create device.\n");
5112 return;
5115 test_object = create_device(NULL);
5117 texture_desc.Width = 512;
5118 texture_desc.Height = 512;
5119 texture_desc.MipLevels = 1;
5120 texture_desc.ArraySize = 1;
5121 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5122 texture_desc.SampleDesc.Count = 1;
5123 texture_desc.SampleDesc.Quality = 0;
5124 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5125 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5126 texture_desc.CPUAccessFlags = 0;
5127 texture_desc.MiscFlags = 0;
5129 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5130 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5131 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
5132 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
5134 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
5135 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5136 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5137 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5138 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5139 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5140 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5141 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5143 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5144 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5145 size = sizeof(ptr) * 2;
5146 ptr = (IUnknown *)0xdeadbeef;
5147 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5148 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5149 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5150 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5152 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
5153 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
5154 size = sizeof(ptr) * 2;
5155 ptr = (IUnknown *)0xdeadbeef;
5156 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
5157 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5158 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5159 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5160 IDXGIDevice_Release(dxgi_device);
5162 refcount = get_refcount(test_object);
5163 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5164 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5165 expected_refcount = refcount + 1;
5166 refcount = get_refcount(test_object);
5167 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5168 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5169 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5170 refcount = get_refcount(test_object);
5171 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5173 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5174 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5175 --expected_refcount;
5176 refcount = get_refcount(test_object);
5177 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5179 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5180 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5181 size = sizeof(data);
5182 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
5183 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5184 refcount = get_refcount(test_object);
5185 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5186 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5187 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5188 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5189 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5191 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5192 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5193 ++expected_refcount;
5194 size = 2 * sizeof(ptr);
5195 ptr = NULL;
5196 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5197 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5198 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
5199 ++expected_refcount;
5200 refcount = get_refcount(test_object);
5201 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5202 IUnknown_Release(ptr);
5203 --expected_refcount;
5205 ptr = (IUnknown *)0xdeadbeef;
5206 size = 1;
5207 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5208 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5209 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5210 size = 2 * sizeof(ptr);
5211 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5212 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5213 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5214 refcount = get_refcount(test_object);
5215 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5217 size = 1;
5218 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5219 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
5220 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5221 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5222 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
5223 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5224 size = 0xdeadbabe;
5225 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
5226 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
5227 ok(size == 0, "Got unexpected size %u.\n", size);
5228 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5229 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
5230 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5231 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5233 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
5234 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5235 ptr = NULL;
5236 size = sizeof(ptr);
5237 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
5238 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5239 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5240 IUnknown_Release(ptr);
5242 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
5243 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5244 "Texture should implement ID3D10Texture2D.\n");
5245 if (SUCCEEDED(hr))
5247 ptr = NULL;
5248 size = sizeof(ptr);
5249 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
5250 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5251 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5252 IUnknown_Release(ptr);
5253 ID3D10Texture2D_Release(d3d10_texture);
5256 IDXGISurface_Release(surface);
5257 ID3D11Texture2D_Release(texture);
5258 refcount = ID3D11Device_Release(device);
5259 ok(!refcount, "Device has %u references left.\n", refcount);
5260 refcount = ID3D11Device_Release(test_object);
5261 ok(!refcount, "Test object has %u references left.\n", refcount);
5264 static void test_state_refcounting(const D3D_FEATURE_LEVEL feature_level)
5266 ID3D11RasterizerState *rasterizer_state, *tmp_rasterizer_state;
5267 ID3D11Predicate *predicate, *tmp_predicate;
5268 ID3D11SamplerState *sampler, *tmp_sampler;
5269 ID3D11ShaderResourceView *srv, *tmp_srv;
5270 ID3D11RenderTargetView *rtv, *tmp_rtv;
5271 D3D11_RASTERIZER_DESC rasterizer_desc;
5272 D3D11_TEXTURE2D_DESC texture_desc;
5273 D3D11_QUERY_DESC predicate_desc;
5274 D3D11_SAMPLER_DESC sampler_desc;
5275 struct device_desc device_desc;
5276 ID3D11DeviceContext *context;
5277 ID3D11Texture2D *texture;
5278 ID3D11Device *device;
5279 ULONG refcount;
5280 HRESULT hr;
5282 device_desc.feature_level = &feature_level;
5283 device_desc.flags = 0;
5284 if (!(device = create_device(&device_desc)))
5286 skip("Failed to create device for feature level %#x.\n", feature_level);
5287 return;
5290 ID3D11Device_GetImmediateContext(device, &context);
5292 /* ID3D11SamplerState */
5293 memset(&sampler_desc, 0, sizeof(sampler_desc));
5294 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5295 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5296 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5297 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5298 sampler_desc.MaxLOD = FLT_MAX;
5299 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
5300 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5302 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
5303 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5304 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5305 ID3D11SamplerState_Release(tmp_sampler);
5307 tmp_sampler = sampler;
5308 refcount = get_refcount(sampler);
5309 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
5310 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
5311 refcount = ID3D11SamplerState_Release(sampler);
5312 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5313 sampler = NULL;
5314 ID3D11DeviceContext_PSGetSamplers(context, 0, 1, &sampler);
5315 ok(sampler == tmp_sampler, "Got sampler %p, expected %p.\n", sampler, tmp_sampler);
5316 refcount = ID3D11SamplerState_Release(sampler);
5317 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5319 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
5320 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5321 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5322 refcount = ID3D11SamplerState_Release(tmp_sampler);
5323 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5325 /* ID3D11RasterizerState */
5326 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
5327 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
5328 rasterizer_desc.CullMode = D3D11_CULL_BACK;
5329 rasterizer_desc.DepthClipEnable = TRUE;
5330 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
5331 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5333 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
5334 refcount = ID3D11RasterizerState_Release(rasterizer_state);
5335 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5336 ID3D11DeviceContext_RSGetState(context, &tmp_rasterizer_state);
5337 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
5338 tmp_rasterizer_state, rasterizer_state);
5339 refcount = ID3D11RasterizerState_Release(tmp_rasterizer_state);
5340 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5342 /* ID3D11ShaderResourceView */
5343 memset(&texture_desc, 0, sizeof(texture_desc));
5344 texture_desc.Width = 32;
5345 texture_desc.Height = 32;
5346 texture_desc.MipLevels = 1;
5347 texture_desc.ArraySize = 1;
5348 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5349 texture_desc.SampleDesc.Count = 1;
5350 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5351 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
5352 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5353 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5354 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
5355 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
5356 ID3D11Texture2D_Release(texture);
5358 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
5359 refcount = ID3D11ShaderResourceView_Release(srv);
5360 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5361 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &tmp_srv);
5362 ok(tmp_srv == srv, "Got SRV %p, expected %p.\n", tmp_srv, srv);
5363 refcount = ID3D11ShaderResourceView_Release(tmp_srv);
5364 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5366 /* ID3D11RenderTargetView */
5367 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5368 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5369 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5370 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
5371 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5372 ID3D11Texture2D_Release(texture);
5374 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
5375 refcount = ID3D11RenderTargetView_Release(rtv);
5376 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5377 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &tmp_rtv, NULL);
5378 ok(tmp_rtv == rtv, "Got RTV %p, expected %p.\n", tmp_rtv, rtv);
5379 refcount = ID3D11RenderTargetView_Release(tmp_rtv);
5380 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5382 /* ID3D11Predicate */
5383 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
5385 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
5386 predicate_desc.MiscFlags = 0;
5387 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
5388 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5390 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
5391 refcount = ID3D11Predicate_Release(predicate);
5392 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5393 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, NULL);
5394 ok(tmp_predicate == predicate, "Got predicate %p, expected %p.\n", tmp_predicate, predicate);
5395 refcount = ID3D11Predicate_Release(tmp_predicate);
5396 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5399 ID3D11DeviceContext_Release(context);
5400 refcount = ID3D11Device_Release(device);
5401 ok(!refcount, "Device has %u references left.\n", refcount);
5404 static void test_device_context_state(void)
5406 ID3DDeviceContextState *context_state, *previous_context_state;
5407 ID3D11SamplerState *sampler, *tmp_sampler;
5408 D3D11_SAMPLER_DESC sampler_desc;
5409 D3D_FEATURE_LEVEL feature_level;
5410 ID3D11DeviceContext1 *context;
5411 ID3D11Device *d3d11_device;
5412 ID3D11Device1 *device;
5413 ULONG refcount;
5414 HRESULT hr;
5416 if (!(d3d11_device = create_device(NULL)))
5418 skip("Failed to create device.\n");
5419 return;
5422 hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11Device1, (void **)&device);
5423 ID3D11Device_Release(d3d11_device);
5424 if (FAILED(hr))
5426 skip("ID3D11Device1 is not available.\n");
5427 return;
5430 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
5431 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
5433 feature_level = ID3D11Device1_GetFeatureLevel(device);
5434 ID3D11Device1_GetImmediateContext1(device, &context);
5436 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5437 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5438 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5439 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5440 sampler_desc.MipLODBias = 0.0f;
5441 sampler_desc.MaxAnisotropy = 0;
5442 sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
5443 sampler_desc.BorderColor[0] = 0.0f;
5444 sampler_desc.BorderColor[1] = 1.0f;
5445 sampler_desc.BorderColor[2] = 0.0f;
5446 sampler_desc.BorderColor[3] = 1.0f;
5447 sampler_desc.MinLOD = 0.0f;
5448 sampler_desc.MaxLOD = 16.0f;
5449 hr = ID3D11Device1_CreateSamplerState(device, &sampler_desc, &sampler);
5450 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5452 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5453 tmp_sampler = NULL;
5454 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5455 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5456 ID3D11SamplerState_Release(tmp_sampler);
5458 feature_level = min(feature_level, D3D_FEATURE_LEVEL_10_1);
5459 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
5460 &IID_ID3D10Device, NULL, &context_state);
5461 ok(SUCCEEDED(hr), "Failed to create device context state, hr %#x.\n", hr);
5462 refcount = get_refcount(context_state);
5463 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
5465 /* Enable ID3D10Device behavior. */
5466 previous_context_state = NULL;
5467 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
5468 refcount = ID3DDeviceContextState_Release(context_state);
5469 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5471 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5472 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
5473 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5474 ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler);
5475 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
5477 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
5478 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
5480 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
5481 refcount = ID3DDeviceContextState_Release(context_state);
5482 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5483 refcount = ID3DDeviceContextState_Release(previous_context_state);
5484 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5486 /* ID3DDeviceContextState retains the previous state. */
5487 tmp_sampler = NULL;
5488 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5489 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5490 ID3D11SamplerState_Release(tmp_sampler);
5492 tmp_sampler = NULL;
5493 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
5494 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
5495 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5496 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
5497 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5498 tmp_sampler = NULL;
5499 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5500 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5501 ID3D11SamplerState_Release(tmp_sampler);
5503 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
5504 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
5506 ID3D11SamplerState_Release(sampler);
5507 ID3D11DeviceContext1_Release(context);
5508 refcount = ID3D11Device1_Release(device);
5509 ok(!refcount, "Device has %u references left.\n", refcount);
5512 static void test_blend(void)
5514 ID3D11BlendState *src_blend, *dst_blend;
5515 struct d3d11_test_context test_context;
5516 ID3D11RenderTargetView *offscreen_rtv;
5517 D3D11_TEXTURE2D_DESC texture_desc;
5518 ID3D11InputLayout *input_layout;
5519 ID3D11DeviceContext *context;
5520 D3D11_BLEND_DESC blend_desc;
5521 unsigned int stride, offset;
5522 ID3D11Texture2D *offscreen;
5523 ID3D11VertexShader *vs;
5524 ID3D11PixelShader *ps;
5525 ID3D11Device *device;
5526 D3D11_VIEWPORT vp;
5527 ID3D11Buffer *vb;
5528 DWORD color;
5529 HRESULT hr;
5531 static const DWORD vs_code[] =
5533 #if 0
5534 struct vs_out
5536 float4 position : SV_POSITION;
5537 float4 color : COLOR;
5540 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5542 struct vs_out o;
5544 o.position = position;
5545 o.color = color;
5547 return o;
5549 #endif
5550 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5551 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5552 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5553 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5554 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5555 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5556 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5557 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5558 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5559 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5561 static const DWORD ps_code[] =
5563 #if 0
5564 struct vs_out
5566 float4 position : SV_POSITION;
5567 float4 color : COLOR;
5570 float4 main(struct vs_out i) : SV_TARGET
5572 return i.color;
5574 #endif
5575 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5576 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5577 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5578 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5579 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5580 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5581 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5582 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5584 static const struct
5586 struct vec3 position;
5587 DWORD diffuse;
5589 quads[] =
5591 /* quad1 */
5592 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5593 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5594 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5595 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5596 /* quad2 */
5597 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5598 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5599 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5600 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5602 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
5604 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
5605 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
5607 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5608 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5610 if (!init_test_context(&test_context, NULL))
5611 return;
5613 device = test_context.device;
5614 context = test_context.immediate_context;
5616 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
5617 vs_code, sizeof(vs_code), &input_layout);
5618 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5620 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5622 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
5623 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5624 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5625 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5627 memset(&blend_desc, 0, sizeof(blend_desc));
5628 blend_desc.RenderTarget[0].BlendEnable = TRUE;
5629 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
5630 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
5631 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
5632 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
5633 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
5634 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
5635 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5637 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
5638 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5640 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
5641 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
5642 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
5643 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
5645 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
5646 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5648 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
5649 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5650 stride = sizeof(*quads);
5651 offset = 0;
5652 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
5653 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
5654 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5656 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
5658 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5659 ID3D11DeviceContext_Draw(context, 4, 0);
5660 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5661 ID3D11DeviceContext_Draw(context, 4, 4);
5663 color = get_texture_color(test_context.backbuffer, 320, 360);
5664 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5665 color = get_texture_color(test_context.backbuffer, 320, 120);
5666 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5668 texture_desc.Width = 128;
5669 texture_desc.Height = 128;
5670 texture_desc.MipLevels = 1;
5671 texture_desc.ArraySize = 1;
5672 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5673 texture_desc.SampleDesc.Count = 1;
5674 texture_desc.SampleDesc.Quality = 0;
5675 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5676 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
5677 texture_desc.CPUAccessFlags = 0;
5678 texture_desc.MiscFlags = 0;
5680 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5681 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5683 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
5684 goto done;
5687 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
5688 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5690 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
5692 vp.TopLeftX = 0.0f;
5693 vp.TopLeftY = 0.0f;
5694 vp.Width = 128.0f;
5695 vp.Height = 128.0f;
5696 vp.MinDepth = 0.0f;
5697 vp.MaxDepth = 1.0f;
5698 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
5700 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
5702 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5703 ID3D11DeviceContext_Draw(context, 4, 0);
5704 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5705 ID3D11DeviceContext_Draw(context, 4, 4);
5707 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5708 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5709 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5710 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5712 ID3D11RenderTargetView_Release(offscreen_rtv);
5713 ID3D11Texture2D_Release(offscreen);
5714 done:
5715 ID3D11BlendState_Release(dst_blend);
5716 ID3D11BlendState_Release(src_blend);
5717 ID3D11PixelShader_Release(ps);
5718 ID3D11VertexShader_Release(vs);
5719 ID3D11Buffer_Release(vb);
5720 ID3D11InputLayout_Release(input_layout);
5721 release_test_context(&test_context);
5724 static void test_texture(void)
5726 struct shader
5728 const DWORD *code;
5729 size_t size;
5731 struct texture
5733 UINT width;
5734 UINT height;
5735 UINT miplevel_count;
5736 UINT array_size;
5737 DXGI_FORMAT format;
5738 D3D11_SUBRESOURCE_DATA data[3];
5741 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
5742 struct d3d11_test_context test_context;
5743 const struct texture *current_texture;
5744 D3D11_TEXTURE2D_DESC texture_desc;
5745 D3D11_SAMPLER_DESC sampler_desc;
5746 const struct shader *current_ps;
5747 D3D_FEATURE_LEVEL feature_level;
5748 ID3D11ShaderResourceView *srv;
5749 ID3D11DeviceContext *context;
5750 ID3D11SamplerState *sampler;
5751 struct resource_readback rb;
5752 ID3D11Texture2D *texture;
5753 struct vec4 ps_constant;
5754 ID3D11PixelShader *ps;
5755 ID3D11Device *device;
5756 unsigned int i, x, y;
5757 ID3D11Buffer *cb;
5758 DWORD color;
5759 HRESULT hr;
5761 static const DWORD ps_ld_code[] =
5763 #if 0
5764 Texture2D t;
5766 float miplevel;
5768 float4 main(float4 position : SV_POSITION) : SV_TARGET
5770 float3 p;
5771 t.GetDimensions(miplevel, p.x, p.y, p.z);
5772 p.z = miplevel;
5773 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5774 return t.Load(int3(p));
5776 #endif
5777 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5778 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5779 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5780 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5781 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5782 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5783 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5784 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5785 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5786 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5787 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5788 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5789 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5790 0x00107e46, 0x00000000, 0x0100003e,
5792 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5793 static const DWORD ps_ld_sint8_code[] =
5795 #if 0
5796 Texture2D<int4> t;
5798 float4 main(float4 position : SV_POSITION) : SV_TARGET
5800 float3 p, s;
5801 int4 c;
5803 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5804 t.GetDimensions(0, s.x, s.y, s.z);
5805 p *= s;
5807 c = t.Load(int3(p));
5808 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5810 #endif
5811 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
5812 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5813 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5814 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5815 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5816 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5817 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5818 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5819 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5820 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5821 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5822 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5823 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5824 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5825 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5826 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5827 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5828 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5830 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5831 static const DWORD ps_ld_uint8_code[] =
5833 #if 0
5834 Texture2D<uint4> t;
5836 float4 main(float4 position : SV_POSITION) : SV_TARGET
5838 float3 p, s;
5840 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5841 t.GetDimensions(0, s.x, s.y, s.z);
5842 p *= s;
5844 return t.Load(int3(p)) / (float4)255;
5846 #endif
5847 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5848 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5849 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5850 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5851 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5852 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5853 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5854 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5855 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5856 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5857 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5858 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5859 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5860 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5861 0x3b808081, 0x0100003e,
5863 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5864 static const DWORD ps_sample_code[] =
5866 #if 0
5867 Texture2D t;
5868 SamplerState s;
5870 float4 main(float4 position : SV_POSITION) : SV_Target
5872 float2 p;
5874 p.x = position.x / 640.0f;
5875 p.y = position.y / 480.0f;
5876 return t.Sample(s, p);
5878 #endif
5879 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5880 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5881 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5882 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5883 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5884 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5885 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5886 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5887 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5888 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5890 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
5891 static const DWORD ps_sample_b_code[] =
5893 #if 0
5894 Texture2D t;
5895 SamplerState s;
5897 float bias;
5899 float4 main(float4 position : SV_POSITION) : SV_Target
5901 float2 p;
5903 p.x = position.x / 640.0f;
5904 p.y = position.y / 480.0f;
5905 return t.SampleBias(s, p, bias);
5907 #endif
5908 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
5909 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5910 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5911 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5912 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5913 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5914 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5915 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5916 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
5917 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5918 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5920 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
5921 static const DWORD ps_sample_l_code[] =
5923 #if 0
5924 Texture2D t;
5925 SamplerState s;
5927 float level;
5929 float4 main(float4 position : SV_POSITION) : SV_Target
5931 float2 p;
5933 p.x = position.x / 640.0f;
5934 p.y = position.y / 480.0f;
5935 return t.SampleLevel(s, p, level);
5937 #endif
5938 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
5939 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5940 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5941 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5942 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5943 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5944 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5945 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5946 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
5947 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5948 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5950 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
5951 static const DWORD ps_sample_2d_array_code[] =
5953 #if 0
5954 Texture2DArray t;
5955 SamplerState s;
5957 float layer;
5959 float4 main(float4 position : SV_POSITION) : SV_TARGET
5961 float3 d;
5962 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5963 t.GetDimensions(d.x, d.y, d.z);
5964 d.z = layer;
5965 return t.Sample(s, p * d);
5967 #endif
5968 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
5969 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5970 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5971 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5972 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
5973 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5974 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5975 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
5976 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
5977 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
5978 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
5979 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
5980 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5982 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
5983 static const DWORD red_data[] =
5985 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5986 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5987 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5988 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5990 static const DWORD green_data[] =
5992 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5993 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5994 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5995 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5997 static const DWORD blue_data[] =
5999 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6000 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6001 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6002 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6004 static const DWORD rgba_level_0[] =
6006 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6007 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6008 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6009 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6011 static const DWORD rgba_level_1[] =
6013 0xffffffff, 0xff0000ff,
6014 0xff000000, 0xff00ff00,
6016 static const DWORD rgba_level_2[] =
6018 0xffff0000,
6020 static const DWORD srgb_data[] =
6022 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
6023 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
6024 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
6025 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
6027 static const BYTE a8_data[] =
6029 0x00, 0x10, 0x20, 0x30,
6030 0x40, 0x50, 0x60, 0x70,
6031 0x80, 0x90, 0xa0, 0xb0,
6032 0xc0, 0xd0, 0xe0, 0xf0,
6034 static const BYTE bc1_data[] =
6036 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6037 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6038 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6039 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6041 static const BYTE bc2_data[] =
6043 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6044 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6045 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6046 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6048 static const BYTE bc3_data[] =
6050 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6051 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6052 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6053 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6055 static const BYTE bc4_data[] =
6057 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6058 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6059 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6060 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6062 static const BYTE bc5_data[] =
6064 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6065 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6066 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6067 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6069 static const BYTE bc6h_u_data[] =
6071 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6072 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6073 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6074 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6076 static const BYTE bc6h_s_data[] =
6078 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6079 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6080 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6081 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6083 static const BYTE bc7_data[] =
6085 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6086 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6087 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6088 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
6090 static const float r32_float[] =
6092 0.0f, 1.0f, 0.5f, 0.50f,
6093 1.0f, 0.0f, 0.0f, 0.75f,
6094 0.0f, 1.0f, 0.5f, 0.25f,
6095 1.0f, 0.0f, 0.0f, 0.75f,
6097 static const DWORD r32_uint[] =
6099 0, 1, 2, 3,
6100 100, 200, 255, 128,
6101 40, 30, 20, 10,
6102 250, 210, 155, 190,
6104 static const struct texture rgba_texture =
6106 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
6108 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
6109 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
6110 {rgba_level_2, sizeof(*rgba_level_2), 0},
6113 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6114 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6115 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
6116 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6117 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
6118 {{a8_data, 4 * sizeof(*a8_data)}}};
6119 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
6120 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
6121 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
6122 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
6123 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
6124 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
6125 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
6126 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
6127 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
6128 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
6129 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
6130 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
6131 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
6132 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
6133 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
6134 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
6135 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6136 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
6137 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6138 static const struct texture array_2d_texture =
6140 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
6142 {red_data, 6 * sizeof(*red_data)},
6143 {green_data, 4 * sizeof(*green_data)},
6144 {blue_data, 5 * sizeof(*blue_data)},
6147 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6148 {{r32_float, 4 * sizeof(*r32_float)}}};
6149 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6150 {{r32_uint, 4 * sizeof(*r32_uint)}}};
6151 static const DWORD red_colors[] =
6153 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6154 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6155 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6156 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6158 static const DWORD blue_colors[] =
6160 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6161 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6162 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6163 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6165 static const DWORD level_1_colors[] =
6167 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6168 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6169 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6170 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6172 static const DWORD lerp_1_2_colors[] =
6174 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6175 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6176 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6177 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6179 static const DWORD level_2_colors[] =
6181 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6182 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6183 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6184 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6186 static const DWORD srgb_colors[] =
6188 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
6189 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
6190 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
6191 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
6193 static const DWORD a8_colors[] =
6195 0x00000000, 0x10000000, 0x20000000, 0x30000000,
6196 0x40000000, 0x50000000, 0x60000000, 0x70000000,
6197 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
6198 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
6200 static const DWORD bc_colors[] =
6202 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6203 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6204 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6205 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6207 static const DWORD bc4_colors[] =
6209 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
6210 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
6211 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6212 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6214 static const DWORD bc5_colors[] =
6216 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
6217 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
6218 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6219 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6221 static const DWORD bc7_colors[] =
6223 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6224 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6225 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6226 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6228 static const DWORD sint8_colors[] =
6230 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
6231 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
6232 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
6233 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
6235 static const DWORD r32f_colors[] =
6237 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
6238 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6239 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
6240 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6242 static const DWORD r32u_colors[16] =
6244 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6245 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
6246 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
6247 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
6249 static const DWORD zero_colors[4 * 4] = {0};
6250 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6252 static const struct texture_test
6254 const struct shader *ps;
6255 const struct texture *texture;
6256 D3D11_FILTER filter;
6257 float lod_bias;
6258 float min_lod;
6259 float max_lod;
6260 float ps_constant;
6261 const DWORD *expected_colors;
6263 texture_tests[] =
6265 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
6266 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
6267 #define MIP_MAX D3D11_FLOAT32_MAX
6268 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6269 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6270 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6271 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6272 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6273 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6274 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6275 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6276 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6277 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6278 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6279 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6280 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6281 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6282 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6283 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6284 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6285 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6286 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6287 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6288 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6289 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6290 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6291 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6292 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6293 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6294 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6295 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6296 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6297 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6298 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6299 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6300 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6301 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6302 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6303 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6304 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6305 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6306 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
6307 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6308 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6309 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6310 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6311 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
6312 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
6313 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
6314 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
6315 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
6316 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
6317 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
6318 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
6319 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6320 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6321 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6322 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6323 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
6324 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6325 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
6326 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
6327 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
6328 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
6329 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6330 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
6331 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
6332 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
6333 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
6334 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
6335 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
6336 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
6337 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
6338 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6339 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6340 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6341 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6342 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6343 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6344 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6345 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6346 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6347 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6348 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6349 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
6350 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
6351 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
6352 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
6353 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
6354 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
6355 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
6356 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
6357 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
6358 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
6359 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
6360 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
6361 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
6362 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
6363 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
6364 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
6365 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6366 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6367 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
6368 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6369 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6370 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
6371 #undef POINT
6372 #undef POINT_LINEAR
6373 #undef MIP_MAX
6375 static const struct srv_test
6377 const struct shader *ps;
6378 const struct texture *texture;
6379 struct srv_desc srv_desc;
6380 float ps_constant;
6381 const DWORD *expected_colors;
6383 srv_tests[] =
6385 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
6386 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
6387 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
6388 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
6389 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
6390 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
6391 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
6392 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
6393 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
6394 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
6395 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
6396 #define R32_UINT DXGI_FORMAT_R32_UINT
6397 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
6398 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6399 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6400 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6401 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6402 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6403 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6404 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
6405 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
6406 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
6407 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
6408 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
6409 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
6410 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
6411 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
6412 #undef TEX_2D
6413 #undef TEX_2D_ARRAY
6414 #undef BC1_UNORM
6415 #undef BC1_UNORM_SRGB
6416 #undef BC2_UNORM
6417 #undef BC2_UNORM_SRGB
6418 #undef BC3_UNORM
6419 #undef BC3_UNORM_SRGB
6420 #undef R8G8B8A8_UNORM_SRGB
6421 #undef R8G8B8A8_UNORM
6422 #undef R32_FLOAT
6423 #undef R32_UINT
6424 #undef FMT_UNKNOWN
6427 if (!init_test_context(&test_context, NULL))
6428 return;
6430 device = test_context.device;
6431 context = test_context.immediate_context;
6432 feature_level = ID3D11Device_GetFeatureLevel(device);
6434 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6436 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6438 texture_desc.SampleDesc.Count = 1;
6439 texture_desc.SampleDesc.Quality = 0;
6440 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6441 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6442 texture_desc.CPUAccessFlags = 0;
6443 texture_desc.MiscFlags = 0;
6445 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6446 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
6447 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
6448 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
6449 sampler_desc.MipLODBias = 0.0f;
6450 sampler_desc.MaxAnisotropy = 0;
6451 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
6452 sampler_desc.BorderColor[0] = 0.0f;
6453 sampler_desc.BorderColor[1] = 0.0f;
6454 sampler_desc.BorderColor[2] = 0.0f;
6455 sampler_desc.BorderColor[3] = 0.0f;
6456 sampler_desc.MinLOD = 0.0f;
6457 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6459 ps = NULL;
6460 srv = NULL;
6461 sampler = NULL;
6462 texture = NULL;
6463 current_ps = NULL;
6464 current_texture = NULL;
6465 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6467 const struct texture_test *test = &texture_tests[i];
6469 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
6470 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
6471 && feature_level < D3D_FEATURE_LEVEL_11_0)
6473 skip("Feature level >= 11.0 is required for BC7 tests.\n");
6474 continue;
6477 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
6478 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
6479 && feature_level < D3D_FEATURE_LEVEL_11_0)
6481 skip("Feature level >= 11.0 is required for BC6H tests.\n");
6482 continue;
6485 if (current_ps != test->ps)
6487 if (ps)
6488 ID3D11PixelShader_Release(ps);
6490 current_ps = test->ps;
6492 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6493 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6495 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6498 if (current_texture != test->texture)
6500 if (texture)
6501 ID3D11Texture2D_Release(texture);
6502 if (srv)
6503 ID3D11ShaderResourceView_Release(srv);
6505 current_texture = test->texture;
6507 if (current_texture)
6509 texture_desc.Width = current_texture->width;
6510 texture_desc.Height = current_texture->height;
6511 texture_desc.MipLevels = current_texture->miplevel_count;
6512 texture_desc.ArraySize = current_texture->array_size;
6513 texture_desc.Format = current_texture->format;
6515 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6516 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6518 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6519 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6521 else
6523 texture = NULL;
6524 srv = NULL;
6527 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6530 if (!sampler || (sampler_desc.Filter != test->filter
6531 || sampler_desc.MipLODBias != test->lod_bias
6532 || sampler_desc.MinLOD != test->min_lod
6533 || sampler_desc.MaxLOD != test->max_lod))
6535 if (sampler)
6536 ID3D11SamplerState_Release(sampler);
6538 sampler_desc.Filter = test->filter;
6539 sampler_desc.MipLODBias = test->lod_bias;
6540 sampler_desc.MinLOD = test->min_lod;
6541 sampler_desc.MaxLOD = test->max_lod;
6543 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6544 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6546 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6549 ps_constant.x = test->ps_constant;
6550 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6552 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6554 draw_quad(&test_context);
6556 get_texture_readback(test_context.backbuffer, 0, &rb);
6557 for (y = 0; y < 4; ++y)
6559 for (x = 0; x < 4; ++x)
6561 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6562 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
6563 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6566 release_resource_readback(&rb);
6568 if (srv)
6569 ID3D11ShaderResourceView_Release(srv);
6570 ID3D11SamplerState_Release(sampler);
6571 if (texture)
6572 ID3D11Texture2D_Release(texture);
6573 ID3D11PixelShader_Release(ps);
6575 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_10_1)
6577 win_skip("SRV tests are broken on WARP.\n");
6578 ID3D11Buffer_Release(cb);
6579 release_test_context(&test_context);
6580 return;
6583 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6584 sampler_desc.MipLODBias = 0.0f;
6585 sampler_desc.MinLOD = 0.0f;
6586 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6588 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6589 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6591 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6593 ps = NULL;
6594 srv = NULL;
6595 texture = NULL;
6596 current_ps = NULL;
6597 current_texture = NULL;
6598 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
6600 const struct srv_test *test = &srv_tests[i];
6602 if (current_ps != test->ps)
6604 if (ps)
6605 ID3D11PixelShader_Release(ps);
6607 current_ps = test->ps;
6609 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6610 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6612 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6615 if (current_texture != test->texture)
6617 if (texture)
6618 ID3D11Texture2D_Release(texture);
6620 current_texture = test->texture;
6622 texture_desc.Width = current_texture->width;
6623 texture_desc.Height = current_texture->height;
6624 texture_desc.MipLevels = current_texture->miplevel_count;
6625 texture_desc.ArraySize = current_texture->array_size;
6626 texture_desc.Format = current_texture->format;
6628 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6629 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6632 if (srv)
6633 ID3D11ShaderResourceView_Release(srv);
6635 get_srv_desc(&srv_desc, &test->srv_desc);
6636 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
6637 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6639 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6641 ps_constant.x = test->ps_constant;
6642 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6644 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6646 draw_quad(&test_context);
6648 get_texture_readback(test_context.backbuffer, 0, &rb);
6649 for (y = 0; y < 4; ++y)
6651 for (x = 0; x < 4; ++x)
6653 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6654 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
6655 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6658 release_resource_readback(&rb);
6660 ID3D11PixelShader_Release(ps);
6661 ID3D11Texture2D_Release(texture);
6662 ID3D11ShaderResourceView_Release(srv);
6663 ID3D11SamplerState_Release(sampler);
6665 ID3D11Buffer_Release(cb);
6666 release_test_context(&test_context);
6669 static void test_cube_maps(void)
6671 struct shader
6673 const DWORD *code;
6674 size_t size;
6677 unsigned int i, j, sub_resource_idx, sub_resource_count;
6678 struct d3d11_test_context test_context;
6679 D3D11_TEXTURE2D_DESC texture_desc;
6680 const struct shader *current_ps;
6681 D3D_FEATURE_LEVEL feature_level;
6682 ID3D11ShaderResourceView *srv;
6683 ID3D11DeviceContext *context;
6684 ID3D11Texture2D *rtv_texture;
6685 ID3D11RenderTargetView *rtv;
6686 struct vec4 expected_result;
6687 ID3D11Resource *texture;
6688 ID3D11PixelShader *ps;
6689 ID3D11Device *device;
6690 float data[64 * 64];
6691 ID3D11Buffer *cb;
6692 HRESULT hr;
6693 RECT rect;
6694 struct
6696 unsigned int face;
6697 unsigned int level;
6698 unsigned int cube;
6699 unsigned int padding;
6700 } constant;
6702 static const DWORD ps_cube_code[] =
6704 #if 0
6705 TextureCube t;
6706 SamplerState s;
6708 uint face;
6709 uint level;
6711 float4 main(float4 position : SV_POSITION) : SV_Target
6713 float2 p;
6714 p.x = position.x / 640.0f;
6715 p.y = position.y / 480.0f;
6717 float3 coord;
6718 switch (face)
6720 case 0:
6721 coord = float3(1.0f, p.x, p.y);
6722 break;
6723 case 1:
6724 coord = float3(-1.0f, p.x, p.y);
6725 break;
6726 case 2:
6727 coord = float3(p.x, 1.0f, p.y);
6728 break;
6729 case 3:
6730 coord = float3(p.x, -1.0f, p.y);
6731 break;
6732 case 4:
6733 coord = float3(p.x, p.y, 1.0f);
6734 break;
6735 case 5:
6736 default:
6737 coord = float3(p.x, p.y, -1.0f);
6738 break;
6740 return t.SampleLevel(s, coord, level);
6742 #endif
6743 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
6744 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6745 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6746 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6747 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
6748 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6749 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6750 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
6751 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
6752 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
6753 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
6754 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
6755 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
6756 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6757 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
6758 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
6759 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
6760 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
6761 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
6762 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
6763 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6764 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
6765 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
6766 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
6767 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
6769 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
6770 static const DWORD ps_cube_array_code[] =
6772 #if 0
6773 TextureCubeArray t;
6774 SamplerState s;
6776 uint face;
6777 uint level;
6778 uint cube;
6780 float4 main(float4 position : SV_POSITION) : SV_Target
6782 float2 p;
6783 p.x = position.x / 640.0f;
6784 p.y = position.y / 480.0f;
6786 float3 coord;
6787 switch (face)
6789 case 0:
6790 coord = float3(1.0f, p.x, p.y);
6791 break;
6792 case 1:
6793 coord = float3(-1.0f, p.x, p.y);
6794 break;
6795 case 2:
6796 coord = float3(p.x, 1.0f, p.y);
6797 break;
6798 case 3:
6799 coord = float3(p.x, -1.0f, p.y);
6800 break;
6801 case 4:
6802 coord = float3(p.x, p.y, 1.0f);
6803 break;
6804 case 5:
6805 default:
6806 coord = float3(p.x, p.y, -1.0f);
6807 break;
6809 return t.SampleLevel(s, float4(coord, cube), level);
6811 #endif
6812 0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
6813 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6814 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6815 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6816 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
6817 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
6818 0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
6819 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
6820 0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
6821 0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6822 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
6823 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
6824 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
6825 0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
6826 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
6827 0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
6828 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
6829 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
6830 0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6831 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
6832 0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
6833 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
6834 0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
6835 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
6836 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
6837 0x00000001, 0x0100003e,
6839 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
6840 static const struct ps_test
6842 const struct shader *ps;
6843 unsigned int miplevel_count;
6844 unsigned int array_size;
6846 ps_tests[] =
6848 {&ps_cube, 1, 6},
6849 {&ps_cube, 2, 6},
6850 {&ps_cube, 3, 6},
6851 {&ps_cube, 0, 6},
6853 {&ps_cube_array, 1, 12},
6854 {&ps_cube_array, 2, 12},
6855 {&ps_cube_array, 3, 12},
6856 {&ps_cube_array, 0, 12},
6859 if (!init_test_context(&test_context, NULL))
6860 return;
6862 device = test_context.device;
6863 context = test_context.immediate_context;
6864 feature_level = ID3D11Device_GetFeatureLevel(device);
6866 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
6867 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
6868 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
6869 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6870 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
6871 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
6873 memset(&constant, 0, sizeof(constant));
6874 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
6876 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6877 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6879 ps = NULL;
6880 current_ps = NULL;
6881 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
6883 const struct ps_test *test = &ps_tests[i];
6885 if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
6887 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
6888 continue;
6891 if (current_ps != test->ps)
6893 if (ps)
6894 ID3D11PixelShader_Release(ps);
6896 current_ps = test->ps;
6898 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6899 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6900 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6903 if (!test->miplevel_count)
6905 srv = NULL;
6906 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6908 memset(&expected_result, 0, sizeof(expected_result));
6910 memset(&constant, 0, sizeof(constant));
6911 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
6912 draw_quad(&test_context);
6913 check_texture_vec4(rtv_texture, &expected_result, 0);
6914 constant.level = 1;
6915 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
6916 draw_quad(&test_context);
6917 check_texture_vec4(rtv_texture, &expected_result, 0);
6918 continue;
6921 texture_desc.Width = 64;
6922 texture_desc.Height = 64;
6923 texture_desc.MipLevels = test->miplevel_count;
6924 texture_desc.ArraySize = test->array_size;
6925 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
6926 texture_desc.SampleDesc.Count = 1;
6927 texture_desc.SampleDesc.Quality = 0;
6928 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6929 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6930 texture_desc.CPUAccessFlags = 0;
6931 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
6932 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
6933 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6935 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
6936 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6937 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6939 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
6940 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
6942 for (j = 0; j < ARRAY_SIZE(data); ++j)
6943 data[j] = sub_resource_idx;
6944 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, sub_resource_idx, NULL,
6945 data, texture_desc.Width * sizeof(*data), 0);
6948 expected_result.y = expected_result.z = 0.0f;
6949 expected_result.w = 1.0f;
6950 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
6952 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
6953 constant.level = sub_resource_idx % texture_desc.MipLevels;
6954 constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
6955 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
6957 draw_quad(&test_context);
6958 expected_result.x = sub_resource_idx;
6959 /* Avoid testing values affected by seamless cube map filtering. */
6960 SetRect(&rect, 100, 100, 540, 380);
6961 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
6964 ID3D11Resource_Release(texture);
6965 ID3D11ShaderResourceView_Release(srv);
6967 ID3D11PixelShader_Release(ps);
6969 ID3D11Buffer_Release(cb);
6970 ID3D11RenderTargetView_Release(rtv);
6971 ID3D11Texture2D_Release(rtv_texture);
6972 release_test_context(&test_context);
6975 static void test_depth_stencil_sampling(void)
6977 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
6978 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
6979 ID3D11SamplerState *cmp_sampler, *sampler;
6980 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
6981 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
6982 struct d3d11_test_context test_context;
6983 ID3D11Texture2D *texture, *rt_texture;
6984 D3D11_TEXTURE2D_DESC texture_desc;
6985 D3D11_SAMPLER_DESC sampler_desc;
6986 ID3D11DeviceContext *context;
6987 ID3D11DepthStencilView *dsv;
6988 ID3D11RenderTargetView *rtv;
6989 struct vec4 ps_constant;
6990 ID3D11Device *device;
6991 ID3D11Buffer *cb;
6992 unsigned int i;
6993 HRESULT hr;
6995 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
6996 static const DWORD ps_compare_code[] =
6998 #if 0
6999 Texture2D t;
7000 SamplerComparisonState s;
7002 float ref;
7004 float4 main(float4 position : SV_Position) : SV_Target
7006 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
7008 #endif
7009 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
7010 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7011 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7012 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7013 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
7014 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
7015 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7016 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
7017 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
7018 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
7019 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
7020 0x0100003e,
7022 static const DWORD ps_sample_code[] =
7024 #if 0
7025 Texture2D t;
7026 SamplerState s;
7028 float4 main(float4 position : SV_Position) : SV_Target
7030 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
7032 #endif
7033 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
7034 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7035 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7036 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7037 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7038 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7039 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7040 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7041 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7042 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7044 static const DWORD ps_stencil_code[] =
7046 #if 0
7047 Texture2D<uint4> t;
7049 float4 main(float4 position : SV_Position) : SV_Target
7051 float2 s;
7052 t.GetDimensions(s.x, s.y);
7053 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
7055 #endif
7056 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
7057 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7058 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7059 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7060 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
7061 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
7062 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
7063 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
7064 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
7065 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
7066 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
7067 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7068 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
7070 static const DWORD ps_depth_stencil_code[] =
7072 #if 0
7073 SamplerState samp;
7074 Texture2D depth_tex;
7075 Texture2D<uint4> stencil_tex;
7077 float main(float4 position: SV_Position) : SV_Target
7079 float2 s, p;
7080 float depth, stencil;
7081 depth_tex.GetDimensions(s.x, s.y);
7082 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
7083 depth = depth_tex.Sample(samp, p).r;
7084 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
7085 return depth + stencil;
7087 #endif
7088 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
7089 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7090 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7091 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7092 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
7093 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7094 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7095 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
7096 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
7097 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
7098 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
7099 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
7100 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
7101 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
7102 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
7103 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
7105 static const struct test
7107 DXGI_FORMAT typeless_format;
7108 DXGI_FORMAT dsv_format;
7109 DXGI_FORMAT depth_view_format;
7110 DXGI_FORMAT stencil_view_format;
7112 tests[] =
7114 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
7115 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
7116 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
7117 DXGI_FORMAT_R32_FLOAT},
7118 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
7119 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
7120 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
7121 DXGI_FORMAT_R16_UNORM},
7124 if (!init_test_context(&test_context, NULL))
7125 return;
7127 device = test_context.device;
7128 context = test_context.immediate_context;
7130 if (is_amd_device(device))
7132 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
7133 win_skip("Some AMD drivers have a bug affecting the test.\n");
7134 release_test_context(&test_context);
7135 return;
7138 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
7139 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7140 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7141 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7142 sampler_desc.MipLODBias = 0.0f;
7143 sampler_desc.MaxAnisotropy = 0;
7144 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
7145 sampler_desc.BorderColor[0] = 0.0f;
7146 sampler_desc.BorderColor[1] = 0.0f;
7147 sampler_desc.BorderColor[2] = 0.0f;
7148 sampler_desc.BorderColor[3] = 0.0f;
7149 sampler_desc.MinLOD = 0.0f;
7150 sampler_desc.MaxLOD = 0.0f;
7151 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
7152 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7154 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7155 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7156 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
7157 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7159 texture_desc.Width = 640;
7160 texture_desc.Height = 480;
7161 texture_desc.MipLevels = 1;
7162 texture_desc.ArraySize = 1;
7163 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7164 texture_desc.SampleDesc.Count = 1;
7165 texture_desc.SampleDesc.Quality = 0;
7166 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7167 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7168 texture_desc.CPUAccessFlags = 0;
7169 texture_desc.MiscFlags = 0;
7170 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
7171 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7172 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
7173 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
7174 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7176 memset(&ps_constant, 0, sizeof(ps_constant));
7177 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
7178 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7180 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
7181 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7182 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
7183 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7184 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
7185 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7186 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
7187 &ps_depth_stencil);
7188 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7190 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7192 texture_desc.Format = tests[i].typeless_format;
7193 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
7194 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7195 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
7196 texture_desc.Format, hr);
7198 dsv_desc.Format = tests[i].dsv_format;
7199 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
7200 dsv_desc.Flags = 0;
7201 U(dsv_desc).Texture2D.MipSlice = 0;
7202 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7203 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
7204 dsv_desc.Format, hr);
7206 srv_desc.Format = tests[i].depth_view_format;
7207 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
7208 U(srv_desc).Texture2D.MostDetailedMip = 0;
7209 U(srv_desc).Texture2D.MipLevels = 1;
7210 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
7211 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
7212 srv_desc.Format, hr);
7214 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
7215 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
7216 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
7218 ps_constant.x = 0.5f;
7219 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7220 NULL, &ps_constant, 0, 0);
7222 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7223 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7224 draw_quad(&test_context);
7225 check_texture_float(rt_texture, 0.0f, 2);
7227 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
7228 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7229 draw_quad(&test_context);
7230 check_texture_float(rt_texture, 1.0f, 2);
7232 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
7233 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7234 draw_quad(&test_context);
7235 check_texture_float(rt_texture, 0.0f, 2);
7237 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
7238 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7239 draw_quad(&test_context);
7240 check_texture_float(rt_texture, 0.0f, 2);
7242 ps_constant.x = 0.7f;
7243 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7244 NULL, &ps_constant, 0, 0);
7246 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7247 draw_quad(&test_context);
7248 check_texture_float(rt_texture, 1.0f, 2);
7250 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
7251 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7253 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7254 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7255 draw_quad(&test_context);
7256 check_texture_float(rt_texture, 1.0f, 2);
7258 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
7259 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7260 draw_quad(&test_context);
7261 check_texture_float(rt_texture, 0.2f, 2);
7263 if (!tests[i].stencil_view_format)
7265 ID3D11DepthStencilView_Release(dsv);
7266 ID3D11ShaderResourceView_Release(depth_srv);
7267 ID3D11Texture2D_Release(texture);
7268 continue;
7271 srv_desc.Format = tests[i].stencil_view_format;
7272 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
7273 if (hr == E_OUTOFMEMORY)
7275 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
7276 ID3D11DepthStencilView_Release(dsv);
7277 ID3D11ShaderResourceView_Release(depth_srv);
7278 ID3D11Texture2D_Release(texture);
7279 continue;
7281 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
7282 srv_desc.Format, hr);
7284 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
7285 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
7287 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
7288 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7289 draw_quad(&test_context);
7290 check_texture_float(rt_texture, 0.0f, 0);
7292 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
7293 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7294 draw_quad(&test_context);
7295 check_texture_float(rt_texture, 100.0f, 0);
7297 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
7298 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7299 draw_quad(&test_context);
7300 check_texture_float(rt_texture, 255.0f, 0);
7302 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
7303 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
7304 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
7306 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
7307 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7308 draw_quad(&test_context);
7309 check_texture_float(rt_texture, 3.3f, 2);
7311 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
7312 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7313 draw_quad(&test_context);
7314 check_texture_float(rt_texture, 4.0f, 2);
7316 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
7317 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7318 draw_quad(&test_context);
7319 check_texture_float(rt_texture, 0.0f, 2);
7321 ID3D11DepthStencilView_Release(dsv);
7322 ID3D11ShaderResourceView_Release(depth_srv);
7323 ID3D11ShaderResourceView_Release(stencil_srv);
7324 ID3D11Texture2D_Release(texture);
7327 ID3D11Buffer_Release(cb);
7328 ID3D11PixelShader_Release(ps_cmp);
7329 ID3D11PixelShader_Release(ps_depth);
7330 ID3D11PixelShader_Release(ps_depth_stencil);
7331 ID3D11PixelShader_Release(ps_stencil);
7332 ID3D11RenderTargetView_Release(rtv);
7333 ID3D11SamplerState_Release(cmp_sampler);
7334 ID3D11SamplerState_Release(sampler);
7335 ID3D11Texture2D_Release(rt_texture);
7336 release_test_context(&test_context);
7339 static void test_multiple_render_targets(void)
7341 D3D11_TEXTURE2D_DESC texture_desc;
7342 ID3D11InputLayout *input_layout;
7343 unsigned int stride, offset, i;
7344 ID3D11RenderTargetView *rtv[4];
7345 ID3D11DeviceContext *context;
7346 ID3D11Texture2D *rt[4];
7347 ID3D11VertexShader *vs;
7348 ID3D11PixelShader *ps;
7349 ID3D11Device *device;
7350 D3D11_VIEWPORT vp;
7351 ID3D11Buffer *vb;
7352 ULONG refcount;
7353 HRESULT hr;
7355 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
7357 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
7359 static const DWORD vs_code[] =
7361 #if 0
7362 float4 main(float4 position : POSITION) : SV_POSITION
7364 return position;
7366 #endif
7367 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
7368 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7369 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7370 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
7371 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
7372 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7373 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
7375 static const DWORD ps_code[] =
7377 #if 0
7378 struct output
7380 float4 t1 : SV_TARGET0;
7381 float4 t2 : SV_Target1;
7382 float4 t3 : SV_TARGET2;
7383 float4 t4 : SV_Target3;
7386 output main(float4 position : SV_POSITION)
7388 struct output o;
7389 o.t1 = (float4)1.0f;
7390 o.t2 = (float4)0.5f;
7391 o.t3 = (float4)0.2f;
7392 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
7393 return o;
7395 #endif
7396 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
7397 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7398 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7399 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
7400 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
7401 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
7402 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
7403 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
7404 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
7405 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
7406 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
7407 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
7408 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
7409 0x3f800000, 0x0100003e,
7411 static const struct vec2 quad[] =
7413 {-1.0f, -1.0f},
7414 {-1.0f, 1.0f},
7415 { 1.0f, -1.0f},
7416 { 1.0f, 1.0f},
7418 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
7420 if (!(device = create_device(NULL)))
7422 skip("Failed to create device.\n");
7423 return;
7426 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
7427 vs_code, sizeof(vs_code), &input_layout);
7428 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7430 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7432 texture_desc.Width = 640;
7433 texture_desc.Height = 480;
7434 texture_desc.MipLevels = 1;
7435 texture_desc.ArraySize = 1;
7436 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7437 texture_desc.SampleDesc.Count = 1;
7438 texture_desc.SampleDesc.Quality = 0;
7439 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7440 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7441 texture_desc.CPUAccessFlags = 0;
7442 texture_desc.MiscFlags = 0;
7444 for (i = 0; i < ARRAY_SIZE(rt); ++i)
7446 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
7447 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
7449 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
7450 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
7453 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
7454 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7455 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7456 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7458 ID3D11Device_GetImmediateContext(device, &context);
7460 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
7461 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
7462 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7463 stride = sizeof(*quad);
7464 offset = 0;
7465 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
7466 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
7467 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7469 vp.TopLeftX = 0.0f;
7470 vp.TopLeftY = 0.0f;
7471 vp.Width = 640.0f;
7472 vp.Height = 480.0f;
7473 vp.MinDepth = 0.0f;
7474 vp.MaxDepth = 1.0f;
7475 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
7477 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7478 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
7480 ID3D11DeviceContext_Draw(context, 4, 0);
7482 check_texture_color(rt[0], 0xffffffff, 2);
7483 check_texture_color(rt[1], 0x7f7f7f7f, 2);
7484 check_texture_color(rt[2], 0x33333333, 2);
7485 check_texture_color(rt[3], 0xff7f3300, 2);
7487 ID3D11Buffer_Release(vb);
7488 ID3D11PixelShader_Release(ps);
7489 ID3D11VertexShader_Release(vs);
7490 ID3D11InputLayout_Release(input_layout);
7491 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7493 ID3D11RenderTargetView_Release(rtv[i]);
7494 ID3D11Texture2D_Release(rt[i]);
7496 ID3D11DeviceContext_Release(context);
7497 refcount = ID3D11Device_Release(device);
7498 ok(!refcount, "Device has %u references left.\n", refcount);
7501 static void test_render_target_views(void)
7503 struct texture
7505 UINT miplevel_count;
7506 UINT array_size;
7509 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
7510 static struct test
7512 struct texture texture;
7513 struct rtv_desc rtv;
7514 DWORD expected_colors[4];
7516 tests[] =
7518 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7519 {0xff0000ff, 0x00000000}},
7520 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
7521 {0x00000000, 0xff0000ff}},
7522 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7523 {0xff0000ff, 0x00000000}},
7524 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7525 {0x00000000, 0xff0000ff}},
7526 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7527 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7528 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7529 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7530 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7531 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7532 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
7533 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7534 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
7535 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7536 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
7537 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7538 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7539 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7540 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7541 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7542 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7543 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7544 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7545 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7546 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
7547 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7550 struct d3d11_test_context test_context;
7551 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7552 D3D11_TEXTURE2D_DESC texture_desc;
7553 ID3D11DeviceContext *context;
7554 ID3D11RenderTargetView *rtv;
7555 ID3D11Texture2D *texture;
7556 ID3D11Device *device;
7557 unsigned int i, j, k;
7558 void *data;
7559 HRESULT hr;
7561 if (!init_test_context(&test_context, NULL))
7562 return;
7564 device = test_context.device;
7565 context = test_context.immediate_context;
7567 texture_desc.Width = 32;
7568 texture_desc.Height = 32;
7569 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7570 texture_desc.SampleDesc.Count = 1;
7571 texture_desc.SampleDesc.Quality = 0;
7572 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7573 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7574 texture_desc.CPUAccessFlags = 0;
7575 texture_desc.MiscFlags = 0;
7577 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, texture_desc.Width * texture_desc.Height * 4);
7578 ok(!!data, "Failed to allocate memory.\n");
7580 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7582 const struct test *test = &tests[i];
7583 unsigned int sub_resource_count;
7585 texture_desc.MipLevels = test->texture.miplevel_count;
7586 texture_desc.ArraySize = test->texture.array_size;
7588 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7589 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
7591 get_rtv_desc(&rtv_desc, &test->rtv);
7592 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7593 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
7595 for (j = 0; j < texture_desc.ArraySize; ++j)
7597 for (k = 0; k < texture_desc.MipLevels; ++k)
7599 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
7600 ID3D11DeviceContext_UpdateSubresource(context,
7601 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
7604 check_texture_color(texture, 0, 0);
7606 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7607 draw_color_quad(&test_context, &red);
7609 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7610 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
7611 for (j = 0; j < sub_resource_count; ++j)
7612 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
7614 ID3D11RenderTargetView_Release(rtv);
7615 ID3D11Texture2D_Release(texture);
7618 HeapFree(GetProcessHeap(), 0, data);
7619 release_test_context(&test_context);
7622 static void test_layered_rendering(void)
7624 struct
7626 unsigned int layer_offset;
7627 unsigned int draw_id;
7628 unsigned int padding[2];
7629 } constant;
7630 struct d3d11_test_context test_context;
7631 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7632 unsigned int i, sub_resource_count;
7633 D3D11_TEXTURE2D_DESC texture_desc;
7634 ID3D11DeviceContext *context;
7635 ID3D11RenderTargetView *rtv;
7636 ID3D11Texture2D *texture;
7637 ID3D11GeometryShader *gs;
7638 ID3D11PixelShader *ps;
7639 ID3D11Device *device;
7640 ID3D11Buffer *cb;
7641 HRESULT hr;
7642 BOOL warp;
7644 static const DWORD gs_5_code[] =
7646 #if 0
7647 uint layer_offset;
7649 struct gs_in
7651 float4 pos : SV_Position;
7654 struct gs_out
7656 float4 pos : SV_Position;
7657 uint layer : SV_RenderTargetArrayIndex;
7660 [instance(4)]
7661 [maxvertexcount(3)]
7662 void main(triangle gs_in vin[3], in uint instance_id : SV_GSInstanceID,
7663 inout TriangleStream<gs_out> vout)
7665 gs_out o;
7666 o.layer = layer_offset + instance_id;
7667 for (uint i = 0; i < 3; ++i)
7669 o.pos = vin[i].pos;
7670 vout.Append(o);
7673 #endif
7674 0x43425844, 0xb52da162, 0x9a13d8ee, 0xf7c30b50, 0xe80bc2e7, 0x00000001, 0x00000218, 0x00000003,
7675 0x0000002c, 0x00000060, 0x000000d0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7676 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
7677 0x3547534f, 0x00000068, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
7678 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000004, 0x00000001,
7679 0x00000001, 0x00000e01, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472,
7680 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x58454853, 0x00000140, 0x00020050, 0x00000050,
7681 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
7682 0x00000000, 0x00000001, 0x0200005f, 0x00025000, 0x02000068, 0x00000001, 0x020000ce, 0x00000004,
7683 0x0100185d, 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
7684 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x00000003, 0x0700001e,
7685 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0002500a, 0x05000036, 0x00100022,
7686 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a,
7687 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000, 0x07000036, 0x001020f2,
7688 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001,
7689 0x0010000a, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x0700001e, 0x00100022, 0x00000000,
7690 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
7692 static const DWORD gs_4_code[] =
7694 #if 0
7695 uint layer_offset;
7697 struct gs_in
7699 float4 pos : SV_Position;
7702 struct gs_out
7704 float4 pos : SV_Position;
7705 uint layer : SV_RenderTargetArrayIndex;
7708 [maxvertexcount(12)]
7709 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
7711 gs_out o;
7712 for (uint instance_id = 0; instance_id < 4; ++instance_id)
7714 o.layer = layer_offset + instance_id;
7715 for (uint i = 0; i < 3; ++i)
7717 o.pos = vin[i].pos;
7718 vout.Append(o);
7720 vout.RestartStrip();
7723 #endif
7724 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
7725 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7726 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
7727 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
7728 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
7729 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
7730 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
7731 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
7732 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
7733 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
7734 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
7735 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
7736 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
7737 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
7738 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
7739 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
7740 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
7741 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
7742 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
7744 static const DWORD ps_code[] =
7746 #if 0
7747 uint layer_offset;
7748 uint draw_id;
7750 float4 main(in float4 pos : SV_Position,
7751 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
7753 return float4(layer, draw_id, 0, 0);
7755 #endif
7756 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
7757 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
7758 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
7759 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
7760 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
7761 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
7762 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
7763 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
7764 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
7765 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
7766 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
7768 static const struct vec4 expected_values[] =
7770 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
7771 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
7772 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
7773 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
7776 if (!init_test_context(&test_context, NULL))
7777 return;
7779 device = test_context.device;
7780 context = test_context.immediate_context;
7782 warp = is_warp_device(device);
7784 memset(&constant, 0, sizeof(constant));
7785 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
7786 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
7787 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7789 /* Geometry shader instancing seems broken on WARP. */
7790 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0 || warp)
7792 hr = ID3D11Device_CreateGeometryShader(device, gs_4_code, sizeof(gs_4_code), NULL, &gs);
7793 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
7795 else
7797 hr = ID3D11Device_CreateGeometryShader(device, gs_5_code, sizeof(gs_5_code), NULL, &gs);
7798 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
7800 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
7802 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7803 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7804 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7806 texture_desc.Width = 32;
7807 texture_desc.Height = 32;
7808 texture_desc.MipLevels = 3;
7809 texture_desc.ArraySize = 8;
7810 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
7811 texture_desc.SampleDesc.Count = 1;
7812 texture_desc.SampleDesc.Quality = 0;
7813 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7814 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7815 texture_desc.CPUAccessFlags = 0;
7816 texture_desc.MiscFlags = 0;
7817 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7818 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7820 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
7821 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7822 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7823 constant.layer_offset = 0;
7824 constant.draw_id = 0;
7825 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7826 draw_quad(&test_context);
7827 constant.layer_offset = 4;
7828 constant.draw_id = 1;
7829 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7830 draw_quad(&test_context);
7831 ID3D11RenderTargetView_Release(rtv);
7833 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
7834 rtv_desc.Format = texture_desc.Format;
7835 U(rtv_desc).Texture2DArray.MipSlice = 0;
7836 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
7837 U(rtv_desc).Texture2DArray.ArraySize = 1;
7838 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7839 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7840 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7841 constant.layer_offset = 1;
7842 constant.draw_id = 2;
7843 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7844 draw_quad(&test_context);
7845 ID3D11RenderTargetView_Release(rtv);
7847 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
7848 U(rtv_desc).Texture2DArray.MipSlice = 1;
7849 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
7850 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
7851 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7852 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7853 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7854 constant.layer_offset = 0;
7855 constant.draw_id = 3;
7856 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7857 draw_quad(&test_context);
7858 constant.layer_offset = 4;
7859 constant.draw_id = 3;
7860 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7861 draw_quad(&test_context);
7862 ID3D11RenderTargetView_Release(rtv);
7864 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
7865 U(rtv_desc).Texture2DArray.MipSlice = 2;
7866 U(rtv_desc).Texture2DArray.ArraySize = 1;
7867 for (i = 0; i < texture_desc.ArraySize; ++i)
7869 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
7870 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7871 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7872 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7873 constant.layer_offset = 0;
7874 constant.draw_id = 4 + i;
7875 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7876 draw_quad(&test_context);
7877 ID3D11RenderTargetView_Release(rtv);
7880 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7881 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
7882 for (i = 0; i < sub_resource_count; ++i)
7884 if (warp && (i == 3 || i == 4)) /* Broken on WARP. */
7885 continue;
7886 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
7889 ID3D11Texture2D_Release(texture);
7891 ID3D11Buffer_Release(cb);
7892 ID3D11GeometryShader_Release(gs);
7893 ID3D11PixelShader_Release(ps);
7894 release_test_context(&test_context);
7897 static void test_scissor(void)
7899 struct d3d11_test_context test_context;
7900 ID3D11DeviceContext *immediate_context;
7901 D3D11_RASTERIZER_DESC rs_desc;
7902 ID3D11RasterizerState *rs;
7903 D3D11_RECT scissor_rect;
7904 ID3D11PixelShader *ps;
7905 ID3D11Device *device;
7906 DWORD color;
7907 HRESULT hr;
7909 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
7910 static const DWORD ps_code[] =
7912 #if 0
7913 float4 main(float4 position : SV_POSITION) : SV_Target
7915 return float4(0.0, 1.0, 0.0, 1.0);
7917 #endif
7918 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
7919 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7920 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7921 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7922 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
7923 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
7924 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
7927 if (!init_test_context(&test_context, NULL))
7928 return;
7930 device = test_context.device;
7931 immediate_context = test_context.immediate_context;
7933 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7934 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7936 rs_desc.FillMode = D3D11_FILL_SOLID;
7937 rs_desc.CullMode = D3D11_CULL_BACK;
7938 rs_desc.FrontCounterClockwise = FALSE;
7939 rs_desc.DepthBias = 0;
7940 rs_desc.DepthBiasClamp = 0.0f;
7941 rs_desc.SlopeScaledDepthBias = 0.0f;
7942 rs_desc.DepthClipEnable = TRUE;
7943 rs_desc.ScissorEnable = TRUE;
7944 rs_desc.MultisampleEnable = FALSE;
7945 rs_desc.AntialiasedLineEnable = FALSE;
7946 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
7947 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
7949 ID3D11DeviceContext_PSSetShader(immediate_context, ps, NULL, 0);
7951 scissor_rect.left = 160;
7952 scissor_rect.top = 120;
7953 scissor_rect.right = 480;
7954 scissor_rect.bottom = 360;
7955 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
7957 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
7958 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
7960 draw_quad(&test_context);
7961 color = get_texture_color(test_context.backbuffer, 320, 60);
7962 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7963 color = get_texture_color(test_context.backbuffer, 80, 240);
7964 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7965 color = get_texture_color(test_context.backbuffer, 320, 240);
7966 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7967 color = get_texture_color(test_context.backbuffer, 560, 240);
7968 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7969 color = get_texture_color(test_context.backbuffer, 320, 420);
7970 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7972 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
7973 ID3D11DeviceContext_RSSetState(immediate_context, rs);
7974 draw_quad(&test_context);
7975 color = get_texture_color(test_context.backbuffer, 320, 60);
7976 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7977 color = get_texture_color(test_context.backbuffer, 80, 240);
7978 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7979 color = get_texture_color(test_context.backbuffer, 320, 240);
7980 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7981 color = get_texture_color(test_context.backbuffer, 560, 240);
7982 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7983 color = get_texture_color(test_context.backbuffer, 320, 420);
7984 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7986 ID3D11RasterizerState_Release(rs);
7987 ID3D11PixelShader_Release(ps);
7988 release_test_context(&test_context);
7991 static void test_clear_state(void)
7993 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
7994 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
7996 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
7998 #if 0
7999 float4 main(float4 pos : POSITION) : POSITION
8001 return pos;
8003 #endif
8004 static const DWORD simple_vs[] =
8006 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
8007 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8008 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8009 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8010 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
8011 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
8012 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8014 #if 0
8015 struct data
8017 float4 position : SV_Position;
8020 struct patch_constant_data
8022 float edges[3] : SV_TessFactor;
8023 float inside : SV_InsideTessFactor;
8026 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
8028 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
8029 output.inside = 1.0f;
8032 [domain("tri")]
8033 [outputcontrolpoints(3)]
8034 [partitioning("integer")]
8035 [outputtopology("triangle_ccw")]
8036 [patchconstantfunc("patch_constant")]
8037 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
8039 return input[i];
8042 [domain("tri")]
8043 void ds_main(patch_constant_data input,
8044 float3 tess_coord : SV_DomainLocation,
8045 const OutputPatch<data, 3> patch,
8046 out data output)
8048 output.position = tess_coord.x * patch[0].position
8049 + tess_coord.y * patch[1].position
8050 + tess_coord.z * patch[2].position;
8052 #endif
8053 static const DWORD simple_hs[] =
8055 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
8056 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
8057 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
8058 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
8059 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
8060 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
8061 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
8062 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
8063 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
8064 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
8065 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
8066 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
8067 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
8068 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
8069 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
8070 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
8071 0x00004001, 0x3f800000, 0x0100003e,
8073 static const DWORD simple_ds[] =
8075 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
8076 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
8077 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
8078 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
8079 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
8080 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
8081 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
8082 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
8083 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
8084 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
8085 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
8086 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
8087 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
8088 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
8089 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
8091 #if 0
8092 struct gs_out
8094 float4 pos : SV_POSITION;
8097 [maxvertexcount(4)]
8098 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
8100 float offset = 0.1 * vin[0].w;
8101 gs_out v;
8103 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
8104 vout.Append(v);
8105 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
8106 vout.Append(v);
8107 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
8108 vout.Append(v);
8109 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
8110 vout.Append(v);
8112 #endif
8113 static const DWORD simple_gs[] =
8115 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
8116 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8117 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8118 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8119 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
8120 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
8121 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
8122 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
8123 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
8124 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
8125 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
8126 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
8127 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
8128 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
8129 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
8130 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
8131 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
8132 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
8134 #if 0
8135 float4 main(float4 color : COLOR) : SV_TARGET
8137 return color;
8139 #endif
8140 static const DWORD simple_ps[] =
8142 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
8143 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
8144 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
8145 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8146 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8147 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
8148 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8150 #if 0
8151 [numthreads(1, 1, 1)]
8152 void main() { }
8153 #endif
8154 static const DWORD simple_cs[] =
8156 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
8157 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8158 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
8159 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
8162 D3D11_VIEWPORT tmp_viewport[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
8163 ID3D11ShaderResourceView *tmp_srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
8164 ID3D11ShaderResourceView *srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
8165 ID3D11RenderTargetView *tmp_rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8166 RECT tmp_rect[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
8167 ID3D11SamplerState *tmp_sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
8168 ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8169 ID3D11Texture2D *rt_texture[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8170 ID3D11Buffer *cb[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
8171 ID3D11Buffer *tmp_buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8172 ID3D11SamplerState *sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
8173 ID3D11UnorderedAccessView *tmp_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
8174 ID3D11UnorderedAccessView *cs_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
8175 ID3D11Buffer *buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8176 ID3D11Buffer *cs_uav_buffer[D3D11_PS_CS_UAV_REGISTER_COUNT];
8177 UINT offset[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8178 UINT stride[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8179 ID3D11Buffer *so_buffer[D3D11_SO_BUFFER_SLOT_COUNT];
8180 ID3D11InputLayout *tmp_input_layout, *input_layout;
8181 ID3D11DepthStencilState *tmp_ds_state, *ds_state;
8182 ID3D11BlendState *tmp_blend_state, *blend_state;
8183 ID3D11RasterizerState *tmp_rs_state, *rs_state;
8184 ID3D11Predicate *tmp_predicate, *predicate;
8185 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
8186 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8187 ID3D11DepthStencilView *tmp_dsv, *dsv;
8188 ID3D11UnorderedAccessView *ps_uav;
8189 D3D11_PRIMITIVE_TOPOLOGY topology;
8190 D3D11_TEXTURE2D_DESC texture_desc;
8191 ID3D11GeometryShader *tmp_gs, *gs;
8192 ID3D11ComputeShader *tmp_cs, *cs;
8193 D3D11_DEPTH_STENCIL_DESC ds_desc;
8194 ID3D11VertexShader *tmp_vs, *vs;
8195 ID3D11DomainShader *tmp_ds, *ds;
8196 D3D11_SAMPLER_DESC sampler_desc;
8197 D3D11_QUERY_DESC predicate_desc;
8198 struct device_desc device_desc;
8199 ID3D11PixelShader *tmp_ps, *ps;
8200 ID3D11HullShader *tmp_hs, *hs;
8201 D3D11_RASTERIZER_DESC rs_desc;
8202 ID3D11DeviceContext *context;
8203 D3D11_BLEND_DESC blend_desc;
8204 ID3D11Texture2D *ds_texture;
8205 ID3D11Buffer *ps_uav_buffer;
8206 float blend_factor[4];
8207 ID3D11Device *device;
8208 BOOL predicate_value;
8209 DXGI_FORMAT format;
8210 UINT sample_mask;
8211 UINT stencil_ref;
8212 ULONG refcount;
8213 UINT count, i;
8214 HRESULT hr;
8216 device_desc.feature_level = &feature_level;
8217 device_desc.flags = 0;
8218 if (!(device = create_device(&device_desc)))
8220 skip("Failed to create device.\n");
8221 return;
8224 ID3D11Device_GetImmediateContext(device, &context);
8226 /* Verify the initial state after device creation. */
8228 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8229 tmp_buffer);
8230 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8232 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8234 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8235 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8237 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8239 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8240 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8242 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8244 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
8245 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
8247 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8248 tmp_buffer);
8249 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8251 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8253 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8254 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8256 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8258 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8259 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8261 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8263 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
8264 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
8266 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8267 tmp_buffer);
8268 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8270 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8272 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8273 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8275 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8277 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8278 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8280 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8282 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
8283 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
8285 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8286 tmp_buffer);
8287 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8289 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8291 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8292 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8294 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8296 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8297 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8299 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8301 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
8302 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
8304 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8305 tmp_buffer);
8306 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8308 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8310 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
8311 tmp_srv);
8312 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8314 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8316 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8317 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8319 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8321 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
8322 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
8324 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8325 tmp_buffer);
8326 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8328 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8330 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
8331 tmp_srv);
8332 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8334 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8336 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8337 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8339 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8341 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
8342 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
8343 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8344 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8346 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
8349 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
8350 tmp_buffer, stride, offset);
8351 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
8353 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
8354 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
8355 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
8357 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
8358 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
8359 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
8360 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
8361 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
8362 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
8363 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
8364 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
8366 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
8367 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
8368 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
8369 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
8370 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
8371 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
8372 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
8373 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
8374 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
8375 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
8376 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
8377 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8379 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8381 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
8382 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
8383 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
8384 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8385 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8387 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8389 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
8390 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8392 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
8395 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
8396 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
8397 memset(tmp_rect, 0x55, sizeof(tmp_rect));
8398 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
8399 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
8400 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
8402 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
8403 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
8405 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
8406 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
8407 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
8408 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
8409 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
8410 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
8412 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
8413 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
8414 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
8415 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
8416 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
8418 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
8419 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
8421 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
8422 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
8424 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
8427 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
8428 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
8429 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
8431 /* Create resources. */
8433 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8434 cb[i] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 1024, NULL);
8436 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
8438 buffer[i] = create_buffer(device,
8439 D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_SHADER_RESOURCE,
8440 1024, NULL);
8442 stride[i] = (i + 1) * 4;
8443 offset[i] = (i + 1) * 16;
8446 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
8447 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
8449 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8450 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
8451 U(srv_desc).Buffer.ElementOffset = 0;
8452 U(srv_desc).Buffer.ElementWidth = 64;
8454 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8456 hr = ID3D11Device_CreateShaderResourceView(device,
8457 (ID3D11Resource *)buffer[i % D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
8458 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8461 uav_desc.Format = DXGI_FORMAT_R32_UINT;
8462 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
8463 U(uav_desc).Buffer.FirstElement = 0;
8464 U(uav_desc).Buffer.NumElements = 8;
8465 U(uav_desc).Buffer.Flags = 0;
8467 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8469 cs_uav_buffer[i] = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
8470 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_uav_buffer[i],
8471 &uav_desc, &cs_uav[i]);
8472 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
8475 ps_uav_buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
8476 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_uav_buffer,
8477 &uav_desc, &ps_uav);
8478 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
8480 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
8481 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8482 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8483 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8484 sampler_desc.MipLODBias = 0.0f;
8485 sampler_desc.MaxAnisotropy = 16;
8486 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8487 sampler_desc.BorderColor[0] = 0.0f;
8488 sampler_desc.BorderColor[1] = 0.0f;
8489 sampler_desc.BorderColor[2] = 0.0f;
8490 sampler_desc.BorderColor[3] = 0.0f;
8491 sampler_desc.MinLOD = 0.0f;
8492 sampler_desc.MaxLOD = 16.0f;
8494 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8496 sampler_desc.MinLOD = (float)i;
8498 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
8499 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8502 hr = ID3D11Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
8503 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8505 hr = ID3D11Device_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
8506 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
8508 hr = ID3D11Device_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
8509 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
8511 hr = ID3D11Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
8512 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
8514 hr = ID3D11Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
8515 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8517 hr = ID3D11Device_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
8518 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
8520 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8521 simple_vs, sizeof(simple_vs), &input_layout);
8522 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8524 memset(&blend_desc, 0, sizeof(blend_desc));
8525 blend_desc.AlphaToCoverageEnable = FALSE;
8526 blend_desc.IndependentBlendEnable = FALSE;
8527 blend_desc.RenderTarget[0].BlendEnable = TRUE;
8528 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
8529 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
8530 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
8531 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
8532 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
8533 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
8534 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
8536 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
8537 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8539 ds_desc.DepthEnable = TRUE;
8540 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
8541 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
8542 ds_desc.StencilEnable = FALSE;
8543 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
8544 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
8545 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
8546 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
8547 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
8548 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
8549 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
8550 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
8551 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
8552 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
8554 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
8555 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
8557 texture_desc.Width = 512;
8558 texture_desc.Height = 512;
8559 texture_desc.MipLevels = 1;
8560 texture_desc.ArraySize = 1;
8561 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8562 texture_desc.SampleDesc.Count = 1;
8563 texture_desc.SampleDesc.Quality = 0;
8564 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8565 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8566 texture_desc.CPUAccessFlags = 0;
8567 texture_desc.MiscFlags = 0;
8569 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8571 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
8572 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8575 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
8576 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
8578 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
8579 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8581 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8583 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture[i], NULL, &rtv[i]);
8584 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8587 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)ds_texture, NULL, &dsv);
8588 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
8590 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
8592 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
8594 tmp_viewport[i].TopLeftX = i * 3;
8595 tmp_viewport[i].TopLeftY = i * 4;
8596 tmp_viewport[i].Width = 3;
8597 tmp_viewport[i].Height = 4;
8598 tmp_viewport[i].MinDepth = i * 0.01f;
8599 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
8602 rs_desc.FillMode = D3D11_FILL_SOLID;
8603 rs_desc.CullMode = D3D11_CULL_BACK;
8604 rs_desc.FrontCounterClockwise = FALSE;
8605 rs_desc.DepthBias = 0;
8606 rs_desc.DepthBiasClamp = 0.0f;
8607 rs_desc.SlopeScaledDepthBias = 0.0f;
8608 rs_desc.DepthClipEnable = TRUE;
8609 rs_desc.ScissorEnable = FALSE;
8610 rs_desc.MultisampleEnable = FALSE;
8611 rs_desc.AntialiasedLineEnable = FALSE;
8613 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs_state);
8614 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
8616 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
8617 predicate_desc.MiscFlags = 0;
8619 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
8620 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
8622 /* Setup state. */
8624 /* Some versions of Windows AMD drivers hang while the device is being
8625 * released, if the total number of used resource slots exceeds some limit.
8626 * Do not use all constant buffers slots in order to not trigger this
8627 * driver bug. */
8628 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb[0]);
8629 ID3D11DeviceContext_VSSetConstantBuffers(context, 7, 1, &cb[7]);
8630 ID3D11DeviceContext_VSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
8631 ID3D11DeviceContext_VSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
8632 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
8634 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb[0]);
8635 ID3D11DeviceContext_HSSetConstantBuffers(context, 7, 1, &cb[7]);
8636 ID3D11DeviceContext_HSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
8637 ID3D11DeviceContext_HSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
8638 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
8640 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
8641 ID3D11DeviceContext_DSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
8642 ID3D11DeviceContext_DSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
8643 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
8645 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
8646 ID3D11DeviceContext_GSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
8647 ID3D11DeviceContext_GSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
8648 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
8650 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
8651 ID3D11DeviceContext_PSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
8652 ID3D11DeviceContext_PSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
8653 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8655 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
8656 ID3D11DeviceContext_CSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
8657 ID3D11DeviceContext_CSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
8658 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
8659 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, cs_uav, NULL);
8661 ID3D11DeviceContext_IASetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
8662 buffer, stride, offset);
8663 ID3D11DeviceContext_IASetIndexBuffer(context, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
8664 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
8665 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8667 blend_factor[0] = 0.1f;
8668 blend_factor[1] = 0.2f;
8669 blend_factor[2] = 0.3f;
8670 blend_factor[3] = 0.4f;
8671 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, 0xff00ff00);
8672 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 3);
8673 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
8674 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, rtv, dsv,
8675 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, 1, &ps_uav, NULL);
8677 ID3D11DeviceContext_RSSetScissorRects(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
8678 tmp_rect);
8679 ID3D11DeviceContext_RSSetViewports(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
8680 tmp_viewport);
8681 ID3D11DeviceContext_RSSetState(context, rs_state);
8683 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
8685 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
8687 /* Verify the set state. */
8689 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8690 tmp_buffer);
8691 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8693 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
8694 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
8695 tmp_buffer[i], i, expected_cb);
8696 if (tmp_buffer[i])
8697 ID3D11Buffer_Release(tmp_buffer[i]);
8699 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8700 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8702 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
8703 tmp_srv[i], i, srv[i]);
8704 ID3D11ShaderResourceView_Release(tmp_srv[i]);
8706 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8707 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8709 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
8710 tmp_sampler[i], i, sampler[i]);
8711 ID3D11SamplerState_Release(tmp_sampler[i]);
8713 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
8714 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
8715 ID3D11VertexShader_Release(tmp_vs);
8717 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8718 tmp_buffer);
8719 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8721 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
8722 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
8723 tmp_buffer[i], i, expected_cb);
8724 if (tmp_buffer[i])
8725 ID3D11Buffer_Release(tmp_buffer[i]);
8727 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8728 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8730 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
8731 tmp_srv[i], i, srv[i]);
8732 ID3D11ShaderResourceView_Release(tmp_srv[i]);
8734 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8735 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8737 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
8738 tmp_sampler[i], i, sampler[i]);
8739 ID3D11SamplerState_Release(tmp_sampler[i]);
8741 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
8742 ok(tmp_hs == hs, "Got unexpected hull shader %p, expected %p.\n", tmp_hs, hs);
8743 ID3D11HullShader_Release(tmp_hs);
8745 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8746 tmp_buffer);
8747 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8749 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
8750 tmp_buffer[i], i, cb[i]);
8751 ID3D11Buffer_Release(tmp_buffer[i]);
8753 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8754 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8756 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
8757 tmp_srv[i], i, srv[i]);
8758 ID3D11ShaderResourceView_Release(tmp_srv[i]);
8760 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8761 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8763 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
8764 tmp_sampler[i], i, sampler[i]);
8765 ID3D11SamplerState_Release(tmp_sampler[i]);
8767 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
8768 ok(tmp_ds == ds, "Got unexpected domain shader %p, expected %p.\n", tmp_ds, ds);
8769 ID3D11DomainShader_Release(tmp_ds);
8771 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8772 tmp_buffer);
8773 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8775 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
8776 tmp_buffer[i], i, cb[i]);
8777 ID3D11Buffer_Release(tmp_buffer[i]);
8779 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8780 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8782 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
8783 tmp_srv[i], i, srv[i]);
8784 ID3D11ShaderResourceView_Release(tmp_srv[i]);
8786 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8787 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8789 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
8790 tmp_sampler[i], i, sampler[i]);
8791 ID3D11SamplerState_Release(tmp_sampler[i]);
8793 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
8794 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
8795 ID3D11GeometryShader_Release(tmp_gs);
8797 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8798 tmp_buffer);
8799 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8801 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
8802 tmp_buffer[i], i, cb[i]);
8803 ID3D11Buffer_Release(tmp_buffer[i]);
8805 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8806 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8808 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
8809 tmp_srv[i], i, srv[i]);
8810 ID3D11ShaderResourceView_Release(tmp_srv[i]);
8812 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8813 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8815 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
8816 tmp_sampler[i], i, sampler[i]);
8817 ID3D11SamplerState_Release(tmp_sampler[i]);
8819 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
8820 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
8821 ID3D11PixelShader_Release(tmp_ps);
8823 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8824 tmp_buffer);
8825 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8827 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
8828 tmp_buffer[i], i, cb[i]);
8829 ID3D11Buffer_Release(tmp_buffer[i]);
8831 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8832 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8834 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
8835 tmp_srv[i], i, srv[i]);
8836 ID3D11ShaderResourceView_Release(tmp_srv[i]);
8838 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8839 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8841 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
8842 tmp_sampler[i], i, sampler[i]);
8843 ID3D11SamplerState_Release(tmp_sampler[i]);
8845 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
8846 ok(tmp_cs == cs, "Got unexpected compute shader %p, expected %p.\n", tmp_cs, cs);
8847 ID3D11ComputeShader_Release(tmp_cs);
8848 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8849 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8851 ok(tmp_uav[i] == cs_uav[i], "Got unexpected unordered access view %p in slot %u, expected %p.\n",
8852 tmp_uav[i], i, cs_uav[i]);
8853 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
8856 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
8857 tmp_buffer, stride, offset);
8858 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
8860 todo_wine_if(i >= D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
8862 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
8863 tmp_buffer[i], i, buffer[i]);
8864 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
8865 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
8867 if (tmp_buffer[i])
8868 ID3D11Buffer_Release(tmp_buffer[i]);
8870 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
8871 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
8872 ID3D11Buffer_Release(tmp_buffer[0]);
8873 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
8874 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
8875 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
8876 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
8877 tmp_input_layout, input_layout);
8878 ID3D11InputLayout_Release(tmp_input_layout);
8879 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
8880 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
8882 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
8883 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
8884 ID3D11BlendState_Release(tmp_blend_state);
8885 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
8886 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
8887 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
8888 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
8889 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
8890 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
8891 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
8892 ID3D11DepthStencilState_Release(tmp_ds_state);
8893 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
8894 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
8895 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
8897 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
8898 tmp_rtv[i], i, rtv[i]);
8899 ID3D11RenderTargetView_Release(tmp_rtv[i]);
8901 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8902 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
8903 ID3D11DepthStencilView_Release(tmp_dsv);
8904 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
8905 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
8906 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8907 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
8909 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
8910 tmp_rtv[i], i, rtv[i]);
8911 ID3D11RenderTargetView_Release(tmp_rtv[i]);
8913 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8914 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
8915 ID3D11DepthStencilView_Release(tmp_dsv);
8916 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT - 1; ++i)
8918 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
8920 ok(tmp_uav[i] == ps_uav, "Got unexpected unordered access view %p in slot %u, expected %p.\n",
8921 tmp_uav[i], i, ps_uav);
8922 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
8924 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
8925 todo_wine ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
8926 "Got unexpected scissor rect count %u.\n", count);
8927 memset(tmp_rect, 0x55, sizeof(tmp_rect));
8928 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
8929 for (i = 0; i < count; ++i)
8931 ok(tmp_rect[i].left == i
8932 && tmp_rect[i].top == i * 2
8933 && tmp_rect[i].right == i + 1
8934 && tmp_rect[i].bottom == (i + 1) * 2,
8935 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
8937 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
8938 todo_wine ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
8939 "Got unexpected viewport count %u.\n", count);
8940 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
8941 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
8942 for (i = 0; i < count; ++i)
8944 ok(tmp_viewport[i].TopLeftX == i * 3
8945 && tmp_viewport[i].TopLeftY == i * 4
8946 && tmp_viewport[i].Width == 3
8947 && tmp_viewport[i].Height == 4
8948 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
8949 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
8950 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
8951 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
8952 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
8954 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
8955 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
8956 ID3D11RasterizerState_Release(tmp_rs_state);
8958 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
8959 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
8961 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
8962 tmp_buffer[i], i, so_buffer[i]);
8963 ID3D11Buffer_Release(tmp_buffer[i]);
8966 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
8967 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
8968 ID3D11Predicate_Release(tmp_predicate);
8969 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
8971 /* Verify ClearState(). */
8973 ID3D11DeviceContext_ClearState(context);
8975 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8976 tmp_buffer);
8977 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8979 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8981 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8982 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8984 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8986 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8987 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8989 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8991 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
8992 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
8994 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8995 tmp_buffer);
8996 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8998 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9000 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9001 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9003 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9005 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9006 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9008 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9010 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
9011 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
9013 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9014 tmp_buffer);
9015 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9017 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9019 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9020 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9022 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9024 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9025 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9027 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9029 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
9030 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
9032 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9033 tmp_buffer);
9034 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9036 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9038 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9039 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9041 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9043 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9044 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9046 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9048 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
9049 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
9051 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9052 tmp_buffer);
9053 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9055 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9057 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9058 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9060 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9062 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9063 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9065 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9067 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
9068 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
9070 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9071 tmp_buffer);
9072 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9074 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9076 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
9077 tmp_srv);
9078 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9080 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9082 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9083 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9085 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9087 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
9088 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
9089 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9090 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9092 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9095 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
9096 tmp_buffer, stride, offset);
9097 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9099 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
9100 todo_wine_if(i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
9102 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
9103 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
9106 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
9107 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
9108 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
9109 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
9110 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
9111 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
9112 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
9113 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
9115 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
9116 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
9117 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
9118 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
9119 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
9120 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
9121 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
9122 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
9123 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
9124 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
9125 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
9126 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9128 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9130 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
9131 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
9132 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
9133 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9134 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9136 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9138 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
9139 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9141 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9144 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
9145 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
9146 memset(tmp_rect, 0x55, sizeof(tmp_rect));
9147 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
9148 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
9149 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
9151 todo_wine_if(!i)
9152 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
9153 "Got unexpected scissor rect %s in slot %u.\n",
9154 wine_dbgstr_rect(&tmp_rect[i]), i);
9156 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
9157 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
9158 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
9159 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
9160 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
9161 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
9163 todo_wine_if(!i)
9164 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
9165 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
9166 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
9167 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
9168 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
9170 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
9171 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
9173 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
9174 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
9176 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
9179 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
9180 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
9181 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
9183 /* Cleanup. */
9185 ID3D11Predicate_Release(predicate);
9186 ID3D11RasterizerState_Release(rs_state);
9187 ID3D11DepthStencilView_Release(dsv);
9188 ID3D11Texture2D_Release(ds_texture);
9190 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9192 ID3D11RenderTargetView_Release(rtv[i]);
9193 ID3D11Texture2D_Release(rt_texture[i]);
9196 ID3D11DepthStencilState_Release(ds_state);
9197 ID3D11BlendState_Release(blend_state);
9198 ID3D11InputLayout_Release(input_layout);
9199 ID3D11VertexShader_Release(vs);
9200 ID3D11HullShader_Release(hs);
9201 ID3D11DomainShader_Release(ds);
9202 ID3D11GeometryShader_Release(gs);
9203 ID3D11PixelShader_Release(ps);
9204 ID3D11ComputeShader_Release(cs);
9206 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9208 ID3D11SamplerState_Release(sampler[i]);
9211 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9213 ID3D11ShaderResourceView_Release(srv[i]);
9216 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9218 ID3D11UnorderedAccessView_Release(cs_uav[i]);
9219 ID3D11Buffer_Release(cs_uav_buffer[i]);
9221 ID3D11UnorderedAccessView_Release(ps_uav);
9222 ID3D11Buffer_Release(ps_uav_buffer);
9224 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
9226 ID3D11Buffer_Release(so_buffer[i]);
9229 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9231 ID3D11Buffer_Release(buffer[i]);
9234 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9236 ID3D11Buffer_Release(cb[i]);
9239 ID3D11DeviceContext_Release(context);
9240 refcount = ID3D11Device_Release(device);
9241 ok(!refcount, "Device has %u references left.\n", refcount);
9244 static void test_il_append_aligned(void)
9246 struct d3d11_test_context test_context;
9247 ID3D11InputLayout *input_layout;
9248 ID3D11DeviceContext *context;
9249 unsigned int stride, offset;
9250 ID3D11VertexShader *vs;
9251 ID3D11PixelShader *ps;
9252 ID3D11Device *device;
9253 ID3D11Buffer *vb[3];
9254 DWORD color;
9255 HRESULT hr;
9257 /* Semantic names are case-insensitive. */
9258 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9260 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9261 D3D11_INPUT_PER_INSTANCE_DATA, 2},
9262 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
9263 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9264 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
9265 D3D11_INPUT_PER_VERTEX_DATA, 0},
9266 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
9267 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9268 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9269 D3D11_INPUT_PER_INSTANCE_DATA, 2},
9271 static const DWORD vs_code[] =
9273 #if 0
9274 struct vs_in
9276 float4 position : POSITION;
9277 float2 color_xy : COLOR0;
9278 float2 color_zw : COLOR1;
9279 unsigned int instance_id : SV_INSTANCEID;
9282 struct vs_out
9284 float4 position : SV_POSITION;
9285 float2 color_xy : COLOR0;
9286 float2 color_zw : COLOR1;
9289 struct vs_out main(struct vs_in i)
9291 struct vs_out o;
9293 o.position = i.position;
9294 o.position.x += i.instance_id * 0.5;
9295 o.color_xy = i.color_xy;
9296 o.color_zw = i.color_zw;
9298 return o;
9300 #endif
9301 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
9302 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
9303 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
9304 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
9305 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
9306 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
9307 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
9308 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
9309 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
9310 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
9311 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
9312 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
9313 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
9314 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
9315 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
9316 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
9317 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
9319 static const DWORD ps_code[] =
9321 #if 0
9322 struct vs_out
9324 float4 position : SV_POSITION;
9325 float2 color_xy : COLOR0;
9326 float2 color_zw : COLOR1;
9329 float4 main(struct vs_out i) : SV_TARGET
9331 return float4(i.color_xy.xy, i.color_zw.xy);
9333 #endif
9334 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
9335 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
9336 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
9337 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
9338 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
9339 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
9340 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
9341 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9342 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9344 static const struct
9346 struct vec4 position;
9348 stream0[] =
9350 {{-1.0f, -1.0f, 0.0f, 1.0f}},
9351 {{-1.0f, 1.0f, 0.0f, 1.0f}},
9352 {{-0.5f, -1.0f, 0.0f, 1.0f}},
9353 {{-0.5f, 1.0f, 0.0f, 1.0f}},
9355 static const struct
9357 struct vec2 color2;
9358 struct vec2 color1;
9360 stream1[] =
9362 {{0.5f, 0.5f}, {0.0f, 1.0f}},
9363 {{0.5f, 0.5f}, {1.0f, 1.0f}},
9365 static const struct
9367 struct vec2 color3;
9368 struct vec2 color0;
9370 stream2[] =
9372 {{0.5f, 0.5f}, {1.0f, 0.0f}},
9373 {{0.5f, 0.5f}, {0.0f, 1.0f}},
9374 {{0.5f, 0.5f}, {0.0f, 0.0f}},
9375 {{0.5f, 0.5f}, {1.0f, 0.0f}},
9377 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9379 if (!init_test_context(&test_context, NULL))
9380 return;
9382 device = test_context.device;
9383 context = test_context.immediate_context;
9385 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9386 vs_code, sizeof(vs_code), &input_layout);
9387 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9389 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
9390 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
9391 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
9393 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
9394 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9395 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9396 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9398 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
9399 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9400 offset = 0;
9401 stride = sizeof(*stream0);
9402 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
9403 stride = sizeof(*stream1);
9404 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
9405 stride = sizeof(*stream2);
9406 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
9407 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
9408 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9410 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9412 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
9414 color = get_texture_color(test_context.backbuffer, 80, 240);
9415 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9416 color = get_texture_color(test_context.backbuffer, 240, 240);
9417 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9418 color = get_texture_color(test_context.backbuffer, 400, 240);
9419 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9420 color = get_texture_color(test_context.backbuffer, 560, 240);
9421 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
9423 ID3D11PixelShader_Release(ps);
9424 ID3D11VertexShader_Release(vs);
9425 ID3D11Buffer_Release(vb[2]);
9426 ID3D11Buffer_Release(vb[1]);
9427 ID3D11Buffer_Release(vb[0]);
9428 ID3D11InputLayout_Release(input_layout);
9429 release_test_context(&test_context);
9432 static void test_fragment_coords(void)
9434 struct d3d11_test_context test_context;
9435 ID3D11PixelShader *ps, *ps_frac;
9436 ID3D11DeviceContext *context;
9437 ID3D11Device *device;
9438 ID3D11Buffer *ps_cb;
9439 DWORD color;
9440 HRESULT hr;
9442 static const DWORD ps_code[] =
9444 #if 0
9445 float2 cutoff;
9447 float4 main(float4 position : SV_POSITION) : SV_TARGET
9449 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
9451 if (position.x > cutoff.x)
9452 ret.y = 1.0;
9453 if (position.y > cutoff.y)
9454 ret.z = 1.0;
9456 return ret;
9458 #endif
9459 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
9460 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9461 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9462 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9463 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
9464 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
9465 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
9466 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
9467 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
9468 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
9469 0x0100003e,
9471 static const DWORD ps_frac_code[] =
9473 #if 0
9474 float4 main(float4 position : SV_POSITION) : SV_TARGET
9476 return float4(frac(position.xy), 0.0, 1.0);
9478 #endif
9479 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
9480 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9481 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9482 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9483 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
9484 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9485 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
9486 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
9488 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9489 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
9491 if (!init_test_context(&test_context, NULL))
9492 return;
9494 device = test_context.device;
9495 context = test_context.immediate_context;
9497 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
9499 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9500 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9501 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
9502 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9504 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
9505 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9507 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9509 draw_quad(&test_context);
9511 color = get_texture_color(test_context.backbuffer, 319, 239);
9512 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
9513 color = get_texture_color(test_context.backbuffer, 320, 239);
9514 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9515 color = get_texture_color(test_context.backbuffer, 319, 240);
9516 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9517 color = get_texture_color(test_context.backbuffer, 320, 240);
9518 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
9520 ID3D11Buffer_Release(ps_cb);
9521 cutoff.x = 16.0f;
9522 cutoff.y = 16.0f;
9523 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
9524 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
9526 draw_quad(&test_context);
9528 color = get_texture_color(test_context.backbuffer, 14, 14);
9529 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
9530 color = get_texture_color(test_context.backbuffer, 18, 14);
9531 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9532 color = get_texture_color(test_context.backbuffer, 14, 18);
9533 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9534 color = get_texture_color(test_context.backbuffer, 18, 18);
9535 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
9537 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
9538 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9540 ID3D11DeviceContext_Draw(context, 4, 0);
9542 color = get_texture_color(test_context.backbuffer, 14, 14);
9543 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
9545 ID3D11Buffer_Release(ps_cb);
9546 ID3D11PixelShader_Release(ps_frac);
9547 ID3D11PixelShader_Release(ps);
9548 release_test_context(&test_context);
9551 static void test_update_subresource(void)
9553 struct d3d11_test_context test_context;
9554 D3D11_SUBRESOURCE_DATA resource_data;
9555 D3D11_TEXTURE2D_DESC texture_desc;
9556 ID3D11SamplerState *sampler_state;
9557 ID3D11ShaderResourceView *ps_srv;
9558 D3D11_SAMPLER_DESC sampler_desc;
9559 ID3D11DeviceContext *context;
9560 struct resource_readback rb;
9561 ID3D11Texture2D *texture;
9562 ID3D11PixelShader *ps;
9563 ID3D11Device *device;
9564 unsigned int i, j;
9565 D3D11_BOX box;
9566 DWORD color;
9567 HRESULT hr;
9569 static const DWORD ps_code[] =
9571 #if 0
9572 Texture2D t;
9573 SamplerState s;
9575 float4 main(float4 position : SV_POSITION) : SV_Target
9577 float2 p;
9579 p.x = position.x / 640.0f;
9580 p.y = position.y / 480.0f;
9581 return t.Sample(s, p);
9583 #endif
9584 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9585 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9586 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9587 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9588 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9589 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9590 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9591 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9592 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9593 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9595 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9596 static const DWORD initial_data[16] = {0};
9597 static const DWORD bitmap_data[] =
9599 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9600 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9601 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9602 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9604 static const DWORD expected_colors[] =
9606 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
9607 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
9608 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
9609 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
9612 if (!init_test_context(&test_context, NULL))
9613 return;
9615 device = test_context.device;
9616 context = test_context.immediate_context;
9618 texture_desc.Width = 4;
9619 texture_desc.Height = 4;
9620 texture_desc.MipLevels = 1;
9621 texture_desc.ArraySize = 1;
9622 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9623 texture_desc.SampleDesc.Count = 1;
9624 texture_desc.SampleDesc.Quality = 0;
9625 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9626 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
9627 texture_desc.CPUAccessFlags = 0;
9628 texture_desc.MiscFlags = 0;
9630 resource_data.pSysMem = initial_data;
9631 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
9632 resource_data.SysMemSlicePitch = 0;
9634 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
9635 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9637 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
9638 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9640 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
9641 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
9642 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
9643 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
9644 sampler_desc.MipLODBias = 0.0f;
9645 sampler_desc.MaxAnisotropy = 0;
9646 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
9647 sampler_desc.BorderColor[0] = 0.0f;
9648 sampler_desc.BorderColor[1] = 0.0f;
9649 sampler_desc.BorderColor[2] = 0.0f;
9650 sampler_desc.BorderColor[3] = 0.0f;
9651 sampler_desc.MinLOD = 0.0f;
9652 sampler_desc.MaxLOD = 0.0f;
9654 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9655 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9657 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9658 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9660 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
9661 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
9662 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9664 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9665 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
9667 draw_quad(&test_context);
9668 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9670 set_box(&box, 1, 1, 0, 3, 3, 1);
9671 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
9672 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9673 set_box(&box, 0, 3, 0, 3, 4, 1);
9674 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
9675 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
9676 set_box(&box, 0, 0, 0, 4, 1, 1);
9677 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
9678 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
9679 set_box(&box, 0, 1, 0, 1, 3, 1);
9680 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
9681 &bitmap_data[2], sizeof(*bitmap_data), 0);
9682 set_box(&box, 4, 4, 0, 3, 1, 1);
9683 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
9684 bitmap_data, sizeof(*bitmap_data), 0);
9685 set_box(&box, 0, 0, 0, 4, 4, 0);
9686 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
9687 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9688 draw_quad(&test_context);
9689 get_texture_readback(test_context.backbuffer, 0, &rb);
9690 for (i = 0; i < 4; ++i)
9692 for (j = 0; j < 4; ++j)
9694 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9695 ok(compare_color(color, expected_colors[j + i * 4], 1),
9696 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9697 color, j, i, expected_colors[j + i * 4]);
9700 release_resource_readback(&rb);
9702 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
9703 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9704 draw_quad(&test_context);
9705 get_texture_readback(test_context.backbuffer, 0, &rb);
9706 for (i = 0; i < 4; ++i)
9708 for (j = 0; j < 4; ++j)
9710 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9711 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9712 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9713 color, j, i, bitmap_data[j + i * 4]);
9716 release_resource_readback(&rb);
9718 ID3D11PixelShader_Release(ps);
9719 ID3D11SamplerState_Release(sampler_state);
9720 ID3D11ShaderResourceView_Release(ps_srv);
9721 ID3D11Texture2D_Release(texture);
9722 release_test_context(&test_context);
9725 static void test_copy_subresource_region(void)
9727 ID3D11Texture2D *dst_texture, *src_texture;
9728 struct d3d11_test_context test_context;
9729 ID3D11Buffer *dst_buffer, *src_buffer;
9730 D3D11_SUBRESOURCE_DATA resource_data;
9731 D3D11_TEXTURE2D_DESC texture_desc;
9732 ID3D11SamplerState *sampler_state;
9733 ID3D11ShaderResourceView *ps_srv;
9734 D3D11_SAMPLER_DESC sampler_desc;
9735 ID3D11DeviceContext *context;
9736 struct vec4 float_colors[16];
9737 struct resource_readback rb;
9738 ID3D11PixelShader *ps;
9739 ID3D11Device *device;
9740 unsigned int i, j;
9741 D3D11_BOX box;
9742 DWORD color;
9743 HRESULT hr;
9745 static const DWORD ps_code[] =
9747 #if 0
9748 Texture2D t;
9749 SamplerState s;
9751 float4 main(float4 position : SV_POSITION) : SV_Target
9753 float2 p;
9755 p.x = position.x / 640.0f;
9756 p.y = position.y / 480.0f;
9757 return t.Sample(s, p);
9759 #endif
9760 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9761 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9762 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9763 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9764 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9765 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9766 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9767 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9768 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9769 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9771 static const DWORD ps_buffer_code[] =
9773 #if 0
9774 float4 buffer[16];
9776 float4 main(float4 position : SV_POSITION) : SV_TARGET
9778 float2 p = (float2)4;
9779 p *= float2(position.x / 640.0f, position.y / 480.0f);
9780 return buffer[(int)p.y * 4 + (int)p.x];
9782 #endif
9783 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
9784 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9785 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9786 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9787 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
9788 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
9789 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
9790 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
9791 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
9792 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
9793 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
9794 0x0010000a, 0x00000000, 0x0100003e,
9796 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9797 static const DWORD initial_data[16] = {0};
9798 static const DWORD bitmap_data[] =
9800 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9801 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9802 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9803 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9805 static const DWORD expected_colors[] =
9807 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9808 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
9809 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
9810 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
9813 if (!init_test_context(&test_context, NULL))
9814 return;
9816 device = test_context.device;
9817 context = test_context.immediate_context;
9819 texture_desc.Width = 4;
9820 texture_desc.Height = 4;
9821 texture_desc.MipLevels = 1;
9822 texture_desc.ArraySize = 1;
9823 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9824 texture_desc.SampleDesc.Count = 1;
9825 texture_desc.SampleDesc.Quality = 0;
9826 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9827 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
9828 texture_desc.CPUAccessFlags = 0;
9829 texture_desc.MiscFlags = 0;
9831 resource_data.pSysMem = initial_data;
9832 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
9833 resource_data.SysMemSlicePitch = 0;
9835 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
9836 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9838 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
9840 resource_data.pSysMem = bitmap_data;
9841 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
9842 resource_data.SysMemSlicePitch = 0;
9844 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
9845 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9847 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
9848 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9850 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
9851 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
9852 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
9853 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
9854 sampler_desc.MipLODBias = 0.0f;
9855 sampler_desc.MaxAnisotropy = 0;
9856 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
9857 sampler_desc.BorderColor[0] = 0.0f;
9858 sampler_desc.BorderColor[1] = 0.0f;
9859 sampler_desc.BorderColor[2] = 0.0f;
9860 sampler_desc.BorderColor[3] = 0.0f;
9861 sampler_desc.MinLOD = 0.0f;
9862 sampler_desc.MaxLOD = 0.0f;
9864 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9865 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9867 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9868 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9870 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
9871 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
9872 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9874 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9876 set_box(&box, 0, 0, 0, 2, 2, 1);
9877 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9878 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
9879 set_box(&box, 1, 2, 0, 4, 3, 1);
9880 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9881 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
9882 set_box(&box, 0, 3, 0, 4, 4, 1);
9883 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9884 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
9885 set_box(&box, 3, 0, 0, 4, 2, 1);
9886 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9887 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
9888 set_box(&box, 3, 1, 0, 4, 2, 1);
9889 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9890 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
9891 set_box(&box, 0, 0, 0, 4, 4, 0);
9892 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9893 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
9894 draw_quad(&test_context);
9895 get_texture_readback(test_context.backbuffer, 0, &rb);
9896 for (i = 0; i < 4; ++i)
9898 for (j = 0; j < 4; ++j)
9900 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9901 ok(compare_color(color, expected_colors[j + i * 4], 1),
9902 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9903 color, j, i, expected_colors[j + i * 4]);
9906 release_resource_readback(&rb);
9908 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9909 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
9910 draw_quad(&test_context);
9911 get_texture_readback(test_context.backbuffer, 0, &rb);
9912 for (i = 0; i < 4; ++i)
9914 for (j = 0; j < 4; ++j)
9916 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9917 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9918 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9919 color, j, i, bitmap_data[j + i * 4]);
9922 release_resource_readback(&rb);
9924 ID3D11PixelShader_Release(ps);
9925 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
9926 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9928 ID3D11ShaderResourceView_Release(ps_srv);
9929 ps_srv = NULL;
9931 ID3D11SamplerState_Release(sampler_state);
9932 sampler_state = NULL;
9934 ID3D11Texture2D_Release(dst_texture);
9935 ID3D11Texture2D_Release(src_texture);
9937 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
9938 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
9939 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9941 memset(float_colors, 0, sizeof(float_colors));
9942 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
9943 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
9945 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
9947 for (i = 0; i < 4; ++i)
9949 for (j = 0; j < 4; ++j)
9951 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
9952 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
9953 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
9954 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
9957 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
9958 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
9960 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
9961 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
9962 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
9963 draw_quad(&test_context);
9964 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9966 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
9967 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
9968 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
9969 draw_quad(&test_context);
9970 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9972 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
9973 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
9974 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
9975 draw_quad(&test_context);
9976 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9978 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
9979 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
9980 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
9981 draw_quad(&test_context);
9982 get_texture_readback(test_context.backbuffer, 0, &rb);
9983 for (i = 0; i < 4; ++i)
9985 for (j = 0; j < 4; ++j)
9987 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9988 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9989 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9990 color, j, i, bitmap_data[j + i * 4]);
9993 release_resource_readback(&rb);
9995 ID3D11Buffer_Release(dst_buffer);
9996 ID3D11Buffer_Release(src_buffer);
9997 ID3D11PixelShader_Release(ps);
9998 release_test_context(&test_context);
10001 static void test_resource_map(void)
10003 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
10004 D3D11_TEXTURE3D_DESC texture3d_desc;
10005 D3D11_TEXTURE2D_DESC texture2d_desc;
10006 D3D11_BUFFER_DESC buffer_desc;
10007 ID3D11DeviceContext *context;
10008 ID3D11Texture3D *texture3d;
10009 ID3D11Texture2D *texture2d;
10010 ID3D11Buffer *buffer;
10011 ID3D11Device *device;
10012 ULONG refcount;
10013 HRESULT hr;
10014 DWORD data;
10016 if (!(device = create_device(NULL)))
10018 skip("Failed to create device.\n");
10019 return;
10022 ID3D11Device_GetImmediateContext(device, &context);
10024 buffer_desc.ByteWidth = 1024;
10025 buffer_desc.Usage = D3D11_USAGE_STAGING;
10026 buffer_desc.BindFlags = 0;
10027 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10028 buffer_desc.MiscFlags = 0;
10029 buffer_desc.StructureByteStride = 0;
10031 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
10032 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
10034 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10035 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10037 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10038 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10039 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
10040 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10041 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
10042 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10043 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
10045 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10046 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10047 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
10048 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10049 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
10050 data = *((DWORD *)mapped_subresource.pData);
10051 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10052 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
10054 refcount = ID3D11Buffer_Release(buffer);
10055 ok(!refcount, "Buffer has %u references left.\n", refcount);
10057 texture2d_desc.Width = 512;
10058 texture2d_desc.Height = 512;
10059 texture2d_desc.MipLevels = 1;
10060 texture2d_desc.ArraySize = 1;
10061 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10062 texture2d_desc.SampleDesc.Count = 1;
10063 texture2d_desc.SampleDesc.Quality = 0;
10064 texture2d_desc.Usage = D3D11_USAGE_STAGING;
10065 texture2d_desc.BindFlags = 0;
10066 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10067 texture2d_desc.MiscFlags = 0;
10069 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
10070 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10072 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10073 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10075 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10076 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10077 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10078 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10079 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
10080 mapped_subresource.DepthPitch);
10081 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10082 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
10084 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10085 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10086 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10087 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10088 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
10089 mapped_subresource.DepthPitch);
10090 data = *((DWORD *)mapped_subresource.pData);
10091 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10092 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
10094 refcount = ID3D11Texture2D_Release(texture2d);
10095 ok(!refcount, "2D texture has %u references left.\n", refcount);
10097 texture3d_desc.Width = 64;
10098 texture3d_desc.Height = 64;
10099 texture3d_desc.Depth = 64;
10100 texture3d_desc.MipLevels = 1;
10101 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10102 texture3d_desc.Usage = D3D11_USAGE_STAGING;
10103 texture3d_desc.BindFlags = 0;
10104 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10105 texture3d_desc.MiscFlags = 0;
10107 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
10108 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
10110 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10111 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10113 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10114 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10115 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10116 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10117 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
10118 mapped_subresource.DepthPitch);
10119 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10120 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
10122 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10123 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10124 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10125 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10126 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
10127 mapped_subresource.DepthPitch);
10128 data = *((DWORD *)mapped_subresource.pData);
10129 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10130 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
10132 refcount = ID3D11Texture3D_Release(texture3d);
10133 ok(!refcount, "3D texture has %u references left.\n", refcount);
10135 ID3D11DeviceContext_Release(context);
10137 refcount = ID3D11Device_Release(device);
10138 ok(!refcount, "Device has %u references left.\n", refcount);
10141 static void test_check_multisample_quality_levels(void)
10143 ID3D11Device *device;
10144 UINT quality_levels;
10145 ULONG refcount;
10146 HRESULT hr;
10148 if (!(device = create_device(NULL)))
10150 skip("Failed to create device.\n");
10151 return;
10154 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10155 if (!quality_levels)
10157 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
10158 goto done;
10161 quality_levels = 0xdeadbeef;
10162 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
10163 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10164 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10165 quality_levels = 0xdeadbeef;
10166 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
10167 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10168 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
10170 quality_levels = 0xdeadbeef;
10171 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
10172 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10173 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
10174 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10175 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10177 quality_levels = 0xdeadbeef;
10178 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
10179 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10180 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
10181 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10182 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
10184 quality_levels = 0xdeadbeef;
10185 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
10186 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10187 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10188 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10189 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10191 /* We assume 15 samples multisampling is never supported in practice. */
10192 quality_levels = 0xdeadbeef;
10193 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
10194 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10195 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10196 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
10197 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10198 quality_levels = 0xdeadbeef;
10199 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
10200 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10201 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10202 quality_levels = 0xdeadbeef;
10203 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
10204 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10205 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10207 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
10208 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10209 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10211 done:
10212 refcount = ID3D11Device_Release(device);
10213 ok(!refcount, "Device has %u references left.\n", refcount);
10216 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
10218 DXGI_SWAP_CHAIN_DESC swapchain_desc;
10219 struct device_desc device_desc;
10220 IDXGISwapChain *swapchain;
10221 IDXGIDevice *dxgi_device;
10222 HRESULT hr, expected_hr;
10223 IDXGIAdapter *adapter;
10224 IDXGIFactory *factory;
10225 ID3D11Device *device;
10226 unsigned int i;
10227 ULONG refcount;
10229 swapchain_desc.BufferDesc.Width = 800;
10230 swapchain_desc.BufferDesc.Height = 600;
10231 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
10232 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
10233 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
10234 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
10235 swapchain_desc.SampleDesc.Count = 1;
10236 swapchain_desc.SampleDesc.Quality = 0;
10237 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
10238 swapchain_desc.BufferCount = 1;
10239 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
10240 swapchain_desc.Windowed = TRUE;
10241 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
10242 swapchain_desc.Flags = 0;
10244 device_desc.feature_level = &feature_level;
10245 device_desc.flags = 0;
10246 if (!(device = create_device(&device_desc)))
10248 skip("Failed to create device for feature level %#x.\n", feature_level);
10249 return;
10252 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
10253 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
10254 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
10255 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
10256 IDXGIDevice_Release(dxgi_device);
10257 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
10258 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
10259 IDXGIAdapter_Release(adapter);
10261 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
10262 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10263 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
10264 hr, feature_level);
10265 if (SUCCEEDED(hr))
10266 IDXGISwapChain_Release(swapchain);
10268 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
10270 DXGI_FORMAT format = display_format_support[i].format;
10271 BOOL todo = FALSE;
10273 if (display_format_support[i].fl_required <= feature_level)
10275 expected_hr = S_OK;
10276 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
10277 todo = TRUE;
10279 else if (!display_format_support[i].fl_optional
10280 || display_format_support[i].fl_optional > feature_level)
10282 expected_hr = E_INVALIDARG;
10283 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
10284 todo = TRUE;
10286 else
10288 continue;
10291 swapchain_desc.BufferDesc.Format = format;
10292 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10293 todo_wine_if(todo)
10294 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
10295 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
10296 hr, expected_hr, feature_level, format);
10297 if (FAILED(hr))
10298 continue;
10299 refcount = IDXGISwapChain_Release(swapchain);
10300 ok(!refcount, "Swapchain has %u references left.\n", refcount);
10303 refcount = ID3D11Device_Release(device);
10304 ok(!refcount, "Device has %u references left.\n", refcount);
10305 refcount = IDXGIFactory_Release(factory);
10306 ok(!refcount, "Factory has %u references left.\n", refcount);
10307 DestroyWindow(swapchain_desc.OutputWindow);
10310 static void test_swapchain_views(void)
10312 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10313 struct d3d11_test_context test_context;
10314 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
10315 ID3D11ShaderResourceView *srv;
10316 ID3D11DeviceContext *context;
10317 ID3D11RenderTargetView *rtv;
10318 ID3D11Device *device;
10319 ULONG refcount;
10320 HRESULT hr;
10322 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
10324 if (!init_test_context(&test_context, NULL))
10325 return;
10327 device = test_context.device;
10328 context = test_context.immediate_context;
10330 refcount = get_refcount(test_context.backbuffer);
10331 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
10333 draw_color_quad(&test_context, &color);
10334 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
10336 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10337 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
10338 U(rtv_desc).Texture2D.MipSlice = 0;
10339 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
10340 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10341 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10343 refcount = get_refcount(test_context.backbuffer);
10344 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
10346 draw_color_quad(&test_context, &color);
10347 todo_wine check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
10349 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10350 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
10351 U(srv_desc).Texture2D.MostDetailedMip = 0;
10352 U(srv_desc).Texture2D.MipLevels = 1;
10353 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
10354 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10355 if (SUCCEEDED(hr))
10356 ID3D11ShaderResourceView_Release(srv);
10358 ID3D11RenderTargetView_Release(rtv);
10359 release_test_context(&test_context);
10362 static void test_swapchain_flip(void)
10364 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
10365 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
10366 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
10367 D3D11_TEXTURE2D_DESC texture_desc;
10368 ID3D11InputLayout *input_layout;
10369 ID3D11DeviceContext *context;
10370 unsigned int stride, offset;
10371 struct swapchain_desc desc;
10372 IDXGISwapChain *swapchain;
10373 ID3D11VertexShader *vs;
10374 ID3D11PixelShader *ps;
10375 ID3D11Device *device;
10376 D3D11_VIEWPORT vp;
10377 ID3D11Buffer *vb;
10378 ULONG refcount;
10379 DWORD color;
10380 HWND window;
10381 HRESULT hr;
10382 RECT rect;
10384 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
10386 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10388 static const DWORD vs_code[] =
10390 #if 0
10391 float4 main(float4 position : POSITION) : SV_POSITION
10393 return position;
10395 #endif
10396 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
10397 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10398 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10399 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
10400 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
10401 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10402 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
10405 static const DWORD ps_code[] =
10407 #if 0
10408 Texture2D t0, t1;
10409 SamplerState s;
10411 float4 main(float4 position : SV_POSITION) : SV_Target
10413 float2 p;
10415 p.x = 0.5;
10416 p.y = 0.5;
10417 if (position.x < 320)
10418 return t0.Sample(s, p);
10419 return t1.Sample(s, p);
10421 #endif
10422 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
10423 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10424 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
10425 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10426 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
10427 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10428 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
10429 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
10430 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
10431 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
10432 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
10433 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
10434 0x00000000, 0x0100003e,
10436 static const struct vec2 quad[] =
10438 {-1.0f, -1.0f},
10439 {-1.0f, 1.0f},
10440 { 1.0f, -1.0f},
10441 { 1.0f, 1.0f},
10443 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10444 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
10445 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
10447 if (!(device = create_device(NULL)))
10449 skip("Failed to create device, skipping tests.\n");
10450 return;
10452 SetRect(&rect, 0, 0, 640, 480);
10453 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
10454 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10455 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
10456 desc.buffer_count = 3;
10457 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
10458 desc.windowed = TRUE;
10459 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
10460 swapchain = create_swapchain(device, window, &desc);
10462 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
10463 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10464 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
10465 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10466 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
10467 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10469 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
10470 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10471 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
10472 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10473 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
10474 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10476 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
10477 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
10478 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
10479 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
10480 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
10482 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
10483 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
10484 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
10485 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
10486 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
10488 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
10489 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10490 if (SUCCEEDED(hr))
10491 ID3D11RenderTargetView_Release(offscreen_rtv);
10493 ID3D11Device_GetImmediateContext(device, &context);
10495 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
10496 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
10498 texture_desc.Width = 640;
10499 texture_desc.Height = 480;
10500 texture_desc.MipLevels = 1;
10501 texture_desc.ArraySize = 1;
10502 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10503 texture_desc.SampleDesc.Count = 1;
10504 texture_desc.SampleDesc.Quality = 0;
10505 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10506 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10507 texture_desc.CPUAccessFlags = 0;
10508 texture_desc.MiscFlags = 0;
10509 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
10510 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
10511 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
10512 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10513 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
10514 vp.TopLeftX = 0;
10515 vp.TopLeftY = 0;
10516 vp.Width = 640;
10517 vp.Height = 480;
10518 vp.MinDepth = 0.0f;
10519 vp.MaxDepth = 1.0f;
10520 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
10522 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
10524 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
10525 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10526 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10527 vs_code, sizeof(vs_code), &input_layout);
10528 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10529 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
10530 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10531 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
10532 stride = sizeof(*quad);
10533 offset = 0;
10534 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
10536 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10537 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10538 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10540 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
10542 ID3D11DeviceContext_Draw(context, 4, 0);
10543 color = get_texture_color(offscreen, 120, 240);
10544 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10546 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
10547 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
10548 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
10550 * What is this good for? I don't know. Ad-hoc tests suggest that
10551 * Present() always waits for the next V-sync interval, even if there are
10552 * still untouched buffers. Buffer 0 is the buffer that is shown on the
10553 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
10554 * rendering finishes before the V-sync interval is over. I haven't found
10555 * any productive use for more than one buffer. */
10556 IDXGISwapChain_Present(swapchain, 0, 0);
10558 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
10560 ID3D11DeviceContext_Draw(context, 4, 0);
10561 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
10562 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10563 /* Buffer 1 is still untouched. */
10565 color = get_texture_color(backbuffer_0, 320, 240); /* green */
10566 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10567 color = get_texture_color(backbuffer_2, 320, 240); /* red */
10568 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10570 IDXGISwapChain_Present(swapchain, 0, 0);
10572 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
10574 ID3D11DeviceContext_Draw(context, 4, 0);
10575 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
10576 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
10577 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
10578 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10580 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
10581 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
10582 color = get_texture_color(backbuffer_1, 320, 240); /* red */
10583 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10584 color = get_texture_color(backbuffer_2, 320, 240); /* green */
10585 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10587 ID3D11VertexShader_Release(vs);
10588 ID3D11PixelShader_Release(ps);
10589 ID3D11Buffer_Release(vb);
10590 ID3D11InputLayout_Release(input_layout);
10591 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
10592 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
10593 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
10594 ID3D11RenderTargetView_Release(offscreen_rtv);
10595 ID3D11Texture2D_Release(offscreen);
10596 ID3D11Texture2D_Release(backbuffer_0);
10597 ID3D11Texture2D_Release(backbuffer_1);
10598 ID3D11Texture2D_Release(backbuffer_2);
10599 IDXGISwapChain_Release(swapchain);
10601 ID3D11DeviceContext_Release(context);
10602 refcount = ID3D11Device_Release(device);
10603 ok(!refcount, "Device has %u references left.\n", refcount);
10604 DestroyWindow(window);
10607 static void test_clear_render_target_view(void)
10609 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
10610 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
10611 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
10613 ID3D11Texture2D *texture, *srgb_texture;
10614 struct d3d11_test_context test_context;
10615 ID3D11RenderTargetView *rtv, *srgb_rtv;
10616 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
10617 D3D11_TEXTURE2D_DESC texture_desc;
10618 ID3D11DeviceContext *context;
10619 struct resource_readback rb;
10620 ID3D11Device *device;
10621 unsigned int i, j;
10622 HRESULT hr;
10624 if (!init_test_context(&test_context, NULL))
10625 return;
10627 device = test_context.device;
10628 context = test_context.immediate_context;
10630 texture_desc.Width = 640;
10631 texture_desc.Height = 480;
10632 texture_desc.MipLevels = 1;
10633 texture_desc.ArraySize = 1;
10634 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10635 texture_desc.SampleDesc.Count = 1;
10636 texture_desc.SampleDesc.Quality = 0;
10637 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10638 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10639 texture_desc.CPUAccessFlags = 0;
10640 texture_desc.MiscFlags = 0;
10641 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10642 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10644 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10645 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
10646 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10648 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
10649 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10651 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
10652 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10654 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
10655 check_texture_color(test_context.backbuffer, expected_color, 1);
10657 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
10658 check_texture_color(texture, expected_color, 1);
10660 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
10661 check_texture_color(texture, expected_color, 1);
10663 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
10664 check_texture_color(srgb_texture, expected_srgb_color, 1);
10666 ID3D11RenderTargetView_Release(srgb_rtv);
10667 ID3D11RenderTargetView_Release(rtv);
10668 ID3D11Texture2D_Release(srgb_texture);
10669 ID3D11Texture2D_Release(texture);
10671 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
10672 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10673 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10675 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10676 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
10677 U(rtv_desc).Texture2D.MipSlice = 0;
10678 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
10679 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10681 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10682 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
10683 U(rtv_desc).Texture2D.MipSlice = 0;
10684 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
10685 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10687 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
10688 check_texture_color(texture, expected_color, 1);
10690 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
10691 get_texture_readback(texture, 0, &rb);
10692 for (i = 0; i < 4; ++i)
10694 for (j = 0; j < 4; ++j)
10696 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
10697 DWORD color = get_readback_color(&rb, 80 + i * 160, 60 + j * 120);
10698 ok(compare_color(color, expected_srgb_color, 1)
10699 || broken(compare_color(color, expected_color, 1) && broken_device),
10700 "Got unexpected color 0x%08x.\n", color);
10703 release_resource_readback(&rb);
10705 ID3D11RenderTargetView_Release(srgb_rtv);
10706 ID3D11RenderTargetView_Release(rtv);
10707 ID3D11Texture2D_Release(texture);
10708 release_test_context(&test_context);
10711 static void test_clear_depth_stencil_view(void)
10713 D3D11_TEXTURE2D_DESC texture_desc;
10714 ID3D11Texture2D *depth_texture;
10715 ID3D11DeviceContext *context;
10716 ID3D11DepthStencilView *dsv;
10717 ID3D11Device *device;
10718 ULONG refcount;
10719 HRESULT hr;
10721 if (!(device = create_device(NULL)))
10723 skip("Failed to create device.\n");
10724 return;
10727 ID3D11Device_GetImmediateContext(device, &context);
10729 texture_desc.Width = 640;
10730 texture_desc.Height = 480;
10731 texture_desc.MipLevels = 1;
10732 texture_desc.ArraySize = 1;
10733 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
10734 texture_desc.SampleDesc.Count = 1;
10735 texture_desc.SampleDesc.Quality = 0;
10736 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10737 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
10738 texture_desc.CPUAccessFlags = 0;
10739 texture_desc.MiscFlags = 0;
10740 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
10741 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10743 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
10744 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10746 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10747 check_texture_float(depth_texture, 1.0f, 0);
10749 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
10750 check_texture_float(depth_texture, 0.25f, 0);
10752 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
10753 check_texture_float(depth_texture, 0.25f, 0);
10755 ID3D11Texture2D_Release(depth_texture);
10756 ID3D11DepthStencilView_Release(dsv);
10758 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
10759 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
10760 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10762 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
10763 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10765 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
10766 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
10768 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
10769 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
10771 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
10772 check_texture_color(depth_texture, 0xffffffff, 0);
10774 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
10775 check_texture_color(depth_texture, 0x00000000, 0);
10777 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
10778 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
10780 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
10781 check_texture_color(depth_texture, 0xffffffff, 0);
10783 ID3D11Texture2D_Release(depth_texture);
10784 ID3D11DepthStencilView_Release(dsv);
10786 ID3D11DeviceContext_Release(context);
10788 refcount = ID3D11Device_Release(device);
10789 ok(!refcount, "Device has %u references left.\n", refcount);
10792 static unsigned int to_sint8(unsigned int x)
10794 union
10796 signed int s;
10797 unsigned int u;
10798 } bits;
10799 bits.u = x;
10800 return min(max(bits.s, -128), 127) & 0xff;
10803 #define check_rgba_sint8(data, uvec) check_rgba_sint8_(__LINE__, data, uvec)
10804 static void check_rgba_sint8_(unsigned int line, DWORD data, const struct uvec4 *v)
10806 unsigned int x = to_sint8(v->x);
10807 unsigned int y = to_sint8(v->y);
10808 unsigned int z = to_sint8(v->z);
10809 unsigned int w = to_sint8(v->w);
10810 DWORD expected[] =
10812 /* Windows 7 - Nvidia, WARP */
10813 (v->x & 0xff) | (v->y & 0xff) << 8 | (v->z & 0xff) << 16 | (v->w & 0xff) << 24,
10814 /* Windows 10 - AMD */
10815 x | y << 8 | z << 16 | w << 24,
10816 /* Windows 10 - Intel */
10817 x | x << 8 | x << 16 | x << 24,
10820 ok_(__FILE__, line)(data == expected[0] || data == expected[1] || broken(data == expected[2]),
10821 "Got %#x, expected %#x or %#x at %u, uvec4 %#x, %#x, %#x, %#x.\n",
10822 data, expected[0], expected[1], x, v->x, v->y, v->z, v->w);
10825 static void test_clear_buffer_unordered_access_view(void)
10827 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
10828 ID3D11UnorderedAccessView *uav, *uav2;
10829 struct device_desc device_desc;
10830 D3D11_BUFFER_DESC buffer_desc;
10831 ID3D11DeviceContext *context;
10832 struct resource_readback rb;
10833 ID3D11Buffer *buffer;
10834 ID3D11Device *device;
10835 struct uvec4 uvec4;
10836 unsigned int i, x;
10837 ULONG refcount;
10838 HRESULT hr;
10840 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
10841 static const struct uvec4 fe_uvec4 = {0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe};
10842 static const struct uvec4 uvec4_data[] =
10844 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
10846 {0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
10847 {0xffffffff, 0x00000000, 0x00000000, 0x00000000},
10848 {0x00000000, 0xffffffff, 0x00000000, 0x00000000},
10849 {0x00000000, 0x00000000, 0xffffffff, 0x00000000},
10850 {0x00000000, 0x00000000, 0x00000000, 0xffffffff},
10852 {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff},
10853 {0x80000000, 0x80000000, 0x80000000, 0x80000000},
10854 {0x000000ff, 0x00000080, 0x80000080, 0x00000080},
10855 {0x000000ff, 0x0000007f, 0x000000ef, 0x000000fe},
10856 {0x800000ff, 0x8000007f, 0x800000ef, 0x800000fe},
10857 {0xfefefefe, 0xf0f0f0f0, 0xefefefef, 0x0f0f0f0f},
10858 {0xaaaaaaaa, 0xdeadbeef, 0xdeadbabe, 0xdeadf00d},
10860 {0x00000001, 0x00000002, 0x00000003, 0x00000004},
10861 {0x000000ff, 0x000000fe, 0x000000fd, 0x000000fc},
10862 {0x000000f2, 0x000000f1, 0x000000f0, 0x000000ef},
10863 {0x0000000a, 0x0000000d, 0x0000000e, 0x0000000f},
10864 {0x0000001a, 0x0000002d, 0x0000003e, 0x0000004f},
10865 {0x00000050, 0x00000060, 0x00000070, 0x00000080},
10866 {0x00000090, 0x000000a0, 0x000000b0, 0x000000c0},
10867 {0x000000d0, 0x000000e0, 0x000000f0, 0x000000ff},
10868 {0x00000073, 0x00000077, 0x0000007a, 0x0000007b},
10869 {0x0000007c, 0x0000007d, 0x0000007e, 0x0000007f},
10871 {0x80000001, 0x80000002, 0x80000003, 0x80000004},
10872 {0x800000ff, 0x800000fe, 0x800000fd, 0x800000fc},
10873 {0x800000f2, 0x800000f1, 0x800000f0, 0x800000ef},
10874 {0x8000000a, 0x0000000d, 0x8000000e, 0x8000000f},
10875 {0x8000001a, 0x8000002d, 0x8000003e, 0x8000004f},
10876 {0x80000050, 0x80000060, 0x80000070, 0x00000080},
10877 {0x80000090, 0x800000a0, 0x800000b0, 0x800000c0},
10878 {0x800000d0, 0x800000e0, 0x800000f0, 0x800000ff},
10879 {0x80000073, 0x80000077, 0x8000007a, 0x8000007b},
10880 {0x8000007c, 0x8000007d, 0x8000007e, 0x8000007f},
10882 {0x7fffff01, 0x7fffff02, 0x7fffff03, 0x7fffff04},
10883 {0x7fffffff, 0x7ffffffe, 0x7ffffffd, 0x7ffffffc},
10884 {0x7ffffff2, 0x7ffffff1, 0x7ffffff0, 0x7fffffef},
10885 {0x7fffff0a, 0x7fffff0d, 0x7fffff0e, 0x7fffff0f},
10886 {0x7fffff1a, 0x7fffff2d, 0x7fffff3e, 0x7fffff4f},
10887 {0x7fffff50, 0x7fffff60, 0x7fffff70, 0x7fffff80},
10888 {0x8fffff90, 0x7fffffa0, 0x7fffffb0, 0x7fffffc0},
10889 {0x7fffffd0, 0x7fffffe0, 0x7ffffff0, 0x7fffffff},
10890 {0x7fffff73, 0x7fffff77, 0x7fffff7a, 0x7fffff7b},
10891 {0x7fffff7c, 0x7fffff7d, 0x7fffff7e, 0x7fffff7f},
10893 {0xffffff01, 0xffffff02, 0xffffff03, 0xffffff04},
10894 {0xffffffff, 0xfffffffe, 0xfffffffd, 0xfffffffc},
10895 {0xfffffff2, 0xfffffff1, 0xfffffff0, 0xffffffef},
10896 {0xffffff0a, 0xffffff0d, 0xffffff0e, 0xffffff0f},
10897 {0xffffff1a, 0xffffff2d, 0xffffff3e, 0xffffff4f},
10898 {0xffffff50, 0xffffff60, 0xffffff70, 0xffffff80},
10899 {0xffffff90, 0xffffffa0, 0xffffffb0, 0xffffffc0},
10900 {0xffffffd0, 0xffffffe0, 0xfffffff0, 0xffffffff},
10901 {0xffffff73, 0xffffff77, 0xffffff7a, 0xffffff7b},
10902 {0xffffff7c, 0xffffff7d, 0xffffff7e, 0xffffff7f},
10905 device_desc.feature_level = &feature_level;
10906 device_desc.flags = 0;
10907 if (!(device = create_device(&device_desc)))
10909 skip("Failed to create device for feature level %#x.\n", feature_level);
10910 return;
10913 ID3D11Device_GetImmediateContext(device, &context);
10915 /* Structured buffer views */
10916 buffer_desc.ByteWidth = 64;
10917 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
10918 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
10919 buffer_desc.CPUAccessFlags = 0;
10920 buffer_desc.MiscFlags = 0;
10921 buffer_desc.StructureByteStride = 0;
10922 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
10923 buffer_desc.StructureByteStride = 4;
10924 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
10925 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
10927 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
10928 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
10930 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
10931 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
10932 U(uav_desc).Buffer.FirstElement = 0;
10933 U(uav_desc).Buffer.NumElements = 4;
10934 U(uav_desc).Buffer.Flags = 0;
10935 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
10936 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
10938 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
10940 uvec4 = uvec4_data[i];
10941 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
10942 get_buffer_readback(buffer, &rb);
10943 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
10945 DWORD data = get_readback_color(&rb, x, 0);
10946 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
10948 release_resource_readback(&rb);
10950 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
10951 get_buffer_readback(buffer, &rb);
10952 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
10954 DWORD data = get_readback_color(&rb, x, 0);
10955 uvec4 = x < U(uav_desc).Buffer.NumElements ? fe_uvec4 : uvec4_data[i];
10956 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
10958 release_resource_readback(&rb);
10961 ID3D11Buffer_Release(buffer);
10962 ID3D11UnorderedAccessView_Release(uav);
10963 ID3D11UnorderedAccessView_Release(uav2);
10965 /* Raw buffer views */
10966 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
10967 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
10968 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
10970 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
10971 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
10972 U(uav_desc).Buffer.FirstElement = 0;
10973 U(uav_desc).Buffer.NumElements = 16;
10974 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
10975 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
10976 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
10977 U(uav_desc).Buffer.FirstElement = 8;
10978 U(uav_desc).Buffer.NumElements = 8;
10979 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
10980 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
10982 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
10984 uvec4 = uvec4_data[i];
10985 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
10986 get_buffer_readback(buffer, &rb);
10987 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
10989 DWORD data = get_readback_color(&rb, x, 0);
10990 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
10992 release_resource_readback(&rb);
10994 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
10995 get_buffer_readback(buffer, &rb);
10996 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
10998 DWORD data = get_readback_color(&rb, x, 0);
10999 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11000 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11002 release_resource_readback(&rb);
11005 ID3D11Buffer_Release(buffer);
11006 ID3D11UnorderedAccessView_Release(uav);
11007 ID3D11UnorderedAccessView_Release(uav2);
11009 /* Typed buffer views */
11010 buffer_desc.MiscFlags = 0;
11011 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11012 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11014 uav_desc.Format = DXGI_FORMAT_R32_SINT;
11015 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11016 U(uav_desc).Buffer.FirstElement = 0;
11017 U(uav_desc).Buffer.NumElements = 16;
11018 U(uav_desc).Buffer.Flags = 0;
11019 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11020 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11021 U(uav_desc).Buffer.FirstElement = 9;
11022 U(uav_desc).Buffer.NumElements = 7;
11023 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11024 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11026 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11028 uvec4 = uvec4_data[i];
11029 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11030 get_buffer_readback(buffer, &rb);
11031 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11033 DWORD data = get_readback_color(&rb, x, 0);
11034 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11036 release_resource_readback(&rb);
11038 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11039 get_buffer_readback(buffer, &rb);
11040 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11042 DWORD data = get_readback_color(&rb, x, 0);
11043 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11044 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11046 release_resource_readback(&rb);
11049 ID3D11UnorderedAccessView_Release(uav);
11050 ID3D11UnorderedAccessView_Release(uav2);
11052 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
11053 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11054 U(uav_desc).Buffer.FirstElement = 0;
11055 U(uav_desc).Buffer.NumElements = 4;
11056 U(uav_desc).Buffer.Flags = 0;
11057 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11058 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11059 U(uav_desc).Buffer.FirstElement = 2;
11060 U(uav_desc).Buffer.NumElements = 2;
11061 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11062 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11064 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11066 uvec4 = uvec4_data[i];
11067 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11068 get_buffer_readback(buffer, &rb);
11069 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
11071 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
11072 const struct uvec4 broken_result = {uvec4.x, uvec4.x, uvec4.x, uvec4.x}; /* Intel */
11073 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
11074 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
11075 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
11077 release_resource_readback(&rb);
11079 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11080 get_buffer_readback(buffer, &rb);
11081 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
11083 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
11084 struct uvec4 broken_result;
11085 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11086 broken_result.x = broken_result.y = broken_result.z = broken_result.w = uvec4.x;
11087 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
11088 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
11089 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
11091 release_resource_readback(&rb);
11094 uvec4.x = uvec4.y = uvec4.z = uvec4.w = 0xdeadbeef;
11095 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11096 ID3D11UnorderedAccessView_Release(uav);
11097 ID3D11UnorderedAccessView_Release(uav2);
11099 uav_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT;
11100 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11101 U(uav_desc).Buffer.FirstElement = 0;
11102 U(uav_desc).Buffer.NumElements = 16;
11103 U(uav_desc).Buffer.Flags = 0;
11104 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11105 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11106 U(uav_desc).Buffer.FirstElement = 8;
11107 U(uav_desc).Buffer.NumElements = 8;
11108 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11109 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11111 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11113 uvec4 = uvec4_data[i];
11114 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11115 get_buffer_readback(buffer, &rb);
11116 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11117 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0), &uvec4);
11118 release_resource_readback(&rb);
11120 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11121 get_buffer_readback(buffer, &rb);
11122 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11124 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11125 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0), &uvec4);
11127 release_resource_readback(&rb);
11130 ID3D11UnorderedAccessView_Release(uav);
11131 ID3D11UnorderedAccessView_Release(uav2);
11133 ID3D11Buffer_Release(buffer);
11135 ID3D11DeviceContext_Release(context);
11136 refcount = ID3D11Device_Release(device);
11137 ok(!refcount, "Device has %u references left.\n", refcount);
11140 static void test_draw_depth_only(void)
11142 ID3D11DepthStencilState *depth_stencil_state;
11143 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
11144 struct d3d11_test_context test_context;
11145 ID3D11PixelShader *ps_color, *ps_depth;
11146 D3D11_TEXTURE2D_DESC texture_desc;
11147 ID3D11DeviceContext *context;
11148 ID3D11DepthStencilView *dsv;
11149 struct resource_readback rb;
11150 ID3D11Texture2D *texture;
11151 ID3D11Device *device;
11152 unsigned int i, j;
11153 D3D11_VIEWPORT vp;
11154 struct vec4 depth;
11155 ID3D11Buffer *cb;
11156 HRESULT hr;
11158 static const DWORD ps_color_code[] =
11160 #if 0
11161 float4 main(float4 position : SV_POSITION) : SV_Target
11163 return float4(0.0, 1.0, 0.0, 1.0);
11165 #endif
11166 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
11167 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11168 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
11169 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11170 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
11171 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
11172 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
11174 static const DWORD ps_depth_code[] =
11176 #if 0
11177 float depth;
11179 float main() : SV_Depth
11181 return depth;
11183 #endif
11184 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
11185 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11186 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
11187 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11188 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
11189 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
11192 if (!init_test_context(&test_context, NULL))
11193 return;
11195 device = test_context.device;
11196 context = test_context.immediate_context;
11198 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
11200 texture_desc.Width = 640;
11201 texture_desc.Height = 480;
11202 texture_desc.MipLevels = 1;
11203 texture_desc.ArraySize = 1;
11204 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11205 texture_desc.SampleDesc.Count = 1;
11206 texture_desc.SampleDesc.Quality = 0;
11207 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11208 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
11209 texture_desc.CPUAccessFlags = 0;
11210 texture_desc.MiscFlags = 0;
11212 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11213 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11215 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
11216 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11218 depth_stencil_desc.DepthEnable = TRUE;
11219 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
11220 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS;
11221 depth_stencil_desc.StencilEnable = FALSE;
11223 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
11224 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
11226 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
11227 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11228 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
11229 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11231 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11232 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
11233 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
11234 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
11236 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11237 check_texture_float(texture, 1.0f, 1);
11238 draw_quad(&test_context);
11239 check_texture_float(texture, 0.0f, 1);
11241 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
11243 depth.x = 0.7f;
11244 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11245 draw_quad(&test_context);
11246 check_texture_float(texture, 0.0f, 1);
11247 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11248 check_texture_float(texture, 1.0f, 1);
11249 draw_quad(&test_context);
11250 check_texture_float(texture, 0.7f, 1);
11251 depth.x = 0.8f;
11252 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11253 draw_quad(&test_context);
11254 check_texture_float(texture, 0.7f, 1);
11255 depth.x = 0.5f;
11256 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11257 draw_quad(&test_context);
11258 check_texture_float(texture, 0.5f, 1);
11260 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11261 depth.x = 0.1f;
11262 for (i = 0; i < 4; ++i)
11264 for (j = 0; j < 4; ++j)
11266 depth.x = 1.0f / 16.0f * (j + 4 * i);
11267 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11269 vp.TopLeftX = 160.0f * j;
11270 vp.TopLeftY = 120.0f * i;
11271 vp.Width = 160.0f;
11272 vp.Height = 120.0f;
11273 vp.MinDepth = 0.0f;
11274 vp.MaxDepth = 1.0f;
11275 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11277 draw_quad(&test_context);
11280 get_texture_readback(texture, 0, &rb);
11281 for (i = 0; i < 4; ++i)
11283 for (j = 0; j < 4; ++j)
11285 float obtained_depth, expected_depth;
11287 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
11288 expected_depth = 1.0f / 16.0f * (j + 4 * i);
11289 ok(compare_float(obtained_depth, expected_depth, 1),
11290 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
11291 obtained_depth, j, i, expected_depth);
11294 release_resource_readback(&rb);
11296 ID3D11Buffer_Release(cb);
11297 ID3D11PixelShader_Release(ps_color);
11298 ID3D11PixelShader_Release(ps_depth);
11299 ID3D11DepthStencilView_Release(dsv);
11300 ID3D11DepthStencilState_Release(depth_stencil_state);
11301 ID3D11Texture2D_Release(texture);
11302 release_test_context(&test_context);
11305 static void test_draw_uav_only(void)
11307 struct d3d11_test_context test_context;
11308 D3D11_TEXTURE2D_DESC texture_desc;
11309 ID3D11UnorderedAccessView *uav;
11310 ID3D11DeviceContext *context;
11311 ID3D11Texture2D *texture;
11312 ID3D11PixelShader *ps;
11313 ID3D11Device *device;
11314 D3D11_VIEWPORT vp;
11315 HRESULT hr;
11317 static const DWORD ps_code[] =
11319 #if 0
11320 RWTexture2D<int> u;
11322 void main()
11324 InterlockedAdd(u[uint2(0, 0)], 1);
11326 #endif
11327 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
11328 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11329 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
11330 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
11331 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
11333 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11334 static const UINT values[4] = {0};
11336 if (!init_test_context(&test_context, &feature_level))
11337 return;
11339 device = test_context.device;
11340 context = test_context.immediate_context;
11342 texture_desc.Width = 1;
11343 texture_desc.Height = 1;
11344 texture_desc.MipLevels = 1;
11345 texture_desc.ArraySize = 1;
11346 texture_desc.Format = DXGI_FORMAT_R32_SINT;
11347 texture_desc.SampleDesc.Count = 1;
11348 texture_desc.SampleDesc.Quality = 0;
11349 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11350 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
11351 texture_desc.CPUAccessFlags = 0;
11352 texture_desc.MiscFlags = 0;
11354 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11355 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11357 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
11358 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11360 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11361 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11363 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11364 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
11365 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &test_context.backbuffer_rtv, NULL,
11366 0, 1, &uav, NULL);
11368 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
11369 memset(&vp, 0, sizeof(vp));
11370 vp.Width = 1.0f;
11371 vp.Height = 100.0f;
11372 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11373 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
11374 draw_quad(&test_context);
11375 check_texture_color(texture, 100, 1);
11377 draw_quad(&test_context);
11378 draw_quad(&test_context);
11379 draw_quad(&test_context);
11380 draw_quad(&test_context);
11381 check_texture_color(texture, 500, 1);
11383 ID3D11PixelShader_Release(ps);
11384 ID3D11Texture2D_Release(texture);
11385 ID3D11UnorderedAccessView_Release(uav);
11386 release_test_context(&test_context);
11389 static void test_cb_relative_addressing(void)
11391 struct d3d11_test_context test_context;
11392 ID3D11Buffer *colors_cb, *index_cb;
11393 unsigned int i, index[4] = {0};
11394 ID3D11DeviceContext *context;
11395 ID3D11PixelShader *ps;
11396 ID3D11Device *device;
11397 HRESULT hr;
11399 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11401 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11403 static const DWORD vs_code[] =
11405 #if 0
11406 int color_index;
11408 cbuffer colors
11410 float4 colors[8];
11413 struct vs_in
11415 float4 position : POSITION;
11418 struct vs_out
11420 float4 position : SV_POSITION;
11421 float4 color : COLOR;
11424 vs_out main(const vs_in v)
11426 vs_out o;
11428 o.position = v.position;
11429 o.color = colors[color_index];
11431 return o;
11433 #endif
11434 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
11435 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11436 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11437 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11438 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11439 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
11440 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
11441 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
11442 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
11443 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
11444 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
11445 0x0100003e,
11447 static const DWORD ps_code[] =
11449 #if 0
11450 struct ps_in
11452 float4 position : SV_POSITION;
11453 float4 color : COLOR;
11456 float4 main(const ps_in v) : SV_TARGET
11458 return v.color;
11460 #endif
11461 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
11462 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11463 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
11464 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
11465 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11466 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
11467 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11468 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
11470 static const struct vec2 quad[] =
11472 {-1.0f, -1.0f},
11473 {-1.0f, 1.0f},
11474 { 1.0f, -1.0f},
11475 { 1.0f, 1.0f},
11477 static const struct
11479 float color[4];
11481 colors[10] =
11483 {{0.0f, 0.0f, 0.0f, 1.0f}},
11484 {{0.0f, 0.0f, 1.0f, 0.0f}},
11485 {{0.0f, 0.0f, 1.0f, 1.0f}},
11486 {{0.0f, 1.0f, 0.0f, 0.0f}},
11487 {{0.0f, 1.0f, 0.0f, 1.0f}},
11488 {{0.0f, 1.0f, 1.0f, 0.0f}},
11489 {{0.0f, 1.0f, 1.0f, 1.0f}},
11490 {{1.0f, 0.0f, 0.0f, 0.0f}},
11491 {{1.0f, 0.0f, 0.0f, 1.0f}},
11492 {{1.0f, 0.0f, 1.0f, 0.0f}},
11494 static const struct
11496 unsigned int index;
11497 DWORD expected;
11499 test_data[] =
11501 {0, 0xff000000},
11502 {1, 0x00ff0000},
11503 {2, 0xffff0000},
11504 {3, 0x0000ff00},
11505 {4, 0xff00ff00},
11506 {5, 0x00ffff00},
11507 {6, 0xffffff00},
11508 {7, 0x000000ff},
11510 {8, 0xff0000ff},
11511 {9, 0x00ff00ff},
11513 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
11514 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11516 if (!init_test_context(&test_context, &feature_level))
11517 return;
11519 device = test_context.device;
11520 context = test_context.immediate_context;
11522 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11523 vs_code, sizeof(vs_code), &test_context.input_layout);
11524 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11526 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11527 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
11528 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
11530 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
11531 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11532 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11533 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11535 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
11536 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
11537 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11539 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
11541 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
11543 index[0] = test_data[i].index;
11544 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
11546 draw_quad(&test_context);
11547 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
11550 ID3D11Buffer_Release(index_cb);
11551 ID3D11Buffer_Release(colors_cb);
11552 ID3D11PixelShader_Release(ps);
11554 release_test_context(&test_context);
11557 static void test_getdc(void)
11559 static const struct
11561 const char *name;
11562 DXGI_FORMAT format;
11563 BOOL getdc_supported;
11565 testdata[] =
11567 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
11568 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
11569 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
11570 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
11571 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
11572 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
11574 struct device_desc device_desc;
11575 D3D11_TEXTURE2D_DESC desc;
11576 ID3D11Texture2D *texture;
11577 IDXGISurface1 *surface;
11578 ID3D11Device *device;
11579 unsigned int i;
11580 ULONG refcount;
11581 HRESULT hr;
11582 HDC dc;
11584 device_desc.feature_level = NULL;
11585 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
11586 if (!(device = create_device(&device_desc)))
11588 skip("Failed to create device.\n");
11589 return;
11592 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
11593 desc.Width = 512;
11594 desc.Height = 512;
11595 desc.MipLevels = 1;
11596 desc.ArraySize = 1;
11597 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
11598 desc.SampleDesc.Count = 1;
11599 desc.SampleDesc.Quality = 0;
11600 desc.Usage = D3D11_USAGE_DEFAULT;
11601 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11602 desc.CPUAccessFlags = 0;
11603 desc.MiscFlags = 0;
11604 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
11605 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11607 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
11608 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
11610 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
11611 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
11613 IDXGISurface1_Release(surface);
11614 ID3D11Texture2D_Release(texture);
11616 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
11617 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
11618 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11620 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
11621 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
11623 hr = IDXGISurface1_ReleaseDC(surface, NULL);
11624 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
11626 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
11627 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
11629 hr = IDXGISurface1_ReleaseDC(surface, NULL);
11630 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
11632 IDXGISurface1_Release(surface);
11633 ID3D11Texture2D_Release(texture);
11635 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
11637 static const unsigned int bit_count = 32;
11638 unsigned int width_bytes;
11639 DIBSECTION dib;
11640 HBITMAP bitmap;
11641 DWORD type;
11642 int size;
11644 desc.Width = 64;
11645 desc.Height = 64;
11646 desc.MipLevels = 1;
11647 desc.ArraySize = 1;
11648 desc.Format = testdata[i].format;
11649 desc.SampleDesc.Count = 1;
11650 desc.SampleDesc.Quality = 0;
11651 desc.Usage = D3D11_USAGE_STAGING;
11652 desc.BindFlags = 0;
11653 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
11654 desc.MiscFlags = 0;
11656 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
11657 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11658 ID3D11Texture2D_Release(texture);
11660 /* STAGING usage, requesting GDI compatibility mode. */
11661 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
11662 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
11663 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
11665 desc.Usage = D3D11_USAGE_DEFAULT;
11666 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11667 desc.CPUAccessFlags = 0;
11668 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
11669 if (testdata[i].getdc_supported)
11670 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
11671 else
11672 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
11674 if (FAILED(hr))
11675 continue;
11677 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
11678 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
11680 dc = (void *)0x1234;
11681 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
11682 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
11684 if (FAILED(hr))
11686 IDXGISurface1_Release(surface);
11687 ID3D11Texture2D_Release(texture);
11688 continue;
11691 type = GetObjectType(dc);
11692 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
11693 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
11694 type = GetObjectType(bitmap);
11695 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
11697 size = GetObjectA(bitmap, sizeof(dib), &dib);
11698 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
11699 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
11701 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
11702 dib.dsBm.bmType, testdata[i].name);
11703 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
11704 dib.dsBm.bmWidth, testdata[i].name);
11705 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
11706 dib.dsBm.bmHeight, testdata[i].name);
11707 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
11708 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
11709 dib.dsBm.bmWidthBytes, testdata[i].name);
11710 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
11711 dib.dsBm.bmPlanes, testdata[i].name);
11712 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
11713 dib.dsBm.bmBitsPixel, testdata[i].name);
11715 if (size == sizeof(dib))
11716 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
11717 dib.dsBm.bmBits, testdata[i].name);
11718 else
11719 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
11720 dib.dsBm.bmBits, testdata[i].name);
11722 if (size == sizeof(dib))
11724 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
11725 dib.dsBmih.biSize, testdata[i].name);
11726 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
11727 dib.dsBmih.biHeight, testdata[i].name);
11728 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
11729 dib.dsBmih.biHeight, testdata[i].name);
11730 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
11731 dib.dsBmih.biPlanes, testdata[i].name);
11732 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
11733 dib.dsBmih.biBitCount, testdata[i].name);
11734 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
11735 dib.dsBmih.biCompression, testdata[i].name);
11736 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
11737 dib.dsBmih.biSizeImage, testdata[i].name);
11738 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
11739 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
11740 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
11741 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
11742 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
11743 dib.dsBmih.biClrUsed, testdata[i].name);
11744 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
11745 dib.dsBmih.biClrImportant, testdata[i].name);
11746 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
11747 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11748 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
11749 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
11750 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
11753 hr = IDXGISurface1_ReleaseDC(surface, NULL);
11754 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
11756 IDXGISurface1_Release(surface);
11757 ID3D11Texture2D_Release(texture);
11760 refcount = ID3D11Device_Release(device);
11761 ok(!refcount, "Device has %u references left.\n", refcount);
11764 static void test_shader_stage_input_output_matching(void)
11766 struct d3d11_test_context test_context;
11767 D3D11_TEXTURE2D_DESC texture_desc;
11768 ID3D11Texture2D *render_target;
11769 ID3D11RenderTargetView *rtv[2];
11770 ID3D11DeviceContext *context;
11771 ID3D11VertexShader *vs;
11772 ID3D11PixelShader *ps;
11773 ID3D11Device *device;
11774 HRESULT hr;
11776 static const DWORD vs_code[] =
11778 #if 0
11779 struct output
11781 float4 position : SV_PoSiTion;
11782 float4 color0 : COLOR0;
11783 float4 color1 : COLOR1;
11786 void main(uint id : SV_VertexID, out output o)
11788 float2 coords = float2((id << 1) & 2, id & 2);
11789 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
11790 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
11791 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
11793 #endif
11794 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
11795 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11796 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
11797 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
11798 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11799 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
11800 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
11801 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
11802 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
11803 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
11804 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
11805 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
11806 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
11807 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
11808 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
11809 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
11810 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
11811 0x0100003e,
11813 static const DWORD ps_code[] =
11815 #if 0
11816 struct input
11818 float4 position : SV_PoSiTiOn;
11819 float4 color1 : COLOR1;
11820 float4 color0 : COLOR0;
11823 struct output
11825 float4 target0 : SV_Target0;
11826 float4 target1 : SV_Target1;
11829 void main(const in input i, out output o)
11831 o.target0 = i.color0;
11832 o.target1 = i.color1;
11834 #endif
11835 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
11836 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
11837 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
11838 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
11839 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
11840 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
11841 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
11842 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
11843 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
11844 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
11845 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
11848 if (!init_test_context(&test_context, NULL))
11849 return;
11851 device = test_context.device;
11852 context = test_context.immediate_context;
11854 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11855 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11856 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11857 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11859 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11860 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
11861 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11863 rtv[0] = test_context.backbuffer_rtv;
11864 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
11865 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11867 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11868 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11869 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
11870 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
11871 ID3D11DeviceContext_Draw(context, 3, 0);
11873 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11874 check_texture_color(render_target, 0xff0000ff, 0);
11876 ID3D11RenderTargetView_Release(rtv[1]);
11877 ID3D11Texture2D_Release(render_target);
11878 ID3D11PixelShader_Release(ps);
11879 ID3D11VertexShader_Release(vs);
11880 release_test_context(&test_context);
11883 static void test_sm4_if_instruction(void)
11885 struct d3d11_test_context test_context;
11886 ID3D11PixelShader *ps_if_nz, *ps_if_z;
11887 ID3D11DeviceContext *context;
11888 ID3D11Device *device;
11889 unsigned int bits[4];
11890 DWORD expected_color;
11891 ID3D11Buffer *cb;
11892 unsigned int i;
11893 HRESULT hr;
11895 static const DWORD ps_if_nz_code[] =
11897 #if 0
11898 uint bits;
11900 float4 main() : SV_TARGET
11902 if (bits)
11903 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11904 else
11905 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11907 #endif
11908 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
11909 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11910 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11911 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
11912 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
11913 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
11914 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
11915 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
11917 static const DWORD ps_if_z_code[] =
11919 #if 0
11920 uint bits;
11922 float4 main() : SV_TARGET
11924 if (!bits)
11925 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11926 else
11927 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11929 #endif
11930 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
11931 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11932 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11933 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
11934 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
11935 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
11936 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
11937 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
11939 static unsigned int bit_patterns[] =
11941 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
11944 if (!init_test_context(&test_context, NULL))
11945 return;
11947 device = test_context.device;
11948 context = test_context.immediate_context;
11950 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
11951 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
11952 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
11953 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
11955 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
11956 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11958 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
11960 *bits = bit_patterns[i];
11961 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
11963 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
11964 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
11965 draw_quad(&test_context);
11966 check_texture_color(test_context.backbuffer, expected_color, 0);
11968 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
11969 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
11970 draw_quad(&test_context);
11971 check_texture_color(test_context.backbuffer, expected_color, 0);
11974 ID3D11Buffer_Release(cb);
11975 ID3D11PixelShader_Release(ps_if_z);
11976 ID3D11PixelShader_Release(ps_if_nz);
11977 release_test_context(&test_context);
11980 static void test_sm4_breakc_instruction(void)
11982 struct d3d11_test_context test_context;
11983 ID3D11DeviceContext *context;
11984 ID3D11PixelShader *ps;
11985 ID3D11Device *device;
11986 HRESULT hr;
11988 static const DWORD ps_breakc_nz_code[] =
11990 #if 0
11991 float4 main() : SV_TARGET
11993 uint counter = 0;
11995 for (uint i = 0; i < 255; ++i)
11996 ++counter;
11998 if (counter == 255)
11999 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12000 else
12001 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12003 #endif
12004 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
12005 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12006 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12007 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
12008 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
12009 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
12010 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12011 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
12012 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
12013 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
12014 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
12015 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12016 0x01000015, 0x0100003e,
12018 static const DWORD ps_breakc_z_code[] =
12020 #if 0
12021 float4 main() : SV_TARGET
12023 uint counter = 0;
12025 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
12026 ++counter;
12028 if (counter == 255)
12029 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12030 else
12031 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12033 #endif
12034 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
12035 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12036 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12037 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
12038 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
12039 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
12040 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
12041 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
12042 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
12043 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
12044 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
12045 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12046 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12047 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12050 if (!init_test_context(&test_context, NULL))
12051 return;
12053 device = test_context.device;
12054 context = test_context.immediate_context;
12056 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
12057 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
12058 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12059 draw_quad(&test_context);
12060 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12061 ID3D11PixelShader_Release(ps);
12063 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
12064 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
12065 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12066 draw_quad(&test_context);
12067 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12068 ID3D11PixelShader_Release(ps);
12070 release_test_context(&test_context);
12073 static void test_sm4_continuec_instruction(void)
12075 struct d3d11_test_context test_context;
12076 ID3D11DeviceContext *context;
12077 ID3D11PixelShader *ps;
12078 ID3D11Device *device;
12079 HRESULT hr;
12081 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
12082 * with a normal continue inside, the shaders have been compiled with
12083 * the /Gfa flag. */
12084 static const DWORD ps_continuec_nz_code[] =
12086 #if 0
12087 float4 main() : SV_TARGET
12089 uint counter = 0;
12090 int i = -1;
12092 while (i < 255) {
12093 ++i;
12095 if (i != 0)
12096 continue;
12098 ++counter;
12101 if (counter == 1)
12102 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12103 else
12104 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12106 #endif
12107 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
12108 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12109 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12110 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
12111 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
12112 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12113 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12114 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
12115 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
12116 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
12117 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
12118 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
12119 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
12120 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
12121 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
12122 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
12123 0x3f800000, 0x0100003e,
12126 static const DWORD ps_continuec_z_code[] =
12128 #if 0
12129 float4 main() : SV_TARGET
12131 uint counter = 0;
12132 int i = -1;
12134 while (i < 255) {
12135 ++i;
12137 if (i == 0)
12138 continue;
12140 ++counter;
12143 if (counter == 255)
12144 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12145 else
12146 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12148 #endif
12149 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
12150 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12151 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12152 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
12153 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
12154 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12155 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12156 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
12157 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
12158 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
12159 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
12160 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
12161 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
12162 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
12163 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12166 if (!init_test_context(&test_context, NULL))
12167 return;
12169 device = test_context.device;
12170 context = test_context.immediate_context;
12172 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), NULL, &ps);
12173 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
12174 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12175 draw_quad(&test_context);
12176 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12177 ID3D11PixelShader_Release(ps);
12179 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), NULL, &ps);
12180 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
12181 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12182 draw_quad(&test_context);
12183 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12184 ID3D11PixelShader_Release(ps);
12186 release_test_context(&test_context);
12189 static void test_create_input_layout(void)
12191 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12193 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12195 ULONG refcount, expected_refcount;
12196 ID3D11InputLayout *input_layout;
12197 ID3D11Device *device;
12198 unsigned int i;
12199 HRESULT hr;
12201 static const DWORD vs_code[] =
12203 #if 0
12204 float4 main(float4 position : POSITION) : SV_POSITION
12206 return position;
12208 #endif
12209 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
12210 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12211 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
12212 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
12213 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
12214 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
12215 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
12217 static const DXGI_FORMAT vertex_formats[] =
12219 DXGI_FORMAT_R32G32_FLOAT,
12220 DXGI_FORMAT_R32G32_UINT,
12221 DXGI_FORMAT_R32G32_SINT,
12222 DXGI_FORMAT_R16G16_FLOAT,
12223 DXGI_FORMAT_R16G16_UINT,
12224 DXGI_FORMAT_R16G16_SINT,
12225 DXGI_FORMAT_R32_FLOAT,
12226 DXGI_FORMAT_R32_UINT,
12227 DXGI_FORMAT_R32_SINT,
12228 DXGI_FORMAT_R16_UINT,
12229 DXGI_FORMAT_R16_SINT,
12230 DXGI_FORMAT_R8_UINT,
12231 DXGI_FORMAT_R8_SINT,
12234 if (!(device = create_device(NULL)))
12236 skip("Failed to create device.\n");
12237 return;
12240 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
12242 expected_refcount = get_refcount(device) + 1;
12243 layout_desc->Format = vertex_formats[i];
12244 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12245 vs_code, sizeof(vs_code), &input_layout);
12246 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
12247 vertex_formats[i], hr);
12248 refcount = get_refcount(device);
12249 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
12250 refcount, expected_refcount);
12251 ID3D11InputLayout_Release(input_layout);
12254 refcount = ID3D11Device_Release(device);
12255 ok(!refcount, "Device has %u references left.\n", refcount);
12258 static void test_input_assembler(void)
12260 enum layout_id
12262 LAYOUT_FLOAT32,
12263 LAYOUT_UINT16,
12264 LAYOUT_SINT16,
12265 LAYOUT_UNORM16,
12266 LAYOUT_SNORM16,
12267 LAYOUT_UINT8,
12268 LAYOUT_SINT8,
12269 LAYOUT_UNORM8,
12270 LAYOUT_SNORM8,
12271 LAYOUT_UNORM10_2,
12272 LAYOUT_UINT10_2,
12274 LAYOUT_COUNT,
12277 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
12279 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12280 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12282 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
12283 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
12284 ID3D11Buffer *vb_position, *vb_attribute;
12285 struct d3d11_test_context test_context;
12286 D3D11_TEXTURE2D_DESC texture_desc;
12287 unsigned int i, j, stride, offset;
12288 ID3D11Texture2D *render_target;
12289 ID3D11DeviceContext *context;
12290 ID3D11RenderTargetView *rtv;
12291 ID3D11PixelShader *ps;
12292 ID3D11Device *device;
12293 HRESULT hr;
12295 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
12297 DXGI_FORMAT_R32G32B32A32_FLOAT,
12298 DXGI_FORMAT_R16G16B16A16_UINT,
12299 DXGI_FORMAT_R16G16B16A16_SINT,
12300 DXGI_FORMAT_R16G16B16A16_UNORM,
12301 DXGI_FORMAT_R16G16B16A16_SNORM,
12302 DXGI_FORMAT_R8G8B8A8_UINT,
12303 DXGI_FORMAT_R8G8B8A8_SINT,
12304 DXGI_FORMAT_R8G8B8A8_UNORM,
12305 DXGI_FORMAT_R8G8B8A8_SNORM,
12306 DXGI_FORMAT_R10G10B10A2_UNORM,
12307 DXGI_FORMAT_R10G10B10A2_UINT,
12309 static const struct vec2 quad[] =
12311 {-1.0f, -1.0f},
12312 {-1.0f, 1.0f},
12313 { 1.0f, -1.0f},
12314 { 1.0f, 1.0f},
12316 static const DWORD ps_code[] =
12318 #if 0
12319 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
12321 return color;
12323 #endif
12324 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
12325 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
12326 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
12327 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
12328 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12329 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
12330 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
12331 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12333 static const DWORD vs_float_code[] =
12335 #if 0
12336 struct output
12338 float4 position : SV_Position;
12339 float4 color : COLOR;
12342 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
12344 o.position = position;
12345 o.color = color;
12347 #endif
12348 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
12349 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12350 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12351 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12352 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12353 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12354 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12355 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12356 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12357 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12358 0x0100003e,
12360 static const DWORD vs_uint_code[] =
12362 #if 0
12363 struct output
12365 float4 position : SV_Position;
12366 float4 color : COLOR;
12369 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
12371 o.position = position;
12372 o.color = color;
12374 #endif
12375 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
12376 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12377 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12378 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12379 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12380 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12381 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12382 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12383 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12384 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12385 0x0100003e,
12387 static const DWORD vs_sint_code[] =
12389 #if 0
12390 struct output
12392 float4 position : SV_Position;
12393 float4 color : COLOR;
12396 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
12398 o.position = position;
12399 o.color = color;
12401 #endif
12402 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
12403 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12404 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12405 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12406 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12407 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12408 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12409 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12410 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12411 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12412 0x0100003e,
12414 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
12415 static const unsigned short uint16_data[] = {6, 8, 55, 777};
12416 static const short sint16_data[] = {-1, 33, 8, -77};
12417 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
12418 static const short snorm16_data[] = {-32768, 0, 32767, 0};
12419 static const unsigned char uint8_data[] = {0, 64, 128, 255};
12420 static const signed char sint8_data[] = {-128, 0, 127, 64};
12421 static const unsigned int uint32_zero = 0;
12422 static const unsigned int uint32_max = 0xffffffff;
12423 static const unsigned int unorm10_2_data= 0xa00003ff;
12424 static const unsigned int g10_data = 0x000ffc00;
12425 static const unsigned int a2_data = 0xc0000000;
12426 static const struct
12428 enum layout_id layout_id;
12429 unsigned int stride;
12430 const void *data;
12431 struct vec4 expected_color;
12432 BOOL todo;
12434 tests[] =
12436 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
12437 {1.0f, 2.0f, 3.0f, 4.0f}},
12438 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
12439 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
12440 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
12441 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
12442 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
12443 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
12444 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
12445 {-1.0f, 0.0f, 1.0f, 0.0f}},
12446 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
12447 {0.0f, 0.0f, 0.0f, 0.0f}},
12448 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
12449 {255.0f, 255.0f, 255.0f, 255.0f}},
12450 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
12451 {0.0f, 64.0f, 128.0f, 255.0f}},
12452 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
12453 {0.0f, 0.0f, 0.0f, 0.0f}},
12454 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
12455 {-1.0f, -1.0f, -1.0f, -1.0f}},
12456 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
12457 {-128.0f, 0.0f, 127.0f, 64.0f}},
12458 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
12459 {0.0f, 0.0f, 0.0f, 0.0f}},
12460 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
12461 {1.0f, 1.0f, 1.0f, 1.0f}},
12462 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
12463 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
12464 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
12465 {0.0f, 0.0f, 0.0f, 0.0f}},
12466 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
12467 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
12468 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
12469 {0.0f, 0.0f, 0.0f, 0.0f}},
12470 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
12471 {1.0f, 1.0f, 1.0f, 1.0f}},
12472 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
12473 {0.0f, 1.0f, 0.0f, 0.0f}},
12474 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
12475 {0.0f, 0.0f, 0.0f, 1.0f}},
12476 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
12477 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
12478 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
12479 {0.0f, 0.0f, 0.0f, 0.0f}},
12480 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
12481 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
12482 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
12483 {0.0f, 1023.0f, 0.0f, 0.0f}},
12484 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
12485 {0.0f, 0.0f, 0.0f, 3.0f}},
12486 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
12487 {1023.0f, 0.0f, 512.0f, 2.0f}},
12490 if (!init_test_context(&test_context, NULL))
12491 return;
12493 device = test_context.device;
12494 context = test_context.immediate_context;
12496 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12497 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12499 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
12500 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
12501 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
12502 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
12503 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
12504 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
12506 for (i = 0; i < LAYOUT_COUNT; ++i)
12508 input_layout_desc[1].Format = layout_formats[i];
12509 input_layout[i] = NULL;
12510 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
12511 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
12512 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
12513 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
12516 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
12517 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
12519 texture_desc.Width = 640;
12520 texture_desc.Height = 480;
12521 texture_desc.MipLevels = 1;
12522 texture_desc.ArraySize = 1;
12523 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12524 texture_desc.SampleDesc.Count = 1;
12525 texture_desc.SampleDesc.Quality = 0;
12526 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12527 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12528 texture_desc.CPUAccessFlags = 0;
12529 texture_desc.MiscFlags = 0;
12531 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
12532 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
12534 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
12535 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12537 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12538 offset = 0;
12539 stride = sizeof(*quad);
12540 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
12541 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12542 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
12544 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12546 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
12548 if (tests[i].layout_id == LAYOUT_UINT10_2)
12549 continue;
12551 assert(tests[i].layout_id < LAYOUT_COUNT);
12552 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
12554 assert(4 * tests[i].stride <= 1024);
12555 box.right = tests[i].stride;
12556 for (j = 0; j < 4; ++j)
12558 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
12559 &box, tests[i].data, 0, 0);
12560 box.left += tests[i].stride;
12561 box.right += tests[i].stride;
12564 stride = tests[i].stride;
12565 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
12567 switch (layout_formats[tests[i].layout_id])
12569 case DXGI_FORMAT_R16G16B16A16_UINT:
12570 case DXGI_FORMAT_R10G10B10A2_UINT:
12571 case DXGI_FORMAT_R8G8B8A8_UINT:
12572 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
12573 break;
12574 case DXGI_FORMAT_R16G16B16A16_SINT:
12575 case DXGI_FORMAT_R8G8B8A8_SINT:
12576 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
12577 break;
12579 default:
12580 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
12581 /* Fall through. */
12582 case DXGI_FORMAT_R32G32B32A32_FLOAT:
12583 case DXGI_FORMAT_R16G16B16A16_UNORM:
12584 case DXGI_FORMAT_R16G16B16A16_SNORM:
12585 case DXGI_FORMAT_R10G10B10A2_UNORM:
12586 case DXGI_FORMAT_R8G8B8A8_UNORM:
12587 case DXGI_FORMAT_R8G8B8A8_SNORM:
12588 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
12589 break;
12592 ID3D11DeviceContext_Draw(context, 4, 0);
12593 check_texture_vec4(render_target, &tests[i].expected_color, 2);
12596 ID3D11Texture2D_Release(render_target);
12597 ID3D11RenderTargetView_Release(rtv);
12598 ID3D11Buffer_Release(vb_attribute);
12599 ID3D11Buffer_Release(vb_position);
12600 for (i = 0; i < LAYOUT_COUNT; ++i)
12602 if (input_layout[i])
12603 ID3D11InputLayout_Release(input_layout[i]);
12605 ID3D11PixelShader_Release(ps);
12606 ID3D11VertexShader_Release(vs_float);
12607 ID3D11VertexShader_Release(vs_uint);
12608 ID3D11VertexShader_Release(vs_sint);
12609 release_test_context(&test_context);
12612 static void test_null_sampler(void)
12614 struct d3d11_test_context test_context;
12615 D3D11_TEXTURE2D_DESC texture_desc;
12616 ID3D11ShaderResourceView *srv;
12617 ID3D11DeviceContext *context;
12618 ID3D11RenderTargetView *rtv;
12619 ID3D11SamplerState *sampler;
12620 ID3D11Texture2D *texture;
12621 ID3D11PixelShader *ps;
12622 ID3D11Device *device;
12623 HRESULT hr;
12625 static const DWORD ps_code[] =
12627 #if 0
12628 Texture2D t;
12629 SamplerState s;
12631 float4 main(float4 position : SV_POSITION) : SV_Target
12633 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
12635 #endif
12636 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
12637 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12638 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
12639 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12640 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
12641 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
12642 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12643 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
12644 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
12645 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
12647 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
12649 if (!init_test_context(&test_context, NULL))
12650 return;
12652 device = test_context.device;
12653 context = test_context.immediate_context;
12655 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12656 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12658 texture_desc.Width = 64;
12659 texture_desc.Height = 64;
12660 texture_desc.MipLevels = 1;
12661 texture_desc.ArraySize = 1;
12662 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12663 texture_desc.SampleDesc.Count = 1;
12664 texture_desc.SampleDesc.Quality = 0;
12665 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12666 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
12667 texture_desc.CPUAccessFlags = 0;
12668 texture_desc.MiscFlags = 0;
12670 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12671 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12673 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
12674 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12676 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
12677 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12679 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
12681 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12682 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
12683 sampler = NULL;
12684 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
12685 draw_quad(&test_context);
12686 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
12688 ID3D11ShaderResourceView_Release(srv);
12689 ID3D11RenderTargetView_Release(rtv);
12690 ID3D11Texture2D_Release(texture);
12691 ID3D11PixelShader_Release(ps);
12692 release_test_context(&test_context);
12695 static void test_check_feature_support(void)
12697 D3D11_FEATURE_DATA_THREADING threading[2];
12698 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
12699 ID3D11Device *device;
12700 ULONG refcount;
12701 HRESULT hr;
12703 if (!(device = create_device(NULL)))
12705 skip("Failed to create device.\n");
12706 return;
12709 memset(threading, 0xef, sizeof(threading));
12711 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
12712 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12713 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
12714 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12715 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
12716 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12717 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
12718 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12719 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
12720 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12721 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
12722 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12724 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
12725 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
12726 ok(threading[0].DriverCommandLists == 0xefefefef,
12727 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
12728 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
12729 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
12730 ok(threading[1].DriverCommandLists == 0xefefefef,
12731 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
12733 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
12734 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
12735 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
12736 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
12737 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
12738 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
12740 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
12741 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12742 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
12743 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12744 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
12745 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12746 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
12747 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12748 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
12749 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12750 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
12751 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12753 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
12754 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
12755 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
12757 refcount = ID3D11Device_Release(device);
12758 ok(!refcount, "Device has %u references left.\n", refcount);
12761 static void test_create_unordered_access_view(void)
12763 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12764 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
12765 D3D11_TEXTURE3D_DESC texture3d_desc;
12766 D3D11_TEXTURE2D_DESC texture2d_desc;
12767 ULONG refcount, expected_refcount;
12768 D3D11_SUBRESOURCE_DATA data = {0};
12769 ID3D11UnorderedAccessView *uav;
12770 struct device_desc device_desc;
12771 D3D11_BUFFER_DESC buffer_desc;
12772 ID3D11Device *device, *tmp;
12773 ID3D11Texture3D *texture3d;
12774 ID3D11Texture2D *texture2d;
12775 ID3D11Resource *texture;
12776 ID3D11Buffer *buffer;
12777 unsigned int i;
12778 HRESULT hr;
12780 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
12781 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
12782 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
12783 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
12784 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
12785 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
12786 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
12787 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
12788 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
12789 static const struct
12791 struct
12793 unsigned int miplevel_count;
12794 unsigned int depth_or_array_size;
12795 DXGI_FORMAT format;
12796 } texture;
12797 struct uav_desc uav_desc;
12798 struct uav_desc expected_uav_desc;
12800 tests[] =
12802 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
12803 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
12804 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
12805 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
12806 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
12807 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
12808 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
12809 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
12810 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
12811 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
12812 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
12813 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
12814 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
12815 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
12816 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
12817 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
12818 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
12819 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
12820 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
12821 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
12822 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
12823 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
12824 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
12825 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
12826 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
12827 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
12828 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
12829 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
12830 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
12831 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
12832 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
12833 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
12834 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
12835 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
12837 static const struct
12839 struct
12841 D3D11_UAV_DIMENSION dimension;
12842 unsigned int miplevel_count;
12843 unsigned int depth_or_array_size;
12844 DXGI_FORMAT format;
12845 } texture;
12846 struct uav_desc uav_desc;
12848 invalid_desc_tests[] =
12850 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
12851 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
12852 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
12853 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
12854 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
12855 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
12856 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
12857 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
12858 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
12859 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
12860 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
12861 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
12862 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
12863 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
12864 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
12865 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
12866 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
12867 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
12868 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
12869 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
12870 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
12871 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
12872 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
12873 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
12874 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
12875 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
12876 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
12877 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
12878 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
12879 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
12880 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
12881 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
12882 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
12884 #undef FMT_UNKNOWN
12885 #undef RGBA8_UNORM
12886 #undef RGBA8_TL
12887 #undef DIM_UNKNOWN
12888 #undef TEX_1D
12889 #undef TEX_1D_ARRAY
12890 #undef TEX_2D
12891 #undef TEX_2D_ARRAY
12892 #undef TEX_3D
12894 device_desc.feature_level = &feature_level;
12895 device_desc.flags = 0;
12896 if (!(device = create_device(&device_desc)))
12898 skip("Failed to create device.\n");
12899 return;
12902 buffer_desc.ByteWidth = 1024;
12903 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
12904 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
12905 buffer_desc.CPUAccessFlags = 0;
12906 buffer_desc.MiscFlags = 0;
12907 buffer_desc.StructureByteStride = 0;
12909 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
12910 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12912 expected_refcount = get_refcount(device) + 1;
12913 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
12914 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
12915 refcount = get_refcount(device);
12916 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
12917 tmp = NULL;
12918 expected_refcount = refcount + 1;
12919 ID3D11Buffer_GetDevice(buffer, &tmp);
12920 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
12921 refcount = get_refcount(device);
12922 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
12923 ID3D11Device_Release(tmp);
12925 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12926 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
12927 U(uav_desc).Buffer.FirstElement = 0;
12928 U(uav_desc).Buffer.NumElements = 64;
12929 U(uav_desc).Buffer.Flags = 0;
12931 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
12932 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12934 expected_refcount = get_refcount(device) + 1;
12935 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
12936 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12937 refcount = get_refcount(device);
12938 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
12939 tmp = NULL;
12940 expected_refcount = refcount + 1;
12941 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
12942 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
12943 refcount = get_refcount(device);
12944 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
12945 ID3D11Device_Release(tmp);
12947 ID3D11UnorderedAccessView_Release(uav);
12948 ID3D11Buffer_Release(buffer);
12950 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
12951 buffer_desc.StructureByteStride = 4;
12953 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
12954 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
12956 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
12957 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
12959 memset(&uav_desc, 0, sizeof(uav_desc));
12960 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
12962 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
12963 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
12964 uav_desc.ViewDimension);
12965 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
12966 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
12967 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
12969 ID3D11UnorderedAccessView_Release(uav);
12970 ID3D11Buffer_Release(buffer);
12972 texture2d_desc.Width = 512;
12973 texture2d_desc.Height = 512;
12974 texture2d_desc.SampleDesc.Count = 1;
12975 texture2d_desc.SampleDesc.Quality = 0;
12976 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
12977 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
12978 texture2d_desc.CPUAccessFlags = 0;
12979 texture2d_desc.MiscFlags = 0;
12981 texture3d_desc.Width = 64;
12982 texture3d_desc.Height = 64;
12983 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
12984 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
12985 texture3d_desc.CPUAccessFlags = 0;
12986 texture3d_desc.MiscFlags = 0;
12988 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12990 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
12992 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
12994 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
12995 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
12996 texture2d_desc.Format = tests[i].texture.format;
12998 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
12999 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
13000 texture = (ID3D11Resource *)texture2d;
13002 else
13004 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
13005 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
13006 texture3d_desc.Format = tests[i].texture.format;
13008 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
13009 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
13010 texture = (ID3D11Resource *)texture3d;
13013 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
13015 current_desc = NULL;
13017 else
13019 current_desc = &uav_desc;
13020 get_uav_desc(current_desc, &tests[i].uav_desc);
13023 expected_refcount = get_refcount(texture);
13024 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
13025 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
13026 refcount = get_refcount(texture);
13027 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
13029 memset(&uav_desc, 0, sizeof(uav_desc));
13030 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
13031 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
13033 ID3D11UnorderedAccessView_Release(uav);
13034 ID3D11Resource_Release(texture);
13037 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
13039 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
13040 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
13042 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
13044 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
13045 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
13046 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
13048 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
13049 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
13050 texture = (ID3D11Resource *)texture2d;
13052 else
13054 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
13055 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
13056 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
13058 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
13059 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
13060 texture = (ID3D11Resource *)texture3d;
13063 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
13064 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
13065 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
13067 ID3D11Resource_Release(texture);
13070 refcount = ID3D11Device_Release(device);
13071 ok(!refcount, "Device has %u references left.\n", refcount);
13074 static void test_immediate_constant_buffer(void)
13076 struct d3d11_test_context test_context;
13077 D3D11_TEXTURE2D_DESC texture_desc;
13078 ID3D11DeviceContext *context;
13079 ID3D11RenderTargetView *rtv;
13080 unsigned int index[4] = {0};
13081 ID3D11Texture2D *texture;
13082 ID3D11PixelShader *ps;
13083 ID3D11Device *device;
13084 ID3D11Buffer *cb;
13085 unsigned int i;
13086 HRESULT hr;
13088 static const DWORD ps_code[] =
13090 #if 0
13091 uint index;
13093 static const int int_array[6] =
13095 310, 111, 212, -513, -318, 0,
13098 static const uint uint_array[6] =
13100 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
13103 static const float float_array[6] =
13105 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
13108 float4 main() : SV_Target
13110 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
13112 #endif
13113 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
13114 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13115 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13116 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
13117 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
13118 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
13119 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
13120 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
13121 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
13122 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
13123 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
13124 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
13125 0x0100003e,
13127 static struct vec4 expected_result[] =
13129 { 310.0f, 2.0f, 76.00f, 1.0f},
13130 { 111.0f, 7.0f, 83.50f, 1.0f},
13131 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
13132 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
13133 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
13134 { 0.0f, 0.0f, 0.0f, 1.0f},
13137 if (!init_test_context(&test_context, NULL))
13138 return;
13140 device = test_context.device;
13141 context = test_context.immediate_context;
13143 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13144 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13145 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13147 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
13148 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13150 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13151 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
13152 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13153 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13155 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13156 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13157 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13159 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
13161 *index = i;
13162 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
13164 draw_quad(&test_context);
13165 check_texture_vec4(texture, &expected_result[i], 0);
13168 ID3D11Buffer_Release(cb);
13169 ID3D11PixelShader_Release(ps);
13170 ID3D11Texture2D_Release(texture);
13171 ID3D11RenderTargetView_Release(rtv);
13172 release_test_context(&test_context);
13175 static void test_fp_specials(void)
13177 struct d3d11_test_context test_context;
13178 D3D11_TEXTURE2D_DESC texture_desc;
13179 ID3D11DeviceContext *context;
13180 ID3D11RenderTargetView *rtv;
13181 ID3D11Texture2D *texture;
13182 ID3D11PixelShader *ps;
13183 ID3D11Device *device;
13184 HRESULT hr;
13186 static const DWORD ps_code[] =
13188 #if 0
13189 float4 main() : SV_Target
13191 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
13193 #endif
13194 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
13195 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13196 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13197 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
13198 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
13199 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
13201 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
13203 if (!init_test_context(&test_context, NULL))
13204 return;
13206 device = test_context.device;
13207 context = test_context.immediate_context;
13209 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13210 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13211 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13213 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13214 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
13215 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13216 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13218 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13219 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13221 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13223 draw_quad(&test_context);
13224 check_texture_uvec4(texture, &expected_result);
13226 ID3D11PixelShader_Release(ps);
13227 ID3D11Texture2D_Release(texture);
13228 ID3D11RenderTargetView_Release(rtv);
13229 release_test_context(&test_context);
13232 static void test_uint_shader_instructions(void)
13234 struct shader
13236 const DWORD *code;
13237 size_t size;
13238 D3D_FEATURE_LEVEL required_feature_level;
13241 struct d3d11_test_context test_context;
13242 D3D11_TEXTURE2D_DESC texture_desc;
13243 D3D_FEATURE_LEVEL feature_level;
13244 ID3D11DeviceContext *context;
13245 ID3D11RenderTargetView *rtv;
13246 ID3D11Texture2D *texture;
13247 ID3D11PixelShader *ps;
13248 ID3D11Device *device;
13249 ID3D11Buffer *cb;
13250 unsigned int i;
13251 HRESULT hr;
13253 static const DWORD ps_bfi_code[] =
13255 #if 0
13256 uint bits, offset, insert, base;
13258 uint4 main() : SV_Target
13260 uint mask = ((1 << bits) - 1) << offset;
13261 return ((insert << offset) & mask) | (base & ~mask);
13263 #endif
13264 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
13265 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13266 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13267 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
13268 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13269 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
13270 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
13272 static const DWORD ps_ibfe_code[] =
13274 #if 0
13275 ps_5_0
13276 dcl_globalFlags refactoringAllowed
13277 dcl_constantbuffer cb0[1], immediateIndexed
13278 dcl_output o0.xyzw
13279 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
13281 #endif
13282 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
13283 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13284 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13285 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
13286 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13287 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
13288 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
13290 static const DWORD ps_ubfe_code[] =
13292 #if 0
13293 uint u;
13295 uint4 main() : SV_Target
13297 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
13299 #endif
13300 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
13301 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13302 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13303 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
13304 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13305 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
13306 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
13307 0x0100003e,
13309 static const DWORD ps_bfrev_code[] =
13311 #if 0
13312 uint bits;
13314 uint4 main() : SV_Target
13316 return uint4(reversebits(bits), reversebits(reversebits(bits)),
13317 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
13319 #endif
13320 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
13321 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13322 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13323 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
13324 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13325 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
13326 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
13327 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
13328 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
13329 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
13330 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
13332 static const DWORD ps_bits_code[] =
13334 #if 0
13335 uint u;
13336 int i;
13338 uint4 main() : SV_Target
13340 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
13342 #endif
13343 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
13344 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13345 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13346 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
13347 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13348 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
13349 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
13350 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
13351 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
13352 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
13353 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
13354 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
13355 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
13356 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
13358 static const DWORD ps_ftou_code[] =
13360 #if 0
13361 float f;
13363 uint4 main() : SV_Target
13365 return uint4(f, -f, 0, 0);
13367 #endif
13368 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
13369 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13370 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13371 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
13372 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
13373 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
13374 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
13375 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
13377 static const DWORD ps_f16tof32_code[] =
13379 #if 0
13380 uint4 hf;
13382 uint4 main() : SV_Target
13384 return f16tof32(hf);
13386 #endif
13387 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
13388 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13389 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13390 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
13391 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13392 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
13393 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
13395 static const DWORD ps_f32tof16_code[] =
13397 #if 0
13398 float4 f;
13400 uint4 main() : SV_Target
13402 return f32tof16(f);
13404 #endif
13405 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
13406 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13407 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13408 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
13409 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13410 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
13412 static const DWORD ps_not_code[] =
13414 #if 0
13415 uint2 bits;
13417 uint4 main() : SV_Target
13419 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
13421 #endif
13422 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
13423 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13424 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13425 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
13426 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13427 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
13428 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
13429 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
13431 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
13432 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
13433 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
13434 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
13435 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
13436 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
13437 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
13438 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
13439 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
13440 static const struct
13442 const struct shader *ps;
13443 unsigned int bits[4];
13444 struct uvec4 expected_result;
13446 tests[] =
13448 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
13449 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
13450 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
13451 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
13452 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
13453 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
13454 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
13455 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
13456 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
13457 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
13458 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
13459 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
13460 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
13461 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
13462 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
13463 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
13464 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
13465 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
13466 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
13468 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13469 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13470 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13471 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13472 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
13473 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
13474 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13475 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13476 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
13477 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13478 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13479 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13480 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13481 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13482 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13483 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13484 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13485 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13486 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
13487 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
13488 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13489 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
13490 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13491 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13492 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13493 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13495 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13496 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
13497 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
13498 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
13499 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
13500 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13501 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
13503 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
13504 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
13505 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
13507 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
13508 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
13509 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
13510 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
13511 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
13512 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
13513 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
13514 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
13515 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
13516 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
13517 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
13518 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
13520 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
13521 {&ps_ftou, {BITS_NAN}, { 0, 0}},
13522 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
13523 {&ps_ftou, {BITS_INF}, {~0u, 0}},
13524 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
13525 {&ps_ftou, {BITS_1_0}, { 1, 0}},
13527 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
13528 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
13529 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
13530 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
13532 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
13534 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
13535 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
13538 if (!init_test_context(&test_context, NULL))
13539 return;
13541 device = test_context.device;
13542 context = test_context.immediate_context;
13543 feature_level = ID3D11Device_GetFeatureLevel(device);
13545 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
13546 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13548 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13549 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
13550 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13551 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13553 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13554 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13556 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13558 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13560 if (feature_level < tests[i].ps->required_feature_level)
13561 continue;
13563 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
13564 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13565 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13567 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
13569 draw_quad(&test_context);
13570 check_texture_uvec4(texture, &tests[i].expected_result);
13572 ID3D11PixelShader_Release(ps);
13575 ID3D11Buffer_Release(cb);
13576 ID3D11Texture2D_Release(texture);
13577 ID3D11RenderTargetView_Release(rtv);
13578 release_test_context(&test_context);
13581 static void test_index_buffer_offset(void)
13583 struct d3d11_test_context test_context;
13584 ID3D11Buffer *vb, *ib, *so_buffer;
13585 ID3D11InputLayout *input_layout;
13586 ID3D11DeviceContext *context;
13587 struct resource_readback rb;
13588 ID3D11GeometryShader *gs;
13589 const struct vec4 *data;
13590 ID3D11VertexShader *vs;
13591 ID3D11Device *device;
13592 UINT stride, offset;
13593 unsigned int i;
13594 HRESULT hr;
13596 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13597 static const DWORD vs_code[] =
13599 #if 0
13600 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
13601 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
13603 out_position = position;
13604 out_attrib = attrib;
13606 #endif
13607 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
13608 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13609 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13610 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
13611 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13612 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13613 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
13614 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13615 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13616 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13617 0x0100003e,
13619 static const DWORD gs_code[] =
13621 #if 0
13622 struct vertex
13624 float4 position : SV_POSITION;
13625 float4 attrib : ATTRIB;
13628 [maxvertexcount(1)]
13629 void main(point vertex input[1], inout PointStream<vertex> output)
13631 output.Append(input[0]);
13632 output.RestartStrip();
13634 #endif
13635 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
13636 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13637 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13638 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
13639 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13640 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13641 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
13642 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
13643 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
13644 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
13645 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
13646 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
13648 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
13650 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13651 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
13653 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
13655 {0, "SV_Position", 0, 0, 4, 0},
13656 {0, "ATTRIB", 0, 0, 4, 0},
13658 static const struct
13660 struct vec4 position;
13661 struct vec4 attrib;
13663 vertices[] =
13665 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
13666 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
13667 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
13668 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
13670 static const unsigned int indices[] =
13672 0, 1, 2, 3,
13673 3, 2, 1, 0,
13674 1, 3, 2, 0,
13676 static const struct vec4 expected_data[] =
13678 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13679 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13680 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13681 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13683 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13684 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13685 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13686 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13688 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13689 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13690 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13691 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13693 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
13695 if (!init_test_context(&test_context, &feature_level))
13696 return;
13698 device = test_context.device;
13699 context = test_context.immediate_context;
13701 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
13702 vs_code, sizeof(vs_code), &input_layout);
13703 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13705 stride = 32;
13706 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
13707 so_declaration, ARRAY_SIZE(so_declaration),
13708 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
13709 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
13711 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13712 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13714 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
13715 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
13716 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
13718 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13719 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
13721 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13722 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
13723 stride = sizeof(*vertices);
13724 offset = 0;
13725 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
13727 offset = 0;
13728 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
13730 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
13731 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
13733 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
13734 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
13736 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
13737 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
13739 get_buffer_readback(so_buffer, &rb);
13740 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
13742 data = get_readback_vec4(&rb, i, 0);
13743 ok(compare_vec4(data, &expected_data[i], 0)
13744 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
13745 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
13746 data->x, data->y, data->z, data->w, i);
13748 release_resource_readback(&rb);
13750 ID3D11Buffer_Release(so_buffer);
13751 ID3D11Buffer_Release(ib);
13752 ID3D11Buffer_Release(vb);
13753 ID3D11VertexShader_Release(vs);
13754 ID3D11GeometryShader_Release(gs);
13755 ID3D11InputLayout_Release(input_layout);
13756 release_test_context(&test_context);
13759 static void test_face_culling(void)
13761 struct d3d11_test_context test_context;
13762 D3D11_RASTERIZER_DESC rasterizer_desc;
13763 ID3D11RasterizerState *state;
13764 ID3D11DeviceContext *context;
13765 ID3D11Buffer *cw_vb, *ccw_vb;
13766 ID3D11Device *device;
13767 BOOL broken_warp;
13768 unsigned int i;
13769 HRESULT hr;
13771 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
13772 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
13773 static const DWORD ps_code[] =
13775 #if 0
13776 float4 main(uint front : SV_IsFrontFace) : SV_Target
13778 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
13780 #endif
13781 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
13782 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
13783 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
13784 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
13785 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
13786 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
13787 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
13788 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
13789 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
13790 0x3f800000, 0x0100003e,
13792 static const struct vec2 ccw_quad[] =
13794 {-1.0f, 1.0f},
13795 {-1.0f, -1.0f},
13796 { 1.0f, 1.0f},
13797 { 1.0f, -1.0f},
13799 static const struct
13801 D3D11_CULL_MODE cull_mode;
13802 BOOL front_ccw;
13803 BOOL expected_cw;
13804 BOOL expected_ccw;
13806 tests[] =
13808 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
13809 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
13810 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
13811 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
13812 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
13813 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
13816 if (!init_test_context(&test_context, NULL))
13817 return;
13819 device = test_context.device;
13820 context = test_context.immediate_context;
13822 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13823 draw_color_quad(&test_context, &green);
13824 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13826 cw_vb = test_context.vb;
13827 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
13829 test_context.vb = ccw_vb;
13830 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13831 draw_color_quad(&test_context, &green);
13832 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
13834 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
13835 rasterizer_desc.CullMode = D3D11_CULL_BACK;
13836 rasterizer_desc.FrontCounterClockwise = FALSE;
13837 rasterizer_desc.DepthBias = 0;
13838 rasterizer_desc.DepthBiasClamp = 0.0f;
13839 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
13840 rasterizer_desc.DepthClipEnable = TRUE;
13841 rasterizer_desc.ScissorEnable = FALSE;
13842 rasterizer_desc.MultisampleEnable = FALSE;
13843 rasterizer_desc.AntialiasedLineEnable = FALSE;
13845 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13847 rasterizer_desc.CullMode = tests[i].cull_mode;
13848 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
13849 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13850 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
13852 ID3D11DeviceContext_RSSetState(context, state);
13854 test_context.vb = cw_vb;
13855 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13856 draw_color_quad(&test_context, &green);
13857 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
13859 test_context.vb = ccw_vb;
13860 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13861 draw_color_quad(&test_context, &green);
13862 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
13864 ID3D11RasterizerState_Release(state);
13867 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1;
13869 /* Test SV_IsFrontFace. */
13870 ID3D11PixelShader_Release(test_context.ps);
13871 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
13872 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13874 rasterizer_desc.CullMode = D3D11_CULL_NONE;
13875 rasterizer_desc.FrontCounterClockwise = FALSE;
13876 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13877 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13878 ID3D11DeviceContext_RSSetState(context, state);
13880 test_context.vb = cw_vb;
13881 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13882 draw_color_quad(&test_context, &green);
13883 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13884 test_context.vb = ccw_vb;
13885 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13886 draw_color_quad(&test_context, &green);
13887 if (!broken_warp)
13888 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
13889 else
13890 win_skip("Broken WARP.\n");
13892 ID3D11RasterizerState_Release(state);
13894 rasterizer_desc.CullMode = D3D11_CULL_NONE;
13895 rasterizer_desc.FrontCounterClockwise = TRUE;
13896 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13897 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13898 ID3D11DeviceContext_RSSetState(context, state);
13900 test_context.vb = cw_vb;
13901 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13902 draw_color_quad(&test_context, &green);
13903 if (!broken_warp)
13904 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
13905 else
13906 win_skip("Broken WARP.\n");
13907 test_context.vb = ccw_vb;
13908 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13909 draw_color_quad(&test_context, &green);
13910 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13912 ID3D11RasterizerState_Release(state);
13914 test_context.vb = cw_vb;
13915 ID3D11Buffer_Release(ccw_vb);
13916 release_test_context(&test_context);
13919 static void test_line_antialiasing_blending(void)
13921 ID3D11RasterizerState *rasterizer_state;
13922 struct d3d11_test_context test_context;
13923 D3D11_RASTERIZER_DESC rasterizer_desc;
13924 ID3D11BlendState *blend_state;
13925 ID3D11DeviceContext *context;
13926 D3D11_BLEND_DESC blend_desc;
13927 ID3D11Device *device;
13928 HRESULT hr;
13930 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
13931 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
13933 if (!init_test_context(&test_context, NULL))
13934 return;
13936 device = test_context.device;
13937 context = test_context.immediate_context;
13939 memset(&blend_desc, 0, sizeof(blend_desc));
13940 blend_desc.AlphaToCoverageEnable = FALSE;
13941 blend_desc.IndependentBlendEnable = FALSE;
13942 blend_desc.RenderTarget[0].BlendEnable = TRUE;
13943 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
13944 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
13945 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
13946 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
13947 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
13948 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
13949 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
13951 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
13952 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
13953 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
13955 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13956 draw_color_quad(&test_context, &green);
13957 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
13959 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
13960 draw_color_quad(&test_context, &red);
13961 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
13963 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
13964 ID3D11BlendState_Release(blend_state);
13966 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13967 draw_color_quad(&test_context, &green);
13968 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
13970 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
13971 draw_color_quad(&test_context, &red);
13972 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
13974 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
13975 rasterizer_desc.CullMode = D3D11_CULL_BACK;
13976 rasterizer_desc.FrontCounterClockwise = FALSE;
13977 rasterizer_desc.DepthBias = 0;
13978 rasterizer_desc.DepthBiasClamp = 0.0f;
13979 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
13980 rasterizer_desc.DepthClipEnable = TRUE;
13981 rasterizer_desc.ScissorEnable = FALSE;
13982 rasterizer_desc.MultisampleEnable = FALSE;
13983 rasterizer_desc.AntialiasedLineEnable = TRUE;
13985 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
13986 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13987 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
13989 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13990 draw_color_quad(&test_context, &green);
13991 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
13993 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
13994 draw_color_quad(&test_context, &red);
13995 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
13997 ID3D11RasterizerState_Release(rasterizer_state);
13998 release_test_context(&test_context);
14001 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
14002 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
14003 const char *feature_name)
14005 unsigned int i;
14007 for (i = 0; i < format_count; ++i)
14009 DXGI_FORMAT format = formats[i].format;
14010 unsigned int supported = format_support[format] & feature_flag;
14012 if (formats[i].fl_required <= feature_level)
14014 ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
14015 format, feature_name, feature_level, format_support[format]);
14016 continue;
14019 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
14021 if (supported)
14022 trace("Optional format %#x - %s supported, feature level %#x.\n",
14023 format, feature_name, feature_level);
14024 continue;
14027 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
14028 format, feature_name, feature_level, format_support[format]);
14032 static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
14034 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
14035 struct device_desc device_desc;
14036 ID3D11Device *device;
14037 DXGI_FORMAT format;
14038 ULONG refcount;
14039 HRESULT hr;
14041 static const struct format_support index_buffers[] =
14043 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
14044 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
14047 device_desc.feature_level = &feature_level;
14048 device_desc.flags = 0;
14049 if (!(device = create_device(&device_desc)))
14051 skip("Failed to create device for feature level %#x.\n", feature_level);
14052 return;
14055 memset(format_support, 0, sizeof(format_support));
14056 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
14058 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
14059 todo_wine ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
14060 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
14061 format, hr, format_support[format]);
14063 if (hr == E_NOTIMPL)
14065 skip("CheckFormatSupport not implemented.\n");
14066 ID3D11Device_Release(device);
14067 return;
14070 check_format_support(format_support, feature_level,
14071 index_buffers, ARRAY_SIZE(index_buffers),
14072 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
14074 check_format_support(format_support, feature_level,
14075 display_format_support, ARRAY_SIZE(display_format_support),
14076 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
14078 refcount = ID3D11Device_Release(device);
14079 ok(!refcount, "Device has %u references left.\n", refcount);
14082 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
14084 struct d3d11_test_context test_context;
14085 D3D11_SUBRESOURCE_DATA resource_data;
14086 D3D11_TEXTURE2D_DESC texture_desc;
14087 ID3D11ShaderResourceView *srv;
14088 ID3D11DeviceContext *context;
14089 ID3D11Texture2D *texture;
14090 ID3D11PixelShader *ps;
14091 ID3D11Device *device;
14092 HRESULT hr;
14094 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
14095 static const DWORD ps_code[] =
14097 #if 0
14098 float4 main() : SV_TARGET
14100 return float4(1.0f, 0.0f, 0.0f, 0.5f);
14102 #endif
14103 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
14104 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
14105 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
14106 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
14107 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
14108 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
14109 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
14110 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
14111 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
14112 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
14113 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
14114 0x45475241, 0xabab0054,
14116 static const DWORD ps_texture_code[] =
14118 #if 0
14119 Texture2D t;
14120 SamplerState s;
14122 float4 main() : SV_TARGET
14124 return t.Sample(s, (float2)0);
14126 #endif
14127 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
14128 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
14129 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
14130 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
14131 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
14132 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
14133 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
14134 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
14135 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
14136 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
14137 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
14138 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
14139 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
14140 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14141 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
14143 static const DWORD texture_data[] = {0xffffff00};
14145 if (!init_test_context(&test_context, &feature_level))
14146 return;
14148 device = test_context.device;
14149 context = test_context.immediate_context;
14151 texture_desc.Width = 1;
14152 texture_desc.Height = 1;
14153 texture_desc.MipLevels = 0;
14154 texture_desc.ArraySize = 1;
14155 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14156 texture_desc.SampleDesc.Count = 1;
14157 texture_desc.SampleDesc.Quality = 0;
14158 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14159 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14160 texture_desc.CPUAccessFlags = 0;
14161 texture_desc.MiscFlags = 0;
14162 resource_data.pSysMem = texture_data;
14163 resource_data.SysMemPitch = sizeof(texture_data);
14164 resource_data.SysMemSlicePitch = 0;
14165 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
14166 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14167 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
14168 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14170 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14171 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
14172 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14173 draw_quad(&test_context);
14174 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
14175 ID3D11PixelShader_Release(ps);
14177 draw_color_quad(&test_context, &color);
14178 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
14180 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
14181 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
14182 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14183 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
14184 draw_quad(&test_context);
14185 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
14186 ID3D11PixelShader_Release(ps);
14188 ID3D11ShaderResourceView_Release(srv);
14189 ID3D11Texture2D_Release(texture);
14190 release_test_context(&test_context);
14193 static void run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
14194 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
14196 static const D3D_FEATURE_LEVEL feature_levels[] =
14198 D3D_FEATURE_LEVEL_11_1,
14199 D3D_FEATURE_LEVEL_11_0,
14200 D3D_FEATURE_LEVEL_10_1,
14201 D3D_FEATURE_LEVEL_10_0,
14202 D3D_FEATURE_LEVEL_9_3,
14203 D3D_FEATURE_LEVEL_9_2,
14204 D3D_FEATURE_LEVEL_9_1
14206 unsigned int i;
14208 assert(begin <= end);
14209 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
14211 if (begin <= feature_levels[i] && feature_levels[i] <= end)
14212 test_func(feature_levels[i]);
14216 static void run_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
14218 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
14219 D3D_FEATURE_LEVEL_11_1, test_func);
14222 static void run_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
14224 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
14225 D3D_FEATURE_LEVEL_9_3, test_func);
14228 static void test_ddy(void)
14230 static const struct
14232 struct vec4 position;
14233 unsigned int color;
14235 quad[] =
14237 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
14238 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
14239 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
14240 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
14242 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
14244 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
14245 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
14247 #if 0
14248 struct vs_data
14250 float4 pos : SV_POSITION;
14251 float4 color : COLOR;
14254 void main(in struct vs_data vs_input, out struct vs_data vs_output)
14256 vs_output.pos = vs_input.pos;
14257 vs_output.color = vs_input.color;
14259 #endif
14260 static const DWORD vs_code[] =
14262 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
14263 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14264 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
14265 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14266 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
14267 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
14268 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
14269 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
14270 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
14271 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
14272 0x0100003e,
14274 #if 0
14275 struct ps_data
14277 float4 pos : SV_POSITION;
14278 float4 color : COLOR;
14281 float4 main(struct ps_data ps_input) : SV_Target
14283 return ddy(ps_input.color) * 240.0 + 0.5;
14285 #endif
14286 static const DWORD ps_code_ddy[] =
14288 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
14289 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14290 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14291 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14292 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14293 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
14294 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14295 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
14296 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
14297 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
14299 #if 0
14300 struct ps_data
14302 float4 pos : SV_POSITION;
14303 float4 color : COLOR;
14306 float4 main(struct ps_data ps_input) : SV_Target
14308 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
14310 #endif
14311 static const DWORD ps_code_ddy_coarse[] =
14313 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
14314 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14315 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14316 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14317 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14318 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
14319 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14320 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
14321 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
14322 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
14324 #if 0
14325 struct ps_data
14327 float4 pos : SV_POSITION;
14328 float4 color : COLOR;
14331 float4 main(struct ps_data ps_input) : SV_Target
14333 return ddy_fine(ps_input.color) * 240.0 + 0.5;
14335 #endif
14336 static const DWORD ps_code_ddy_fine[] =
14338 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
14339 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14340 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14341 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14342 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14343 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
14344 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14345 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
14346 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
14347 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
14349 static const struct
14351 D3D_FEATURE_LEVEL min_feature_level;
14352 const DWORD *ps_code;
14353 unsigned int ps_code_size;
14355 tests[] =
14357 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
14358 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
14359 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
14361 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
14362 struct d3d11_test_context test_context;
14363 D3D11_TEXTURE2D_DESC texture_desc;
14364 D3D_FEATURE_LEVEL feature_level;
14365 ID3D11InputLayout *input_layout;
14366 ID3D11DeviceContext *context;
14367 unsigned int stride, offset;
14368 struct resource_readback rb;
14369 ID3D11RenderTargetView *rtv;
14370 ID3D11Texture2D *texture;
14371 ID3D11VertexShader *vs;
14372 ID3D11PixelShader *ps;
14373 ID3D11Device *device;
14374 ID3D11Buffer *vb;
14375 unsigned int i;
14376 DWORD color;
14377 HRESULT hr;
14379 if (!init_test_context(&test_context, NULL))
14380 return;
14382 device = test_context.device;
14383 context = test_context.immediate_context;
14384 feature_level = ID3D11Device_GetFeatureLevel(device);
14386 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14387 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14388 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14390 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14391 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14393 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
14394 vs_code, sizeof(vs_code), &input_layout);
14395 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
14397 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
14399 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
14400 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
14402 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
14403 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
14404 stride = sizeof(*quad);
14405 offset = 0;
14406 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
14407 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
14409 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14411 if (feature_level < tests[i].min_feature_level)
14413 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
14414 feature_level, tests[i].min_feature_level);
14415 continue;
14418 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
14419 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14421 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14423 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14424 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
14425 ID3D11DeviceContext_Draw(context, 4, 0);
14427 get_texture_readback(texture, 0, &rb);
14428 color = get_readback_color(&rb, 320, 190);
14429 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14430 color = get_readback_color(&rb, 255, 240);
14431 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14432 color = get_readback_color(&rb, 320, 240);
14433 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14434 color = get_readback_color(&rb, 385, 240);
14435 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14436 color = get_readback_color(&rb, 320, 290);
14437 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14438 release_resource_readback(&rb);
14440 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
14441 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14442 ID3D11DeviceContext_Draw(context, 4, 0);
14444 get_texture_readback(test_context.backbuffer, 0, &rb);
14445 color = get_readback_color(&rb, 320, 190);
14446 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14447 color = get_readback_color(&rb, 255, 240);
14448 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14449 color = get_readback_color(&rb, 320, 240);
14450 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14451 color = get_readback_color(&rb, 385, 240);
14452 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14453 color = get_readback_color(&rb, 320, 290);
14454 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14455 release_resource_readback(&rb);
14457 ID3D11PixelShader_Release(ps);
14460 ID3D11VertexShader_Release(vs);
14461 ID3D11Buffer_Release(vb);
14462 ID3D11InputLayout_Release(input_layout);
14463 ID3D11Texture2D_Release(texture);
14464 ID3D11RenderTargetView_Release(rtv);
14465 release_test_context(&test_context);
14468 static void test_shader_input_registers_limits(void)
14470 struct d3d11_test_context test_context;
14471 D3D11_SUBRESOURCE_DATA resource_data;
14472 D3D11_TEXTURE2D_DESC texture_desc;
14473 D3D11_SAMPLER_DESC sampler_desc;
14474 ID3D11ShaderResourceView *srv;
14475 ID3D11DeviceContext *context;
14476 ID3D11SamplerState *sampler;
14477 ID3D11Texture2D *texture;
14478 ID3D11PixelShader *ps;
14479 ID3D11Device *device;
14480 HRESULT hr;
14482 static const DWORD ps_last_register_code[] =
14484 #if 0
14485 Texture2D t : register(t127);
14486 SamplerState s : register(s15);
14488 void main(out float4 target : SV_Target)
14490 target = t.Sample(s, float2(0, 0));
14492 #endif
14493 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
14494 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14495 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14496 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
14497 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
14498 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
14499 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
14501 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
14502 static const DWORD texture_data[] = {0xff00ff00};
14504 if (!init_test_context(&test_context, NULL))
14505 return;
14507 device = test_context.device;
14508 context = test_context.immediate_context;
14510 texture_desc.Width = 1;
14511 texture_desc.Height = 1;
14512 texture_desc.MipLevels = 0;
14513 texture_desc.ArraySize = 1;
14514 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14515 texture_desc.SampleDesc.Count = 1;
14516 texture_desc.SampleDesc.Quality = 0;
14517 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14518 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14519 texture_desc.CPUAccessFlags = 0;
14520 texture_desc.MiscFlags = 0;
14522 resource_data.pSysMem = texture_data;
14523 resource_data.SysMemPitch = sizeof(texture_data);
14524 resource_data.SysMemSlicePitch = 0;
14526 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
14527 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
14529 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
14530 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14532 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
14533 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
14534 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
14535 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
14536 sampler_desc.MipLODBias = 0.0f;
14537 sampler_desc.MaxAnisotropy = 0;
14538 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
14539 sampler_desc.BorderColor[0] = 0.0f;
14540 sampler_desc.BorderColor[1] = 0.0f;
14541 sampler_desc.BorderColor[2] = 0.0f;
14542 sampler_desc.BorderColor[3] = 0.0f;
14543 sampler_desc.MinLOD = 0.0f;
14544 sampler_desc.MaxLOD = 0.0f;
14546 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
14547 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
14549 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
14550 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14551 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14553 ID3D11DeviceContext_PSSetShaderResources(context,
14554 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
14555 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
14556 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
14557 draw_quad(&test_context);
14558 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14560 ID3D11PixelShader_Release(ps);
14561 ID3D11SamplerState_Release(sampler);
14562 ID3D11ShaderResourceView_Release(srv);
14563 ID3D11Texture2D_Release(texture);
14564 release_test_context(&test_context);
14567 static void test_unbind_shader_resource_view(void)
14569 struct d3d11_test_context test_context;
14570 D3D11_SUBRESOURCE_DATA resource_data;
14571 ID3D11ShaderResourceView *srv, *srv2;
14572 D3D11_TEXTURE2D_DESC texture_desc;
14573 ID3D11DeviceContext *context;
14574 ID3D11Texture2D *texture;
14575 ID3D11PixelShader *ps;
14576 ID3D11Device *device;
14577 HRESULT hr;
14579 static const DWORD ps_code[] =
14581 #if 0
14582 Texture2D t0;
14583 Texture2D t1;
14584 SamplerState s;
14586 float4 main() : SV_Target
14588 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
14590 #endif
14591 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
14592 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14593 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14594 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
14595 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
14596 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
14597 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
14598 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
14599 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
14600 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
14601 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
14602 0x3f800000, 0x0100003e,
14604 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
14605 static const DWORD texture_data[] = {0xff00ff00};
14607 if (!init_test_context(&test_context, NULL))
14608 return;
14610 device = test_context.device;
14611 context = test_context.immediate_context;
14613 texture_desc.Width = 1;
14614 texture_desc.Height = 1;
14615 texture_desc.MipLevels = 0;
14616 texture_desc.ArraySize = 1;
14617 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14618 texture_desc.SampleDesc.Count = 1;
14619 texture_desc.SampleDesc.Quality = 0;
14620 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14621 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14622 texture_desc.CPUAccessFlags = 0;
14623 texture_desc.MiscFlags = 0;
14625 resource_data.pSysMem = texture_data;
14626 resource_data.SysMemPitch = sizeof(texture_data);
14627 resource_data.SysMemSlicePitch = 0;
14629 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
14630 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
14631 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
14632 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14633 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14634 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14635 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14637 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
14638 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
14639 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
14640 draw_quad(&test_context);
14641 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14643 srv2 = NULL;
14644 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
14645 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
14646 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
14647 draw_quad(&test_context);
14648 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
14650 ID3D11PixelShader_Release(ps);
14651 ID3D11ShaderResourceView_Release(srv);
14652 ID3D11Texture2D_Release(texture);
14653 release_test_context(&test_context);
14656 static void test_stencil_separate(void)
14658 struct d3d11_test_context test_context;
14659 D3D11_TEXTURE2D_DESC texture_desc;
14660 D3D11_DEPTH_STENCIL_DESC ds_desc;
14661 ID3D11DepthStencilState *ds_state;
14662 ID3D11DepthStencilView *ds_view;
14663 D3D11_RASTERIZER_DESC rs_desc;
14664 ID3D11DeviceContext *context;
14665 ID3D11RasterizerState *rs;
14666 ID3D11Texture2D *texture;
14667 ID3D11Device *device;
14668 HRESULT hr;
14670 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
14671 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
14672 static const struct vec2 ccw_quad[] =
14674 {-1.0f, -1.0f},
14675 { 1.0f, -1.0f},
14676 {-1.0f, 1.0f},
14677 { 1.0f, 1.0f},
14680 if (!init_test_context(&test_context, NULL))
14681 return;
14683 device = test_context.device;
14684 context = test_context.immediate_context;
14686 texture_desc.Width = 640;
14687 texture_desc.Height = 480;
14688 texture_desc.MipLevels = 1;
14689 texture_desc.ArraySize = 1;
14690 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
14691 texture_desc.SampleDesc.Count = 1;
14692 texture_desc.SampleDesc.Quality = 0;
14693 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14694 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
14695 texture_desc.CPUAccessFlags = 0;
14696 texture_desc.MiscFlags = 0;
14697 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14698 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14699 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
14700 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
14702 ds_desc.DepthEnable = TRUE;
14703 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
14704 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
14705 ds_desc.StencilEnable = TRUE;
14706 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
14707 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
14708 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
14709 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
14710 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
14711 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
14712 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
14713 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
14714 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
14715 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
14716 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
14717 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
14719 rs_desc.FillMode = D3D11_FILL_SOLID;
14720 rs_desc.CullMode = D3D11_CULL_NONE;
14721 rs_desc.FrontCounterClockwise = FALSE;
14722 rs_desc.DepthBias = 0;
14723 rs_desc.DepthBiasClamp = 0.0f;
14724 rs_desc.SlopeScaledDepthBias = 0.0f;
14725 rs_desc.DepthClipEnable = TRUE;
14726 rs_desc.ScissorEnable = FALSE;
14727 rs_desc.MultisampleEnable = FALSE;
14728 rs_desc.AntialiasedLineEnable = FALSE;
14729 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
14730 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
14732 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14733 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
14734 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
14735 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
14736 ID3D11DeviceContext_RSSetState(context, rs);
14738 draw_color_quad(&test_context, &green);
14739 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14741 ID3D11Buffer_Release(test_context.vb);
14742 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
14744 draw_color_quad(&test_context, &green);
14745 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14747 ID3D11RasterizerState_Release(rs);
14748 rs_desc.FrontCounterClockwise = TRUE;
14749 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
14750 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
14751 ID3D11DeviceContext_RSSetState(context, rs);
14753 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14754 draw_color_quad(&test_context, &green);
14755 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14757 ID3D11DepthStencilState_Release(ds_state);
14758 ID3D11DepthStencilView_Release(ds_view);
14759 ID3D11RasterizerState_Release(rs);
14760 ID3D11Texture2D_Release(texture);
14761 release_test_context(&test_context);
14764 static void test_uav_load(void)
14766 struct shader
14768 const DWORD *code;
14769 size_t size;
14771 struct texture
14773 UINT width;
14774 UINT height;
14775 UINT miplevel_count;
14776 UINT array_size;
14777 DXGI_FORMAT format;
14778 D3D11_SUBRESOURCE_DATA data[3];
14781 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
14782 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
14783 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
14784 struct d3d11_test_context test_context;
14785 const struct texture *current_texture;
14786 ID3D11Texture2D *texture, *rt_texture;
14787 D3D11_TEXTURE2D_DESC texture_desc;
14788 const struct shader *current_ps;
14789 ID3D11UnorderedAccessView *uav;
14790 ID3D11DeviceContext *context;
14791 struct resource_readback rb;
14792 ID3D11PixelShader *ps;
14793 ID3D11Device *device;
14794 unsigned int i, x, y;
14795 ID3D11Buffer *cb;
14796 HRESULT hr;
14798 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
14799 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
14800 static const DWORD ps_ld_2d_float_code[] =
14802 #if 0
14803 RWTexture2D<float> u;
14805 float main(float4 position : SV_Position) : SV_Target
14807 float2 s;
14808 u.GetDimensions(s.x, s.y);
14809 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
14811 #endif
14812 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
14813 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14814 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
14815 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14816 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
14817 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
14818 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
14819 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
14820 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
14821 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
14822 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
14823 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
14824 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
14826 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
14827 static const DWORD ps_ld_2d_uint_code[] =
14829 #if 0
14830 RWTexture2D<uint> u;
14832 uint main(float4 position : SV_Position) : SV_Target
14834 float2 s;
14835 u.GetDimensions(s.x, s.y);
14836 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
14838 #endif
14839 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
14840 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14841 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
14842 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
14843 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
14844 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
14845 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
14846 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
14847 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
14848 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
14849 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
14850 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
14851 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
14853 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
14854 static const DWORD ps_ld_2d_int_code[] =
14856 #if 0
14857 RWTexture2D<int> u;
14859 int main(float4 position : SV_Position) : SV_Target
14861 float2 s;
14862 u.GetDimensions(s.x, s.y);
14863 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
14865 #endif
14866 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
14867 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14868 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
14869 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
14870 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
14871 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
14872 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
14873 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
14874 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
14875 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
14876 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
14877 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
14878 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
14880 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
14881 static const DWORD ps_ld_2d_uint_arr_code[] =
14883 #if 0
14884 RWTexture2DArray<uint> u;
14886 uint layer;
14888 uint main(float4 position : SV_Position) : SV_Target
14890 float3 s;
14891 u.GetDimensions(s.x, s.y, s.z);
14892 s.z = layer;
14893 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
14895 #endif
14896 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
14897 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14898 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
14899 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
14900 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
14901 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
14902 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
14903 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
14904 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
14905 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
14906 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
14907 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
14908 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
14909 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
14911 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
14912 static const float float_data[] =
14914 0.50f, 0.25f, 1.00f, 0.00f,
14915 -1.00f, -2.00f, -3.00f, -4.00f,
14916 -0.50f, -0.25f, -1.00f, -0.00f,
14917 1.00f, 2.00f, 3.00f, 4.00f,
14919 static const unsigned int uint_data[] =
14921 0x00, 0x10, 0x20, 0x30,
14922 0x40, 0x50, 0x60, 0x70,
14923 0x80, 0x90, 0xa0, 0xb0,
14924 0xc0, 0xd0, 0xe0, 0xf0,
14926 static const unsigned int uint_data2[] =
14928 0xffff, 0xffff, 0xffff, 0xffff,
14929 0xffff, 0xc000, 0xc000, 0xffff,
14930 0xffff, 0xc000, 0xc000, 0xffff,
14931 0xffff, 0xffff, 0xffff, 0xffff,
14933 static const unsigned int uint_data3[] =
14935 0xaa, 0xaa, 0xcc, 0xcc,
14936 0xaa, 0xaa, 0xdd, 0xdd,
14937 0xbb, 0xbb, 0xee, 0xee,
14938 0xbb, 0xbb, 0xff, 0xff,
14940 static const int int_data[] =
14942 -1, 0x10, 0x20, 0x30,
14943 0x40, 0x50, 0x60, -777,
14944 -666, 0x90, -555, 0xb0,
14945 0xc0, 0xd0, 0xe0, -101,
14947 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
14948 {{float_data, 4 * sizeof(*float_data), 0}}};
14949 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
14950 {{uint_data, 4 * sizeof(*uint_data), 0}}};
14951 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
14952 {{uint_data, 4 * sizeof(*uint_data), 0},
14953 {uint_data2, 4 * sizeof(*uint_data2), 0},
14954 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
14955 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
14956 {{int_data, 4 * sizeof(*int_data), 0}}};
14958 static const struct test
14960 const struct shader *ps;
14961 const struct texture *texture;
14962 struct uav_desc uav_desc;
14963 struct uvec4 constant;
14964 const DWORD *expected_colors;
14966 tests[] =
14968 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
14969 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
14970 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
14971 #define R32_UINT DXGI_FORMAT_R32_UINT
14972 #define R32_SINT DXGI_FORMAT_R32_SINT
14973 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {}, (const DWORD *)float_data},
14974 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {}, (const DWORD *)uint_data},
14975 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {}, (const DWORD *)int_data},
14976 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
14977 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
14978 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
14979 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
14980 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
14981 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
14982 #undef TEX_2D
14983 #undef TEX_2D_ARRAY
14984 #undef R32_FLOAT
14985 #undef R32_UINT
14986 #undef R32_SINT
14989 if (!init_test_context(&test_context, &feature_level))
14990 return;
14992 device = test_context.device;
14993 context = test_context.immediate_context;
14995 texture_desc.Width = 640;
14996 texture_desc.Height = 480;
14997 texture_desc.MipLevels = 1;
14998 texture_desc.ArraySize = 1;
14999 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
15000 texture_desc.SampleDesc.Count = 1;
15001 texture_desc.SampleDesc.Quality = 0;
15002 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15003 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15004 texture_desc.CPUAccessFlags = 0;
15005 texture_desc.MiscFlags = 0;
15006 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
15007 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15009 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15010 U(rtv_desc).Texture2D.MipSlice = 0;
15012 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
15013 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
15014 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15016 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
15017 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
15018 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15020 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
15021 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
15022 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15024 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15026 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
15027 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
15029 ps = NULL;
15030 uav = NULL;
15031 texture = NULL;
15032 current_ps = NULL;
15033 current_texture = NULL;
15034 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15036 const struct test *test = &tests[i];
15037 ID3D11RenderTargetView *current_rtv;
15039 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15040 NULL, &test->constant, 0, 0);
15042 if (current_ps != test->ps)
15044 if (ps)
15045 ID3D11PixelShader_Release(ps);
15047 current_ps = test->ps;
15049 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
15050 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
15052 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15055 if (current_texture != test->texture)
15057 if (texture)
15058 ID3D11Texture2D_Release(texture);
15060 current_texture = test->texture;
15062 texture_desc.Width = current_texture->width;
15063 texture_desc.Height = current_texture->height;
15064 texture_desc.MipLevels = current_texture->miplevel_count;
15065 texture_desc.ArraySize = current_texture->array_size;
15066 texture_desc.Format = current_texture->format;
15068 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
15069 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
15072 if (uav)
15073 ID3D11UnorderedAccessView_Release(uav);
15075 get_uav_desc(&uav_desc, &test->uav_desc);
15076 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
15077 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
15079 switch (uav_desc.Format)
15081 case DXGI_FORMAT_R32_FLOAT:
15082 current_rtv = rtv_float;
15083 break;
15084 case DXGI_FORMAT_R32_UINT:
15085 current_rtv = rtv_uint;
15086 break;
15087 case DXGI_FORMAT_R32_SINT:
15088 current_rtv = rtv_sint;
15089 break;
15090 default:
15091 trace("Unhandled format %#x.\n", uav_desc.Format);
15092 current_rtv = NULL;
15093 break;
15096 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
15098 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
15099 1, 1, &uav, NULL);
15101 draw_quad(&test_context);
15103 get_texture_readback(rt_texture, 0, &rb);
15104 for (y = 0; y < 4; ++y)
15106 for (x = 0; x < 4; ++x)
15108 DWORD expected = test->expected_colors[y * 4 + x];
15109 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
15110 ok(compare_color(color, expected, 0),
15111 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
15112 i, color, expected, x, y);
15115 release_resource_readback(&rb);
15117 ID3D11PixelShader_Release(ps);
15118 ID3D11Texture2D_Release(texture);
15119 ID3D11UnorderedAccessView_Release(uav);
15121 ID3D11Buffer_Release(cb);
15122 ID3D11RenderTargetView_Release(rtv_float);
15123 ID3D11RenderTargetView_Release(rtv_sint);
15124 ID3D11RenderTargetView_Release(rtv_uint);
15125 ID3D11Texture2D_Release(rt_texture);
15126 release_test_context(&test_context);
15129 static void test_cs_uav_store(void)
15131 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15132 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
15133 static const float zero[4] = {0.0f};
15134 D3D11_TEXTURE2D_DESC texture_desc;
15135 ID3D11UnorderedAccessView *uav;
15136 struct device_desc device_desc;
15137 ID3D11DeviceContext *context;
15138 struct vec4 input = {1.0f};
15139 ID3D11Texture2D *texture;
15140 ID3D11ComputeShader *cs;
15141 ID3D11Device *device;
15142 ID3D11Buffer *cb;
15143 ULONG refcount;
15144 HRESULT hr;
15145 RECT rect;
15147 static const DWORD cs_1_thread_code[] =
15149 #if 0
15150 RWTexture2D<float> u;
15152 float value;
15154 [numthreads(1, 1, 1)]
15155 void main()
15157 uint x, y, width, height;
15158 u.GetDimensions(width, height);
15159 for (y = 0; y < height; ++y)
15161 for (x = 0; x < width; ++x)
15162 u[uint2(x, y)] = value;
15165 #endif
15166 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
15167 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15168 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
15169 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
15170 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
15171 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
15172 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
15173 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
15174 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
15175 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
15176 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
15177 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
15178 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
15179 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
15180 0x01000016, 0x0100003e,
15182 static const DWORD cs_1_group_code[] =
15184 #if 0
15185 RWTexture2D<float> u;
15187 float value;
15189 [numthreads(16, 16, 1)]
15190 void main(uint3 threadID : SV_GroupThreadID)
15192 uint2 count, size ;
15193 u.GetDimensions(size.x, size.y);
15194 count = size / (uint2)16;
15195 for (uint y = 0; y < count.y; ++y)
15196 for (uint x = 0; x < count.x; ++x)
15197 u[count * threadID.xy + uint2(x, y)] = value;
15199 #endif
15200 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
15201 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15202 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
15203 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
15204 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
15205 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
15206 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
15207 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
15208 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
15209 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
15210 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
15211 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
15212 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
15213 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
15214 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
15215 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
15216 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
15218 static const DWORD cs_1_store_code[] =
15220 #if 0
15221 RWTexture2D<float> u;
15223 float value;
15225 [numthreads(1, 1, 1)]
15226 void main(uint3 groupID : SV_GroupID)
15228 u[groupID.xy] = value;
15230 #endif
15231 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
15232 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15233 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
15234 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
15235 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
15236 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
15238 static const DWORD cs_dispatch_id_code[] =
15240 #if 0
15241 RWTexture2D<float> u;
15243 float value;
15245 [numthreads(4, 4, 1)]
15246 void main(uint3 id : SV_DispatchThreadID)
15248 u[id.xy] = value;
15250 #endif
15251 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
15252 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15253 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
15254 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
15255 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
15256 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
15258 static const DWORD cs_group_index_code[] =
15260 #if 0
15261 RWTexture2D<float> u;
15263 float value;
15265 [numthreads(32, 1, 1)]
15266 void main(uint index : SV_GroupIndex)
15268 uint2 size;
15269 u.GetDimensions(size.x, size.y);
15270 uint count = size.x * size.y / 32;
15271 index *= count;
15272 for (uint i = 0; i < count; ++i, ++index)
15273 u[uint2(index % size.x, index / size.x)] = value;
15275 #endif
15276 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
15277 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15278 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
15279 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
15280 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
15281 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
15282 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
15283 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
15284 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
15285 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
15286 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
15287 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
15288 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
15289 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
15290 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
15291 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
15294 device_desc.feature_level = &feature_level;
15295 device_desc.flags = 0;
15296 if (!(device = create_device(&device_desc)))
15298 skip("Failed to create device for feature level %#x.\n", feature_level);
15299 return;
15302 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
15304 texture_desc.Width = 64;
15305 texture_desc.Height = 64;
15306 texture_desc.MipLevels = 1;
15307 texture_desc.ArraySize = 1;
15308 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
15309 texture_desc.SampleDesc.Count = 1;
15310 texture_desc.SampleDesc.Quality = 0;
15311 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15312 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15313 texture_desc.CPUAccessFlags = 0;
15314 texture_desc.MiscFlags = 0;
15316 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15317 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15319 uav_desc.Format = texture_desc.Format;
15320 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
15321 U(uav_desc).Texture2D.MipSlice = 0;
15323 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
15324 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15326 ID3D11Device_GetImmediateContext(device, &context);
15328 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
15329 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
15331 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
15332 check_texture_float(texture, 0.0f, 2);
15334 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
15335 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15336 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15338 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15339 check_texture_float(texture, 1.0f, 2);
15341 input.x = 0.5f;
15342 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15343 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15344 check_texture_float(texture, 0.5f, 2);
15346 ID3D11ComputeShader_Release(cs);
15348 input.x = 2.0f;
15349 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15350 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
15351 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15352 check_texture_float(texture, 0.5f, 2);
15354 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
15355 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15356 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15358 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15359 check_texture_float(texture, 2.0f, 2);
15361 input.x = 4.0f;
15362 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15363 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15364 check_texture_float(texture, 4.0f, 2);
15366 ID3D11ComputeShader_Release(cs);
15368 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
15369 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15370 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15372 input.x = 1.0f;
15373 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15374 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
15375 check_texture_float(texture, 1.0f, 2);
15377 input.x = 0.5f;
15378 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15379 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
15380 SetRect(&rect, 0, 0, 16, 32);
15381 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
15382 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
15383 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
15384 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
15385 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
15387 ID3D11ComputeShader_Release(cs);
15389 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
15390 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15391 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15393 input.x = 0.6f;
15394 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15395 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
15396 SetRect(&rect, 0, 0, 60, 60);
15397 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
15398 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
15399 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
15400 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
15401 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
15403 input.x = 0.7f;
15404 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15405 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
15406 check_texture_float(texture, 0.7f, 2);
15408 ID3D11ComputeShader_Release(cs);
15410 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
15411 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15412 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15414 input.x = 0.3f;
15415 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15416 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15417 check_texture_float(texture, 0.3f, 2);
15419 input.x = 0.1f;
15420 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15421 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
15422 check_texture_float(texture, 0.1f, 2);
15424 ID3D11ComputeShader_Release(cs);
15426 ID3D11Buffer_Release(cb);
15427 ID3D11Texture2D_Release(texture);
15428 ID3D11UnorderedAccessView_Release(uav);
15429 ID3D11DeviceContext_Release(context);
15430 refcount = ID3D11Device_Release(device);
15431 ok(!refcount, "Device has %u references left.\n", refcount);
15434 static void test_ps_cs_uav_binding(void)
15436 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15437 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
15438 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
15439 ID3D11Texture2D *cs_texture, *ps_texture;
15440 struct d3d11_test_context test_context;
15441 static const float zero[4] = {0.0f};
15442 D3D11_TEXTURE2D_DESC texture_desc;
15443 ID3D11DeviceContext *context;
15444 ID3D11Buffer *cs_cb, *ps_cb;
15445 struct vec4 input = {1.0f};
15446 ID3D11ComputeShader *cs;
15447 ID3D11PixelShader *ps;
15448 ID3D11Device *device;
15449 HRESULT hr;
15451 static const DWORD cs_code[] =
15453 #if 0
15454 RWTexture2D<float> u;
15456 float value;
15458 [numthreads(1, 1, 1)]
15459 void main()
15461 uint x, y, width, height;
15462 u.GetDimensions(width, height);
15463 for (y = 0; y < height; ++y)
15465 for (x = 0; x < width; ++x)
15466 u[uint2(x, y)] = value;
15469 #endif
15470 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
15471 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15472 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
15473 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
15474 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
15475 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
15476 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
15477 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
15478 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
15479 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
15480 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
15481 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
15482 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
15483 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
15484 0x01000016, 0x0100003e,
15486 static const DWORD ps_code[] =
15488 #if 0
15489 RWTexture2D<float> u : register(u1);
15491 float value;
15493 void main()
15495 uint x, y, width, height;
15496 u.GetDimensions(width, height);
15497 for (y = 0; y < height; ++y)
15499 for (x = 0; x < width; ++x)
15500 u[uint2(x, y)] = value;
15503 #endif
15504 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
15505 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15506 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
15507 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
15508 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
15509 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
15510 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
15511 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
15512 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
15513 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
15514 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
15515 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
15516 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
15517 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
15520 if (!init_test_context(&test_context, &feature_level))
15521 return;
15523 device = test_context.device;
15524 context = test_context.immediate_context;
15526 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
15527 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
15529 texture_desc.Width = 64;
15530 texture_desc.Height = 64;
15531 texture_desc.MipLevels = 1;
15532 texture_desc.ArraySize = 1;
15533 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
15534 texture_desc.SampleDesc.Count = 1;
15535 texture_desc.SampleDesc.Quality = 0;
15536 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15537 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15538 texture_desc.CPUAccessFlags = 0;
15539 texture_desc.MiscFlags = 0;
15540 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
15541 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15542 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
15543 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15545 uav_desc.Format = texture_desc.Format;
15546 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
15547 U(uav_desc).Texture2D.MipSlice = 0;
15548 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
15549 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15550 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
15551 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15553 ID3D11Device_GetImmediateContext(device, &context);
15555 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
15556 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
15557 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
15558 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
15559 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
15560 1, &test_context.backbuffer_rtv, NULL, 1, 1, &ps_uav, NULL);
15562 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
15563 check_texture_float(cs_texture, 0.0f, 2);
15564 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
15565 check_texture_float(ps_texture, 0.0f, 2);
15567 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
15568 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15569 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15570 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15571 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15572 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15574 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15575 check_texture_float(cs_texture, 1.0f, 2);
15576 check_texture_float(ps_texture, 0.0f, 2);
15577 draw_quad(&test_context);
15578 check_texture_float(cs_texture, 1.0f, 2);
15579 check_texture_float(ps_texture, 1.0f, 2);
15581 input.x = 0.5f;
15582 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
15583 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15584 check_texture_float(cs_texture, 0.5f, 2);
15585 check_texture_float(ps_texture, 1.0f, 2);
15586 input.x = 2.0f;
15587 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
15588 draw_quad(&test_context);
15589 check_texture_float(cs_texture, 0.5f, 2);
15590 check_texture_float(ps_texture, 2.0f, 2);
15592 input.x = 8.0f;
15593 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
15594 input.x = 4.0f;
15595 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
15596 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15597 check_texture_float(cs_texture, 8.0f, 2);
15598 check_texture_float(ps_texture, 2.0f, 2);
15599 draw_quad(&test_context);
15600 check_texture_float(cs_texture, 8.0f, 2);
15601 check_texture_float(ps_texture, 4.0f, 2);
15603 ID3D11ComputeShader_Release(cs);
15604 ID3D11PixelShader_Release(ps);
15605 ID3D11Buffer_Release(cs_cb);
15606 ID3D11Buffer_Release(ps_cb);
15607 ID3D11Texture2D_Release(cs_texture);
15608 ID3D11Texture2D_Release(ps_texture);
15609 ID3D11UnorderedAccessView_Release(cs_uav);
15610 ID3D11UnorderedAccessView_Release(ps_uav);
15611 ID3D11DeviceContext_Release(context);
15612 release_test_context(&test_context);
15615 static void test_atomic_instructions(void)
15617 ID3D11UnorderedAccessView *in_uav, *out_uav;
15618 ID3D11Buffer *cb, *in_buffer, *out_buffer;
15619 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
15620 struct d3d11_test_context test_context;
15621 struct resource_readback rb, out_rb;
15622 D3D11_TEXTURE2D_DESC texture_desc;
15623 D3D11_BUFFER_DESC buffer_desc;
15624 ID3D11DeviceContext *context;
15625 ID3D11RenderTargetView *rtv;
15626 ID3D11Texture2D *texture;
15627 ID3D11ComputeShader *cs;
15628 ID3D11PixelShader *ps;
15629 ID3D11Device *device;
15630 D3D11_VIEWPORT vp;
15631 unsigned int i, j;
15632 HRESULT hr;
15634 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15635 static const unsigned int zero[4] = {0, 0, 0, 0};
15636 static const DWORD ps_atomics_code[] =
15638 #if 0
15639 RWByteAddressBuffer u;
15641 uint4 v;
15642 int4 i;
15644 void main()
15646 u.InterlockedAnd(0 * 4, v.x);
15647 u.InterlockedCompareStore(1 * 4, v.y, v.x);
15648 u.InterlockedAdd(2 * 4, v.x);
15649 u.InterlockedOr(3 * 4, v.x);
15650 u.InterlockedMax(4 * 4, i.x);
15651 u.InterlockedMin(5 * 4, i.x);
15652 u.InterlockedMax(6 * 4, v.x);
15653 u.InterlockedMin(7 * 4, v.x);
15654 u.InterlockedXor(8 * 4, v.x);
15656 #endif
15657 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
15658 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15659 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
15660 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
15661 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
15662 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
15663 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
15664 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
15665 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
15666 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
15667 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
15668 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
15669 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
15670 0x00000000, 0x00000000, 0x0100003e,
15672 static const DWORD cs_atomics_code[] =
15674 #if 0
15675 RWByteAddressBuffer u;
15676 RWByteAddressBuffer u2;
15678 uint4 v;
15679 int4 i;
15681 [numthreads(1, 1, 1)]
15682 void main()
15684 uint r;
15685 u.InterlockedAnd(0 * 4, v.x, r);
15686 u2.Store(0 * 4, r);
15687 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
15688 u2.Store(1 * 4, r);
15689 u.InterlockedAdd(2 * 4, v.x, r);
15690 u2.Store(2 * 4, r);
15691 u.InterlockedOr(3 * 4, v.x, r);
15692 u2.Store(3 * 4, r);
15693 u.InterlockedMax(4 * 4, i.x, r);
15694 u2.Store(4 * 4, r);
15695 u.InterlockedMin(5 * 4, i.x, r);
15696 u2.Store(5 * 4, r);
15697 u.InterlockedMax(6 * 4, v.x, r);
15698 u2.Store(6 * 4, r);
15699 u.InterlockedMin(7 * 4, v.x, r);
15700 u2.Store(7 * 4, r);
15701 u.InterlockedXor(8 * 4, v.x, r);
15702 u2.Store(8 * 4, r);
15704 #endif
15705 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
15706 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15707 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
15708 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
15709 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
15710 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
15711 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
15712 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
15713 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
15714 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
15715 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
15716 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
15717 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
15718 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
15719 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
15720 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
15721 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
15722 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
15723 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
15724 0x0010000a, 0x00000000, 0x0100003e,
15727 static const char * const instructions[] =
15729 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
15730 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
15732 static const char * const imm_instructions[] =
15734 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
15735 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
15737 static const struct test
15739 struct uvec4 v;
15740 struct ivec4 i;
15741 unsigned int input[ARRAY_SIZE(instructions)];
15742 unsigned int expected_result[ARRAY_SIZE(instructions)];
15744 tests[] =
15746 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
15747 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
15750 if (!init_test_context(&test_context, &feature_level))
15751 return;
15753 device = test_context.device;
15754 context = test_context.immediate_context;
15756 texture_desc.Width = 1;
15757 texture_desc.Height = 1;
15758 texture_desc.MipLevels = 1;
15759 texture_desc.ArraySize = 1;
15760 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
15761 texture_desc.SampleDesc.Count = 1;
15762 texture_desc.SampleDesc.Quality = 0;
15763 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15764 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15765 texture_desc.CPUAccessFlags = 0;
15766 texture_desc.MiscFlags = 0;
15767 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15768 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15769 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15770 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15772 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
15773 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
15774 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
15776 buffer_desc.ByteWidth = sizeof(tests->input);
15777 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
15778 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15779 buffer_desc.CPUAccessFlags = 0;
15780 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
15781 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
15782 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
15783 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
15784 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
15786 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
15787 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
15788 U(uav_desc).Buffer.FirstElement = 0;
15789 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
15790 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
15791 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
15792 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15793 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
15794 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15796 vp.TopLeftX = 0.0f;
15797 vp.TopLeftY = 0.0f;
15798 vp.Width = texture_desc.Width;
15799 vp.Height = texture_desc.Height;
15800 vp.MinDepth = 0.0f;
15801 vp.MaxDepth = 1.0f;
15802 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
15804 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
15805 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15806 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15808 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
15809 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15810 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15812 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15814 const struct test *test = &tests[i];
15816 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15817 NULL, &test->v, 0, 0);
15819 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
15820 NULL, test->input, 0, 0);
15822 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
15823 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
15824 0, 1, &in_uav, NULL);
15826 draw_quad(&test_context);
15827 get_buffer_readback(in_buffer, &rb);
15828 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
15830 unsigned int value = get_readback_color(&rb, j, 0);
15831 unsigned int expected = test->expected_result[j];
15833 todo_wine_if(expected != test->input[j]
15834 && (!strcmp(instructions[j], "atomic_imax")
15835 || !strcmp(instructions[j], "atomic_imin")))
15836 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
15837 "with inputs (%u, %u), (%d), %#x (%d).\n",
15838 i, value, value, expected, expected, instructions[j],
15839 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
15841 release_resource_readback(&rb);
15843 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
15844 NULL, test->input, 0, 0);
15845 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
15847 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
15848 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
15850 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15851 get_buffer_readback(in_buffer, &rb);
15852 get_buffer_readback(out_buffer, &out_rb);
15853 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
15855 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
15856 || !strcmp(imm_instructions[j], "imm_atomic_imin");
15857 unsigned int out_value = get_readback_color(&out_rb, j, 0);
15858 unsigned int value = get_readback_color(&rb, j, 0);
15859 unsigned int expected = test->expected_result[j];
15861 todo_wine_if(expected != test->input[j] && todo_instruction)
15862 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
15863 "with inputs (%u, %u), (%d), %#x (%d).\n",
15864 i, value, value, expected, expected, imm_instructions[j],
15865 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
15867 todo_wine_if(todo_instruction && out_value != test->input[j])
15868 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
15869 out_value, test->input[j], imm_instructions[j]);
15871 release_resource_readback(&out_rb);
15872 release_resource_readback(&rb);
15875 ID3D11Buffer_Release(cb);
15876 ID3D11Buffer_Release(in_buffer);
15877 ID3D11Buffer_Release(out_buffer);
15878 ID3D11ComputeShader_Release(cs);
15879 ID3D11PixelShader_Release(ps);
15880 ID3D11RenderTargetView_Release(rtv);
15881 ID3D11Texture2D_Release(texture);
15882 ID3D11UnorderedAccessView_Release(in_uav);
15883 ID3D11UnorderedAccessView_Release(out_uav);
15884 release_test_context(&test_context);
15887 static void test_sm4_ret_instruction(void)
15889 struct d3d11_test_context test_context;
15890 ID3D11DeviceContext *context;
15891 ID3D11PixelShader *ps;
15892 struct uvec4 constant;
15893 ID3D11Device *device;
15894 ID3D11Buffer *cb;
15895 HRESULT hr;
15897 static const DWORD ps_code[] =
15899 #if 0
15900 uint c;
15902 float4 main() : SV_TARGET
15904 if (c == 1)
15905 return float4(1, 0, 0, 1);
15906 if (c == 2)
15907 return float4(0, 1, 0, 1);
15908 if (c == 3)
15909 return float4(0, 0, 1, 1);
15910 return float4(1, 1, 1, 1);
15912 #endif
15913 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
15914 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15915 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15916 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
15917 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
15918 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
15919 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
15920 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
15921 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
15922 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
15923 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
15924 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
15925 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
15926 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
15927 0x0100003e,
15930 if (!init_test_context(&test_context, NULL))
15931 return;
15933 device = test_context.device;
15934 context = test_context.immediate_context;
15936 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15937 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
15938 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15939 memset(&constant, 0, sizeof(constant));
15940 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
15941 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
15943 draw_quad(&test_context);
15944 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
15946 constant.x = 1;
15947 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
15948 draw_quad(&test_context);
15949 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15951 constant.x = 2;
15952 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
15953 draw_quad(&test_context);
15954 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15956 constant.x = 3;
15957 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
15958 draw_quad(&test_context);
15959 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
15961 constant.x = 4;
15962 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
15963 draw_quad(&test_context);
15964 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
15966 ID3D11Buffer_Release(cb);
15967 ID3D11PixelShader_Release(ps);
15968 release_test_context(&test_context);
15971 static void test_primitive_restart(void)
15973 struct d3d11_test_context test_context;
15974 ID3D11Buffer *ib32, *ib16, *vb;
15975 ID3D11DeviceContext *context;
15976 unsigned int stride, offset;
15977 ID3D11InputLayout *layout;
15978 ID3D11VertexShader *vs;
15979 ID3D11PixelShader *ps;
15980 ID3D11Device *device;
15981 unsigned int i;
15982 HRESULT hr;
15983 RECT rect;
15985 static const DWORD ps_code[] =
15987 #if 0
15988 struct vs_out
15990 float4 position : SV_Position;
15991 float4 color : color;
15994 float4 main(vs_out input) : SV_TARGET
15996 return input.color;
15998 #endif
15999 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
16000 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16001 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
16002 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
16003 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16004 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
16005 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
16006 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
16008 static const DWORD vs_code[] =
16010 #if 0
16011 struct vs_out
16013 float4 position : SV_Position;
16014 float4 color : color;
16017 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
16019 output.position = position;
16020 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
16022 #endif
16023 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
16024 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
16025 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
16026 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
16027 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
16028 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
16029 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
16030 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
16031 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
16032 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
16033 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
16034 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
16035 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
16037 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
16039 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
16041 static const struct vec2 vertices[] =
16043 {-1.00f, -1.0f},
16044 {-1.00f, 1.0f},
16045 {-0.25f, -1.0f},
16046 {-0.25f, 1.0f},
16047 { 0.25f, -1.0f},
16048 { 0.25f, 1.0f},
16049 { 1.00f, -1.0f},
16050 { 1.00f, 1.0f},
16052 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
16053 static const unsigned short indices16[] =
16055 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
16057 static const unsigned int indices32[] =
16059 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
16062 if (!init_test_context(&test_context, NULL))
16063 return;
16065 device = test_context.device;
16066 context = test_context.immediate_context;
16068 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
16069 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
16070 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16071 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
16073 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
16074 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
16076 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
16077 vs_code, sizeof(vs_code), &layout);
16078 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
16080 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
16082 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
16083 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16085 ID3D11DeviceContext_IASetInputLayout(context, layout);
16086 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
16087 stride = sizeof(*vertices);
16088 offset = 0;
16089 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
16091 for (i = 0; i < 2; ++i)
16093 if (!i)
16094 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
16095 else
16096 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
16098 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
16099 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
16100 SetRect(&rect, 0, 0, 240, 480);
16101 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
16102 SetRect(&rect, 240, 0, 400, 480);
16103 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
16104 SetRect(&rect, 400, 0, 640, 480);
16105 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
16108 ID3D11Buffer_Release(ib16);
16109 ID3D11Buffer_Release(ib32);
16110 ID3D11Buffer_Release(vb);
16111 ID3D11InputLayout_Release(layout);
16112 ID3D11PixelShader_Release(ps);
16113 ID3D11VertexShader_Release(vs);
16114 release_test_context(&test_context);
16117 static void test_resinfo_instruction(void)
16119 struct shader
16121 const DWORD *code;
16122 size_t size;
16125 struct d3d11_test_context test_context;
16126 D3D11_TEXTURE3D_DESC texture3d_desc;
16127 D3D11_TEXTURE2D_DESC texture_desc;
16128 const struct shader *current_ps;
16129 D3D_FEATURE_LEVEL feature_level;
16130 ID3D11ShaderResourceView *srv;
16131 ID3D11DeviceContext *context;
16132 ID3D11Texture2D *rtv_texture;
16133 ID3D11RenderTargetView *rtv;
16134 ID3D11Resource *texture;
16135 struct uvec4 constant;
16136 ID3D11PixelShader *ps;
16137 ID3D11Device *device;
16138 unsigned int i, type;
16139 ID3D11Buffer *cb;
16140 HRESULT hr;
16142 static const DWORD ps_2d_code[] =
16144 #if 0
16145 Texture2D t;
16147 uint type;
16148 uint level;
16150 float4 main() : SV_TARGET
16152 if (!type)
16154 float width, height, miplevels;
16155 t.GetDimensions(level, width, height, miplevels);
16156 return float4(width, height, miplevels, 0);
16158 else
16160 uint width, height, miplevels;
16161 t.GetDimensions(level, width, height, miplevels);
16162 return float4(width, height, miplevels, 0);
16165 #endif
16166 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
16167 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16168 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16169 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
16170 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
16171 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
16172 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
16173 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
16174 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
16175 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
16176 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
16177 0x01000015, 0x0100003e,
16179 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
16180 static const DWORD ps_2d_array_code[] =
16182 #if 0
16183 Texture2DArray t;
16185 uint type;
16186 uint level;
16188 float4 main() : SV_TARGET
16190 if (!type)
16192 float width, height, elements, miplevels;
16193 t.GetDimensions(level, width, height, elements, miplevels);
16194 return float4(width, height, elements, miplevels);
16196 else
16198 uint width, height, elements, miplevels;
16199 t.GetDimensions(level, width, height, elements, miplevels);
16200 return float4(width, height, elements, miplevels);
16203 #endif
16204 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
16205 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16206 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16207 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
16208 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
16209 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
16210 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
16211 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
16212 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
16213 0x0100003e, 0x01000015, 0x0100003e,
16215 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
16216 static const DWORD ps_3d_code[] =
16218 #if 0
16219 Texture3D t;
16221 uint type;
16222 uint level;
16224 float4 main() : SV_TARGET
16226 if (!type)
16228 float width, height, depth, miplevels;
16229 t.GetDimensions(level, width, height, depth, miplevels);
16230 return float4(width, height, depth, miplevels);
16232 else
16234 uint width, height, depth, miplevels;
16235 t.GetDimensions(level, width, height, depth, miplevels);
16236 return float4(width, height, depth, miplevels);
16239 #endif
16240 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
16241 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16242 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16243 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
16244 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
16245 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
16246 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
16247 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
16248 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
16249 0x0100003e, 0x01000015, 0x0100003e,
16251 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
16252 static const DWORD ps_cube_code[] =
16254 #if 0
16255 TextureCube t;
16257 uint type;
16258 uint level;
16260 float4 main() : SV_TARGET
16262 if (!type)
16264 float width, height, miplevels;
16265 t.GetDimensions(level, width, height, miplevels);
16266 return float4(width, height, miplevels, 0);
16268 else
16270 uint width, height, miplevels;
16271 t.GetDimensions(level, width, height, miplevels);
16272 return float4(width, height, miplevels, 0);
16275 #endif
16276 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
16277 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16278 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16279 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
16280 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
16281 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
16282 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
16283 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
16284 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
16285 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
16286 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
16287 0x01000015, 0x0100003e,
16289 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
16290 static const DWORD ps_cube_array_code[] =
16292 #if 0
16293 TextureCubeArray t;
16295 uint type;
16296 uint level;
16298 float4 main() : SV_TARGET
16300 if (!type)
16302 float width, height, elements, miplevels;
16303 t.GetDimensions(level, width, height, elements, miplevels);
16304 return float4(width, height, miplevels, 0);
16306 else
16308 uint width, height, elements, miplevels;
16309 t.GetDimensions(level, width, height, elements, miplevels);
16310 return float4(width, height, miplevels, 0);
16313 #endif
16314 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
16315 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16316 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16317 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
16318 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
16319 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
16320 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
16321 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
16322 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
16323 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
16324 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
16325 0x0100003e, 0x01000015, 0x0100003e,
16327 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
16328 static const struct ps_test
16330 const struct shader *ps;
16331 struct
16333 unsigned int width;
16334 unsigned int height;
16335 unsigned int depth;
16336 unsigned int miplevel_count;
16337 unsigned int array_size;
16338 unsigned int cube_count;
16339 } texture_desc;
16340 unsigned int miplevel;
16341 struct vec4 expected_result;
16343 ps_tests[] =
16345 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
16346 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
16347 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
16348 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
16350 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
16351 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
16352 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
16353 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
16355 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
16356 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
16357 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
16358 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
16359 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
16360 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
16361 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
16362 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
16363 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
16365 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
16366 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
16367 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
16368 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
16369 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
16371 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
16372 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
16373 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
16376 if (!init_test_context(&test_context, NULL))
16377 return;
16379 device = test_context.device;
16380 context = test_context.immediate_context;
16381 feature_level = ID3D11Device_GetFeatureLevel(device);
16383 texture_desc.Width = 64;
16384 texture_desc.Height = 64;
16385 texture_desc.MipLevels = 1;
16386 texture_desc.ArraySize = 1;
16387 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
16388 texture_desc.SampleDesc.Count = 1;
16389 texture_desc.SampleDesc.Quality = 0;
16390 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16391 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16392 texture_desc.CPUAccessFlags = 0;
16393 texture_desc.MiscFlags = 0;
16394 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
16395 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16396 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
16397 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16399 memset(&constant, 0, sizeof(constant));
16400 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
16402 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
16403 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16405 ps = NULL;
16406 current_ps = NULL;
16407 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
16409 const struct ps_test *test = &ps_tests[i];
16411 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
16413 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
16414 continue;
16417 if (current_ps != test->ps)
16419 if (ps)
16420 ID3D11PixelShader_Release(ps);
16422 current_ps = test->ps;
16424 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
16425 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
16426 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16429 if (test->texture_desc.depth != 1)
16431 texture3d_desc.Width = test->texture_desc.width;
16432 texture3d_desc.Height = test->texture_desc.height;
16433 texture3d_desc.Depth = test->texture_desc.depth;
16434 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
16435 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
16436 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
16437 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
16438 texture3d_desc.CPUAccessFlags = 0;
16439 texture3d_desc.MiscFlags = 0;
16440 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
16441 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
16443 else
16445 texture_desc.Width = test->texture_desc.width;
16446 texture_desc.Height = test->texture_desc.height;
16447 texture_desc.MipLevels = test->texture_desc.miplevel_count;
16448 texture_desc.ArraySize = test->texture_desc.array_size;
16449 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
16450 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
16451 texture_desc.MiscFlags = 0;
16452 if (test->texture_desc.cube_count)
16453 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
16454 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
16455 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
16458 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
16459 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
16460 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
16462 for (type = 0; type < 2; ++type)
16464 constant.x = type;
16465 constant.y = test->miplevel;
16466 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
16468 draw_quad(&test_context);
16469 check_texture_vec4(rtv_texture, &test->expected_result, 0);
16472 ID3D11Resource_Release(texture);
16473 ID3D11ShaderResourceView_Release(srv);
16475 ID3D11PixelShader_Release(ps);
16477 ID3D11Buffer_Release(cb);
16478 ID3D11RenderTargetView_Release(rtv);
16479 ID3D11Texture2D_Release(rtv_texture);
16480 release_test_context(&test_context);
16483 static void test_sm5_bufinfo_instruction(void)
16485 struct shader
16487 const DWORD *code;
16488 size_t size;
16491 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16492 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
16493 struct d3d11_test_context test_context;
16494 D3D11_TEXTURE2D_DESC texture_desc;
16495 const struct shader *current_ps;
16496 ID3D11UnorderedAccessView *uav;
16497 ID3D11ShaderResourceView *srv;
16498 D3D11_BUFFER_DESC buffer_desc;
16499 ID3D11DeviceContext *context;
16500 ID3D11RenderTargetView *rtv;
16501 ID3D11Texture2D *texture;
16502 ID3D11PixelShader *ps;
16503 ID3D11Buffer *buffer;
16504 ID3D11Device *device;
16505 unsigned int i;
16506 HRESULT hr;
16508 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16509 static const DWORD ps_uav_structured_code[] =
16511 #if 0
16512 struct s
16514 uint4 u;
16515 bool b;
16518 RWStructuredBuffer<s> b;
16520 uint4 main(void) : SV_Target
16522 uint count, stride;
16523 b.GetDimensions(count, stride);
16524 return uint4(count, stride, 0, 1);
16526 #endif
16527 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
16528 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16529 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16530 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
16531 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
16532 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
16533 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
16534 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
16536 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
16537 static const DWORD ps_uav_structured32_code[] =
16539 #if 0
16540 struct s
16542 uint4 u;
16543 bool4 b;
16546 RWStructuredBuffer<s> b;
16548 uint4 main(void) : SV_Target
16550 uint count, stride;
16551 b.GetDimensions(count, stride);
16552 return uint4(count, stride, 0, 1);
16554 #endif
16555 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
16556 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16557 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16558 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
16559 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
16560 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
16561 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
16562 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
16564 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
16565 static const DWORD ps_srv_structured_code[] =
16567 #if 0
16568 StructuredBuffer<bool> b;
16570 uint4 main(void) : SV_Target
16572 uint count, stride;
16573 b.GetDimensions(count, stride);
16574 return uint4(count, stride, 0, 1);
16576 #endif
16577 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
16578 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16579 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16580 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
16581 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
16582 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
16583 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
16584 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
16586 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
16587 static const DWORD ps_uav_raw_code[] =
16589 #if 0
16590 RWByteAddressBuffer b;
16592 uint4 main(void) : SV_Target
16594 uint width;
16595 b.GetDimensions(width);
16596 return width;
16598 #endif
16599 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
16600 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16601 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16602 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
16603 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
16604 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
16605 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
16607 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
16608 static const DWORD ps_srv_raw_code[] =
16610 #if 0
16611 ByteAddressBuffer b;
16613 uint4 main(void) : SV_Target
16615 uint width;
16616 b.GetDimensions(width);
16617 return width;
16619 #endif
16620 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
16621 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16622 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16623 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
16624 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
16625 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
16626 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
16628 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
16629 static const DWORD ps_uav_typed_code[] =
16631 #if 0
16632 RWBuffer<float> b;
16634 uint4 main(void) : SV_Target
16636 uint width;
16637 b.GetDimensions(width);
16638 return width;
16640 #endif
16641 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
16642 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16643 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16644 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
16645 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
16646 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
16647 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
16649 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
16650 static const DWORD ps_srv_typed_code[] =
16652 #if 0
16653 Buffer<float> b;
16655 uint4 main(void) : SV_Target
16657 uint width;
16658 b.GetDimensions(width);
16659 return width;
16661 #endif
16662 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
16663 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16664 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16665 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
16666 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
16667 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
16668 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
16670 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
16671 static const struct test
16673 const struct shader *ps;
16674 BOOL uav;
16675 unsigned int buffer_size;
16676 unsigned int buffer_misc_flags;
16677 unsigned int buffer_structure_byte_stride;
16678 DXGI_FORMAT view_format;
16679 unsigned int view_element_idx;
16680 unsigned int view_element_count;
16681 struct uvec4 expected_result;
16683 tests[] =
16685 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
16686 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
16687 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
16688 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
16689 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
16690 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
16691 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
16692 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
16693 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
16694 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
16695 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
16696 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
16697 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
16698 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
16699 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
16700 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
16701 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
16702 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
16703 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
16704 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
16705 #undef RAW
16706 #undef STRUCTURED
16709 if (!init_test_context(&test_context, &feature_level))
16710 return;
16712 device = test_context.device;
16713 context = test_context.immediate_context;
16715 texture_desc.Width = 64;
16716 texture_desc.Height = 64;
16717 texture_desc.MipLevels = 1;
16718 texture_desc.ArraySize = 1;
16719 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
16720 texture_desc.SampleDesc.Count = 1;
16721 texture_desc.SampleDesc.Quality = 0;
16722 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16723 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16724 texture_desc.CPUAccessFlags = 0;
16725 texture_desc.MiscFlags = 0;
16726 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16727 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16728 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
16729 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16731 ps = NULL;
16732 current_ps = NULL;
16733 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16735 const struct test *test = &tests[i];
16737 if (current_ps != test->ps)
16739 if (ps)
16740 ID3D11PixelShader_Release(ps);
16742 current_ps = test->ps;
16744 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
16745 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
16746 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16749 buffer_desc.ByteWidth = test->buffer_size;
16750 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
16751 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
16752 buffer_desc.CPUAccessFlags = 0;
16753 buffer_desc.MiscFlags = test->buffer_misc_flags;
16754 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
16755 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16756 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
16758 if (test->uav)
16760 uav_desc.Format = test->view_format;
16761 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16762 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
16763 U(uav_desc).Buffer.NumElements = test->view_element_count;
16764 U(uav_desc).Buffer.Flags = 0;
16765 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
16766 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
16767 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16768 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
16769 srv = NULL;
16771 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
16772 1, 1, &uav, NULL);
16774 else
16776 srv_desc.Format = test->view_format;
16777 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
16778 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
16779 U(srv_desc).BufferEx.NumElements = test->view_element_count;
16780 U(srv_desc).BufferEx.Flags = 0;
16781 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
16782 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
16783 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
16784 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
16785 uav = NULL;
16787 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
16788 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
16791 draw_quad(&test_context);
16792 check_texture_uvec4(texture, &test->expected_result);
16794 if (srv)
16795 ID3D11ShaderResourceView_Release(srv);
16796 if (uav)
16797 ID3D11UnorderedAccessView_Release(uav);
16798 ID3D11Buffer_Release(buffer);
16800 ID3D11PixelShader_Release(ps);
16802 ID3D11RenderTargetView_Release(rtv);
16803 ID3D11Texture2D_Release(texture);
16804 release_test_context(&test_context);
16807 static void test_render_target_device_mismatch(void)
16809 struct d3d11_test_context test_context;
16810 struct device_desc device_desc = {0};
16811 ID3D11DeviceContext *context;
16812 ID3D11RenderTargetView *rtv;
16813 ID3D11Device *device;
16814 ULONG refcount;
16816 if (!init_test_context(&test_context, NULL))
16817 return;
16819 device = create_device(&device_desc);
16820 ok(!!device, "Failed to create device.\n");
16822 ID3D11Device_GetImmediateContext(device, &context);
16824 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
16825 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
16826 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
16827 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
16828 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
16829 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
16830 ID3D11RenderTargetView_Release(rtv);
16832 rtv = NULL;
16833 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
16835 ID3D11DeviceContext_Release(context);
16836 refcount = ID3D11Device_Release(device);
16837 ok(!refcount, "Device has %u references left.\n", refcount);
16838 release_test_context(&test_context);
16841 static void test_buffer_srv(void)
16843 struct shader
16845 const DWORD *code;
16846 size_t size;
16847 BOOL requires_raw_and_structured_buffers;
16849 struct buffer
16851 unsigned int byte_count;
16852 unsigned int data_offset;
16853 const void *data;
16854 unsigned int structure_byte_stride;
16857 BOOL raw_and_structured_buffers_supported;
16858 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
16859 struct d3d11_test_context test_context;
16860 D3D11_SUBRESOURCE_DATA resource_data;
16861 const struct buffer *current_buffer;
16862 const struct shader *current_shader;
16863 ID3D11ShaderResourceView *srv;
16864 D3D11_BUFFER_DESC buffer_desc;
16865 ID3D11DeviceContext *context;
16866 DWORD color, expected_color;
16867 struct resource_readback rb;
16868 ID3D11Buffer *cb, *buffer;
16869 ID3D11PixelShader *ps;
16870 ID3D11Device *device;
16871 unsigned int i, x, y;
16872 struct vec4 cb_size;
16873 HRESULT hr;
16875 static const DWORD ps_float4_code[] =
16877 #if 0
16878 Buffer<float4> b;
16880 float2 size;
16882 float4 main(float4 position : SV_POSITION) : SV_Target
16884 float2 p;
16885 int2 coords;
16886 p.x = position.x / 640.0f;
16887 p.y = position.y / 480.0f;
16888 coords = int2(p.x * size.x, p.y * size.y);
16889 return b.Load(coords.y * size.x + coords.x);
16891 #endif
16892 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
16893 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16894 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
16895 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16896 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
16897 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
16898 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16899 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
16900 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
16901 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
16902 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
16903 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
16904 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
16906 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
16907 static const DWORD ps_structured_code[] =
16909 #if 0
16910 StructuredBuffer<float4> b;
16912 float2 size;
16914 float4 main(float4 position : SV_POSITION) : SV_Target
16916 float2 p;
16917 int2 coords;
16918 p.x = position.x / 640.0f;
16919 p.y = position.y / 480.0f;
16920 coords = int2(p.x * size.x, p.y * size.y);
16921 return b[coords.y * size.x + coords.x];
16923 #endif
16924 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
16925 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
16926 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
16927 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
16928 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
16929 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
16930 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
16931 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
16932 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
16933 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
16934 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
16935 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
16936 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
16937 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
16939 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
16940 static const DWORD rgba16[] =
16942 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
16943 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
16944 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
16945 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
16947 static const DWORD rgba4[] =
16949 0xffffffff, 0xff0000ff,
16950 0xff000000, 0xff00ff00,
16952 static const BYTE r4[] =
16954 0xde, 0xad,
16955 0xba, 0xbe,
16957 static const struct vec4 rgba_float[] =
16959 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
16960 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
16962 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
16963 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
16964 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
16965 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
16966 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
16967 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
16968 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
16969 &rgba_float, sizeof(*rgba_float)};
16970 static const DWORD rgba16_colors2x2[] =
16972 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
16973 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
16974 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
16975 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
16977 static const DWORD rgba16_colors1x1[] =
16979 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
16980 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
16981 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
16982 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
16984 static const DWORD rgba4_colors[] =
16986 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
16987 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
16988 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
16989 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
16991 static const DWORD r4_colors[] =
16993 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
16994 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
16995 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
16996 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
16998 static const DWORD zero_colors[16] = {0};
16999 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
17001 static const struct test
17003 const struct shader *shader;
17004 const struct buffer *buffer;
17005 DXGI_FORMAT srv_format;
17006 unsigned int srv_first_element;
17007 unsigned int srv_element_count;
17008 struct vec2 size;
17009 const DWORD *expected_colors;
17011 tests[] =
17013 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
17014 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
17015 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
17016 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
17017 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
17018 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
17019 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
17020 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
17021 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
17022 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
17023 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
17026 if (!init_test_context(&test_context, NULL))
17027 return;
17029 device = test_context.device;
17030 context = test_context.immediate_context;
17031 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
17032 || check_compute_shaders_via_sm4_support(device);
17034 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
17035 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17037 ps = NULL;
17038 srv = NULL;
17039 buffer = NULL;
17040 current_shader = NULL;
17041 current_buffer = NULL;
17042 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17044 const struct test *test = &tests[i];
17046 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
17048 skip("Test %u: Raw and structured buffers are not supported.\n", i);
17049 continue;
17051 /* Structured buffer views with an offset don't seem to work on WARP. */
17052 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
17053 && is_warp_device(device))
17055 skip("Test %u: Broken WARP.\n", i);
17056 continue;
17059 if (current_shader != test->shader)
17061 if (ps)
17062 ID3D11PixelShader_Release(ps);
17064 current_shader = test->shader;
17066 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
17067 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
17068 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17071 if (current_buffer != test->buffer)
17073 if (buffer)
17074 ID3D11Buffer_Release(buffer);
17076 current_buffer = test->buffer;
17077 if (current_buffer)
17079 BYTE *data = NULL;
17081 buffer_desc.ByteWidth = current_buffer->byte_count;
17082 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17083 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
17084 buffer_desc.CPUAccessFlags = 0;
17085 buffer_desc.MiscFlags = 0;
17086 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
17087 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
17088 resource_data.SysMemPitch = 0;
17089 resource_data.SysMemSlicePitch = 0;
17090 if (current_buffer->data_offset)
17092 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, current_buffer->byte_count);
17093 ok(!!data, "Failed to allocate memory.\n");
17094 memcpy(data + current_buffer->data_offset, current_buffer->data,
17095 current_buffer->byte_count - current_buffer->data_offset);
17096 resource_data.pSysMem = data;
17098 else
17100 resource_data.pSysMem = current_buffer->data;
17102 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
17103 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
17104 HeapFree(GetProcessHeap(), 0, data);
17106 else
17108 buffer = NULL;
17112 if (srv)
17113 ID3D11ShaderResourceView_Release(srv);
17114 if (current_buffer)
17116 srv_desc.Format = test->srv_format;
17117 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
17118 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
17119 U(srv_desc).Buffer.NumElements = test->srv_element_count;
17120 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
17121 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
17123 else
17125 srv = NULL;
17127 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
17129 cb_size.x = test->size.x;
17130 cb_size.y = test->size.y;
17131 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
17133 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
17134 draw_quad(&test_context);
17136 get_texture_readback(test_context.backbuffer, 0, &rb);
17137 for (y = 0; y < 4; ++y)
17139 for (x = 0; x < 4; ++x)
17141 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
17142 expected_color = test->expected_colors[y * 4 + x];
17143 ok(compare_color(color, expected_color, 1),
17144 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
17145 i, color, expected_color, x, y);
17148 release_resource_readback(&rb);
17150 if (srv)
17151 ID3D11ShaderResourceView_Release(srv);
17152 if (buffer)
17153 ID3D11Buffer_Release(buffer);
17155 ID3D11Buffer_Release(cb);
17156 ID3D11PixelShader_Release(ps);
17157 release_test_context(&test_context);
17160 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
17162 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
17163 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
17164 struct d3d11_test_context test_context;
17165 D3D11_SUBRESOURCE_DATA resource_data;
17166 D3D11_TEXTURE2D_DESC texture_desc;
17167 ID3D11UnorderedAccessView *uav;
17168 ID3D11ShaderResourceView *srv;
17169 D3D11_BUFFER_DESC buffer_desc;
17170 ID3D11Buffer *cb, *raw_buffer;
17171 ID3D11DeviceContext *context;
17172 struct resource_readback rb;
17173 ID3D11RenderTargetView *rtv;
17174 ID3D11Texture2D *texture;
17175 ID3D11ComputeShader *cs;
17176 ID3D11PixelShader *ps;
17177 ID3D11Device *device;
17178 unsigned int i, data;
17179 struct uvec4 offset;
17180 HRESULT hr;
17182 static const unsigned int buffer_data[] =
17184 0xffffffff, 0x00000000,
17186 static const DWORD ps_code[] =
17188 #if 0
17189 ByteAddressBuffer buffer;
17191 uint offset;
17193 uint main() : SV_Target0
17195 return buffer.Load(offset);
17197 #endif
17198 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
17199 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
17200 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
17201 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
17202 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
17203 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
17204 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
17205 0x00000000,
17207 static const DWORD cs_code[] =
17209 #if 0
17210 RWByteAddressBuffer buffer;
17212 uint2 input;
17214 [numthreads(1, 1, 1)]
17215 void main()
17217 buffer.Store(input.x, input.y);
17219 #endif
17220 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
17221 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17222 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
17223 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
17224 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
17225 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
17227 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
17229 if (!init_test_context(&test_context, &feature_level))
17230 return;
17232 device = test_context.device;
17233 context = test_context.immediate_context;
17235 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
17237 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17238 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17239 if (SUCCEEDED(hr))
17240 ID3D11PixelShader_Release(ps);
17241 skip("Raw buffers are not supported.\n");
17242 release_test_context(&test_context);
17243 return;
17246 if (is_intel_device(device))
17248 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
17249 * This test checks what happens when offsets are not properly aligned.
17250 * The behavior seems to be undefined on Intel hardware. */
17251 win_skip("Skipping the test on Intel hardware.\n");
17252 release_test_context(&test_context);
17253 return;
17256 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17257 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17259 memset(&offset, 0, sizeof(offset));
17260 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
17262 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17263 texture_desc.Format = DXGI_FORMAT_R32_UINT;
17264 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17265 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17266 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
17267 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17269 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17271 buffer_desc.ByteWidth = sizeof(buffer_data);
17272 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17273 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
17274 buffer_desc.CPUAccessFlags = 0;
17275 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
17276 resource_data.pSysMem = buffer_data;
17277 resource_data.SysMemPitch = 0;
17278 resource_data.SysMemSlicePitch = 0;
17279 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
17280 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17282 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
17283 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
17284 U(srv_desc).BufferEx.FirstElement = 0;
17285 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
17286 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
17287 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
17288 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
17290 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17291 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17292 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
17294 offset.x = 0;
17295 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17296 NULL, &offset, 0, 0);
17297 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17298 draw_quad(&test_context);
17299 check_texture_color(texture, buffer_data[0], 0);
17300 offset.x = 1;
17301 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17302 NULL, &offset, 0, 0);
17303 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17304 draw_quad(&test_context);
17305 check_texture_color(texture, buffer_data[0], 0);
17306 offset.x = 2;
17307 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17308 NULL, &offset, 0, 0);
17309 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17310 draw_quad(&test_context);
17311 check_texture_color(texture, buffer_data[0], 0);
17312 offset.x = 3;
17313 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17314 NULL, &offset, 0, 0);
17315 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17316 draw_quad(&test_context);
17317 check_texture_color(texture, buffer_data[0], 0);
17319 offset.x = 4;
17320 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17321 NULL, &offset, 0, 0);
17322 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17323 draw_quad(&test_context);
17324 check_texture_color(texture, buffer_data[1], 0);
17325 offset.x = 7;
17326 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17327 NULL, &offset, 0, 0);
17328 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17329 draw_quad(&test_context);
17330 check_texture_color(texture, buffer_data[1], 0);
17332 if (feature_level < D3D_FEATURE_LEVEL_11_0)
17334 skip("Feature level 11_0 required for unaligned UAV test.\n");
17335 goto done;
17338 ID3D11Buffer_Release(raw_buffer);
17339 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17340 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
17341 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17343 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
17344 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
17345 U(uav_desc).Buffer.FirstElement = 0;
17346 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
17347 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
17348 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
17349 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17351 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
17352 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17354 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
17355 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
17356 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
17358 offset.x = 0;
17359 offset.y = 0xffffffff;
17360 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17361 NULL, &offset, 0, 0);
17362 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
17363 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17364 get_buffer_readback(raw_buffer, &rb);
17365 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
17367 data = get_readback_color(&rb, i, 0);
17368 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
17370 release_resource_readback(&rb);
17372 offset.x = 1;
17373 offset.y = 0xffffffff;
17374 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17375 NULL, &offset, 0, 0);
17376 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
17377 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17378 get_buffer_readback(raw_buffer, &rb);
17379 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
17381 data = get_readback_color(&rb, i, 0);
17382 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
17384 release_resource_readback(&rb);
17386 offset.x = 2;
17387 offset.y = 0xffffffff;
17388 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17389 NULL, &offset, 0, 0);
17390 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
17391 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17392 get_buffer_readback(raw_buffer, &rb);
17393 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
17395 data = get_readback_color(&rb, i, 0);
17396 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
17398 release_resource_readback(&rb);
17400 offset.x = 3;
17401 offset.y = 0xffffffff;
17402 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17403 NULL, &offset, 0, 0);
17404 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
17405 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17406 get_buffer_readback(raw_buffer, &rb);
17407 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
17409 data = get_readback_color(&rb, i, 0);
17410 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
17412 release_resource_readback(&rb);
17414 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
17415 offset.x = 3;
17416 offset.y = 0xffff;
17417 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17418 NULL, &offset, 0, 0);
17419 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17420 offset.x = 4;
17421 offset.y = 0xa;
17422 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17423 NULL, &offset, 0, 0);
17424 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17425 get_buffer_readback(raw_buffer, &rb);
17426 data = get_readback_color(&rb, 0, 0);
17427 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
17428 data = get_readback_color(&rb, 1, 0);
17429 ok(data == 0xa, "Got unexpected result %#x.\n", data);
17430 release_resource_readback(&rb);
17432 ID3D11ComputeShader_Release(cs);
17433 ID3D11UnorderedAccessView_Release(uav);
17435 done:
17436 ID3D11Buffer_Release(cb);
17437 ID3D11Buffer_Release(raw_buffer);
17438 ID3D11PixelShader_Release(ps);
17439 ID3D11RenderTargetView_Release(rtv);
17440 ID3D11ShaderResourceView_Release(srv);
17441 ID3D11Texture2D_Release(texture);
17442 release_test_context(&test_context);
17445 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
17446 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
17448 D3D11_MAPPED_SUBRESOURCE map_desc;
17449 unsigned int counter;
17451 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
17453 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
17454 D3D11_MAP_READ, 0, &map_desc)))
17455 return 0xdeadbeef;
17456 counter = *(unsigned int *)map_desc.pData;
17457 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
17458 return counter;
17461 static int compare_id(const void *a, const void *b)
17463 return *(int *)a - *(int *)b;
17466 static void test_uav_counters(void)
17468 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
17469 ID3D11ComputeShader *cs_producer, *cs_consumer;
17470 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
17471 struct d3d11_test_context test_context;
17472 ID3D11UnorderedAccessView *uav, *uav2;
17473 unsigned int data, id[128], i;
17474 D3D11_BUFFER_DESC buffer_desc;
17475 ID3D11DeviceContext *context;
17476 struct resource_readback rb;
17477 ID3D11Device *device;
17478 D3D11_BOX box;
17479 HRESULT hr;
17481 static const DWORD cs_producer_code[] =
17483 #if 0
17484 RWStructuredBuffer<uint> u;
17486 [numthreads(4, 1, 1)]
17487 void main(uint3 dispatch_id : SV_DispatchThreadID)
17489 uint counter = u.IncrementCounter();
17490 u[counter] = dispatch_id.x;
17492 #endif
17493 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
17494 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17495 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
17496 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
17497 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
17498 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
17499 0x0002000a, 0x0100003e,
17501 static const DWORD cs_consumer_code[] =
17503 #if 0
17504 RWStructuredBuffer<uint> u;
17505 RWStructuredBuffer<uint> u2;
17507 [numthreads(4, 1, 1)]
17508 void main()
17510 uint counter = u.DecrementCounter();
17511 u2[counter] = u[counter];
17513 #endif
17514 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
17515 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17516 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
17517 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
17518 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
17519 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
17520 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
17521 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
17523 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17525 if (!init_test_context(&test_context, &feature_level))
17526 return;
17528 device = test_context.device;
17529 context = test_context.immediate_context;
17531 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
17532 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17533 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
17534 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17536 memset(&buffer_desc, 0, sizeof(buffer_desc));
17537 buffer_desc.ByteWidth = sizeof(unsigned int);
17538 buffer_desc.Usage = D3D11_USAGE_STAGING;
17539 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
17540 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
17541 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
17543 buffer_desc.ByteWidth = 1024;
17544 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17545 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17546 buffer_desc.CPUAccessFlags = 0;
17547 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
17548 buffer_desc.StructureByteStride = sizeof(unsigned int);
17549 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
17550 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
17551 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
17552 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
17553 U(uav_desc).Buffer.FirstElement = 0;
17554 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
17555 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
17556 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
17557 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17558 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
17559 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
17560 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
17561 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17563 data = read_uav_counter(context, staging_buffer, uav);
17564 ok(!data, "Got unexpected initial value %u.\n", data);
17565 data = 8;
17566 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
17567 data = read_uav_counter(context, staging_buffer, uav);
17568 todo_wine ok(data == 8, "Got unexpected value %u.\n", data);
17570 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
17571 data = 0;
17572 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
17573 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
17574 data = read_uav_counter(context, staging_buffer, uav);
17575 ok(!data, "Got unexpected value %u.\n", data);
17577 /* produce */
17578 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
17579 data = read_uav_counter(context, staging_buffer, uav);
17580 todo_wine ok(data == 64, "Got unexpected value %u.\n", data);
17581 get_buffer_readback(buffer, &rb);
17582 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
17583 release_resource_readback(&rb);
17584 qsort(id, 64, sizeof(*id), compare_id);
17585 for (i = 0; i < 64; ++i)
17587 if (id[i] != i)
17588 break;
17590 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
17592 /* consume */
17593 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
17594 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
17595 data = read_uav_counter(context, staging_buffer, uav);
17596 ok(!data, "Got unexpected value %u.\n", data);
17597 get_buffer_readback(buffer2, &rb);
17598 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
17599 release_resource_readback(&rb);
17600 qsort(id, 64, sizeof(*id), compare_id);
17601 for (i = 0; i < 64; ++i)
17603 if (id[i] != i)
17604 break;
17606 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
17608 /* produce on CPU */
17609 for (i = 0; i < 8; ++i)
17610 id[i] = 0xdeadbeef;
17611 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
17612 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
17613 data = 8;
17614 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
17615 data = read_uav_counter(context, staging_buffer, uav);
17616 todo_wine ok(data == 8, "Got unexpected value %u.\n", data);
17618 /* consume */
17619 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17620 data = read_uav_counter(context, staging_buffer, uav);
17621 todo_wine ok(data == 4, "Got unexpected value %u.\n", data);
17622 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17623 data = read_uav_counter(context, staging_buffer, uav);
17624 ok(!data, "Got unexpected value %u.\n", data);
17625 get_buffer_readback(buffer2, &rb);
17626 for (i = 0; i < 8; ++i)
17628 data = get_readback_color(&rb, i, 0);
17629 todo_wine ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
17631 release_resource_readback(&rb);
17633 ID3D11Buffer_Release(buffer);
17634 ID3D11Buffer_Release(buffer2);
17635 ID3D11Buffer_Release(staging_buffer);
17636 ID3D11ComputeShader_Release(cs_producer);
17637 ID3D11ComputeShader_Release(cs_consumer);
17638 ID3D11UnorderedAccessView_Release(uav);
17639 ID3D11UnorderedAccessView_Release(uav2);
17640 release_test_context(&test_context);
17643 static void test_compute_shader_registers(void)
17645 struct data
17647 unsigned int group_id[3];
17648 unsigned int group_index;
17649 unsigned int dispatch_id[3];
17650 unsigned int thread_id[3];
17653 struct d3d11_test_context test_context;
17654 unsigned int i, x, y, group_x, group_y;
17655 ID3D11UnorderedAccessView *uav;
17656 D3D11_BUFFER_DESC buffer_desc;
17657 ID3D11DeviceContext *context;
17658 struct resource_readback rb;
17659 ID3D11Buffer *cb, *buffer;
17660 struct uvec4 dimensions;
17661 ID3D11ComputeShader *cs;
17662 const struct data *data;
17663 ID3D11Device *device;
17664 HRESULT hr;
17666 static const DWORD cs_code[] =
17668 #if 0
17669 struct data
17671 uint3 group_id;
17672 uint group_index;
17673 uint3 dispatch_id;
17674 uint3 group_thread_id;
17677 RWStructuredBuffer<data> u;
17679 uint2 dim;
17681 [numthreads(3, 2, 1)]
17682 void main(uint3 group_id : SV_GroupID,
17683 uint group_index : SV_GroupIndex,
17684 uint3 dispatch_id : SV_DispatchThreadID,
17685 uint3 group_thread_id : SV_GroupThreadID)
17687 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
17688 u[i].group_id = group_id;
17689 u[i].group_index = group_index;
17690 u[i].dispatch_id = dispatch_id;
17691 u[i].group_thread_id = group_thread_id;
17693 #endif
17694 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
17695 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17696 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
17697 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
17698 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
17699 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
17700 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
17701 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
17702 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
17703 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
17704 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
17705 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
17706 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
17707 0x0100003e,
17709 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17711 if (!init_test_context(&test_context, &feature_level))
17712 return;
17714 device = test_context.device;
17715 context = test_context.immediate_context;
17717 buffer_desc.ByteWidth = 10240;
17718 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17719 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17720 buffer_desc.CPUAccessFlags = 0;
17721 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
17722 buffer_desc.StructureByteStride = 40;
17723 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
17724 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
17725 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
17726 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
17727 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17729 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
17731 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
17732 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17734 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
17735 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
17736 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
17738 dimensions.x = 2;
17739 dimensions.y = 3;
17740 dimensions.z = 1;
17741 dimensions.w = 0;
17742 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17743 NULL, &dimensions, 0, 0);
17744 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
17746 get_buffer_readback(buffer, &rb);
17747 i = 0;
17748 data = rb.map_desc.pData;
17749 for (y = 0; y < dimensions.y; ++y)
17751 for (group_y = 0; group_y < 2; ++group_y)
17753 for (x = 0; x < dimensions.x; ++x)
17755 for (group_x = 0; group_x < 3; ++group_x)
17757 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
17758 const unsigned int group_index = group_y * 3 + group_x;
17759 const struct data *d = &data[i];
17761 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
17762 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
17763 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
17764 i, x, y, group_x, group_y);
17765 ok(d->group_index == group_index,
17766 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
17767 d->group_index, group_index, i, x, y, group_x, group_y);
17768 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
17769 && !d->dispatch_id[2],
17770 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
17771 "at %u (%u, %u, %u, %u).\n",
17772 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
17773 dispatch_id[0], dispatch_id[1], 0,
17774 i, x, y, group_x, group_y);
17775 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
17776 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
17777 "at %u (%u, %u, %u, %u).\n",
17778 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
17779 i, x, y, group_x, group_y);
17780 ++i;
17785 release_resource_readback(&rb);
17787 ID3D11Buffer_Release(cb);
17788 ID3D11Buffer_Release(buffer);
17789 ID3D11ComputeShader_Release(cs);
17790 ID3D11UnorderedAccessView_Release(uav);
17791 release_test_context(&test_context);
17794 static void test_tgsm(void)
17796 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
17797 struct d3d11_test_context test_context;
17798 ID3D11UnorderedAccessView *uav, *uav2;
17799 struct resource_readback rb, rb2;
17800 unsigned int i, data, expected;
17801 ID3D11Buffer *buffer, *buffer2;
17802 D3D11_BUFFER_DESC buffer_desc;
17803 ID3D11DeviceContext *context;
17804 ID3D11ComputeShader *cs;
17805 ID3D11Device *device;
17806 float float_data;
17807 HRESULT hr;
17809 static const DWORD raw_tgsm_code[] =
17811 #if 0
17812 RWByteAddressBuffer u;
17813 groupshared uint m;
17815 [numthreads(32, 1, 1)]
17816 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
17818 if (!local_idx)
17819 m = group_id.x;
17820 GroupMemoryBarrierWithGroupSync();
17821 InterlockedAdd(m, group_id.x);
17822 GroupMemoryBarrierWithGroupSync();
17823 if (!local_idx)
17824 u.Store(4 * group_id.x, m);
17826 #endif
17827 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
17828 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17829 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
17830 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
17831 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
17832 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
17833 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
17834 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
17835 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
17836 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
17837 0x01000015, 0x0100003e,
17839 static const DWORD structured_tgsm_code[] =
17841 #if 0
17842 #define GROUP_SIZE 32
17844 RWByteAddressBuffer u;
17845 RWByteAddressBuffer u2;
17846 groupshared uint m[GROUP_SIZE];
17848 [numthreads(GROUP_SIZE, 1, 1)]
17849 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
17851 uint sum, original, i;
17853 if (!local_idx)
17855 for (i = 0; i < GROUP_SIZE; ++i)
17856 m[i] = 2 * group_id.x;
17858 GroupMemoryBarrierWithGroupSync();
17859 InterlockedAdd(m[local_idx], 1);
17860 GroupMemoryBarrierWithGroupSync();
17861 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
17862 u.InterlockedExchange(4 * group_id.x, sum, original);
17863 u2.Store(4 * group_id.x, original);
17865 #endif
17866 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
17867 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17868 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
17869 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
17870 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
17871 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
17872 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
17873 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
17874 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
17875 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
17876 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
17877 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
17878 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
17879 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
17880 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
17881 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
17882 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
17883 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
17884 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
17885 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
17886 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
17887 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
17889 static const DWORD structured_tgsm_float_code[] =
17891 #if 0
17892 #define GROUP_SIZE 32
17894 struct data
17896 float f;
17897 uint u;
17900 RWBuffer<float> u;
17901 RWBuffer<uint> u2;
17902 groupshared data m[GROUP_SIZE];
17904 [numthreads(GROUP_SIZE, 1, 1)]
17905 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
17906 uint thread_id : SV_DispatchThreadID)
17908 uint i;
17909 if (!local_idx)
17911 for (i = 0; i < GROUP_SIZE; ++i)
17913 m[i].f = group_id.x;
17914 m[i].u = group_id.x;
17917 GroupMemoryBarrierWithGroupSync();
17918 for (i = 0; i < local_idx; ++i)
17920 m[local_idx].f += group_id.x;
17921 m[local_idx].u += group_id.x;
17923 u[thread_id.x] = m[local_idx].f;
17924 u2[thread_id.x] = m[local_idx].u;
17926 #endif
17927 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
17928 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17929 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
17930 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
17931 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
17932 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
17933 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
17934 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
17935 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
17936 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
17937 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
17938 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
17939 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
17940 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
17941 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
17942 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
17943 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
17944 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
17945 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
17946 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
17947 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
17948 0x00100556, 0x00000000, 0x0100003e,
17950 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17951 static const unsigned int zero[4] = {0};
17953 if (!init_test_context(&test_context, &feature_level))
17954 return;
17956 device = test_context.device;
17957 context = test_context.immediate_context;
17959 buffer_desc.ByteWidth = 1024;
17960 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17961 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17962 buffer_desc.CPUAccessFlags = 0;
17963 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
17964 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
17965 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17967 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
17968 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
17969 U(uav_desc).Buffer.FirstElement = 0;
17970 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
17971 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
17972 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
17973 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17975 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
17976 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17978 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
17979 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
17981 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
17982 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
17983 get_buffer_readback(buffer, &rb);
17984 for (i = 0; i < 64; ++i)
17986 data = get_readback_color(&rb, i, 0);
17987 expected = 33 * i;
17988 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
17990 release_resource_readback(&rb);
17992 ID3D11Buffer_Release(buffer);
17993 ID3D11ComputeShader_Release(cs);
17994 ID3D11UnorderedAccessView_Release(uav);
17996 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
17997 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17998 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
17999 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18000 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
18001 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18002 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
18003 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18004 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
18005 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18007 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18008 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
18009 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
18011 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
18012 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
18013 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
18014 get_buffer_readback(buffer, &rb);
18015 get_buffer_readback(buffer2, &rb2);
18016 for (i = 0; i < 32; ++i)
18018 expected = 64 * i + 32;
18019 data = get_readback_color(&rb, i, 0);
18020 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
18021 data = get_readback_color(&rb2, i, 0);
18022 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
18024 release_resource_readback(&rb);
18025 release_resource_readback(&rb2);
18027 ID3D11Buffer_Release(buffer);
18028 ID3D11Buffer_Release(buffer2);
18029 ID3D11ComputeShader_Release(cs);
18030 ID3D11UnorderedAccessView_Release(uav);
18031 ID3D11UnorderedAccessView_Release(uav2);
18033 buffer_desc.MiscFlags = 0;
18034 U(uav_desc).Buffer.Flags = 0;
18035 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18036 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18037 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
18038 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
18039 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18040 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
18041 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18042 uav_desc.Format = DXGI_FORMAT_R32_UINT;
18043 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
18044 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18045 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
18046 sizeof(structured_tgsm_float_code), NULL, &cs);
18047 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18049 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18050 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
18051 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
18053 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
18054 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
18055 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
18056 get_buffer_readback(buffer, &rb);
18057 get_buffer_readback(buffer2, &rb2);
18058 for (i = 0; i < 96; ++i)
18060 expected = (i % 32 + 1) * (i / 32);
18061 float_data = get_readback_float(&rb, i, 0);
18062 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
18063 data = get_readback_color(&rb2, i, 0);
18064 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
18066 release_resource_readback(&rb);
18067 release_resource_readback(&rb2);
18069 ID3D11Buffer_Release(buffer);
18070 ID3D11Buffer_Release(buffer2);
18071 ID3D11ComputeShader_Release(cs);
18072 ID3D11UnorderedAccessView_Release(uav);
18073 ID3D11UnorderedAccessView_Release(uav2);
18074 release_test_context(&test_context);
18077 static void test_geometry_shader(void)
18079 static const struct
18081 struct vec4 position;
18082 unsigned int color;
18084 vertex[] =
18086 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
18088 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
18090 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18091 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
18093 #if 0
18094 struct vs_data
18096 float4 pos : SV_POSITION;
18097 float4 color : COLOR;
18100 void main(in struct vs_data vs_input, out struct vs_data vs_output)
18102 vs_output.pos = vs_input.pos;
18103 vs_output.color = vs_input.color;
18105 #endif
18106 static const DWORD vs_code[] =
18108 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
18109 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18110 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
18111 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
18112 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18113 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18114 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18115 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18116 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18117 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18118 0x0100003e,
18120 #if 0
18121 struct gs_data
18123 float4 pos : SV_POSITION;
18124 float4 color : COLOR;
18127 [maxvertexcount(4)]
18128 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
18130 float offset = 0.2 * vin[0].pos.w;
18131 gs_data v;
18133 v.color = vin[0].color;
18135 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
18136 vout.Append(v);
18137 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
18138 vout.Append(v);
18139 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
18140 vout.Append(v);
18141 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
18142 vout.Append(v);
18144 #endif
18145 static const DWORD gs_code[] =
18147 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
18148 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18149 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
18150 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
18151 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18152 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18153 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
18154 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
18155 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
18156 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
18157 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
18158 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
18159 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
18160 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
18161 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
18162 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
18163 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
18164 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
18165 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
18166 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
18167 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
18168 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
18169 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
18170 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
18171 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
18172 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
18173 0x00000001, 0x01000013, 0x0100003e,
18175 static const DWORD gs_5_0_code[] =
18177 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
18178 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18179 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
18180 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
18181 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
18182 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
18183 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
18184 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
18185 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
18186 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18187 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
18188 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
18189 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
18190 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
18191 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
18192 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
18193 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
18194 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
18195 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
18196 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
18197 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
18198 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
18199 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
18200 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
18201 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
18202 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
18203 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
18204 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
18205 0x0100003e,
18207 #if 0
18208 struct ps_data
18210 float4 pos : SV_POSITION;
18211 float4 color : COLOR;
18214 float4 main(struct ps_data ps_input) : SV_Target
18216 return ps_input.color;
18218 #endif
18219 static const DWORD ps_code[] =
18221 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
18222 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18223 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
18224 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
18225 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18226 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
18227 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
18228 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
18230 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
18231 struct d3d11_test_context test_context;
18232 ID3D11InputLayout *input_layout;
18233 ID3D11DeviceContext *context;
18234 unsigned int stride, offset;
18235 struct resource_readback rb;
18236 ID3D11GeometryShader *gs;
18237 ID3D11VertexShader *vs;
18238 ID3D11PixelShader *ps;
18239 ID3D11Device *device;
18240 ID3D11Buffer *vb;
18241 DWORD color;
18242 HRESULT hr;
18244 if (!init_test_context(&test_context, NULL))
18245 return;
18247 device = test_context.device;
18248 context = test_context.immediate_context;
18250 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
18251 vs_code, sizeof(vs_code), &input_layout);
18252 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
18254 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
18256 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
18257 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
18258 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
18259 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
18260 else
18261 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
18262 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
18263 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18264 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18266 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
18267 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
18268 stride = sizeof(*vertex);
18269 offset = 0;
18270 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
18271 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
18272 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
18273 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18275 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
18276 ID3D11DeviceContext_Draw(context, 1, 0);
18278 get_texture_readback(test_context.backbuffer, 0, &rb);
18279 color = get_readback_color(&rb, 320, 190);
18280 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
18281 color = get_readback_color(&rb, 255, 240);
18282 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
18283 color = get_readback_color(&rb, 320, 240);
18284 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
18285 color = get_readback_color(&rb, 385, 240);
18286 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
18287 color = get_readback_color(&rb, 320, 290);
18288 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
18289 release_resource_readback(&rb);
18291 ID3D11PixelShader_Release(ps);
18292 ID3D11GeometryShader_Release(gs);
18293 ID3D11VertexShader_Release(vs);
18294 ID3D11Buffer_Release(vb);
18295 ID3D11InputLayout_Release(input_layout);
18296 release_test_context(&test_context);
18299 struct triangle
18301 struct vec4 v[3];
18304 #define check_triangles(buffer, triangles, count) check_triangles_(__LINE__, buffer, triangles, count)
18305 static void check_triangles_(unsigned int line, ID3D11Buffer *buffer,
18306 const struct triangle *triangles, unsigned int triangle_count)
18308 const struct triangle *current, *expected;
18309 struct resource_readback rb;
18310 unsigned int i, j, offset;
18311 BOOL all_match = TRUE;
18313 get_buffer_readback(buffer, &rb);
18315 for (i = 0; i < triangle_count; ++i)
18317 current = get_readback_data(&rb, i, 0, sizeof(*current));
18318 expected = &triangles[i];
18320 offset = ~0u;
18321 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
18323 if (compare_vec4(&current->v[0], &expected->v[j], 0))
18325 offset = j;
18326 break;
18330 if (offset == ~0u)
18332 all_match = FALSE;
18333 break;
18336 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
18338 if (!compare_vec4(&current->v[j], &expected->v[(j + offset) % 3], 0))
18340 all_match = FALSE;
18341 break;
18344 if (!all_match)
18345 break;
18348 ok_(__FILE__, line)(all_match, "Triangle %u vertices {%.8e, %.8e, %.8e, %.8e}, "
18349 "{%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e} "
18350 "do not match {%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e}, "
18351 "{%.8e, %.8e, %.8e, %.8e}.\n", i,
18352 current->v[0].x, current->v[0].y, current->v[0].z, current->v[0].w,
18353 current->v[1].x, current->v[1].y, current->v[1].z, current->v[1].w,
18354 current->v[2].x, current->v[2].y, current->v[2].z, current->v[2].w,
18355 expected->v[0].x, expected->v[0].y, expected->v[0].z, expected->v[0].w,
18356 expected->v[1].x, expected->v[1].y, expected->v[1].z, expected->v[1].w,
18357 expected->v[2].x, expected->v[2].y, expected->v[2].z, expected->v[2].w);
18359 release_resource_readback(&rb);
18362 static void test_quad_tessellation(void)
18364 #if 0
18365 struct point_data
18367 float4 position : SV_POSITION;
18370 struct patch_constant_data
18372 float edges[4] : SV_TessFactor;
18373 float inside[2] : SV_InsideTessFactor;
18376 float4 tess_factors;
18377 float2 inside_tess_factors;
18379 patch_constant_data patch_constant(InputPatch<point_data, 4> input)
18381 patch_constant_data output;
18383 output.edges[0] = tess_factors.x;
18384 output.edges[1] = tess_factors.y;
18385 output.edges[2] = tess_factors.z;
18386 output.edges[3] = tess_factors.w;
18387 output.inside[0] = inside_tess_factors.x;
18388 output.inside[1] = inside_tess_factors.y;
18390 return output;
18393 [domain("quad")]
18394 [outputcontrolpoints(4)]
18395 [outputtopology("triangle_ccw")]
18396 [partitioning("integer")]
18397 [patchconstantfunc("patch_constant")]
18398 point_data hs_main(InputPatch<point_data, 4> input,
18399 uint i : SV_OutputControlPointID)
18401 return input[i];
18404 [domain("quad")]
18405 point_data ds_main(patch_constant_data input,
18406 float2 tess_coord : SV_DomainLocation,
18407 const OutputPatch<point_data, 4> patch)
18409 point_data output;
18411 float4 a = lerp(patch[0].position, patch[1].position, tess_coord.x);
18412 float4 b = lerp(patch[2].position, patch[3].position, tess_coord.x);
18413 output.position = lerp(a, b, tess_coord.y);
18415 return output;
18417 #endif
18418 static const DWORD hs_quad_ccw_code[] =
18420 0x43425844, 0xdf8df700, 0x58b08fb1, 0xbd23d2c3, 0xcf884094, 0x00000001, 0x000002b8, 0x00000004,
18421 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
18422 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
18423 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
18424 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
18425 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
18426 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
18427 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
18428 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
18429 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
18430 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
18431 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
18432 0x01002097, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
18433 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
18434 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
18435 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
18436 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
18437 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
18438 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
18439 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
18440 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
18441 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
18443 static const DWORD ds_quad_code[] =
18445 0x43425844, 0xeb6b7631, 0x07f5469e, 0xed0cbf4a, 0x7158b3a6, 0x00000001, 0x00000284, 0x00000004,
18446 0x00000030, 0x00000064, 0x00000128, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
18447 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
18448 0x004e4f49, 0x47534350, 0x000000bc, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b,
18449 0x00000003, 0x00000000, 0x00000001, 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001,
18450 0x00000001, 0x00000098, 0x00000002, 0x0000000b, 0x00000003, 0x00000002, 0x00000001, 0x00000098,
18451 0x00000003, 0x0000000b, 0x00000003, 0x00000003, 0x00000001, 0x000000a6, 0x00000000, 0x0000000c,
18452 0x00000003, 0x00000004, 0x00000001, 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005,
18453 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365,
18454 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
18455 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853,
18456 0x00000120, 0x00040050, 0x00000048, 0x01002093, 0x01001895, 0x0100086a, 0x0200005f, 0x0001c032,
18457 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18458 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, 0x80219e46, 0x00000041, 0x00000002,
18459 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, 0x001000f2, 0x00000000, 0x0001c006,
18460 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, 0x0a000000, 0x001000f2, 0x00000001,
18461 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, 0x00000001, 0x00000000, 0x09000032,
18462 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, 0x00219e46, 0x00000000, 0x00000000,
18463 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x80100e46, 0x00000041, 0x00000001,
18464 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
18465 0x0100003e,
18467 #if 0
18469 [outputtopology("triangle_cw")]
18471 #endif
18472 static const DWORD hs_quad_cw_code[] =
18474 0x43425844, 0x1ab30cc8, 0x94174771, 0x61f4cdd0, 0xa287f62c, 0x00000001, 0x000002b8, 0x00000004,
18475 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
18476 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
18477 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
18478 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
18479 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
18480 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
18481 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
18482 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
18483 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
18484 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
18485 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
18486 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
18487 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
18488 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
18489 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
18490 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
18491 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
18492 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
18493 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
18494 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
18495 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
18497 #if 0
18498 struct point_data
18500 float4 pos : SV_POSITION;
18503 [maxvertexcount(3)]
18504 void main(triangle point_data vin[3], inout TriangleStream<point_data> vout)
18506 for (uint i = 0; i < 3; ++i)
18507 vout.Append(vin[i]);
18509 #endif
18510 static const DWORD gs_code[] =
18512 0x43425844, 0x8e49d18d, 0x6d08d6e5, 0xb7015628, 0xf9351fdd, 0x00000001, 0x00000164, 0x00000003,
18513 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18514 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
18515 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
18516 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000000c8, 0x00020040,
18517 0x00000032, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068, 0x00000001,
18518 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000003,
18519 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
18520 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010001a, 0x00000000,
18521 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x01000013,
18522 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016,
18523 0x0100003e,
18525 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
18527 {0, "SV_POSITION", 0, 0, 4, 0},
18529 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18530 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
18531 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
18532 static const BYTE zero_data[1024];
18533 static const struct triangle expected_quad_ccw[] =
18535 {{{-1.0f, -1.0f, 0.0f, 1.0f},
18536 { 1.0f, -1.0f, 0.0f, 1.0f},
18537 {-1.0f, 1.0f, 0.0f, 1.0f}}},
18538 {{{-1.0f, 1.0f, 0.0f, 1.0f},
18539 { 1.0f, -1.0f, 0.0f, 1.0f},
18540 { 1.0f, 1.0f, 0.0f, 1.0f}}},
18541 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
18542 { 0.0f, 0.0f, 0.0f, 0.0f},
18543 { 0.0f, 0.0f, 0.0f, 0.0f}}},
18545 static const struct triangle expected_quad_cw[] =
18547 {{{-1.0f, -1.0f, 0.0f, 1.0f},
18548 {-1.0f, 1.0f, 0.0f, 1.0f},
18549 { 1.0f, -1.0f, 0.0f, 1.0f}}},
18550 {{{-1.0f, 1.0f, 0.0f, 1.0f},
18551 { 1.0f, 1.0f, 0.0f, 1.0f},
18552 { 1.0f, -1.0f, 0.0f, 1.0f}}},
18553 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
18554 { 0.0f, 0.0f, 0.0f, 0.0f},
18555 { 0.0f, 0.0f, 0.0f, 0.0f}}},
18557 struct
18559 float tess_factors[4];
18560 float inside_tess_factors[2];
18561 DWORD padding[2];
18562 } constant;
18564 D3D11_QUERY_DATA_SO_STATISTICS so_statistics;
18565 struct d3d11_test_context test_context;
18566 ID3D11DeviceContext *context;
18567 ID3D11Buffer *cb, *so_buffer;
18568 D3D11_QUERY_DESC query_desc;
18569 ID3D11Asynchronous *query;
18570 ID3D11GeometryShader *gs;
18571 ID3D11DomainShader *ds;
18572 const UINT offset = 0;
18573 ID3D11HullShader *hs;
18574 ID3D11Device *device;
18575 unsigned int i;
18576 HRESULT hr;
18578 if (!init_test_context(&test_context, &feature_level))
18579 return;
18581 device = test_context.device;
18582 context = test_context.immediate_context;
18584 draw_color_quad(&test_context, &white);
18585 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
18587 set_quad_color(&test_context, &green);
18588 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
18590 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
18591 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
18592 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0, NULL, &gs);
18593 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
18594 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
18596 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
18597 constant.tess_factors[i] = 1.0f;
18598 for (i = 0; i < ARRAY_SIZE(constant.inside_tess_factors); ++i)
18599 constant.inside_tess_factors[i] = 1.0f;
18600 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
18601 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb);
18602 hr = ID3D11Device_CreateHullShader(device, hs_quad_ccw_code, sizeof(hs_quad_ccw_code), NULL, &hs);
18603 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
18604 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
18605 hr = ID3D11Device_CreateDomainShader(device, ds_quad_code, sizeof(ds_quad_code), NULL, &ds);
18606 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
18607 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
18609 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
18610 ID3D11DeviceContext_Draw(context, 4, 0);
18611 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
18612 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
18613 check_triangles(so_buffer, expected_quad_ccw, ARRAY_SIZE(expected_quad_ccw));
18615 ID3D11Buffer_Release(so_buffer);
18616 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
18618 ID3D11HullShader_Release(hs);
18619 hr = ID3D11Device_CreateHullShader(device, hs_quad_cw_code, sizeof(hs_quad_cw_code), NULL, &hs);
18620 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
18621 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
18623 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
18624 ID3D11DeviceContext_Draw(context, 4, 0);
18625 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
18626 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
18627 check_triangles(so_buffer, expected_quad_cw, ARRAY_SIZE(expected_quad_cw));
18629 ID3D11Buffer_Release(so_buffer);
18630 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
18632 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
18633 query_desc.Query = D3D11_QUERY_SO_STATISTICS_STREAM0;
18634 query_desc.MiscFlags = 0;
18635 query = NULL;
18636 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
18637 todo_wine ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
18638 if (query)
18639 ID3D11DeviceContext_Begin(context, query);
18641 set_quad_color(&test_context, &white);
18642 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
18643 constant.tess_factors[i] = 2.0f;
18644 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
18645 ID3D11DeviceContext_Draw(context, 4, 0);
18646 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
18648 set_quad_color(&test_context, &green);
18649 constant.tess_factors[0] = 0.0f; /* A patch is discarded. */
18650 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
18651 ID3D11DeviceContext_Draw(context, 4, 0);
18652 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
18654 if (query)
18656 ID3D11DeviceContext_End(context, query);
18657 for (i = 0; i < 500; ++i)
18659 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
18660 break;
18661 Sleep(10);
18663 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18664 hr = ID3D11DeviceContext_GetData(context, query, &so_statistics, sizeof(so_statistics), 0);
18665 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18666 ok(so_statistics.NumPrimitivesWritten == 8, "Got unexpected primitives written %u.\n",
18667 (unsigned int)so_statistics.NumPrimitivesWritten);
18668 ok(so_statistics.PrimitivesStorageNeeded == 8, "Got unexpected primitives storage needed %u.\n",
18669 (unsigned int)so_statistics.PrimitivesStorageNeeded);
18670 ID3D11DeviceContext_Begin(context, query);
18673 constant.tess_factors[0] = 5.0f;
18674 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
18675 ID3D11DeviceContext_Draw(context, 4, 0);
18676 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
18678 if (query)
18680 ID3D11DeviceContext_End(context, query);
18681 for (i = 0; i < 500; ++i)
18683 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
18684 break;
18685 Sleep(10);
18687 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18688 hr = ID3D11DeviceContext_GetData(context, query, &so_statistics, sizeof(so_statistics), 0);
18689 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18690 ok(so_statistics.NumPrimitivesWritten == 11, "Got unexpected primitives written %u.\n",
18691 (unsigned int)so_statistics.NumPrimitivesWritten);
18692 ok(so_statistics.PrimitivesStorageNeeded == 11, "Got unexpected primitives storage needed %u.\n",
18693 (unsigned int)so_statistics.PrimitivesStorageNeeded);
18694 ID3D11Asynchronous_Release(query);
18697 ID3D11Buffer_Release(so_buffer);
18698 ID3D11GeometryShader_Release(gs);
18699 ID3D11DomainShader_Release(ds);
18700 ID3D11HullShader_Release(hs);
18701 ID3D11Buffer_Release(cb);
18702 release_test_context(&test_context);
18705 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
18706 static void check_so_desc_(unsigned int line, ID3D11Device *device,
18707 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
18708 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
18709 unsigned int rasterizer_stream)
18711 ID3D11GeometryShader *gs;
18712 HRESULT hr;
18714 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
18715 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
18716 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18717 if (SUCCEEDED(hr))
18718 ID3D11GeometryShader_Release(gs);
18721 #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)
18722 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
18723 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
18724 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
18725 unsigned int rasterizer_stream)
18727 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
18728 HRESULT hr;
18730 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
18731 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
18732 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18733 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
18734 if (SUCCEEDED(hr))
18735 ID3D11GeometryShader_Release(gs);
18738 static void test_stream_output(void)
18740 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
18741 struct d3d11_test_context test_context;
18742 unsigned int i, count;
18743 ID3D11Device *device;
18745 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18746 static const DWORD vs_code[] =
18748 #if 0
18749 struct data
18751 float4 position : SV_Position;
18752 float4 attrib1 : ATTRIB1;
18753 float3 attrib2 : attrib2;
18754 float2 attrib3 : ATTriB3;
18755 float attrib4 : ATTRIB4;
18758 void main(in data i, out data o)
18760 o = i;
18762 #endif
18763 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
18764 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
18765 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
18766 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
18767 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
18768 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
18769 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
18770 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
18771 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
18772 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
18773 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
18774 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
18775 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
18776 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
18777 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18778 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
18779 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
18780 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
18781 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
18782 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
18784 static const DWORD gs_code[] =
18786 #if 0
18787 struct data
18789 float4 position : SV_Position;
18790 float4 attrib1 : ATTRIB1;
18791 float3 attrib2 : attrib2;
18792 float2 attrib3 : ATTriB3;
18793 float attrib4 : ATTRIB4;
18796 [maxvertexcount(1)]
18797 void main(point data i[1], inout PointStream<data> o)
18799 o.Append(i[0]);
18801 #endif
18802 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
18803 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
18804 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
18805 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
18806 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
18807 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
18808 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
18809 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
18810 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
18811 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
18812 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
18813 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
18814 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
18815 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
18816 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
18817 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18818 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
18819 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
18820 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
18821 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
18822 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
18824 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
18826 {0, "SV_Position", 0, 0, 4, 0},
18828 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
18830 {0, "SV_Position", 0, 0, 4, 0},
18831 {0, NULL, 0, 0, 0, 0},
18833 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
18835 /* SemanticName and SemanticIndex */
18837 {0, "sv_position", 0, 0, 4, 0},
18838 {0, "attrib", 1, 0, 4, 0},
18841 {0, "sv_position", 0, 0, 4, 0},
18842 {0, "ATTRIB", 1, 0, 4, 0},
18844 /* Gaps */
18846 {0, "SV_POSITION", 0, 0, 4, 0},
18847 {0, NULL, 0, 0, 8, 0},
18848 {0, "ATTRIB", 1, 0, 4, 0},
18851 {0, "SV_POSITION", 0, 0, 4, 0},
18852 {0, NULL, 0, 0, 4, 0},
18853 {0, NULL, 0, 0, 4, 0},
18854 {0, "ATTRIB", 1, 0, 4, 0},
18856 /* ComponentCount */
18858 {0, "ATTRIB", 1, 0, 4, 0},
18861 {0, "ATTRIB", 2, 0, 3, 0},
18864 {0, "ATTRIB", 3, 0, 2, 0},
18867 {0, "ATTRIB", 4, 0, 1, 0},
18869 /* ComponentIndex */
18871 {0, "ATTRIB", 1, 1, 3, 0},
18874 {0, "ATTRIB", 1, 2, 2, 0},
18877 {0, "ATTRIB", 1, 3, 1, 0},
18880 {0, "ATTRIB", 3, 1, 1, 0},
18882 /* OutputSlot */
18884 {0, "attrib", 1, 0, 4, 0},
18887 {0, "attrib", 1, 0, 4, 1},
18890 {0, "attrib", 1, 0, 4, 2},
18893 {0, "attrib", 1, 0, 4, 3},
18896 {0, "attrib", 1, 0, 4, 0},
18897 {0, "attrib", 2, 0, 3, 1},
18898 {0, NULL, 0, 0, 1, 1},
18899 {0, "attrib", 3, 0, 2, 2},
18900 {0, NULL, 0, 0, 2, 2},
18901 {0, "attrib", 4, 0, 1, 3},
18902 {0, NULL, 0, 0, 7, 3},
18905 {0, "attrib", 1, 0, 4, 0},
18906 {0, "attrib", 2, 0, 3, 1},
18907 {0, NULL, 0, 0, 1, 1},
18908 {0, "attrib", 3, 0, 2, 2},
18909 {0, NULL, 0, 0, 1, 2},
18910 {0, NULL, 0, 0, 1, 2},
18911 {0, "attrib", 4, 0, 1, 3},
18912 {0, NULL, 0, 0, 3, 3},
18913 {0, NULL, 0, 0, 1, 3},
18914 {0, NULL, 0, 0, 1, 3},
18915 {0, NULL, 0, 0, 1, 3},
18916 {0, NULL, 0, 0, 1, 3},
18919 {0, "attrib", 1, 0, 4, 0},
18920 {0, "attrib", 2, 0, 3, 0},
18921 {0, "attrib", 3, 0, 2, 0},
18922 {0, NULL, 0, 0, 1, 0},
18923 {0, "attrib", 4, 0, 1, 0},
18926 {0, "attrib", 1, 0, 4, 0},
18927 {0, "attrib", 2, 0, 3, 0},
18928 {0, "attrib", 3, 0, 2, 3},
18929 {0, NULL, 0, 0, 1, 3},
18930 {0, "attrib", 4, 0, 1, 3},
18932 /* Multiple occurrences of the same output */
18934 {0, "ATTRIB", 1, 0, 2, 0},
18935 {0, "ATTRIB", 1, 2, 2, 1},
18938 {0, "ATTRIB", 1, 0, 1, 0},
18939 {0, "ATTRIB", 1, 1, 3, 0},
18942 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
18944 /* SemanticName and SemanticIndex */
18946 {0, "SV_Position", 0, 0, 4, 0},
18947 {0, "ATTRIB", 0, 0, 4, 0},
18950 {0, "sv_position", 0, 0, 4, 0},
18951 {0, "ATTRIB_", 1, 0, 4, 0},
18953 /* Gaps */
18955 {0, "SV_POSITION", 0, 0, 4, 0},
18956 {0, NULL, 0, 1, 8, 0},
18957 {0, "ATTRIB", 1, 0, 4, 0},
18960 {0, "SV_POSITION", 0, 0, 4, 0},
18961 {0, NULL, 1, 0, 8, 0},
18962 {0, "ATTRIB", 1, 0, 4, 0},
18964 /* Buffer stride */
18966 {0, "SV_POSITION", 0, 0, 4, 0},
18967 {0, NULL, 0, 0, 8, 0},
18968 {0, NULL, 0, 0, 8, 0},
18969 {0, "ATTRIB", 1, 0, 4, 0},
18971 /* ComponentCount */
18973 {0, "ATTRIB", 2, 0, 5, 0},
18976 {0, "ATTRIB", 2, 0, 4, 0},
18979 {0, "ATTRIB", 3, 0, 3, 0},
18982 {0, "ATTRIB", 4, 0, 2, 0},
18984 /* ComponentIndex */
18986 {0, "ATTRIB", 1, 1, 4, 0},
18989 {0, "ATTRIB", 1, 2, 3, 0},
18992 {0, "ATTRIB", 1, 3, 2, 0},
18995 {0, "ATTRIB", 1, 4, 0, 0},
18998 {0, "ATTRIB", 1, 4, 1, 0},
19001 {0, "ATTRIB", 3, 2, 1, 0},
19004 {0, "ATTRIB", 3, 2, 0, 0},
19006 /* OutputSlot */
19008 {0, "attrib", 1, 0, 4, 4},
19011 {0, "attrib", 1, 0, 4, 4},
19014 {0, "attrib", 1, 0, 4, 4},
19017 {0, "attrib", 1, 0, 4, 4},
19020 {0, "attrib", 1, 0, 4, 0},
19021 {0, "attrib", 2, 0, 3, 1},
19022 {0, NULL, 0, 0, 1, 1},
19023 {0, "attrib", 3, 0, 2, 2},
19024 {0, NULL, 0, 0, 2, 2},
19025 {0, "attrib", 4, 0, 1, 3},
19026 {0, NULL, 0, 0, 3, 4},
19029 {0, "attrib", 1, 0, 4, 0},
19030 {0, "attrib", 2, 0, 3, 0},
19031 {0, "attrib", 3, 0, 2, 0},
19032 {0, NULL, 0, 0, 1, 0},
19033 {0, "attrib", 4, 0, 1, 0},
19034 {0, NULL, 0, 0, 3, 3},
19035 {0, NULL, 0, 0, 1, 3},
19036 {0, NULL, 0, 0, 1, 3},
19037 {0, NULL, 0, 0, 1, 3},
19038 {0, NULL, 0, 0, 1, 3},
19041 {0, "attrib", 1, 0, 4, 0},
19042 {0, NULL, 0, 0, 3, 1},
19043 {0, NULL, 0, 0, 1, 1},
19044 {0, NULL, 0, 0, 1, 2},
19045 {0, "attrib", 2, 0, 3, 3},
19046 {0, NULL, 0, 0, 1, 3},
19049 {0, "attrib", 2, 0, 3, 3},
19050 {0, NULL, 0, 0, 3, 1},
19051 {0, NULL, 0, 0, 1, 3},
19052 {0, "attrib", 1, 0, 4, 0},
19053 {0, NULL, 0, 0, 1, 2},
19054 {0, NULL, 0, 0, 1, 1},
19056 /* Stream */
19058 {1, "attrib", 1, 0, 4, 0},
19061 {4, "attrib", 1, 0, 4, 0},
19063 /* Multiple occurrences of the same output */
19065 {0, "ATTRIB", 1, 0, 4, 0},
19066 {0, "ATTRIB", 1, 0, 4, 1},
19069 {0, "ATTRIB", 1, 0, 4, 0},
19070 {0, "ATTRIB", 1, 0, 3, 0},
19074 if (!init_test_context(&test_context, &feature_level))
19075 return;
19077 device = test_context.device;
19079 for (i = 0; i < ARRAY_SIZE(stride); ++i)
19080 stride[i] = 64;
19082 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19083 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19084 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19085 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19086 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19087 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19089 todo_wine
19090 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
19091 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19092 todo_wine
19093 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
19094 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19096 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
19097 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19098 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
19099 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
19100 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19102 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
19103 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19104 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
19105 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19107 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
19109 unsigned int max_output_slot = 0;
19110 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
19112 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
19113 max_output_slot = max(max_output_slot, e->OutputSlot);
19114 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
19115 break;
19118 /* Buffer strides are required for all buffers. */
19119 if (!max_output_slot)
19121 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19122 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19123 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19124 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19125 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19126 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
19127 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19128 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
19129 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19130 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
19132 else
19134 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19135 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19136 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19137 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
19141 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
19143 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
19145 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
19146 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
19147 break;
19150 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19151 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19152 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19153 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
19154 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19155 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
19156 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19157 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
19160 /* Buffer strides */
19161 stride[1] = 63;
19162 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19163 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
19164 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19165 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
19166 stride[1] = 1;
19167 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19168 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
19169 stride[0] = 0;
19170 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19171 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19173 /* Rasterizer stream */
19174 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
19175 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
19176 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19177 NULL, 0, D3D11_SO_STREAM_COUNT);
19179 release_test_context(&test_context);
19182 static void test_fl10_stream_output_desc(void)
19184 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
19185 struct d3d11_test_context test_context;
19186 unsigned int i, count;
19187 ID3D11Device *device;
19189 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
19190 static const DWORD vs_code[] =
19192 #if 0
19193 struct data
19195 float4 position : SV_Position;
19196 float4 attrib1 : ATTRIB1;
19197 float3 attrib2 : attrib2;
19198 float2 attrib3 : ATTriB3;
19199 float attrib4 : ATTRIB4;
19202 void main(in data i, out data o)
19204 o = i;
19206 #endif
19207 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
19208 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
19209 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
19210 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
19211 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
19212 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
19213 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
19214 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
19215 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
19216 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
19217 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
19218 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
19219 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
19220 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
19221 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
19222 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
19223 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
19224 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
19225 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
19226 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
19228 static const DWORD gs_code[] =
19230 #if 0
19231 struct data
19233 float4 position : SV_Position;
19234 float4 attrib1 : ATTRIB1;
19235 float3 attrib2 : attrib2;
19236 float2 attrib3 : ATTriB3;
19237 float attrib4 : ATTRIB4;
19240 [maxvertexcount(1)]
19241 void main(point data i[1], inout PointStream<data> o)
19243 o.Append(i[0]);
19245 #endif
19246 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
19247 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
19248 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
19249 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
19250 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
19251 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
19252 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
19253 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
19254 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
19255 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
19256 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
19257 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
19258 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
19259 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
19260 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
19261 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
19262 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
19263 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
19264 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
19265 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
19266 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
19268 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
19270 {0, "SV_Position", 0, 0, 4, 0},
19272 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
19274 {0, "SV_Position", 0, 0, 4, 0},
19275 {0, NULL, 0, 0, 0, 0},
19277 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
19279 /* Gaps */
19281 {0, "SV_POSITION", 0, 0, 4, 0},
19282 {0, NULL, 0, 0, 8, 0},
19283 {0, "ATTRIB", 1, 0, 4, 0},
19286 {0, "SV_POSITION", 0, 0, 4, 0},
19287 {0, NULL, 0, 0, 4, 0},
19288 {0, NULL, 0, 0, 4, 0},
19289 {0, "ATTRIB", 1, 0, 4, 0},
19291 /* OutputSlot */
19293 {0, "attrib", 1, 0, 4, 0},
19294 {0, "attrib", 2, 0, 3, 0},
19295 {0, "attrib", 3, 0, 2, 0},
19296 {0, "attrib", 4, 0, 1, 0},
19299 {0, "attrib", 1, 0, 4, 0},
19300 {0, "attrib", 2, 0, 3, 1},
19301 {0, "attrib", 3, 0, 2, 2},
19302 {0, "attrib", 4, 0, 1, 3},
19305 {0, "attrib", 1, 0, 4, 0},
19306 {0, "attrib", 2, 0, 3, 3},
19309 {0, "attrib", 1, 0, 4, 0},
19310 {0, "attrib", 2, 0, 3, 0},
19311 {0, "attrib", 3, 0, 2, 0},
19312 {0, NULL, 0, 0, 1, 0},
19313 {0, "attrib", 4, 0, 1, 0},
19315 /* Multiple occurrences of the same output */
19317 {0, "ATTRIB", 1, 0, 2, 0},
19318 {0, "ATTRIB", 1, 2, 2, 1},
19321 {0, "ATTRIB", 1, 0, 1, 0},
19322 {0, "ATTRIB", 1, 1, 3, 0},
19325 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
19327 /* OutputSlot */
19329 {0, "attrib", 1, 0, 4, 0},
19330 {0, NULL, 0, 0, 4, 0},
19331 {0, "attrib", 4, 0, 1, 3},
19334 {0, "attrib", 1, 0, 4, 0},
19335 {0, NULL, 0, 0, 4, 0},
19336 {0, NULL, 0, 0, 4, 0},
19337 {0, "attrib", 4, 0, 1, 3},
19340 {0, "attrib", 1, 0, 4, 0},
19341 {0, "attrib", 2, 0, 3, 0},
19342 {0, "attrib", 3, 0, 2, 0},
19343 {0, "attrib", 4, 0, 1, 1},
19346 {0, "attrib", 1, 0, 4, 0},
19347 {0, "attrib", 2, 0, 3, 0},
19348 {0, "attrib", 3, 0, 2, 3},
19349 {0, NULL, 0, 0, 1, 3},
19350 {0, "attrib", 4, 0, 1, 3},
19353 {0, "attrib", 1, 0, 4, 0},
19354 {0, "attrib", 1, 0, 3, 1},
19355 {0, "attrib", 1, 0, 2, 2},
19356 {0, "attrib", 1, 0, 1, 3},
19357 {0, NULL, 0, 0, 3, 3},
19361 if (!init_test_context(&test_context, &feature_level))
19362 return;
19364 device = test_context.device;
19366 for (i = 0; i < ARRAY_SIZE(stride); ++i)
19367 stride[i] = 64;
19369 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
19370 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
19371 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
19372 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
19374 todo_wine
19375 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
19376 todo_wine
19377 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
19379 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
19380 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
19381 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
19382 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
19383 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
19385 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
19386 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
19388 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
19390 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
19392 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
19393 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
19394 break;
19397 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
19400 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
19402 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
19404 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
19405 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
19406 break;
19409 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19410 stride, 1, 0);
19411 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19412 stride, 2, 0);
19413 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19414 stride, 3, 0);
19415 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19416 stride, 4, 0);
19419 /* Buffer strides */
19420 stride[1] = 63;
19421 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19422 &stride[1], 1, 0);
19423 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19424 stride, 2, 0);
19425 stride[0] = 0;
19426 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19427 stride, 1, 0);
19429 /* Rasterizer stream */
19430 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19431 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19432 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
19433 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19434 NULL, 0, i);
19435 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
19437 release_test_context(&test_context);
19440 static void test_stream_output_resume(void)
19442 struct d3d11_test_context test_context;
19443 ID3D11Buffer *cb, *so_buffer, *buffer;
19444 unsigned int i, j, idx, offset;
19445 ID3D11DeviceContext *context;
19446 struct resource_readback rb;
19447 ID3D11GeometryShader *gs;
19448 const struct vec4 *data;
19449 ID3D11Device *device;
19450 HRESULT hr;
19452 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19453 static const DWORD gs_code[] =
19455 #if 0
19456 float4 constant;
19458 struct vertex
19460 float4 position : SV_POSITION;
19463 struct element
19465 float4 position : SV_POSITION;
19466 float4 so_output : so_output;
19469 [maxvertexcount(3)]
19470 void main(triangle vertex input[3], inout PointStream<element> output)
19472 element o;
19473 o.so_output = constant;
19474 o.position = input[0].position;
19475 output.Append(o);
19476 o.position = input[1].position;
19477 output.Append(o);
19478 o.position = input[2].position;
19479 output.Append(o);
19481 #endif
19482 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
19483 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19484 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
19485 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19486 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19487 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
19488 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
19489 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
19490 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
19491 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
19492 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
19493 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
19494 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
19495 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
19497 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
19499 {0, "so_output", 0, 0, 4, 0},
19501 static const struct vec4 constants[] =
19503 {0.5f, 0.250f, 0.0f, 0.0f},
19504 {0.0f, 0.125f, 0.0f, 1.0f},
19505 {1.0f, 1.000f, 1.0f, 0.0f}
19507 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
19508 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
19509 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
19511 if (!init_test_context(&test_context, &feature_level))
19512 return;
19514 device = test_context.device;
19515 context = test_context.immediate_context;
19517 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
19518 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
19519 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
19521 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
19522 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
19524 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
19525 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
19527 offset = 0;
19528 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
19530 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
19531 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
19533 draw_color_quad(&test_context, &red);
19534 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
19536 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
19537 draw_color_quad(&test_context, &green);
19538 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
19540 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
19541 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
19542 draw_color_quad(&test_context, &red);
19543 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
19545 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
19546 draw_color_quad(&test_context, &red);
19547 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
19549 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
19550 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
19551 draw_color_quad(&test_context, &white);
19552 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
19554 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
19555 draw_color_quad(&test_context, &green);
19556 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
19558 buffer = NULL;
19559 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
19560 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
19561 draw_color_quad(&test_context, &white);
19562 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
19564 idx = 0;
19565 get_buffer_readback(so_buffer, &rb);
19566 for (i = 0; i < ARRAY_SIZE(constants); ++i)
19568 for (j = 0; j < 6; ++j) /* 2 triangles */
19570 data = get_readback_vec4(&rb, idx++, 0);
19571 ok(compare_vec4(data, &constants[i], 0),
19572 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
19573 data->x, data->y, data->z, data->w, idx, i, j);
19576 release_resource_readback(&rb);
19578 ID3D11Buffer_Release(cb);
19579 ID3D11Buffer_Release(so_buffer);
19580 ID3D11GeometryShader_Release(gs);
19581 release_test_context(&test_context);
19584 static void test_gather(void)
19586 struct
19588 int width, height;
19589 int offset_x, offset_y;
19590 } constant;
19591 struct d3d11_test_context test_context;
19592 D3D11_TEXTURE2D_DESC texture_desc;
19593 ID3D11ShaderResourceView *srv;
19594 ID3D11Texture2D *texture, *rt;
19595 ID3D11DeviceContext *context;
19596 ID3D11RenderTargetView *rtv;
19597 struct resource_readback rb;
19598 ID3D11PixelShader *ps;
19599 ID3D11Device *device;
19600 unsigned int x, y;
19601 ID3D11Buffer *cb;
19602 HRESULT hr;
19604 static const DWORD gather4_code[] =
19606 #if 0
19607 SamplerState s;
19608 Texture2D<float4> t;
19610 int2 size;
19612 float4 main(float4 position : SV_Position) : SV_Target
19614 return t.Gather(s, position.xy / size);
19616 #endif
19617 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
19618 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19619 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19620 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19621 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
19622 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
19623 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
19624 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
19625 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
19626 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
19627 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
19629 static const DWORD gather4_offset_code[] =
19631 #if 0
19632 SamplerState s;
19633 Texture2D<float4> t;
19635 int2 size;
19637 float4 main(float4 position : SV_Position) : SV_Target
19639 return t.Gather(s, position.xy / size, int2(1, 1));
19641 #endif
19642 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
19643 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19644 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19645 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19646 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
19647 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
19648 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
19649 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
19650 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
19651 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
19652 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
19654 static const DWORD gather4_green_code[] =
19656 #if 0
19657 SamplerState s;
19658 Texture2D<float4> t;
19660 int2 size;
19662 float4 main(float4 position : SV_Position) : SV_Target
19664 return t.GatherGreen(s, position.xy / size);
19666 #endif
19667 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
19668 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19669 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19670 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19671 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
19672 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
19673 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
19674 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
19675 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
19676 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
19677 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
19679 static const DWORD gather4_po_code[] =
19681 #if 0
19682 SamplerState s;
19683 Texture2D<float4> t;
19685 int2 size;
19686 int2 offset;
19688 float4 main(float4 position : SV_Position) : SV_Target
19690 return t.Gather(s, position.xy / size, offset);
19692 #endif
19693 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
19694 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19695 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19696 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19697 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
19698 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
19699 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
19700 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
19701 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
19702 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
19703 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
19704 0x00000000, 0x0100003e,
19706 static const struct vec4 texture_data[] =
19708 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
19709 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
19710 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
19711 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
19713 static const struct vec4 expected_gather4[] =
19715 {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},
19716 {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},
19717 {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},
19718 {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},
19720 static const struct vec4 expected_gather4_offset[] =
19722 {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},
19723 {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},
19724 {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},
19725 {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},
19727 static const struct vec4 expected_gather4_green[] =
19729 {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},
19730 {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},
19731 {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},
19732 {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},
19734 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
19735 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
19737 if (!init_test_context(&test_context, NULL))
19738 return;
19740 device = test_context.device;
19741 context = test_context.immediate_context;
19743 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
19745 skip("Shader model 4.1 required for gather4 instruction.\n");
19746 release_test_context(&test_context);
19747 return;
19750 texture_desc.Width = 4;
19751 texture_desc.Height = 4;
19752 texture_desc.MipLevels = 1;
19753 texture_desc.ArraySize = 1;
19754 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19755 texture_desc.SampleDesc.Count = 1;
19756 texture_desc.SampleDesc.Quality = 0;
19757 texture_desc.Usage = D3D11_USAGE_DEFAULT;
19758 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
19759 texture_desc.CPUAccessFlags = 0;
19760 texture_desc.MiscFlags = 0;
19761 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
19762 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19763 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
19764 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19765 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19767 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
19768 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
19769 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19770 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
19771 ok(SUCCEEDED(hr), "Fialed to create shader resource view, hr %#x.\n", hr);
19772 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
19774 constant.width = texture_desc.Width;
19775 constant.height = texture_desc.Height;
19776 constant.offset_x = 1;
19777 constant.offset_y = 1;
19778 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
19779 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
19781 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
19782 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19783 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19785 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
19786 draw_quad(&test_context);
19787 get_texture_readback(rt, 0, &rb);
19788 for (y = 0; y < texture_desc.Height; ++y)
19790 for (x = 0; x < texture_desc.Width; ++x)
19792 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
19793 const struct vec4 *got = get_readback_vec4(&rb, x, y);
19794 ok(compare_vec4(got, expected, 0),
19795 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
19796 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
19799 release_resource_readback(&rb);
19801 ID3D11PixelShader_Release(ps);
19802 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
19803 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19804 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19806 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
19807 draw_quad(&test_context);
19808 get_texture_readback(rt, 0, &rb);
19809 for (y = 0; y < texture_desc.Height; ++y)
19811 for (x = 0; x < texture_desc.Width; ++x)
19813 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
19814 const struct vec4 *got = get_readback_vec4(&rb, x, y);
19815 ok(compare_vec4(got, expected, 0),
19816 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
19817 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
19820 release_resource_readback(&rb);
19822 ID3D11PixelShader_Release(ps);
19824 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
19826 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
19827 goto done;
19830 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
19831 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19832 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19834 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
19835 draw_quad(&test_context);
19836 get_texture_readback(rt, 0, &rb);
19837 for (y = 0; y < texture_desc.Height; ++y)
19839 for (x = 0; x < texture_desc.Width; ++x)
19841 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
19842 const struct vec4 *got = get_readback_vec4(&rb, x, y);
19843 ok(compare_vec4(got, expected, 0),
19844 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
19845 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
19848 release_resource_readback(&rb);
19850 ID3D11PixelShader_Release(ps);
19851 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
19852 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19853 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19855 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
19856 draw_quad(&test_context);
19857 get_texture_readback(rt, 0, &rb);
19858 for (y = 0; y < texture_desc.Height; ++y)
19860 for (x = 0; x < texture_desc.Width; ++x)
19862 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
19863 const struct vec4 *got = get_readback_vec4(&rb, x, y);
19864 ok(compare_vec4(got, expected, 0),
19865 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
19866 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
19869 release_resource_readback(&rb);
19871 constant.offset_x = 0;
19872 constant.offset_y = 0;
19873 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
19874 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
19875 draw_quad(&test_context);
19876 get_texture_readback(rt, 0, &rb);
19877 for (y = 0; y < texture_desc.Height; ++y)
19879 for (x = 0; x < texture_desc.Width; ++x)
19881 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
19882 const struct vec4 *got = get_readback_vec4(&rb, x, y);
19883 ok(compare_vec4(got, expected, 0),
19884 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
19885 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
19888 release_resource_readback(&rb);
19890 ID3D11PixelShader_Release(ps);
19892 done:
19893 ID3D11Buffer_Release(cb);
19894 ID3D11Texture2D_Release(rt);
19895 ID3D11Texture2D_Release(texture);
19896 ID3D11RenderTargetView_Release(rtv);
19897 ID3D11ShaderResourceView_Release(srv);
19898 release_test_context(&test_context);
19901 static void test_gather_c(void)
19903 struct
19905 int width, height;
19906 int offset_x, offset_y;
19907 float compare_value;
19908 int padding[3];
19909 } constant;
19910 struct d3d11_test_context test_context;
19911 D3D11_TEXTURE2D_DESC texture_desc;
19912 D3D11_SAMPLER_DESC sampler_desc;
19913 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
19914 ID3D11ShaderResourceView *srv;
19915 ID3D11Texture2D *texture, *rt;
19916 ID3D11DeviceContext *context;
19917 ID3D11SamplerState *sampler;
19918 ID3D11RenderTargetView *rtv;
19919 struct resource_readback rb;
19920 ID3D11PixelShader *ps;
19921 ID3D11Device *device;
19922 unsigned int x, y;
19923 ID3D11Buffer *cb;
19924 HRESULT hr;
19926 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19927 static const DWORD gather4_c_code[] =
19929 #if 0
19930 SamplerComparisonState s;
19931 Texture2D<float4> t;
19933 int2 size;
19934 int2 offset;
19935 float compare;
19937 float4 main(float4 position : SV_Position) : SV_Target
19939 return t.GatherCmp(s, position.xy / size, compare);
19941 #endif
19942 0x43425844, 0xd3d04479, 0x901e9208, 0x7074fd0c, 0xbcadb2da, 0x00000001, 0x00000168, 0x00000003,
19943 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19944 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19945 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19946 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
19947 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
19948 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
19949 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
19950 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
19951 0x00000000, 0x00100046, 0x00000000, 0x8e00007e, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
19952 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0020800a, 0x00000000,
19953 0x00000001, 0x0100003e,
19955 static const DWORD gather4_po_c_code[] =
19957 #if 0
19958 SamplerComparisonState s;
19959 Texture2D<float4> t;
19961 int2 size;
19962 int2 offset;
19963 float compare;
19965 float4 main(float4 position : SV_Position) : SV_Target
19967 return t.GatherCmp(s, position.xy / size, compare, offset);
19969 #endif
19970 0x43425844, 0x501de13e, 0x472d2d20, 0x6df0fee4, 0xef27d9e6, 0x00000001, 0x00000174, 0x00000003,
19971 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19972 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19973 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19974 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d8, 0x00000050,
19975 0x00000036, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
19976 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
19977 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
19978 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
19979 0x00000000, 0x00100046, 0x00000000, 0x91000080, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
19980 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
19981 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
19983 static const float texture_data[] =
19985 0.00f, 0.10f, 0.20f, 0.30f,
19986 0.40f, 0.50f, 0.60f, 0.70f,
19987 0.80f, 0.90f, 0.05f, 0.15f,
19988 0.25f, 0.35f, 0.45f, 0.55f,
19990 static const struct vec4 expected_gather4_c[] =
19992 {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},
19993 {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},
19994 {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},
19995 {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},
19997 static const struct vec4 expected_gather4_po_c[] =
19999 {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},
20000 {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},
20001 {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},
20002 {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},
20004 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
20005 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
20007 if (!init_test_context(&test_context, &feature_level))
20008 return;
20010 device = test_context.device;
20011 context = test_context.immediate_context;
20013 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
20014 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
20015 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
20016 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
20017 sampler_desc.MipLODBias = 0.0f;
20018 sampler_desc.MaxAnisotropy = 0;
20019 sampler_desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
20020 sampler_desc.BorderColor[0] = 0.0f;
20021 sampler_desc.BorderColor[1] = 0.0f;
20022 sampler_desc.BorderColor[2] = 0.0f;
20023 sampler_desc.BorderColor[3] = 0.0f;
20024 sampler_desc.MinLOD = 0.0f;
20025 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
20027 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
20028 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
20029 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
20031 texture_desc.Width = 4;
20032 texture_desc.Height = 4;
20033 texture_desc.MipLevels = 1;
20034 texture_desc.ArraySize = 1;
20035 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
20036 texture_desc.SampleDesc.Count = 1;
20037 texture_desc.SampleDesc.Quality = 0;
20038 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20039 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
20040 texture_desc.CPUAccessFlags = 0;
20041 texture_desc.MiscFlags = 0;
20042 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
20043 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20044 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
20045 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
20046 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
20048 constant.width = texture_desc.Width;
20049 constant.height = texture_desc.Height;
20050 constant.offset_x = 1;
20051 constant.offset_y = 1;
20052 constant.compare_value = 0.5f;
20053 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
20054 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
20056 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
20057 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
20058 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
20059 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20061 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
20062 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
20063 U(srv_desc).Texture2D.MostDetailedMip = 0;
20064 U(srv_desc).Texture2D.MipLevels = 1;
20065 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
20066 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
20067 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
20069 hr = ID3D11Device_CreatePixelShader(device, gather4_c_code, sizeof(gather4_c_code), NULL, &ps);
20070 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20071 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20073 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
20074 draw_quad(&test_context);
20075 get_texture_readback(rt, 0, &rb);
20076 for (y = 0; y < texture_desc.Height; ++y)
20078 for (x = 0; x < texture_desc.Width; ++x)
20080 const struct vec4 *expected = &expected_gather4_c[y * texture_desc.Width + x];
20081 const struct vec4 *got = get_readback_vec4(&rb, x, y);
20082 ok(compare_vec4(got, expected, 0),
20083 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
20084 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
20087 release_resource_readback(&rb);
20088 ID3D11PixelShader_Release(ps);
20090 hr = ID3D11Device_CreatePixelShader(device, gather4_po_c_code, sizeof(gather4_po_c_code), NULL, &ps);
20091 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20092 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20094 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
20095 draw_quad(&test_context);
20096 get_texture_readback(rt, 0, &rb);
20097 for (y = 0; y < texture_desc.Height; ++y)
20099 for (x = 0; x < texture_desc.Width; ++x)
20101 const struct vec4 *expected = &expected_gather4_po_c[y * texture_desc.Width + x];
20102 const struct vec4 *got = get_readback_vec4(&rb, x, y);
20103 ok(compare_vec4(got, expected, 0),
20104 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
20105 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
20108 release_resource_readback(&rb);
20109 ID3D11PixelShader_Release(ps);
20111 ID3D11ShaderResourceView_Release(srv);
20112 ID3D11Texture2D_Release(texture);
20114 ID3D11Buffer_Release(cb);
20115 ID3D11Texture2D_Release(rt);
20116 ID3D11RenderTargetView_Release(rtv);
20117 ID3D11SamplerState_Release(sampler);
20118 release_test_context(&test_context);
20121 static void test_fractional_viewports(void)
20123 struct d3d11_test_context test_context;
20124 D3D11_TEXTURE2D_DESC texture_desc;
20125 ID3D11InputLayout *input_layout;
20126 ID3D11DeviceContext *context;
20127 struct resource_readback rb;
20128 ID3D11RenderTargetView *rtv;
20129 ID3D11VertexShader *vs;
20130 ID3D11PixelShader *ps;
20131 unsigned int i, x, y;
20132 ID3D11Device *device;
20133 ID3D11Texture2D *rt;
20134 UINT offset, stride;
20135 D3D11_VIEWPORT vp;
20136 ID3D11Buffer *vb;
20137 HRESULT hr;
20139 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20140 static const DWORD vs_code[] =
20142 #if 0
20143 void main(in float4 in_position : POSITION,
20144 in float2 in_texcoord : TEXCOORD,
20145 out float4 position : SV_Position,
20146 out float2 texcoord : TEXCOORD)
20148 position = in_position;
20149 texcoord = in_texcoord;
20151 #endif
20152 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
20153 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20154 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
20155 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
20156 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
20157 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
20158 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
20159 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
20160 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
20161 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
20162 0x00000001, 0x0100003e,
20164 static const DWORD ps_code[] =
20166 #if 0
20167 float4 main(float4 position : SV_Position,
20168 float2 texcoord : TEXCOORD) : SV_Target
20170 return float4(position.xy, texcoord);
20172 #endif
20173 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
20174 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
20175 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
20176 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
20177 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20178 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
20179 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
20180 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
20181 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
20183 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
20185 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
20186 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
20188 static const struct
20190 struct vec2 position;
20191 struct vec2 texcoord;
20193 quad[] =
20195 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
20196 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
20197 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
20198 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
20200 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
20201 static const float viewport_offsets[] =
20203 0.0f, 0.5f, 0.25f, 0.125f, 0.0625f, 0.03125f, 0.015625f, 0.0078125f, 0.00390625f,
20204 1.0f / 128.0f, 63.0f / 128.0f,
20207 if (!init_test_context(&test_context, &feature_level))
20208 return;
20209 device = test_context.device;
20210 context = test_context.immediate_context;
20212 texture_desc.Width = 4;
20213 texture_desc.Height = 4;
20214 texture_desc.MipLevels = 1;
20215 texture_desc.ArraySize = 1;
20216 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
20217 texture_desc.SampleDesc.Count = 1;
20218 texture_desc.SampleDesc.Quality = 0;
20219 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20220 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
20221 texture_desc.CPUAccessFlags = 0;
20222 texture_desc.MiscFlags = 0;
20223 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
20224 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20225 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
20226 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
20227 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
20229 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
20230 vs_code, sizeof(vs_code), &input_layout);
20231 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
20232 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
20234 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
20235 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
20236 stride = sizeof(*quad);
20237 offset = 0;
20238 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
20240 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
20241 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
20242 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
20244 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20245 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20246 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20248 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
20250 vp.TopLeftX = viewport_offsets[i];
20251 vp.TopLeftY = viewport_offsets[i];
20252 vp.Width = texture_desc.Width;
20253 vp.Height = texture_desc.Height;
20254 vp.MinDepth = 0.0f;
20255 vp.MaxDepth = 1.0f;
20256 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
20257 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
20258 ID3D11DeviceContext_Draw(context, 4, 0);
20259 get_texture_readback(rt, 0, &rb);
20260 for (y = 0; y < texture_desc.Height; ++y)
20262 for (x = 0; x < texture_desc.Width; ++x)
20264 const struct vec4 *v = get_readback_vec4(&rb, x, y);
20265 struct vec4 expected = {x + 0.5f, y + 0.5f,
20266 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
20267 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
20268 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
20269 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
20270 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
20271 todo_wine
20272 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
20273 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
20274 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
20277 release_resource_readback(&rb);
20280 ID3D11InputLayout_Release(input_layout);
20281 ID3D11Buffer_Release(vb);
20282 ID3D11VertexShader_Release(vs);
20283 ID3D11PixelShader_Release(ps);
20284 ID3D11RenderTargetView_Release(rtv);
20285 ID3D11Texture2D_Release(rt);
20286 release_test_context(&test_context);
20289 START_TEST(d3d11)
20291 test_create_device();
20292 run_for_each_feature_level(test_device_interfaces);
20293 test_get_immediate_context();
20294 test_create_texture2d();
20295 test_texture2d_interfaces();
20296 test_create_texture3d();
20297 test_texture3d_interfaces();
20298 test_create_buffer();
20299 test_create_depthstencil_view();
20300 test_depthstencil_view_interfaces();
20301 test_create_rendertarget_view();
20302 test_create_shader_resource_view();
20303 run_for_each_feature_level(test_create_shader);
20304 test_create_sampler_state();
20305 test_create_blend_state();
20306 test_create_depthstencil_state();
20307 test_create_rasterizer_state();
20308 test_create_query();
20309 test_occlusion_query();
20310 test_timestamp_query();
20311 test_device_removed_reason();
20312 test_private_data();
20313 run_for_each_feature_level(test_state_refcounting);
20314 test_device_context_state();
20315 test_blend();
20316 test_texture();
20317 test_cube_maps();
20318 test_depth_stencil_sampling();
20319 test_multiple_render_targets();
20320 test_render_target_views();
20321 test_layered_rendering();
20322 test_scissor();
20323 test_clear_state();
20324 test_il_append_aligned();
20325 test_fragment_coords();
20326 test_update_subresource();
20327 test_copy_subresource_region();
20328 test_resource_map();
20329 test_check_multisample_quality_levels();
20330 run_for_each_feature_level(test_swapchain_formats);
20331 test_swapchain_views();
20332 test_swapchain_flip();
20333 test_clear_render_target_view();
20334 test_clear_depth_stencil_view();
20335 test_clear_buffer_unordered_access_view();
20336 test_draw_depth_only();
20337 test_draw_uav_only();
20338 test_cb_relative_addressing();
20339 test_getdc();
20340 test_shader_stage_input_output_matching();
20341 test_sm4_if_instruction();
20342 test_sm4_breakc_instruction();
20343 test_sm4_continuec_instruction();
20344 test_create_input_layout();
20345 test_input_assembler();
20346 test_null_sampler();
20347 test_check_feature_support();
20348 test_create_unordered_access_view();
20349 test_immediate_constant_buffer();
20350 test_fp_specials();
20351 test_uint_shader_instructions();
20352 test_index_buffer_offset();
20353 test_face_culling();
20354 test_line_antialiasing_blending();
20355 run_for_each_feature_level(test_required_format_support);
20356 run_for_each_9_x_feature_level(test_fl9_draw);
20357 test_ddy();
20358 test_shader_input_registers_limits();
20359 test_unbind_shader_resource_view();
20360 test_stencil_separate();
20361 test_uav_load();
20362 test_cs_uav_store();
20363 test_ps_cs_uav_binding();
20364 test_atomic_instructions();
20365 test_sm4_ret_instruction();
20366 test_primitive_restart();
20367 test_resinfo_instruction();
20368 test_sm5_bufinfo_instruction();
20369 test_render_target_device_mismatch();
20370 test_buffer_srv();
20371 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
20372 test_unaligned_raw_buffer_access);
20373 test_uav_counters();
20374 test_compute_shader_registers();
20375 test_tgsm();
20376 test_geometry_shader();
20377 test_quad_tessellation();
20378 test_stream_output();
20379 test_fl10_stream_output_desc();
20380 test_stream_output_resume();
20381 test_gather();
20382 test_gather_c();
20383 test_fractional_viewports();