d3d11/tests: Do not recreate SO buffer in test_quad_tessellation().
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob895225df3a36b1ef4db659ea8626838fae251c02
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},
1772 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1773 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1774 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1777 if (!(device = create_device(NULL)))
1779 skip("Failed to create device.\n");
1780 return;
1783 feature_level = ID3D11Device_GetFeatureLevel(device);
1785 desc.Width = 512;
1786 desc.Height = 512;
1787 desc.MipLevels = 1;
1788 desc.ArraySize = 1;
1789 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1790 desc.SampleDesc.Count = 1;
1791 desc.SampleDesc.Quality = 0;
1792 desc.Usage = D3D11_USAGE_DEFAULT;
1793 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1794 desc.CPUAccessFlags = 0;
1795 desc.MiscFlags = 0;
1797 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
1798 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1800 expected_refcount = get_refcount(device) + 1;
1801 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1802 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1803 refcount = get_refcount(device);
1804 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1805 tmp = NULL;
1806 expected_refcount = refcount + 1;
1807 ID3D11Texture2D_GetDevice(texture, &tmp);
1808 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1809 refcount = get_refcount(device);
1810 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1811 ID3D11Device_Release(tmp);
1813 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1814 ID3D11Texture2D_Release(texture);
1816 desc.MipLevels = 0;
1817 expected_refcount = get_refcount(device) + 1;
1818 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1819 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1820 refcount = get_refcount(device);
1821 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1822 tmp = NULL;
1823 expected_refcount = refcount + 1;
1824 ID3D11Texture2D_GetDevice(texture, &tmp);
1825 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1826 refcount = get_refcount(device);
1827 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1828 ID3D11Device_Release(tmp);
1830 ID3D11Texture2D_GetDesc(texture, &desc);
1831 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1832 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1833 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1834 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1835 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1836 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1837 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1838 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1839 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1840 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1841 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1843 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1844 ID3D11Texture2D_Release(texture);
1846 desc.MipLevels = 1;
1847 desc.ArraySize = 2;
1848 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1849 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1851 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1852 ID3D11Texture2D_Release(texture);
1854 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1855 desc.ArraySize = 1;
1856 desc.SampleDesc.Count = 2;
1857 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1858 if (quality_level_count)
1860 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1861 ID3D11Texture2D_Release(texture);
1862 desc.SampleDesc.Quality = quality_level_count;
1863 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1865 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1867 /* We assume 15 samples multisampling is never supported in practice. */
1868 desc.SampleDesc.Count = 15;
1869 desc.SampleDesc.Quality = 0;
1870 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1871 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1873 desc.SampleDesc.Count = 1;
1874 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1876 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
1877 BOOL todo = tests[i].todo;
1879 if (feature_level < D3D_FEATURE_LEVEL_10_1
1880 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
1881 && tests[i].array_size > 6)
1883 expected_hr = E_INVALIDARG;
1884 todo = TRUE;
1887 desc.ArraySize = tests[i].array_size;
1888 desc.Format = tests[i].format;
1889 desc.BindFlags = tests[i].bind_flags;
1890 desc.MiscFlags = tests[i].misc_flags;
1891 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, (ID3D11Texture2D **)&texture);
1893 todo_wine_if(todo)
1894 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
1895 i, hr, desc.Format);
1897 if (SUCCEEDED(hr))
1898 ID3D11Texture2D_Release(texture);
1901 refcount = ID3D11Device_Release(device);
1902 ok(!refcount, "Device has %u references left.\n", refcount);
1905 static void test_texture2d_interfaces(void)
1907 ID3D10Texture2D *d3d10_texture;
1908 D3D11_TEXTURE2D_DESC desc;
1909 ID3D11Texture2D *texture;
1910 ID3D11Device *device;
1911 unsigned int i;
1912 ULONG refcount;
1913 HRESULT hr;
1915 static const struct test
1917 BOOL implements_d3d10_interfaces;
1918 UINT bind_flags;
1919 UINT misc_flags;
1920 UINT expected_bind_flags;
1921 UINT expected_misc_flags;
1923 desc_conversion_tests[] =
1926 TRUE,
1927 D3D11_BIND_SHADER_RESOURCE, 0,
1928 D3D10_BIND_SHADER_RESOURCE, 0
1931 TRUE,
1932 D3D11_BIND_UNORDERED_ACCESS, 0,
1933 D3D11_BIND_UNORDERED_ACCESS, 0
1936 FALSE,
1937 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1938 0, 0
1941 TRUE,
1942 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
1943 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1946 TRUE,
1947 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
1948 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1952 if (!(device = create_device(NULL)))
1954 skip("Failed to create ID3D11Device, skipping tests.\n");
1955 return;
1958 desc.Width = 512;
1959 desc.Height = 512;
1960 desc.MipLevels = 0;
1961 desc.ArraySize = 1;
1962 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1963 desc.SampleDesc.Count = 1;
1964 desc.SampleDesc.Quality = 0;
1965 desc.Usage = D3D11_USAGE_DEFAULT;
1966 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1967 desc.CPUAccessFlags = 0;
1968 desc.MiscFlags = 0;
1970 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1971 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1972 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1973 hr = check_interface(texture, &IID_ID3D10Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
1974 ID3D11Texture2D_Release(texture);
1975 if (FAILED(hr))
1977 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
1978 ID3D11Device_Release(device);
1979 return;
1982 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
1984 const struct test *current = &desc_conversion_tests[i];
1985 D3D10_TEXTURE2D_DESC d3d10_desc;
1986 ID3D10Device *d3d10_device;
1988 desc.Width = 512;
1989 desc.Height = 512;
1990 desc.MipLevels = 1;
1991 desc.ArraySize = 1;
1992 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1993 desc.SampleDesc.Count = 1;
1994 desc.SampleDesc.Quality = 0;
1995 desc.Usage = D3D11_USAGE_DEFAULT;
1996 desc.BindFlags = current->bind_flags;
1997 desc.CPUAccessFlags = 0;
1998 desc.MiscFlags = current->misc_flags;
2000 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2001 /* Shared resources are not supported by REF and WARP devices. */
2002 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2003 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2004 if (FAILED(hr))
2006 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
2007 continue;
2010 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2012 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2013 ID3D11Texture2D_Release(texture);
2015 if (current->implements_d3d10_interfaces)
2017 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2019 else
2021 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2022 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
2023 continue;
2026 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
2028 ok(d3d10_desc.Width == desc.Width,
2029 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2030 ok(d3d10_desc.Height == desc.Height,
2031 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2032 ok(d3d10_desc.MipLevels == desc.MipLevels,
2033 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2034 ok(d3d10_desc.ArraySize == desc.ArraySize,
2035 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2036 ok(d3d10_desc.Format == desc.Format,
2037 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2038 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
2039 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
2040 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2041 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
2042 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2043 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2044 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2045 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2046 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2047 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2048 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2049 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2051 d3d10_device = (ID3D10Device *)0xdeadbeef;
2052 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
2053 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2054 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2056 ID3D10Texture2D_Release(d3d10_texture);
2059 refcount = ID3D11Device_Release(device);
2060 ok(!refcount, "Device has %u references left.\n", refcount);
2063 static void test_create_texture3d(void)
2065 ULONG refcount, expected_refcount;
2066 D3D11_SUBRESOURCE_DATA data = {0};
2067 ID3D11Device *device, *tmp;
2068 D3D11_TEXTURE3D_DESC desc;
2069 ID3D11Texture3D *texture;
2070 unsigned int i;
2071 HRESULT hr;
2073 static const struct
2075 DXGI_FORMAT format;
2076 D3D11_BIND_FLAG bind_flags;
2077 BOOL succeeds;
2078 BOOL todo;
2080 tests[] =
2082 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
2083 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
2084 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2085 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2086 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2087 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2088 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2089 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2090 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2091 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2092 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2093 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2096 if (!(device = create_device(NULL)))
2098 skip("Failed to create ID3D11Device, skipping tests.\n");
2099 return;
2102 desc.Width = 64;
2103 desc.Height = 64;
2104 desc.Depth = 64;
2105 desc.MipLevels = 1;
2106 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2107 desc.Usage = D3D11_USAGE_DEFAULT;
2108 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2109 desc.CPUAccessFlags = 0;
2110 desc.MiscFlags = 0;
2112 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2113 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2115 expected_refcount = get_refcount(device) + 1;
2116 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2117 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2118 refcount = get_refcount(device);
2119 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2120 tmp = NULL;
2121 expected_refcount = refcount + 1;
2122 ID3D11Texture3D_GetDevice(texture, &tmp);
2123 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2124 refcount = get_refcount(device);
2125 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2126 ID3D11Device_Release(tmp);
2128 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2129 ID3D11Texture3D_Release(texture);
2131 desc.MipLevels = 0;
2132 expected_refcount = get_refcount(device) + 1;
2133 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2134 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2135 refcount = get_refcount(device);
2136 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2137 tmp = NULL;
2138 expected_refcount = refcount + 1;
2139 ID3D11Texture3D_GetDevice(texture, &tmp);
2140 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2141 refcount = get_refcount(device);
2142 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2143 ID3D11Device_Release(tmp);
2145 ID3D11Texture3D_GetDesc(texture, &desc);
2146 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2147 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2148 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2149 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2150 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2151 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2152 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2153 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2154 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2156 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2157 ID3D11Texture3D_Release(texture);
2159 desc.MipLevels = 1;
2160 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2162 desc.Format = tests[i].format;
2163 desc.BindFlags = tests[i].bind_flags;
2164 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, (ID3D11Texture3D **)&texture);
2166 todo_wine_if(tests[i].todo)
2167 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2169 if (SUCCEEDED(hr))
2170 ID3D11Texture3D_Release(texture);
2173 refcount = ID3D11Device_Release(device);
2174 ok(!refcount, "Device has %u references left.\n", refcount);
2177 static void test_texture3d_interfaces(void)
2179 ID3D10Texture3D *d3d10_texture;
2180 D3D11_TEXTURE3D_DESC desc;
2181 ID3D11Texture3D *texture;
2182 ID3D11Device *device;
2183 unsigned int i;
2184 ULONG refcount;
2185 HRESULT hr;
2187 static const struct test
2189 BOOL implements_d3d10_interfaces;
2190 UINT bind_flags;
2191 UINT misc_flags;
2192 UINT expected_bind_flags;
2193 UINT expected_misc_flags;
2195 desc_conversion_tests[] =
2198 TRUE,
2199 D3D11_BIND_SHADER_RESOURCE, 0,
2200 D3D10_BIND_SHADER_RESOURCE, 0
2203 TRUE,
2204 D3D11_BIND_UNORDERED_ACCESS, 0,
2205 D3D11_BIND_UNORDERED_ACCESS, 0
2208 FALSE,
2209 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2210 0, 0
2213 TRUE,
2214 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2215 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2219 if (!(device = create_device(NULL)))
2221 skip("Failed to create ID3D11Device.\n");
2222 return;
2225 desc.Width = 64;
2226 desc.Height = 64;
2227 desc.Depth = 64;
2228 desc.MipLevels = 0;
2229 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2230 desc.Usage = D3D11_USAGE_DEFAULT;
2231 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2232 desc.CPUAccessFlags = 0;
2233 desc.MiscFlags = 0;
2235 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2236 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2237 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2238 hr = check_interface(texture, &IID_ID3D10Texture3D, TRUE, TRUE); /* Not available on all Windows versions. */
2239 ID3D11Texture3D_Release(texture);
2240 if (FAILED(hr))
2242 win_skip("3D textures do not implement ID3D10Texture3D.\n");
2243 ID3D11Device_Release(device);
2244 return;
2247 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2249 const struct test *current = &desc_conversion_tests[i];
2250 D3D10_TEXTURE3D_DESC d3d10_desc;
2251 ID3D10Device *d3d10_device;
2253 desc.Width = 64;
2254 desc.Height = 64;
2255 desc.Depth = 64;
2256 desc.MipLevels = 1;
2257 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2258 desc.Usage = D3D11_USAGE_DEFAULT;
2259 desc.BindFlags = current->bind_flags;
2260 desc.CPUAccessFlags = 0;
2261 desc.MiscFlags = current->misc_flags;
2263 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2264 /* Shared resources are not supported by REF and WARP devices. */
2265 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2266 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
2267 if (FAILED(hr))
2269 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
2270 continue;
2273 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2275 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2276 ID3D11Texture3D_Release(texture);
2278 if (current->implements_d3d10_interfaces)
2280 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
2282 else
2284 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
2285 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2286 continue;
2289 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
2291 ok(d3d10_desc.Width == desc.Width,
2292 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2293 ok(d3d10_desc.Height == desc.Height,
2294 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2295 ok(d3d10_desc.Depth == desc.Depth,
2296 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
2297 ok(d3d10_desc.MipLevels == desc.MipLevels,
2298 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2299 ok(d3d10_desc.Format == desc.Format,
2300 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2301 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2302 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2303 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2304 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2305 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2306 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2307 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2308 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2310 d3d10_device = (ID3D10Device *)0xdeadbeef;
2311 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
2312 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2313 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2315 ID3D10Texture3D_Release(d3d10_texture);
2318 refcount = ID3D11Device_Release(device);
2319 ok(!refcount, "Device has %u references left.\n", refcount);
2322 static void test_create_buffer(void)
2324 ID3D10Buffer *d3d10_buffer;
2325 HRESULT expected_hr, hr;
2326 D3D11_BUFFER_DESC desc;
2327 ID3D11Buffer *buffer;
2328 ID3D11Device *device;
2329 unsigned int i;
2330 ULONG refcount;
2332 static const struct test
2334 BOOL succeeds;
2335 BOOL implements_d3d10_interfaces;
2336 UINT bind_flags;
2337 UINT misc_flags;
2338 UINT structure_stride;
2339 UINT expected_bind_flags;
2340 UINT expected_misc_flags;
2342 tests[] =
2345 TRUE, TRUE,
2346 D3D11_BIND_VERTEX_BUFFER, 0, 0,
2347 D3D10_BIND_VERTEX_BUFFER, 0
2350 TRUE, TRUE,
2351 D3D11_BIND_INDEX_BUFFER, 0, 0,
2352 D3D10_BIND_INDEX_BUFFER, 0
2355 TRUE, TRUE,
2356 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
2357 D3D10_BIND_CONSTANT_BUFFER, 0
2360 TRUE, TRUE,
2361 D3D11_BIND_SHADER_RESOURCE, 0, 0,
2362 D3D10_BIND_SHADER_RESOURCE, 0
2365 TRUE, TRUE,
2366 D3D11_BIND_STREAM_OUTPUT, 0, 0,
2367 D3D10_BIND_STREAM_OUTPUT, 0
2370 TRUE, TRUE,
2371 D3D11_BIND_RENDER_TARGET, 0, 0,
2372 D3D10_BIND_RENDER_TARGET, 0
2375 TRUE, TRUE,
2376 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
2377 D3D11_BIND_UNORDERED_ACCESS, 0
2380 TRUE, TRUE,
2381 0, D3D11_RESOURCE_MISC_SHARED, 0,
2382 0, D3D10_RESOURCE_MISC_SHARED
2385 TRUE, TRUE,
2386 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
2387 0, 0
2390 FALSE, FALSE,
2391 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2394 FALSE, FALSE,
2395 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2398 FALSE, FALSE,
2399 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2402 TRUE, TRUE,
2403 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2404 D3D10_BIND_SHADER_RESOURCE, 0
2407 FALSE, FALSE,
2408 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2411 FALSE, FALSE,
2412 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2415 TRUE, TRUE,
2416 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2417 D3D11_BIND_UNORDERED_ACCESS, 0
2420 FALSE, FALSE,
2421 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2423 /* Structured buffers do not implement ID3D10Buffer. */
2425 TRUE, FALSE,
2426 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2429 TRUE, FALSE,
2430 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2433 FALSE, FALSE,
2434 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
2437 FALSE, FALSE,
2438 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
2441 FALSE, FALSE,
2442 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
2445 FALSE, FALSE,
2446 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
2449 FALSE, FALSE,
2450 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
2453 TRUE, FALSE,
2454 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
2457 FALSE, FALSE,
2458 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
2461 TRUE, FALSE,
2462 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
2465 TRUE, FALSE,
2466 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
2469 FALSE, FALSE,
2470 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
2473 TRUE, FALSE,
2474 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
2477 TRUE, TRUE,
2478 0, 0, 513,
2479 0, 0
2482 TRUE, TRUE,
2483 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
2484 D3D10_BIND_CONSTANT_BUFFER, 0
2487 TRUE, TRUE,
2488 D3D11_BIND_SHADER_RESOURCE, 0, 513,
2489 D3D10_BIND_SHADER_RESOURCE, 0
2492 TRUE, TRUE,
2493 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
2494 D3D11_BIND_UNORDERED_ACCESS, 0
2497 FALSE, FALSE,
2498 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2501 FALSE, FALSE,
2502 D3D11_BIND_SHADER_RESOURCE,
2503 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2506 TRUE, TRUE,
2507 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
2508 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2512 if (!(device = create_device(NULL)))
2514 skip("Failed to create ID3D11Device.\n");
2515 return;
2518 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
2519 hr = check_interface(buffer, &IID_ID3D10Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
2520 ID3D11Buffer_Release(buffer);
2521 if (FAILED(hr))
2523 win_skip("Buffers do not implement ID3D10Buffer.\n");
2524 ID3D11Device_Release(device);
2525 return;
2528 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2530 const struct test *current = &tests[i];
2531 D3D11_BUFFER_DESC obtained_desc;
2532 D3D10_BUFFER_DESC d3d10_desc;
2533 ID3D10Device *d3d10_device;
2535 desc.ByteWidth = 1024;
2536 desc.Usage = D3D11_USAGE_DEFAULT;
2537 desc.BindFlags = current->bind_flags;
2538 desc.CPUAccessFlags = 0;
2539 desc.MiscFlags = current->misc_flags;
2540 desc.StructureByteStride = current->structure_stride;
2542 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2543 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
2544 /* Shared resources are not supported by REF and WARP devices. */
2545 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
2546 i, hr, expected_hr);
2547 if (FAILED(hr))
2549 if (hr == E_OUTOFMEMORY)
2550 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2551 continue;
2554 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
2555 desc.StructureByteStride = 0;
2557 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
2559 ok(obtained_desc.ByteWidth == desc.ByteWidth,
2560 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
2561 ok(obtained_desc.Usage == desc.Usage,
2562 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
2563 ok(obtained_desc.BindFlags == desc.BindFlags,
2564 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
2565 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
2566 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
2567 ok(obtained_desc.MiscFlags == desc.MiscFlags,
2568 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
2569 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
2570 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
2572 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2573 ID3D11Buffer_Release(buffer);
2575 if (current->implements_d3d10_interfaces)
2577 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
2579 else
2581 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
2582 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2583 continue;
2586 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
2588 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
2589 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
2590 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2591 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2592 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2593 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2594 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2595 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2596 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2597 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2599 d3d10_device = (ID3D10Device *)0xdeadbeef;
2600 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
2601 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2602 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2604 ID3D10Buffer_Release(d3d10_buffer);
2607 memset(&desc, 0, sizeof(desc));
2608 desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
2609 for (i = 0; i <= 32; ++i)
2611 desc.ByteWidth = i;
2612 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
2613 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2614 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
2615 if (SUCCEEDED(hr))
2616 ID3D11Buffer_Release(buffer);
2619 refcount = ID3D11Device_Release(device);
2620 ok(!refcount, "Device has %u references left.\n", refcount);
2623 static void test_create_depthstencil_view(void)
2625 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2626 D3D11_TEXTURE2D_DESC texture_desc;
2627 ULONG refcount, expected_refcount;
2628 ID3D11DepthStencilView *dsview;
2629 ID3D11Device *device, *tmp;
2630 ID3D11Texture2D *texture;
2631 unsigned int i;
2632 HRESULT hr;
2634 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2635 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2636 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2637 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
2638 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
2639 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
2640 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
2641 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
2642 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
2643 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
2644 static const struct
2646 struct
2648 unsigned int miplevel_count;
2649 unsigned int array_size;
2650 DXGI_FORMAT format;
2651 } texture;
2652 struct dsv_desc dsv_desc;
2653 struct dsv_desc expected_dsv_desc;
2655 tests[] =
2657 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2658 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2659 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2660 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2661 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2662 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2663 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2664 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2665 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2666 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2667 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2668 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2669 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2670 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2671 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2672 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2673 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2674 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2675 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2676 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2677 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2678 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2679 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2680 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2681 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2682 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2683 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2685 static const struct
2687 struct
2689 unsigned int miplevel_count;
2690 unsigned int array_size;
2691 DXGI_FORMAT format;
2692 } texture;
2693 struct dsv_desc dsv_desc;
2695 invalid_desc_tests[] =
2697 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2698 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2699 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2700 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2701 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2702 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2703 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2704 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2705 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2706 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2707 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2708 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2709 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2711 #undef FMT_UNKNOWN
2712 #undef D24S8
2713 #undef R24S8_TL
2714 #undef DIM_UNKNOWN
2715 #undef TEX_1D
2716 #undef TEX_1D_ARRAY
2717 #undef TEX_2D
2718 #undef TEX_2D_ARRAY
2719 #undef TEX_2DMS
2720 #undef TEX_2DMS_ARR
2722 if (!(device = create_device(NULL)))
2724 skip("Failed to create device.\n");
2725 return;
2728 texture_desc.Width = 512;
2729 texture_desc.Height = 512;
2730 texture_desc.MipLevels = 1;
2731 texture_desc.ArraySize = 1;
2732 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2733 texture_desc.SampleDesc.Count = 1;
2734 texture_desc.SampleDesc.Quality = 0;
2735 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2736 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2737 texture_desc.CPUAccessFlags = 0;
2738 texture_desc.MiscFlags = 0;
2740 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2741 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2743 expected_refcount = get_refcount(device) + 1;
2744 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
2745 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2746 refcount = get_refcount(device);
2747 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2748 tmp = NULL;
2749 expected_refcount = refcount + 1;
2750 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
2751 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2752 refcount = get_refcount(device);
2753 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2754 ID3D11Device_Release(tmp);
2756 memset(&dsv_desc, 0, sizeof(dsv_desc));
2757 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2758 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2759 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
2760 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2761 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
2762 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2764 ID3D11DepthStencilView_Release(dsview);
2765 ID3D11Texture2D_Release(texture);
2767 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2769 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
2771 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2772 texture_desc.ArraySize = tests[i].texture.array_size;
2773 texture_desc.Format = tests[i].texture.format;
2775 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2776 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2778 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
2780 current_desc = NULL;
2782 else
2784 current_desc = &dsv_desc;
2785 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2788 expected_refcount = get_refcount(texture);
2789 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
2790 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2791 refcount = get_refcount(texture);
2792 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2794 /* Not available on all Windows versions. */
2795 check_interface(dsview, &IID_ID3D10DepthStencilView, TRUE, TRUE);
2797 memset(&dsv_desc, 0, sizeof(dsv_desc));
2798 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2799 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2801 ID3D11DepthStencilView_Release(dsview);
2802 ID3D11Texture2D_Release(texture);
2805 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2807 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2808 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2809 texture_desc.Format = invalid_desc_tests[i].texture.format;
2811 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2812 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2814 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2815 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2816 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2818 ID3D11Texture2D_Release(texture);
2821 refcount = ID3D11Device_Release(device);
2822 ok(!refcount, "Device has %u references left.\n", refcount);
2825 static void test_depthstencil_view_interfaces(void)
2827 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
2828 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2829 ID3D10DepthStencilView *d3d10_dsview;
2830 D3D11_TEXTURE2D_DESC texture_desc;
2831 ID3D11DepthStencilView *dsview;
2832 ID3D11Texture2D *texture;
2833 ID3D11Device *device;
2834 ULONG refcount;
2835 HRESULT hr;
2837 if (!(device = create_device(NULL)))
2839 skip("Failed to create device.\n");
2840 return;
2843 texture_desc.Width = 512;
2844 texture_desc.Height = 512;
2845 texture_desc.MipLevels = 1;
2846 texture_desc.ArraySize = 1;
2847 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2848 texture_desc.SampleDesc.Count = 1;
2849 texture_desc.SampleDesc.Quality = 0;
2850 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2851 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2852 texture_desc.CPUAccessFlags = 0;
2853 texture_desc.MiscFlags = 0;
2855 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2856 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2858 dsv_desc.Format = texture_desc.Format;
2859 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
2860 dsv_desc.Flags = 0;
2861 U(dsv_desc).Texture2D.MipSlice = 0;
2863 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2864 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2866 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
2867 ID3D11DepthStencilView_Release(dsview);
2868 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2869 "Depth stencil view should implement ID3D10DepthStencilView.\n");
2871 if (FAILED(hr))
2873 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
2874 goto done;
2877 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
2878 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
2879 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
2880 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
2881 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2882 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
2884 ID3D10DepthStencilView_Release(d3d10_dsview);
2886 done:
2887 ID3D11Texture2D_Release(texture);
2889 refcount = ID3D11Device_Release(device);
2890 ok(!refcount, "Device has %u references left.\n", refcount);
2893 static void test_create_rendertarget_view(void)
2895 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
2896 D3D11_TEXTURE3D_DESC texture3d_desc;
2897 D3D11_TEXTURE2D_DESC texture2d_desc;
2898 D3D11_SUBRESOURCE_DATA data = {0};
2899 ULONG refcount, expected_refcount;
2900 D3D11_BUFFER_DESC buffer_desc;
2901 ID3D11RenderTargetView *rtview;
2902 ID3D11Device *device, *tmp;
2903 ID3D11Texture3D *texture3d;
2904 ID3D11Texture2D *texture2d;
2905 ID3D11Resource *texture;
2906 ID3D11Buffer *buffer;
2907 unsigned int i;
2908 HRESULT hr;
2910 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2911 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2912 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2913 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
2914 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
2915 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
2916 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
2917 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
2918 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
2919 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
2920 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
2921 static const struct
2923 struct
2925 unsigned int miplevel_count;
2926 unsigned int depth_or_array_size;
2927 DXGI_FORMAT format;
2928 } texture;
2929 struct rtv_desc rtv_desc;
2930 struct rtv_desc expected_rtv_desc;
2932 tests[] =
2934 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2935 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2936 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2937 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2938 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2939 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2940 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2941 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2942 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2943 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2944 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2945 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2946 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2947 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2948 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2949 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2950 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2951 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2952 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2953 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2954 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2955 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2956 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2957 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2958 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2959 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2960 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2961 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2962 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2963 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2964 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2965 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2966 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2967 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2968 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2969 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2970 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2971 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2972 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2973 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2974 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2975 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2976 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2977 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2979 static const struct
2981 struct
2983 D3D11_RTV_DIMENSION dimension;
2984 unsigned int miplevel_count;
2985 unsigned int depth_or_array_size;
2986 DXGI_FORMAT format;
2987 } texture;
2988 struct rtv_desc rtv_desc;
2990 invalid_desc_tests[] =
2992 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2993 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2994 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2995 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2996 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
2997 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
2998 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
2999 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3000 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
3001 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
3002 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
3003 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
3004 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
3005 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
3006 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
3007 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3008 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3009 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3010 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3011 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3012 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3013 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3014 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3015 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
3016 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
3017 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3018 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3019 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
3020 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3021 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3022 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
3023 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
3024 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
3025 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
3026 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
3028 #undef FMT_UNKNOWN
3029 #undef RGBA8_UNORM
3030 #undef RGBA8_TL
3031 #undef DIM_UNKNOWN
3032 #undef TEX_1D
3033 #undef TEX_1D_ARRAY
3034 #undef TEX_2D
3035 #undef TEX_2D_ARRAY
3036 #undef TEX_2DMS
3037 #undef TEX_2DMS_ARR
3038 #undef TEX_3D
3040 if (!(device = create_device(NULL)))
3042 skip("Failed to create device.\n");
3043 return;
3046 buffer_desc.ByteWidth = 1024;
3047 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3048 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3049 buffer_desc.CPUAccessFlags = 0;
3050 buffer_desc.MiscFlags = 0;
3051 buffer_desc.StructureByteStride = 0;
3053 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
3054 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3056 expected_refcount = get_refcount(device) + 1;
3057 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3058 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3059 refcount = get_refcount(device);
3060 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3061 tmp = NULL;
3062 expected_refcount = refcount + 1;
3063 ID3D11Buffer_GetDevice(buffer, &tmp);
3064 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3065 refcount = get_refcount(device);
3066 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3067 ID3D11Device_Release(tmp);
3069 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3070 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
3071 U1(U(rtv_desc).Buffer).ElementOffset = 0;
3072 U2(U(rtv_desc).Buffer).ElementWidth = 64;
3074 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
3075 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3077 expected_refcount = get_refcount(device) + 1;
3078 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
3079 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
3080 refcount = get_refcount(device);
3081 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3082 tmp = NULL;
3083 expected_refcount = refcount + 1;
3084 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
3085 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3086 refcount = get_refcount(device);
3087 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3088 ID3D11Device_Release(tmp);
3090 /* Not available on all Windows versions. */
3091 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3093 ID3D11RenderTargetView_Release(rtview);
3094 ID3D11Buffer_Release(buffer);
3096 texture2d_desc.Width = 512;
3097 texture2d_desc.Height = 512;
3098 texture2d_desc.SampleDesc.Count = 1;
3099 texture2d_desc.SampleDesc.Quality = 0;
3100 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3101 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3102 texture2d_desc.CPUAccessFlags = 0;
3103 texture2d_desc.MiscFlags = 0;
3105 texture3d_desc.Width = 64;
3106 texture3d_desc.Height = 64;
3107 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3108 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3109 texture3d_desc.CPUAccessFlags = 0;
3110 texture3d_desc.MiscFlags = 0;
3112 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3114 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3116 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3118 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3119 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3120 texture2d_desc.Format = tests[i].texture.format;
3122 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3123 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3124 texture = (ID3D11Resource *)texture2d;
3126 else
3128 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3129 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3130 texture3d_desc.Format = tests[i].texture.format;
3132 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3133 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3134 texture = (ID3D11Resource *)texture3d;
3137 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
3139 current_desc = NULL;
3141 else
3143 current_desc = &rtv_desc;
3144 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3147 expected_refcount = get_refcount(texture);
3148 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3149 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3150 refcount = get_refcount(texture);
3151 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3153 /* Not available on all Windows versions. */
3154 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3156 memset(&rtv_desc, 0, sizeof(rtv_desc));
3157 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
3158 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3160 ID3D11RenderTargetView_Release(rtview);
3161 ID3D11Resource_Release(texture);
3164 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3166 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
3167 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
3169 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3171 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3172 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3173 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3175 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3176 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3177 texture = (ID3D11Resource *)texture2d;
3179 else
3181 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3182 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3183 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3185 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3186 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3187 texture = (ID3D11Resource *)texture3d;
3190 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3191 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3192 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3194 ID3D11Resource_Release(texture);
3197 refcount = ID3D11Device_Release(device);
3198 ok(!refcount, "Device has %u references left.\n", refcount);
3201 static void test_create_shader_resource_view(void)
3203 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
3204 D3D11_TEXTURE3D_DESC texture3d_desc;
3205 D3D11_TEXTURE2D_DESC texture2d_desc;
3206 ULONG refcount, expected_refcount;
3207 ID3D11ShaderResourceView *srview;
3208 D3D_FEATURE_LEVEL feature_level;
3209 D3D11_BUFFER_DESC buffer_desc;
3210 ID3D11Device *device, *tmp;
3211 ID3D11Texture3D *texture3d;
3212 ID3D11Texture2D *texture2d;
3213 ID3D11Resource *texture;
3214 ID3D11Buffer *buffer;
3215 unsigned int i;
3216 HRESULT hr;
3218 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3219 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3220 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3221 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
3222 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
3223 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
3224 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
3225 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
3226 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
3227 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
3228 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
3229 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
3230 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3231 static const struct
3233 struct
3235 unsigned int miplevel_count;
3236 unsigned int depth_or_array_size;
3237 DXGI_FORMAT format;
3238 } texture;
3239 struct srv_desc srv_desc;
3240 struct srv_desc expected_srv_desc;
3242 tests[] =
3244 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3245 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3246 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3247 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3248 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3249 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3250 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3251 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3252 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3253 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3254 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3255 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3256 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3257 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3258 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3259 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3260 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3261 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3262 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3263 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3264 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3265 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3266 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3267 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3268 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3269 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3270 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3271 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3272 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3273 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3274 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3275 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3276 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3277 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3278 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3279 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3280 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3281 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3282 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3283 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3284 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3285 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3286 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3287 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3288 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3289 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
3291 static const struct
3293 struct
3295 D3D11_SRV_DIMENSION dimension;
3296 unsigned int miplevel_count;
3297 unsigned int depth_or_array_size;
3298 DXGI_FORMAT format;
3299 } texture;
3300 struct srv_desc srv_desc;
3302 invalid_desc_tests[] =
3304 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3305 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3306 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3307 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3308 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3309 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3310 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3311 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3312 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3313 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3314 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3315 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3316 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3317 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3318 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3319 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3320 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3321 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3322 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3323 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3324 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3325 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3326 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3327 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3328 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
3329 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
3330 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3331 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3332 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3333 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
3334 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
3335 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
3336 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
3337 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
3338 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3339 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3340 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3341 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3342 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3343 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3344 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3345 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3346 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3347 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3348 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3349 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3350 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3351 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3352 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3353 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3354 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3355 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3357 #undef FMT_UNKNOWN
3358 #undef RGBA8_UNORM
3359 #undef DIM_UNKNOWN
3360 #undef TEX_1D
3361 #undef TEX_1D_ARRAY
3362 #undef TEX_2D
3363 #undef TEX_2D_ARRAY
3364 #undef TEX_2DMS
3365 #undef TEX_2DMS_ARR
3366 #undef TEX_3D
3367 #undef TEX_CUBE
3368 #undef CUBE_ARRAY
3370 if (!(device = create_device(NULL)))
3372 skip("Failed to create device.\n");
3373 return;
3375 feature_level = ID3D11Device_GetFeatureLevel(device);
3377 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
3379 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3380 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3382 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3383 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
3384 U1(U(srv_desc).Buffer).ElementOffset = 0;
3385 U2(U(srv_desc).Buffer).ElementWidth = 64;
3387 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
3388 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3390 expected_refcount = get_refcount(device) + 1;
3391 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
3392 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
3393 refcount = get_refcount(device);
3394 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3395 tmp = NULL;
3396 expected_refcount = refcount + 1;
3397 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
3398 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3399 refcount = get_refcount(device);
3400 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3401 ID3D11Device_Release(tmp);
3403 /* Not available on all Windows versions. */
3404 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
3405 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3407 ID3D11ShaderResourceView_Release(srview);
3408 ID3D11Buffer_Release(buffer);
3410 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
3412 buffer_desc.ByteWidth = 1024;
3413 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3414 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3415 buffer_desc.CPUAccessFlags = 0;
3416 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
3417 buffer_desc.StructureByteStride = 4;
3419 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3420 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3422 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3423 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
3425 memset(&srv_desc, 0, sizeof(srv_desc));
3426 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3428 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
3429 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
3430 srv_desc.ViewDimension);
3431 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
3432 U1(U(srv_desc).Buffer).FirstElement);
3433 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
3434 U2(U(srv_desc).Buffer).NumElements);
3436 ID3D11ShaderResourceView_Release(srview);
3437 ID3D11Buffer_Release(buffer);
3439 else
3441 skip("Structured buffers require feature level 11_0.\n");
3444 texture2d_desc.Width = 512;
3445 texture2d_desc.Height = 512;
3446 texture2d_desc.SampleDesc.Count = 1;
3447 texture2d_desc.SampleDesc.Quality = 0;
3448 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3449 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3450 texture2d_desc.CPUAccessFlags = 0;
3452 texture3d_desc.Width = 64;
3453 texture3d_desc.Height = 64;
3454 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3455 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3456 texture3d_desc.CPUAccessFlags = 0;
3457 texture3d_desc.MiscFlags = 0;
3459 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3461 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
3463 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
3465 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3466 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3467 texture2d_desc.Format = tests[i].texture.format;
3468 texture2d_desc.MiscFlags = 0;
3470 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3471 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3472 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3474 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
3475 && (texture2d_desc.ArraySize != 6
3476 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3477 && feature_level < D3D_FEATURE_LEVEL_10_1)
3479 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3480 continue;
3483 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3484 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3485 texture = (ID3D11Resource *)texture2d;
3487 else
3489 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3490 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3491 texture3d_desc.Format = tests[i].texture.format;
3493 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3494 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3495 texture = (ID3D11Resource *)texture3d;
3498 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
3500 current_desc = NULL;
3502 else
3504 current_desc = &srv_desc;
3505 get_srv_desc(current_desc, &tests[i].srv_desc);
3508 expected_refcount = get_refcount(texture);
3509 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3510 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3511 refcount = get_refcount(texture);
3512 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3514 /* Not available on all Windows versions. */
3515 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
3516 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3518 memset(&srv_desc, 0, sizeof(srv_desc));
3519 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3520 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3522 ID3D11ShaderResourceView_Release(srview);
3523 ID3D11Resource_Release(texture);
3526 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3528 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
3529 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
3531 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
3533 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3534 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3535 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3536 texture2d_desc.MiscFlags = 0;
3538 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3539 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3540 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3542 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3543 && feature_level < D3D_FEATURE_LEVEL_10_1)
3545 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3546 continue;
3549 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3550 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3551 texture = (ID3D11Resource *)texture2d;
3553 else
3555 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3556 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3557 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3559 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3560 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3561 texture = (ID3D11Resource *)texture3d;
3564 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3565 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3566 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3568 ID3D11Resource_Release(texture);
3571 refcount = ID3D11Device_Release(device);
3572 ok(!refcount, "Device has %u references left.\n", refcount);
3575 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
3577 #if 0
3578 float4 light;
3579 float4x4 mat;
3581 struct input
3583 float4 position : POSITION;
3584 float3 normal : NORMAL;
3587 struct output
3589 float4 position : POSITION;
3590 float4 diffuse : COLOR;
3593 output main(const input v)
3595 output o;
3597 o.position = mul(v.position, mat);
3598 o.diffuse = dot((float3)light, v.normal);
3600 return o;
3602 #endif
3603 static const DWORD vs_4_1[] =
3605 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
3606 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
3607 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
3608 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
3609 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3610 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
3611 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
3612 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3613 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
3614 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
3615 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
3616 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
3617 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
3618 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
3619 0x0100003e,
3621 static const DWORD vs_4_0[] =
3623 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3624 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3625 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3626 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3627 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3628 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3629 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3630 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3631 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3632 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3633 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3634 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3635 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3636 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3637 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3638 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3640 static const DWORD vs_3_0[] =
3642 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3643 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3644 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3645 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3646 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3647 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3648 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3649 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3650 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3651 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3652 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3653 0x0000ffff,
3655 static const DWORD vs_2_0[] =
3657 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3658 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3659 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3660 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3661 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3662 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3663 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3664 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3665 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3666 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3667 0x90e40001, 0x0000ffff,
3670 #if 0
3671 float4 main(const float4 color : COLOR) : SV_TARGET
3673 float4 o;
3675 o = color;
3677 return o;
3679 #endif
3680 static const DWORD ps_4_1[] =
3682 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
3683 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3684 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3685 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3686 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
3687 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3688 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3690 static const DWORD ps_4_0[] =
3692 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
3693 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3694 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3695 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3696 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3697 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3698 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3700 static const DWORD ps_4_0_level_9_0[] =
3702 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
3703 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
3704 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
3705 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
3706 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
3707 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
3708 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
3709 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
3710 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3711 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
3712 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3713 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3714 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
3715 0xabab0054,
3717 static const DWORD ps_4_0_level_9_1[] =
3719 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
3720 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3721 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3722 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3723 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3724 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3725 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3726 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3727 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3728 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3729 0x45475241, 0xabab0054,
3731 static const DWORD ps_4_0_level_9_3[] =
3733 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
3734 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3735 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3736 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3737 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3738 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3739 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3740 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3741 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3742 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3743 0x45475241, 0xabab0054,
3746 #if 0
3747 struct gs_out
3749 float4 pos : SV_POSITION;
3752 [maxvertexcount(4)]
3753 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3755 float offset = 0.1 * vin[0].w;
3756 gs_out v;
3758 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3759 vout.Append(v);
3760 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3761 vout.Append(v);
3762 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3763 vout.Append(v);
3764 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3765 vout.Append(v);
3767 #endif
3768 static const DWORD gs_4_1[] =
3770 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
3771 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3772 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3773 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3774 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
3775 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
3776 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
3777 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
3778 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
3779 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3780 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
3781 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3782 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
3783 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3784 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
3785 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3786 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
3787 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3789 static const DWORD gs_4_0[] =
3791 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3792 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3793 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3794 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3795 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3796 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3797 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3798 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3799 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3800 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3801 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3802 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3803 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3804 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3805 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3806 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3807 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3808 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3811 ULONG refcount, expected_refcount;
3812 struct device_desc device_desc;
3813 ID3D11Device *device, *tmp;
3814 ID3D11GeometryShader *gs;
3815 ID3D11VertexShader *vs;
3816 ID3D11PixelShader *ps;
3817 HRESULT hr;
3819 device_desc.feature_level = &feature_level;
3820 device_desc.flags = 0;
3821 if (!(device = create_device(&device_desc)))
3823 skip("Failed to create device for feature level %#x.\n", feature_level);
3824 return;
3827 /* level_9 shaders */
3828 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
3829 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3830 ID3D11PixelShader_Release(ps);
3832 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
3833 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3834 ID3D11PixelShader_Release(ps);
3836 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
3837 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3838 ID3D11PixelShader_Release(ps);
3840 /* vertex shader */
3841 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
3842 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3844 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
3845 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3847 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
3848 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
3849 hr, feature_level);
3851 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3852 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
3853 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3854 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3855 else
3856 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3858 refcount = get_refcount(device);
3859 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3860 refcount, expected_refcount);
3861 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3863 tmp = NULL;
3864 expected_refcount = refcount + 1;
3865 ID3D11VertexShader_GetDevice(vs, &tmp);
3866 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3867 refcount = get_refcount(device);
3868 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3869 refcount, expected_refcount);
3870 ID3D11Device_Release(tmp);
3872 /* Not available on all Windows versions. */
3873 check_interface(vs, &IID_ID3D10VertexShader, TRUE, TRUE);
3875 refcount = ID3D11VertexShader_Release(vs);
3876 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3879 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
3880 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3882 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3883 hr, feature_level);
3884 refcount = ID3D11VertexShader_Release(vs);
3885 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3887 else
3889 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3890 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3891 hr, feature_level);
3892 if (SUCCEEDED(hr))
3893 ID3D11VertexShader_Release(vs);
3896 /* pixel shader */
3897 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3898 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
3899 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3900 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3901 else
3902 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3904 refcount = get_refcount(device);
3905 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3906 refcount, expected_refcount);
3907 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3909 tmp = NULL;
3910 expected_refcount = refcount + 1;
3911 ID3D11PixelShader_GetDevice(ps, &tmp);
3912 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3913 refcount = get_refcount(device);
3914 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3915 refcount, expected_refcount);
3916 ID3D11Device_Release(tmp);
3918 /* Not available on all Windows versions. */
3919 check_interface(ps, &IID_ID3D10PixelShader, TRUE, TRUE);
3921 refcount = ID3D11PixelShader_Release(ps);
3922 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3925 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
3926 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3928 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
3929 hr, feature_level);
3930 refcount = ID3D11PixelShader_Release(ps);
3931 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3933 else
3935 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3936 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3937 if (SUCCEEDED(hr))
3938 ID3D11PixelShader_Release(ps);
3941 /* geometry shader */
3942 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3943 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
3944 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3945 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3946 else
3947 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3949 refcount = get_refcount(device);
3950 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3951 refcount, expected_refcount);
3952 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3954 tmp = NULL;
3955 expected_refcount = refcount + 1;
3956 ID3D11GeometryShader_GetDevice(gs, &tmp);
3957 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3958 refcount = get_refcount(device);
3959 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3960 refcount, expected_refcount);
3961 ID3D11Device_Release(tmp);
3963 /* Not available on all Windows versions. */
3964 check_interface(gs, &IID_ID3D10GeometryShader, TRUE, TRUE);
3966 refcount = ID3D11GeometryShader_Release(gs);
3967 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3970 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
3971 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3973 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
3974 hr, feature_level);
3975 refcount = ID3D11GeometryShader_Release(gs);
3976 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3978 else
3980 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3981 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
3982 hr, feature_level);
3983 if (SUCCEEDED(hr))
3984 ID3D11GeometryShader_Release(gs);
3987 refcount = ID3D11Device_Release(device);
3988 ok(!refcount, "Device has %u references left.\n", refcount);
3991 static void test_create_sampler_state(void)
3993 static const struct test
3995 D3D11_FILTER filter;
3996 D3D10_FILTER expected_filter;
3998 desc_conversion_tests[] =
4000 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
4001 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
4002 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
4003 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
4004 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
4005 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
4006 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
4007 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
4008 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
4009 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
4010 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
4012 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
4013 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
4015 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
4016 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
4018 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
4019 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
4021 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
4022 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
4023 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
4026 ID3D11SamplerState *sampler_state1, *sampler_state2;
4027 ID3D10SamplerState *d3d10_sampler_state;
4028 ULONG refcount, expected_refcount;
4029 ID3D11Device *device, *tmp;
4030 D3D11_SAMPLER_DESC desc;
4031 unsigned int i;
4032 HRESULT hr;
4034 if (!(device = create_device(NULL)))
4036 skip("Failed to create device.\n");
4037 return;
4040 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
4041 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4043 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
4044 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4045 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4046 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
4047 desc.MipLODBias = 0.0f;
4048 desc.MaxAnisotropy = 16;
4049 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4050 desc.BorderColor[0] = 0.0f;
4051 desc.BorderColor[1] = 1.0f;
4052 desc.BorderColor[2] = 0.0f;
4053 desc.BorderColor[3] = 1.0f;
4054 desc.MinLOD = 0.0f;
4055 desc.MaxLOD = 16.0f;
4057 expected_refcount = get_refcount(device) + 1;
4058 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4059 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4060 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
4061 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4062 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4063 refcount = get_refcount(device);
4064 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4065 tmp = NULL;
4066 expected_refcount = refcount + 1;
4067 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
4068 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4069 refcount = get_refcount(device);
4070 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4071 ID3D11Device_Release(tmp);
4073 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
4074 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4075 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4076 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4077 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4078 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4079 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4080 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4081 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4082 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4083 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4084 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4085 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4087 refcount = ID3D11SamplerState_Release(sampler_state2);
4088 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4089 refcount = ID3D11SamplerState_Release(sampler_state1);
4090 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4092 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4094 const struct test *current = &desc_conversion_tests[i];
4095 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4097 desc.Filter = current->filter;
4098 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4099 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4100 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4101 desc.MipLODBias = 0.0f;
4102 desc.MaxAnisotropy = 16;
4103 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4104 desc.BorderColor[0] = 0.0f;
4105 desc.BorderColor[1] = 1.0f;
4106 desc.BorderColor[2] = 0.0f;
4107 desc.BorderColor[3] = 1.0f;
4108 desc.MinLOD = 0.0f;
4109 desc.MaxLOD = 16.0f;
4111 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4112 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4114 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
4115 (void **)&d3d10_sampler_state);
4116 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4117 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4118 if (FAILED(hr))
4120 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
4121 ID3D11SamplerState_Release(sampler_state1);
4122 break;
4125 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4126 expected_desc.Filter = current->expected_filter;
4127 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4128 expected_desc.MaxAnisotropy = 0;
4129 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4130 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4132 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
4133 ok(d3d10_desc.Filter == expected_desc.Filter,
4134 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
4135 ok(d3d10_desc.AddressU == expected_desc.AddressU,
4136 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
4137 ok(d3d10_desc.AddressV == expected_desc.AddressV,
4138 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
4139 ok(d3d10_desc.AddressW == expected_desc.AddressW,
4140 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
4141 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
4142 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
4143 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4144 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
4145 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4146 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
4147 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
4148 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
4149 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
4150 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
4151 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4152 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
4153 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
4154 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
4155 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
4156 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
4157 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
4159 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
4160 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4161 refcount = ID3D11SamplerState_Release(sampler_state1);
4162 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4165 refcount = ID3D11Device_Release(device);
4166 ok(!refcount, "Device has %u references left.\n", refcount);
4169 static void test_create_blend_state(void)
4171 static const D3D11_BLEND_DESC desc_conversion_tests[] =
4174 FALSE, FALSE,
4177 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4178 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
4183 FALSE, TRUE,
4186 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4187 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4190 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4191 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
4194 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4195 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4198 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4199 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
4202 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4203 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
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_ADD,
4211 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4214 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4215 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4220 FALSE, TRUE,
4223 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4224 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4227 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
4228 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4231 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
4232 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4235 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4236 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4239 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
4240 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4243 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
4244 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4247 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4248 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4251 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4252 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4258 ID3D11BlendState *blend_state1, *blend_state2;
4259 D3D11_BLEND_DESC desc, obtained_desc;
4260 ID3D10BlendState *d3d10_blend_state;
4261 D3D10_BLEND_DESC d3d10_blend_desc;
4262 ULONG refcount, expected_refcount;
4263 ID3D11Device *device, *tmp;
4264 unsigned int i, j;
4265 HRESULT hr;
4267 if (!(device = create_device(NULL)))
4269 skip("Failed to create device.\n");
4270 return;
4273 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
4274 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4276 memset(&desc, 0, sizeof(desc));
4277 desc.AlphaToCoverageEnable = FALSE;
4278 desc.IndependentBlendEnable = FALSE;
4279 desc.RenderTarget[0].BlendEnable = FALSE;
4280 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
4281 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
4282 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
4283 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
4284 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
4285 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
4286 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
4288 expected_refcount = get_refcount(device) + 1;
4289 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
4290 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4291 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
4292 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4293 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4294 refcount = get_refcount(device);
4295 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4296 tmp = NULL;
4297 expected_refcount = refcount + 1;
4298 ID3D11BlendState_GetDevice(blend_state1, &tmp);
4299 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4300 refcount = get_refcount(device);
4301 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4302 ID3D11Device_Release(tmp);
4304 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
4305 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
4306 obtained_desc.AlphaToCoverageEnable);
4307 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
4308 obtained_desc.IndependentBlendEnable);
4309 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4311 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
4312 "Got unexpected blend enable %#x for render target %u.\n",
4313 obtained_desc.RenderTarget[i].BlendEnable, i);
4314 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
4315 "Got unexpected src blend %u for render target %u.\n",
4316 obtained_desc.RenderTarget[i].SrcBlend, i);
4317 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
4318 "Got unexpected dest blend %u for render target %u.\n",
4319 obtained_desc.RenderTarget[i].DestBlend, i);
4320 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
4321 "Got unexpected blend op %u for render target %u.\n",
4322 obtained_desc.RenderTarget[i].BlendOp, i);
4323 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
4324 "Got unexpected src blend alpha %u for render target %u.\n",
4325 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
4326 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
4327 "Got unexpected dest blend alpha %u for render target %u.\n",
4328 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
4329 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
4330 "Got unexpected blend op alpha %u for render target %u.\n",
4331 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
4332 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
4333 "Got unexpected render target write mask %#x for render target %u.\n",
4334 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
4337 /* Not available on all Windows versions. */
4338 check_interface(blend_state1, &IID_ID3D10BlendState, TRUE, TRUE);
4339 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
4341 refcount = ID3D11BlendState_Release(blend_state1);
4342 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4343 refcount = ID3D11BlendState_Release(blend_state2);
4344 ok(!refcount, "Blend state has %u references left.\n", refcount);
4346 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4348 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
4350 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
4351 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4353 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
4354 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4355 "Blend state should implement ID3D10BlendState.\n");
4356 if (FAILED(hr))
4358 win_skip("Blend state does not implement ID3D10BlendState.\n");
4359 ID3D11BlendState_Release(blend_state1);
4360 break;
4363 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
4364 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
4365 "Got unexpected alpha to coverage enable %#x for test %u.\n",
4366 d3d10_blend_desc.AlphaToCoverageEnable, i);
4367 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
4368 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
4369 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
4370 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
4371 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
4372 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
4373 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
4374 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
4375 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
4376 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
4377 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
4378 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
4379 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
4381 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
4382 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
4383 "Got unexpected blend enable %#x for test %u, render target %u.\n",
4384 d3d10_blend_desc.BlendEnable[j], i, j);
4385 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
4386 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
4387 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
4390 ID3D10BlendState_Release(d3d10_blend_state);
4392 refcount = ID3D11BlendState_Release(blend_state1);
4393 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4396 refcount = ID3D11Device_Release(device);
4397 ok(!refcount, "Device has %u references left.\n", refcount);
4400 static void test_create_depthstencil_state(void)
4402 ID3D11DepthStencilState *ds_state1, *ds_state2;
4403 ULONG refcount, expected_refcount;
4404 D3D11_DEPTH_STENCIL_DESC ds_desc;
4405 ID3D11Device *device, *tmp;
4406 HRESULT hr;
4408 if (!(device = create_device(NULL)))
4410 skip("Failed to create device.\n");
4411 return;
4414 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
4415 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4417 ds_desc.DepthEnable = TRUE;
4418 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
4419 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
4420 ds_desc.StencilEnable = FALSE;
4421 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
4422 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
4423 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4424 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4425 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4426 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4427 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4428 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4429 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4430 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4432 expected_refcount = get_refcount(device) + 1;
4433 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4434 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4435 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4436 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4437 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4438 refcount = get_refcount(device);
4439 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4440 tmp = NULL;
4441 expected_refcount = refcount + 1;
4442 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
4443 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4444 refcount = get_refcount(device);
4445 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4446 ID3D11Device_Release(tmp);
4448 /* Not available on all Windows versions. */
4449 check_interface(ds_state1, &IID_ID3D10DepthStencilState, TRUE, TRUE);
4451 refcount = ID3D11DepthStencilState_Release(ds_state2);
4452 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4453 refcount = ID3D11DepthStencilState_Release(ds_state1);
4454 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4456 ds_desc.DepthEnable = FALSE;
4457 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
4458 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
4459 ds_desc.StencilEnable = FALSE;
4460 ds_desc.StencilReadMask = 0;
4461 ds_desc.StencilWriteMask = 0;
4462 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
4463 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
4464 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
4465 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
4466 ds_desc.BackFace = ds_desc.FrontFace;
4468 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4469 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4471 memset(&ds_desc, 0, sizeof(ds_desc));
4472 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
4473 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4474 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
4475 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4476 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4477 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4478 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
4479 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4480 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
4481 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4482 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4483 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4484 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4485 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4486 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4487 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4488 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4489 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4490 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4491 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4492 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4493 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4494 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4495 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4496 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4497 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4499 ID3D11DepthStencilState_Release(ds_state1);
4501 refcount = ID3D11Device_Release(device);
4502 ok(!refcount, "Device has %u references left.\n", refcount);
4505 static void test_create_rasterizer_state(void)
4507 ID3D11RasterizerState *rast_state1, *rast_state2;
4508 ID3D10RasterizerState *d3d10_rast_state;
4509 ULONG refcount, expected_refcount;
4510 D3D10_RASTERIZER_DESC d3d10_desc;
4511 D3D11_RASTERIZER_DESC desc;
4512 ID3D11Device *device, *tmp;
4513 HRESULT hr;
4515 if (!(device = create_device(NULL)))
4517 skip("Failed to create device.\n");
4518 return;
4521 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
4522 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4524 desc.FillMode = D3D11_FILL_SOLID;
4525 desc.CullMode = D3D11_CULL_BACK;
4526 desc.FrontCounterClockwise = FALSE;
4527 desc.DepthBias = 0;
4528 desc.DepthBiasClamp = 0.0f;
4529 desc.SlopeScaledDepthBias = 0.0f;
4530 desc.DepthClipEnable = TRUE;
4531 desc.ScissorEnable = FALSE;
4532 desc.MultisampleEnable = FALSE;
4533 desc.AntialiasedLineEnable = FALSE;
4535 expected_refcount = get_refcount(device) + 1;
4536 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
4537 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4538 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
4539 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4540 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4541 refcount = get_refcount(device);
4542 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4543 tmp = NULL;
4544 expected_refcount = refcount + 1;
4545 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
4546 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4547 refcount = get_refcount(device);
4548 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4549 ID3D11Device_Release(tmp);
4551 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
4552 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4553 "Rasterizer state should implement ID3D10RasterizerState.\n");
4554 if (SUCCEEDED(hr))
4556 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
4557 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
4558 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
4559 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
4560 d3d10_desc.FrontCounterClockwise);
4561 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
4562 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
4563 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
4564 d3d10_desc.SlopeScaledDepthBias);
4565 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
4566 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
4567 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
4568 d3d10_desc.MultisampleEnable);
4569 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
4570 d3d10_desc.AntialiasedLineEnable);
4572 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
4573 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4576 refcount = ID3D11RasterizerState_Release(rast_state2);
4577 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4578 refcount = ID3D11RasterizerState_Release(rast_state1);
4579 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4581 refcount = ID3D11Device_Release(device);
4582 ok(!refcount, "Device has %u references left.\n", refcount);
4585 static void test_create_query(void)
4587 static const struct
4589 D3D11_QUERY query;
4590 D3D_FEATURE_LEVEL required_feature_level;
4591 BOOL is_predicate;
4592 BOOL can_use_create_predicate;
4593 BOOL todo;
4595 tests[] =
4597 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4598 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4599 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4600 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4601 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4602 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
4603 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4604 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
4605 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4606 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4607 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4608 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4609 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4610 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4611 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4612 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4615 ULONG refcount, expected_refcount;
4616 D3D_FEATURE_LEVEL feature_level;
4617 D3D11_QUERY_DESC query_desc;
4618 ID3D11Predicate *predicate;
4619 ID3D11Device *device, *tmp;
4620 HRESULT hr, expected_hr;
4621 ID3D11Query *query;
4622 unsigned int i;
4624 if (!(device = create_device(NULL)))
4626 skip("Failed to create device.\n");
4627 return;
4629 feature_level = ID3D11Device_GetFeatureLevel(device);
4631 hr = ID3D11Device_CreateQuery(device, NULL, &query);
4632 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4633 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
4634 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4636 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4638 if (tests[i].required_feature_level > feature_level)
4640 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
4641 continue;
4644 query_desc.Query = tests[i].query;
4645 query_desc.MiscFlags = 0;
4647 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
4648 todo_wine_if(tests[i].todo)
4649 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4651 query_desc.Query = tests[i].query;
4652 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
4653 todo_wine_if(tests[i].todo)
4654 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4655 if (FAILED(hr))
4656 continue;
4658 check_interface(query, &IID_ID3D11Predicate, tests[i].is_predicate, FALSE);
4659 ID3D11Query_Release(query);
4661 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
4662 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
4663 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4665 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
4666 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4667 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4668 if (SUCCEEDED(hr))
4669 ID3D11Predicate_Release(predicate);
4672 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
4673 expected_refcount = get_refcount(device) + 1;
4674 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4675 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4676 refcount = get_refcount(device);
4677 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4678 tmp = NULL;
4679 expected_refcount = refcount + 1;
4680 ID3D11Predicate_GetDevice(predicate, &tmp);
4681 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4682 refcount = get_refcount(device);
4683 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4684 ID3D11Device_Release(tmp);
4685 /* Not available on all Windows versions. */
4686 check_interface(predicate, &IID_ID3D10Predicate, TRUE, TRUE);
4687 ID3D11Predicate_Release(predicate);
4689 refcount = ID3D11Device_Release(device);
4690 ok(!refcount, "Device has %u references left.\n", refcount);
4693 static void test_occlusion_query(void)
4695 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4696 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4698 struct d3d11_test_context test_context;
4699 D3D11_TEXTURE2D_DESC texture_desc;
4700 ID3D11DeviceContext *context;
4701 ID3D11RenderTargetView *rtv;
4702 D3D11_QUERY_DESC query_desc;
4703 ID3D11Asynchronous *query;
4704 unsigned int data_size, i;
4705 ID3D11Texture2D *texture;
4706 ID3D11Device *device;
4707 D3D11_VIEWPORT vp;
4708 union
4710 UINT64 uint;
4711 DWORD dword[2];
4712 } data;
4713 HRESULT hr;
4715 if (!init_test_context(&test_context, NULL))
4716 return;
4718 device = test_context.device;
4719 context = test_context.immediate_context;
4721 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4723 query_desc.Query = D3D11_QUERY_OCCLUSION;
4724 query_desc.MiscFlags = 0;
4725 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4726 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4727 data_size = ID3D11Asynchronous_GetDataSize(query);
4728 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4730 memset(&data, 0xff, sizeof(data));
4731 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4732 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4733 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4734 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4735 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4736 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4738 ID3D11DeviceContext_End(context, query);
4739 ID3D11DeviceContext_Begin(context, query);
4740 ID3D11DeviceContext_Begin(context, query);
4742 memset(&data, 0xff, sizeof(data));
4743 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4744 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4745 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4746 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4747 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4748 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4750 draw_color_quad(&test_context, &red);
4752 ID3D11DeviceContext_End(context, query);
4753 for (i = 0; i < 500; ++i)
4755 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4756 break;
4757 Sleep(10);
4759 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4761 memset(&data, 0xff, sizeof(data));
4762 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4763 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4764 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4766 memset(&data, 0xff, sizeof(data));
4767 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
4768 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4769 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
4770 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4771 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
4772 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4773 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
4774 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4775 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4776 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4778 memset(&data, 0xff, sizeof(data));
4779 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
4780 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4781 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4782 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4784 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
4785 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4786 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
4787 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4789 ID3D11DeviceContext_Begin(context, query);
4790 ID3D11DeviceContext_End(context, query);
4791 ID3D11DeviceContext_End(context, query);
4793 for (i = 0; i < 500; ++i)
4795 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4796 break;
4797 Sleep(10);
4799 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4801 data.dword[0] = 0x12345678;
4802 data.dword[1] = 0x12345678;
4803 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4804 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4805 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4806 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4807 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4809 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4810 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4811 texture_desc.MipLevels = 1;
4812 texture_desc.ArraySize = 1;
4813 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4814 texture_desc.SampleDesc.Count = 1;
4815 texture_desc.SampleDesc.Quality = 0;
4816 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4817 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4818 texture_desc.CPUAccessFlags = 0;
4819 texture_desc.MiscFlags = 0;
4820 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4821 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4822 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
4823 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4825 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
4826 vp.TopLeftX = 0.0f;
4827 vp.TopLeftY = 0.0f;
4828 vp.Width = texture_desc.Width;
4829 vp.Height = texture_desc.Height;
4830 vp.MinDepth = 0.0f;
4831 vp.MaxDepth = 1.0f;
4832 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4834 ID3D11DeviceContext_Begin(context, query);
4835 for (i = 0; i < 100; i++)
4836 draw_color_quad(&test_context, &red);
4837 ID3D11DeviceContext_End(context, query);
4839 for (i = 0; i < 500; ++i)
4841 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4842 break;
4843 Sleep(10);
4845 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4847 memset(&data, 0xff, sizeof(data));
4848 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4849 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4850 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4851 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4852 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4853 || (data.dword[0] == 0xffffffff && !data.dword[1])
4854 || broken(!data.uint),
4855 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4857 ID3D11Asynchronous_Release(query);
4859 /* The following test exercises a code path in wined3d. A wined3d context
4860 * associated with the query is destroyed when the swapchain is released. */
4861 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4862 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4864 vp.Width = 64.0f;
4865 vp.Height = 64.0f;
4866 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4867 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4868 ID3D11DeviceContext_Begin(context, query);
4869 draw_color_quad(&test_context, &red);
4870 ID3D11DeviceContext_End(context, query);
4872 ID3D11RenderTargetView_Release(test_context.backbuffer_rtv);
4873 ID3D11Texture2D_Release(test_context.backbuffer);
4874 IDXGISwapChain_Release(test_context.swapchain);
4875 test_context.swapchain = create_swapchain(device, test_context.window, NULL);
4876 hr = IDXGISwapChain_GetBuffer(test_context.swapchain, 0, &IID_ID3D11Texture2D,
4877 (void **)&test_context.backbuffer);
4878 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
4879 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer,
4880 NULL, &test_context.backbuffer_rtv);
4881 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4882 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
4883 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4885 for (i = 0; i < 500; ++i)
4887 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4888 break;
4889 Sleep(10);
4891 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4892 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4893 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4894 /* This test occasionally succeeds with CSMT enabled because of a race condition. */
4895 if (0)
4896 todo_wine ok(data.dword[0] == 0x1000 && !data.dword[1],
4897 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4899 ID3D11Asynchronous_Release(query);
4900 ID3D11RenderTargetView_Release(rtv);
4901 ID3D11Texture2D_Release(texture);
4902 release_test_context(&test_context);
4905 static void test_timestamp_query(void)
4907 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4909 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
4910 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
4911 struct d3d11_test_context test_context;
4912 ID3D11DeviceContext *context;
4913 D3D11_QUERY_DESC query_desc;
4914 unsigned int data_size, i;
4915 ID3D11Device *device;
4916 UINT64 timestamp;
4917 HRESULT hr;
4919 if (!init_test_context(&test_context, NULL))
4920 return;
4922 device = test_context.device;
4923 context = test_context.immediate_context;
4925 query_desc.Query = D3D11_QUERY_TIMESTAMP;
4926 query_desc.MiscFlags = 0;
4927 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
4928 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4929 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
4930 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
4932 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
4933 query_desc.MiscFlags = 0;
4934 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
4935 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4936 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
4937 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
4939 disjoint.Frequency = 0xdeadbeef;
4940 disjoint.Disjoint = 0xdeadbeef;
4941 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4942 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4943 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4944 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4945 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4946 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
4948 /* Test a TIMESTAMP_DISJOINT query. */
4949 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
4951 disjoint.Frequency = 0xdeadbeef;
4952 disjoint.Disjoint = 0xdeadbeef;
4953 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4954 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4955 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4956 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4957 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4958 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
4960 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
4961 for (i = 0; i < 500; ++i)
4963 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
4964 break;
4965 Sleep(10);
4967 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4969 disjoint.Frequency = 0xdeadbeef;
4970 disjoint.Disjoint = 0xff;
4971 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4972 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4973 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
4974 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4976 prev_disjoint = disjoint;
4978 disjoint.Frequency = 0xdeadbeef;
4979 disjoint.Disjoint = 0xff;
4980 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
4981 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4982 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
4983 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4984 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
4985 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4986 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
4987 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4988 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4989 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
4991 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4992 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4993 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
4994 D3D11_ASYNC_GETDATA_DONOTFLUSH);
4995 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4996 ok(!memcmp(&disjoint, &prev_disjoint, sizeof(disjoint)), "Disjoint data mismatch.\n");
4998 memset(&timestamp, 0xff, sizeof(timestamp));
4999 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
5000 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5001 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5002 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5003 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5005 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
5006 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5008 memset(&timestamp, 0xff, sizeof(timestamp));
5009 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5010 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5011 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5013 draw_color_quad(&test_context, &red);
5015 ID3D11DeviceContext_End(context, timestamp_query);
5016 for (i = 0; i < 500; ++i)
5018 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
5019 break;
5020 Sleep(10);
5022 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5024 timestamp = 0xdeadbeef;
5025 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5026 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5027 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5029 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5030 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5031 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
5033 timestamp = 0xdeadbeef;
5034 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
5035 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5036 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
5037 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5038 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5039 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5040 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
5041 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5042 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5044 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5045 for (i = 0; i < 500; ++i)
5047 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
5048 break;
5049 Sleep(10);
5051 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5053 disjoint.Frequency = 0xdeadbeef;
5054 disjoint.Disjoint = 0xff;
5055 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5056 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5057 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
5058 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5060 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
5061 ID3D11Asynchronous_Release(timestamp_query);
5062 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5063 query_desc.MiscFlags = 0;
5064 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5065 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5067 draw_color_quad(&test_context, &red);
5069 ID3D11DeviceContext_End(context, timestamp_query);
5070 for (i = 0; i < 500; ++i)
5072 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
5073 break;
5074 Sleep(10);
5076 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5077 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5078 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5080 ID3D11Asynchronous_Release(timestamp_query);
5081 ID3D11Asynchronous_Release(timestamp_disjoint_query);
5082 release_test_context(&test_context);
5085 static void test_device_removed_reason(void)
5087 ID3D11Device *device;
5088 ULONG refcount;
5089 HRESULT hr;
5091 if (!(device = create_device(NULL)))
5093 skip("Failed to create device.\n");
5094 return;
5097 hr = ID3D11Device_GetDeviceRemovedReason(device);
5098 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5099 hr = ID3D11Device_GetDeviceRemovedReason(device);
5100 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5102 refcount = ID3D11Device_Release(device);
5103 ok(!refcount, "Device has %u references left.\n", refcount);
5106 static void test_private_data(void)
5108 ULONG refcount, expected_refcount;
5109 D3D11_TEXTURE2D_DESC texture_desc;
5110 ID3D10Texture2D *d3d10_texture;
5111 ID3D11Device *test_object;
5112 ID3D11Texture2D *texture;
5113 IDXGIDevice *dxgi_device;
5114 IDXGISurface *surface;
5115 ID3D11Device *device;
5116 IUnknown *ptr;
5117 HRESULT hr;
5118 UINT size;
5120 static const GUID test_guid =
5121 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
5122 static const GUID test_guid2 =
5123 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
5124 static const DWORD data[] = {1, 2, 3, 4};
5126 if (!(device = create_device(NULL)))
5128 skip("Failed to create device.\n");
5129 return;
5132 test_object = create_device(NULL);
5134 texture_desc.Width = 512;
5135 texture_desc.Height = 512;
5136 texture_desc.MipLevels = 1;
5137 texture_desc.ArraySize = 1;
5138 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5139 texture_desc.SampleDesc.Count = 1;
5140 texture_desc.SampleDesc.Quality = 0;
5141 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5142 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5143 texture_desc.CPUAccessFlags = 0;
5144 texture_desc.MiscFlags = 0;
5146 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5147 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5148 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
5149 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
5151 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
5152 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5153 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5154 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5155 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5156 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5157 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5158 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5160 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5161 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5162 size = sizeof(ptr) * 2;
5163 ptr = (IUnknown *)0xdeadbeef;
5164 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5165 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5166 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5167 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5169 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
5170 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
5171 size = sizeof(ptr) * 2;
5172 ptr = (IUnknown *)0xdeadbeef;
5173 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
5174 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5175 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5176 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5177 IDXGIDevice_Release(dxgi_device);
5179 refcount = get_refcount(test_object);
5180 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5181 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5182 expected_refcount = refcount + 1;
5183 refcount = get_refcount(test_object);
5184 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5185 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5186 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5187 refcount = get_refcount(test_object);
5188 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5190 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5191 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5192 --expected_refcount;
5193 refcount = get_refcount(test_object);
5194 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5196 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5197 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5198 size = sizeof(data);
5199 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
5200 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5201 refcount = get_refcount(test_object);
5202 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5203 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5204 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5205 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5206 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5208 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5209 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5210 ++expected_refcount;
5211 size = 2 * sizeof(ptr);
5212 ptr = NULL;
5213 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5214 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5215 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
5216 ++expected_refcount;
5217 refcount = get_refcount(test_object);
5218 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5219 IUnknown_Release(ptr);
5220 --expected_refcount;
5222 ptr = (IUnknown *)0xdeadbeef;
5223 size = 1;
5224 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5225 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5226 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5227 size = 2 * sizeof(ptr);
5228 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5229 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5230 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5231 refcount = get_refcount(test_object);
5232 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5234 size = 1;
5235 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5236 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
5237 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5238 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5239 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
5240 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5241 size = 0xdeadbabe;
5242 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
5243 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
5244 ok(size == 0, "Got unexpected size %u.\n", size);
5245 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5246 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
5247 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5248 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5250 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
5251 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5252 ptr = NULL;
5253 size = sizeof(ptr);
5254 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
5255 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5256 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5257 IUnknown_Release(ptr);
5259 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
5260 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5261 "Texture should implement ID3D10Texture2D.\n");
5262 if (SUCCEEDED(hr))
5264 ptr = NULL;
5265 size = sizeof(ptr);
5266 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
5267 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5268 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5269 IUnknown_Release(ptr);
5270 ID3D10Texture2D_Release(d3d10_texture);
5273 IDXGISurface_Release(surface);
5274 ID3D11Texture2D_Release(texture);
5275 refcount = ID3D11Device_Release(device);
5276 ok(!refcount, "Device has %u references left.\n", refcount);
5277 refcount = ID3D11Device_Release(test_object);
5278 ok(!refcount, "Test object has %u references left.\n", refcount);
5281 static void test_state_refcounting(const D3D_FEATURE_LEVEL feature_level)
5283 ID3D11RasterizerState *rasterizer_state, *tmp_rasterizer_state;
5284 ID3D11Predicate *predicate, *tmp_predicate;
5285 ID3D11SamplerState *sampler, *tmp_sampler;
5286 ID3D11ShaderResourceView *srv, *tmp_srv;
5287 ID3D11RenderTargetView *rtv, *tmp_rtv;
5288 D3D11_RASTERIZER_DESC rasterizer_desc;
5289 D3D11_TEXTURE2D_DESC texture_desc;
5290 D3D11_QUERY_DESC predicate_desc;
5291 D3D11_SAMPLER_DESC sampler_desc;
5292 struct device_desc device_desc;
5293 ID3D11DeviceContext *context;
5294 ID3D11Texture2D *texture;
5295 ID3D11Device *device;
5296 ULONG refcount;
5297 HRESULT hr;
5299 device_desc.feature_level = &feature_level;
5300 device_desc.flags = 0;
5301 if (!(device = create_device(&device_desc)))
5303 skip("Failed to create device for feature level %#x.\n", feature_level);
5304 return;
5307 ID3D11Device_GetImmediateContext(device, &context);
5309 /* ID3D11SamplerState */
5310 memset(&sampler_desc, 0, sizeof(sampler_desc));
5311 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5312 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5313 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5314 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5315 sampler_desc.MaxLOD = FLT_MAX;
5316 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
5317 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
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 ID3D11SamplerState_Release(tmp_sampler);
5324 tmp_sampler = sampler;
5325 refcount = get_refcount(sampler);
5326 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
5327 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
5328 refcount = ID3D11SamplerState_Release(sampler);
5329 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5330 sampler = NULL;
5331 ID3D11DeviceContext_PSGetSamplers(context, 0, 1, &sampler);
5332 ok(sampler == tmp_sampler, "Got sampler %p, expected %p.\n", sampler, tmp_sampler);
5333 refcount = ID3D11SamplerState_Release(sampler);
5334 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5336 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
5337 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5338 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5339 refcount = ID3D11SamplerState_Release(tmp_sampler);
5340 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5342 /* ID3D11RasterizerState */
5343 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
5344 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
5345 rasterizer_desc.CullMode = D3D11_CULL_BACK;
5346 rasterizer_desc.DepthClipEnable = TRUE;
5347 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
5348 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5350 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
5351 refcount = ID3D11RasterizerState_Release(rasterizer_state);
5352 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5353 ID3D11DeviceContext_RSGetState(context, &tmp_rasterizer_state);
5354 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
5355 tmp_rasterizer_state, rasterizer_state);
5356 refcount = ID3D11RasterizerState_Release(tmp_rasterizer_state);
5357 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5359 /* ID3D11ShaderResourceView */
5360 memset(&texture_desc, 0, sizeof(texture_desc));
5361 texture_desc.Width = 32;
5362 texture_desc.Height = 32;
5363 texture_desc.MipLevels = 1;
5364 texture_desc.ArraySize = 1;
5365 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5366 texture_desc.SampleDesc.Count = 1;
5367 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5368 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
5369 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5370 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5371 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
5372 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
5373 ID3D11Texture2D_Release(texture);
5375 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
5376 refcount = ID3D11ShaderResourceView_Release(srv);
5377 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5378 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &tmp_srv);
5379 ok(tmp_srv == srv, "Got SRV %p, expected %p.\n", tmp_srv, srv);
5380 refcount = ID3D11ShaderResourceView_Release(tmp_srv);
5381 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5383 /* ID3D11RenderTargetView */
5384 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5385 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5386 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5387 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
5388 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5389 ID3D11Texture2D_Release(texture);
5391 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
5392 refcount = ID3D11RenderTargetView_Release(rtv);
5393 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5394 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &tmp_rtv, NULL);
5395 ok(tmp_rtv == rtv, "Got RTV %p, expected %p.\n", tmp_rtv, rtv);
5396 refcount = ID3D11RenderTargetView_Release(tmp_rtv);
5397 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5399 /* ID3D11Predicate */
5400 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
5402 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
5403 predicate_desc.MiscFlags = 0;
5404 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
5405 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5407 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
5408 refcount = ID3D11Predicate_Release(predicate);
5409 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5410 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, NULL);
5411 ok(tmp_predicate == predicate, "Got predicate %p, expected %p.\n", tmp_predicate, predicate);
5412 refcount = ID3D11Predicate_Release(tmp_predicate);
5413 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5416 ID3D11DeviceContext_Release(context);
5417 refcount = ID3D11Device_Release(device);
5418 ok(!refcount, "Device has %u references left.\n", refcount);
5421 static void test_device_context_state(void)
5423 ID3DDeviceContextState *context_state, *previous_context_state;
5424 ID3D11SamplerState *sampler, *tmp_sampler;
5425 D3D11_SAMPLER_DESC sampler_desc;
5426 D3D_FEATURE_LEVEL feature_level;
5427 ID3D11DeviceContext1 *context;
5428 ID3D11Device *d3d11_device;
5429 ID3D11Device1 *device;
5430 ULONG refcount;
5431 HRESULT hr;
5433 if (!(d3d11_device = create_device(NULL)))
5435 skip("Failed to create device.\n");
5436 return;
5439 hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11Device1, (void **)&device);
5440 ID3D11Device_Release(d3d11_device);
5441 if (FAILED(hr))
5443 skip("ID3D11Device1 is not available.\n");
5444 return;
5447 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
5448 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
5450 feature_level = ID3D11Device1_GetFeatureLevel(device);
5451 ID3D11Device1_GetImmediateContext1(device, &context);
5453 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5454 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5455 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5456 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5457 sampler_desc.MipLODBias = 0.0f;
5458 sampler_desc.MaxAnisotropy = 0;
5459 sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
5460 sampler_desc.BorderColor[0] = 0.0f;
5461 sampler_desc.BorderColor[1] = 1.0f;
5462 sampler_desc.BorderColor[2] = 0.0f;
5463 sampler_desc.BorderColor[3] = 1.0f;
5464 sampler_desc.MinLOD = 0.0f;
5465 sampler_desc.MaxLOD = 16.0f;
5466 hr = ID3D11Device1_CreateSamplerState(device, &sampler_desc, &sampler);
5467 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5469 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5470 tmp_sampler = NULL;
5471 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5472 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5473 ID3D11SamplerState_Release(tmp_sampler);
5475 feature_level = min(feature_level, D3D_FEATURE_LEVEL_10_1);
5476 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
5477 &IID_ID3D10Device, NULL, &context_state);
5478 ok(SUCCEEDED(hr), "Failed to create device context state, hr %#x.\n", hr);
5479 refcount = get_refcount(context_state);
5480 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
5482 /* Enable ID3D10Device behavior. */
5483 previous_context_state = NULL;
5484 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
5485 refcount = ID3DDeviceContextState_Release(context_state);
5486 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5488 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5489 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
5490 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5491 ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler);
5492 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
5494 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
5495 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
5497 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
5498 refcount = ID3DDeviceContextState_Release(context_state);
5499 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5500 refcount = ID3DDeviceContextState_Release(previous_context_state);
5501 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5503 /* ID3DDeviceContextState retains the previous state. */
5504 tmp_sampler = NULL;
5505 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5506 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5507 ID3D11SamplerState_Release(tmp_sampler);
5509 tmp_sampler = NULL;
5510 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
5511 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
5512 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5513 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
5514 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5515 tmp_sampler = NULL;
5516 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5517 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5518 ID3D11SamplerState_Release(tmp_sampler);
5520 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
5521 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
5523 ID3D11SamplerState_Release(sampler);
5524 ID3D11DeviceContext1_Release(context);
5525 refcount = ID3D11Device1_Release(device);
5526 ok(!refcount, "Device has %u references left.\n", refcount);
5529 static void test_blend(void)
5531 ID3D11BlendState *src_blend, *dst_blend;
5532 struct d3d11_test_context test_context;
5533 ID3D11RenderTargetView *offscreen_rtv;
5534 D3D11_TEXTURE2D_DESC texture_desc;
5535 ID3D11InputLayout *input_layout;
5536 ID3D11DeviceContext *context;
5537 D3D11_BLEND_DESC blend_desc;
5538 unsigned int stride, offset;
5539 ID3D11Texture2D *offscreen;
5540 ID3D11VertexShader *vs;
5541 ID3D11PixelShader *ps;
5542 ID3D11Device *device;
5543 D3D11_VIEWPORT vp;
5544 ID3D11Buffer *vb;
5545 DWORD color;
5546 HRESULT hr;
5548 static const DWORD vs_code[] =
5550 #if 0
5551 struct vs_out
5553 float4 position : SV_POSITION;
5554 float4 color : COLOR;
5557 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5559 struct vs_out o;
5561 o.position = position;
5562 o.color = color;
5564 return o;
5566 #endif
5567 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5568 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5569 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5570 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5571 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5572 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5573 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5574 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5575 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5576 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5578 static const DWORD ps_code[] =
5580 #if 0
5581 struct vs_out
5583 float4 position : SV_POSITION;
5584 float4 color : COLOR;
5587 float4 main(struct vs_out i) : SV_TARGET
5589 return i.color;
5591 #endif
5592 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5593 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5594 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5595 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5596 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5597 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5598 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5599 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5601 static const struct
5603 struct vec3 position;
5604 DWORD diffuse;
5606 quads[] =
5608 /* quad1 */
5609 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5610 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5611 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5612 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5613 /* quad2 */
5614 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5615 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5616 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5617 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5619 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
5621 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
5622 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
5624 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5625 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5627 if (!init_test_context(&test_context, NULL))
5628 return;
5630 device = test_context.device;
5631 context = test_context.immediate_context;
5633 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
5634 vs_code, sizeof(vs_code), &input_layout);
5635 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5637 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5639 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
5640 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5641 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5642 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5644 memset(&blend_desc, 0, sizeof(blend_desc));
5645 blend_desc.RenderTarget[0].BlendEnable = TRUE;
5646 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
5647 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
5648 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
5649 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
5650 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
5651 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
5652 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5654 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
5655 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5657 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
5658 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
5659 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
5660 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
5662 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
5663 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5665 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
5666 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5667 stride = sizeof(*quads);
5668 offset = 0;
5669 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
5670 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
5671 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5673 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
5675 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5676 ID3D11DeviceContext_Draw(context, 4, 0);
5677 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5678 ID3D11DeviceContext_Draw(context, 4, 4);
5680 color = get_texture_color(test_context.backbuffer, 320, 360);
5681 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5682 color = get_texture_color(test_context.backbuffer, 320, 120);
5683 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5685 texture_desc.Width = 128;
5686 texture_desc.Height = 128;
5687 texture_desc.MipLevels = 1;
5688 texture_desc.ArraySize = 1;
5689 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5690 texture_desc.SampleDesc.Count = 1;
5691 texture_desc.SampleDesc.Quality = 0;
5692 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5693 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
5694 texture_desc.CPUAccessFlags = 0;
5695 texture_desc.MiscFlags = 0;
5697 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5698 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5700 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
5701 goto done;
5704 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
5705 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5707 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
5709 vp.TopLeftX = 0.0f;
5710 vp.TopLeftY = 0.0f;
5711 vp.Width = 128.0f;
5712 vp.Height = 128.0f;
5713 vp.MinDepth = 0.0f;
5714 vp.MaxDepth = 1.0f;
5715 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
5717 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
5719 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5720 ID3D11DeviceContext_Draw(context, 4, 0);
5721 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5722 ID3D11DeviceContext_Draw(context, 4, 4);
5724 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5725 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5726 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5727 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5729 ID3D11RenderTargetView_Release(offscreen_rtv);
5730 ID3D11Texture2D_Release(offscreen);
5731 done:
5732 ID3D11BlendState_Release(dst_blend);
5733 ID3D11BlendState_Release(src_blend);
5734 ID3D11PixelShader_Release(ps);
5735 ID3D11VertexShader_Release(vs);
5736 ID3D11Buffer_Release(vb);
5737 ID3D11InputLayout_Release(input_layout);
5738 release_test_context(&test_context);
5741 static void test_texture(void)
5743 struct shader
5745 const DWORD *code;
5746 size_t size;
5748 struct texture
5750 UINT width;
5751 UINT height;
5752 UINT miplevel_count;
5753 UINT array_size;
5754 DXGI_FORMAT format;
5755 D3D11_SUBRESOURCE_DATA data[3];
5758 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
5759 struct d3d11_test_context test_context;
5760 const struct texture *current_texture;
5761 D3D11_TEXTURE2D_DESC texture_desc;
5762 D3D11_SAMPLER_DESC sampler_desc;
5763 const struct shader *current_ps;
5764 D3D_FEATURE_LEVEL feature_level;
5765 ID3D11ShaderResourceView *srv;
5766 ID3D11DeviceContext *context;
5767 ID3D11SamplerState *sampler;
5768 struct resource_readback rb;
5769 ID3D11Texture2D *texture;
5770 struct vec4 ps_constant;
5771 ID3D11PixelShader *ps;
5772 ID3D11Device *device;
5773 unsigned int i, x, y;
5774 ID3D11Buffer *cb;
5775 DWORD color;
5776 HRESULT hr;
5778 static const DWORD ps_ld_code[] =
5780 #if 0
5781 Texture2D t;
5783 float miplevel;
5785 float4 main(float4 position : SV_POSITION) : SV_TARGET
5787 float3 p;
5788 t.GetDimensions(miplevel, p.x, p.y, p.z);
5789 p.z = miplevel;
5790 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5791 return t.Load(int3(p));
5793 #endif
5794 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5795 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5796 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5797 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5798 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5799 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5800 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5801 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5802 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5803 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5804 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5805 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5806 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5807 0x00107e46, 0x00000000, 0x0100003e,
5809 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5810 static const DWORD ps_ld_sint8_code[] =
5812 #if 0
5813 Texture2D<int4> t;
5815 float4 main(float4 position : SV_POSITION) : SV_TARGET
5817 float3 p, s;
5818 int4 c;
5820 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5821 t.GetDimensions(0, s.x, s.y, s.z);
5822 p *= s;
5824 c = t.Load(int3(p));
5825 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5827 #endif
5828 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
5829 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5830 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5831 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5832 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5833 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5834 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5835 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5836 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5837 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5838 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5839 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5840 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5841 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5842 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5843 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5844 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5845 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5847 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5848 static const DWORD ps_ld_uint8_code[] =
5850 #if 0
5851 Texture2D<uint4> t;
5853 float4 main(float4 position : SV_POSITION) : SV_TARGET
5855 float3 p, s;
5857 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5858 t.GetDimensions(0, s.x, s.y, s.z);
5859 p *= s;
5861 return t.Load(int3(p)) / (float4)255;
5863 #endif
5864 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5865 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5866 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5867 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5868 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5869 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5870 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5871 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5872 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5873 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5874 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5875 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5876 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5877 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5878 0x3b808081, 0x0100003e,
5880 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5881 static const DWORD ps_sample_code[] =
5883 #if 0
5884 Texture2D t;
5885 SamplerState s;
5887 float4 main(float4 position : SV_POSITION) : SV_Target
5889 float2 p;
5891 p.x = position.x / 640.0f;
5892 p.y = position.y / 480.0f;
5893 return t.Sample(s, p);
5895 #endif
5896 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5897 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5898 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5899 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5900 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5901 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5902 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5903 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5904 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5905 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5907 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
5908 static const DWORD ps_sample_b_code[] =
5910 #if 0
5911 Texture2D t;
5912 SamplerState s;
5914 float bias;
5916 float4 main(float4 position : SV_POSITION) : SV_Target
5918 float2 p;
5920 p.x = position.x / 640.0f;
5921 p.y = position.y / 480.0f;
5922 return t.SampleBias(s, p, bias);
5924 #endif
5925 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
5926 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5927 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5928 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5929 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5930 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5931 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5932 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5933 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
5934 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5935 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5937 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
5938 static const DWORD ps_sample_l_code[] =
5940 #if 0
5941 Texture2D t;
5942 SamplerState s;
5944 float level;
5946 float4 main(float4 position : SV_POSITION) : SV_Target
5948 float2 p;
5950 p.x = position.x / 640.0f;
5951 p.y = position.y / 480.0f;
5952 return t.SampleLevel(s, p, level);
5954 #endif
5955 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
5956 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5957 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5958 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5959 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5960 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5961 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5962 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5963 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
5964 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5965 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5967 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
5968 static const DWORD ps_sample_2d_array_code[] =
5970 #if 0
5971 Texture2DArray t;
5972 SamplerState s;
5974 float layer;
5976 float4 main(float4 position : SV_POSITION) : SV_TARGET
5978 float3 d;
5979 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5980 t.GetDimensions(d.x, d.y, d.z);
5981 d.z = layer;
5982 return t.Sample(s, p * d);
5984 #endif
5985 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
5986 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5987 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5988 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5989 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
5990 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5991 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5992 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
5993 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
5994 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
5995 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
5996 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
5997 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5999 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
6000 static const DWORD red_data[] =
6002 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6003 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6004 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6005 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6007 static const DWORD green_data[] =
6009 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6010 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6011 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6012 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6014 static const DWORD blue_data[] =
6016 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6017 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6018 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6019 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6021 static const DWORD rgba_level_0[] =
6023 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6024 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6025 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6026 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6028 static const DWORD rgba_level_1[] =
6030 0xffffffff, 0xff0000ff,
6031 0xff000000, 0xff00ff00,
6033 static const DWORD rgba_level_2[] =
6035 0xffff0000,
6037 static const DWORD srgb_data[] =
6039 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
6040 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
6041 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
6042 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
6044 static const BYTE a8_data[] =
6046 0x00, 0x10, 0x20, 0x30,
6047 0x40, 0x50, 0x60, 0x70,
6048 0x80, 0x90, 0xa0, 0xb0,
6049 0xc0, 0xd0, 0xe0, 0xf0,
6051 static const BYTE bc1_data[] =
6053 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6054 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6055 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6056 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6058 static const BYTE bc2_data[] =
6060 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6061 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6062 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6063 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6065 static const BYTE bc3_data[] =
6067 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6068 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6069 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6070 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6072 static const BYTE bc4_data[] =
6074 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6075 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6076 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6077 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6079 static const BYTE bc5_data[] =
6081 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6082 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6083 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6084 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6086 static const BYTE bc6h_u_data[] =
6088 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6089 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6090 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6091 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6093 static const BYTE bc6h_s_data[] =
6095 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6096 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6097 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6098 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6100 static const BYTE bc7_data[] =
6102 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6103 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6104 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6105 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
6107 static const float r32_float[] =
6109 0.0f, 1.0f, 0.5f, 0.50f,
6110 1.0f, 0.0f, 0.0f, 0.75f,
6111 0.0f, 1.0f, 0.5f, 0.25f,
6112 1.0f, 0.0f, 0.0f, 0.75f,
6114 static const DWORD r32_uint[] =
6116 0, 1, 2, 3,
6117 100, 200, 255, 128,
6118 40, 30, 20, 10,
6119 250, 210, 155, 190,
6121 static const DWORD r9g9b9e5_data[] =
6123 0x80000100, 0x80020000, 0x84000000, 0x84000100,
6124 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
6125 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
6126 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
6128 static const struct texture rgba_texture =
6130 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
6132 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
6133 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
6134 {rgba_level_2, sizeof(*rgba_level_2), 0},
6137 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6138 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6139 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
6140 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6141 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
6142 {{a8_data, 4 * sizeof(*a8_data)}}};
6143 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
6144 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
6145 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
6146 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
6147 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
6148 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
6149 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
6150 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
6151 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
6152 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
6153 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
6154 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
6155 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
6156 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
6157 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
6158 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
6159 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6160 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
6161 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6162 static const struct texture array_2d_texture =
6164 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
6166 {red_data, 6 * sizeof(*red_data)},
6167 {green_data, 4 * sizeof(*green_data)},
6168 {blue_data, 5 * sizeof(*blue_data)},
6171 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6172 {{r32_float, 4 * sizeof(*r32_float)}}};
6173 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6174 {{r32_uint, 4 * sizeof(*r32_uint)}}};
6175 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
6176 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
6177 static const DWORD red_colors[] =
6179 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6180 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6181 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6182 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6184 static const DWORD blue_colors[] =
6186 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6187 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6188 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6189 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6191 static const DWORD level_1_colors[] =
6193 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6194 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6195 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6196 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6198 static const DWORD lerp_1_2_colors[] =
6200 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6201 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6202 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6203 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6205 static const DWORD level_2_colors[] =
6207 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6208 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6209 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6210 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6212 static const DWORD srgb_colors[] =
6214 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
6215 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
6216 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
6217 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
6219 static const DWORD a8_colors[] =
6221 0x00000000, 0x10000000, 0x20000000, 0x30000000,
6222 0x40000000, 0x50000000, 0x60000000, 0x70000000,
6223 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
6224 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
6226 static const DWORD bc_colors[] =
6228 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6229 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6230 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6231 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6233 static const DWORD bc4_colors[] =
6235 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
6236 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
6237 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6238 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6240 static const DWORD bc5_colors[] =
6242 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
6243 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
6244 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6245 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6247 static const DWORD bc7_colors[] =
6249 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6250 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6251 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6252 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6254 static const DWORD sint8_colors[] =
6256 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
6257 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
6258 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
6259 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
6261 static const DWORD r32f_colors[] =
6263 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
6264 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6265 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
6266 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6268 static const DWORD r32u_colors[16] =
6270 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6271 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
6272 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
6273 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
6275 static const DWORD r9g9b9e5_colors[16] =
6277 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
6278 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
6279 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
6280 0xff000033, 0xff003300, 0xff330000, 0xff333333,
6282 static const DWORD zero_colors[4 * 4] = {0};
6283 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6285 static const struct texture_test
6287 const struct shader *ps;
6288 const struct texture *texture;
6289 D3D11_FILTER filter;
6290 float lod_bias;
6291 float min_lod;
6292 float max_lod;
6293 float ps_constant;
6294 const DWORD *expected_colors;
6296 texture_tests[] =
6298 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
6299 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
6300 #define MIP_MAX D3D11_FLOAT32_MAX
6301 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6302 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6303 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6304 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6305 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6306 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6307 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6308 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6309 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6310 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6311 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6312 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6313 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6314 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6315 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6316 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6317 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6318 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6319 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6320 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6321 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6322 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6323 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6324 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6325 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6326 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6327 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6328 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6329 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6330 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6331 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6332 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6333 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6334 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6335 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6336 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6337 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6338 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6339 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6340 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
6341 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6342 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6343 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6344 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6345 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6346 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
6347 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
6348 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
6349 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
6350 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
6351 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
6352 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
6353 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
6354 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6355 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6356 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6357 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6358 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
6359 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6360 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
6361 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
6362 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
6363 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
6364 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6365 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
6366 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
6367 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
6368 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
6369 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
6370 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
6371 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
6372 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
6373 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6374 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6375 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6376 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6377 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6378 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6379 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6380 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6381 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6382 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6383 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6384 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
6385 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
6386 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
6387 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
6388 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
6389 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
6390 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
6391 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
6392 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
6393 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
6394 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
6395 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
6396 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
6397 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
6398 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
6399 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
6400 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6401 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6402 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
6403 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6404 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6405 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
6406 #undef POINT
6407 #undef POINT_LINEAR
6408 #undef MIP_MAX
6410 static const struct srv_test
6412 const struct shader *ps;
6413 const struct texture *texture;
6414 struct srv_desc srv_desc;
6415 float ps_constant;
6416 const DWORD *expected_colors;
6418 srv_tests[] =
6420 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
6421 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
6422 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
6423 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
6424 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
6425 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
6426 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
6427 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
6428 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
6429 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
6430 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
6431 #define R32_UINT DXGI_FORMAT_R32_UINT
6432 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
6433 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6434 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6435 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6436 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6437 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6438 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6439 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
6440 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
6441 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
6442 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
6443 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
6444 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
6445 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
6446 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
6447 #undef TEX_2D
6448 #undef TEX_2D_ARRAY
6449 #undef BC1_UNORM
6450 #undef BC1_UNORM_SRGB
6451 #undef BC2_UNORM
6452 #undef BC2_UNORM_SRGB
6453 #undef BC3_UNORM
6454 #undef BC3_UNORM_SRGB
6455 #undef R8G8B8A8_UNORM_SRGB
6456 #undef R8G8B8A8_UNORM
6457 #undef R32_FLOAT
6458 #undef R32_UINT
6459 #undef FMT_UNKNOWN
6462 if (!init_test_context(&test_context, NULL))
6463 return;
6465 device = test_context.device;
6466 context = test_context.immediate_context;
6467 feature_level = ID3D11Device_GetFeatureLevel(device);
6469 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6471 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6473 texture_desc.SampleDesc.Count = 1;
6474 texture_desc.SampleDesc.Quality = 0;
6475 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6476 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6477 texture_desc.CPUAccessFlags = 0;
6478 texture_desc.MiscFlags = 0;
6480 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6481 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
6482 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
6483 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
6484 sampler_desc.MipLODBias = 0.0f;
6485 sampler_desc.MaxAnisotropy = 0;
6486 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
6487 sampler_desc.BorderColor[0] = 0.0f;
6488 sampler_desc.BorderColor[1] = 0.0f;
6489 sampler_desc.BorderColor[2] = 0.0f;
6490 sampler_desc.BorderColor[3] = 0.0f;
6491 sampler_desc.MinLOD = 0.0f;
6492 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6494 ps = NULL;
6495 srv = NULL;
6496 sampler = NULL;
6497 texture = NULL;
6498 current_ps = NULL;
6499 current_texture = NULL;
6500 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6502 const struct texture_test *test = &texture_tests[i];
6504 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
6505 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
6506 && feature_level < D3D_FEATURE_LEVEL_11_0)
6508 skip("Feature level >= 11.0 is required for BC7 tests.\n");
6509 continue;
6512 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
6513 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
6514 && feature_level < D3D_FEATURE_LEVEL_11_0)
6516 skip("Feature level >= 11.0 is required for BC6H tests.\n");
6517 continue;
6520 if (current_ps != test->ps)
6522 if (ps)
6523 ID3D11PixelShader_Release(ps);
6525 current_ps = test->ps;
6527 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6528 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6530 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6533 if (current_texture != test->texture)
6535 if (texture)
6536 ID3D11Texture2D_Release(texture);
6537 if (srv)
6538 ID3D11ShaderResourceView_Release(srv);
6540 current_texture = test->texture;
6542 if (current_texture)
6544 texture_desc.Width = current_texture->width;
6545 texture_desc.Height = current_texture->height;
6546 texture_desc.MipLevels = current_texture->miplevel_count;
6547 texture_desc.ArraySize = current_texture->array_size;
6548 texture_desc.Format = current_texture->format;
6550 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6551 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6553 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6554 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6556 else
6558 texture = NULL;
6559 srv = NULL;
6562 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6565 if (!sampler || (sampler_desc.Filter != test->filter
6566 || sampler_desc.MipLODBias != test->lod_bias
6567 || sampler_desc.MinLOD != test->min_lod
6568 || sampler_desc.MaxLOD != test->max_lod))
6570 if (sampler)
6571 ID3D11SamplerState_Release(sampler);
6573 sampler_desc.Filter = test->filter;
6574 sampler_desc.MipLODBias = test->lod_bias;
6575 sampler_desc.MinLOD = test->min_lod;
6576 sampler_desc.MaxLOD = test->max_lod;
6578 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6579 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6581 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6584 ps_constant.x = test->ps_constant;
6585 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6587 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6589 draw_quad(&test_context);
6591 get_texture_readback(test_context.backbuffer, 0, &rb);
6592 for (y = 0; y < 4; ++y)
6594 for (x = 0; x < 4; ++x)
6596 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6597 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
6598 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6601 release_resource_readback(&rb);
6603 if (srv)
6604 ID3D11ShaderResourceView_Release(srv);
6605 ID3D11SamplerState_Release(sampler);
6606 if (texture)
6607 ID3D11Texture2D_Release(texture);
6608 ID3D11PixelShader_Release(ps);
6610 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_10_1)
6612 win_skip("SRV tests are broken on WARP.\n");
6613 ID3D11Buffer_Release(cb);
6614 release_test_context(&test_context);
6615 return;
6618 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6619 sampler_desc.MipLODBias = 0.0f;
6620 sampler_desc.MinLOD = 0.0f;
6621 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6623 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6624 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6626 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6628 ps = NULL;
6629 srv = NULL;
6630 texture = NULL;
6631 current_ps = NULL;
6632 current_texture = NULL;
6633 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
6635 const struct srv_test *test = &srv_tests[i];
6637 if (current_ps != test->ps)
6639 if (ps)
6640 ID3D11PixelShader_Release(ps);
6642 current_ps = test->ps;
6644 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6645 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6647 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6650 if (current_texture != test->texture)
6652 if (texture)
6653 ID3D11Texture2D_Release(texture);
6655 current_texture = test->texture;
6657 texture_desc.Width = current_texture->width;
6658 texture_desc.Height = current_texture->height;
6659 texture_desc.MipLevels = current_texture->miplevel_count;
6660 texture_desc.ArraySize = current_texture->array_size;
6661 texture_desc.Format = current_texture->format;
6663 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6664 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6667 if (srv)
6668 ID3D11ShaderResourceView_Release(srv);
6670 get_srv_desc(&srv_desc, &test->srv_desc);
6671 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
6672 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6674 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6676 ps_constant.x = test->ps_constant;
6677 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6679 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6681 draw_quad(&test_context);
6683 get_texture_readback(test_context.backbuffer, 0, &rb);
6684 for (y = 0; y < 4; ++y)
6686 for (x = 0; x < 4; ++x)
6688 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6689 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
6690 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6693 release_resource_readback(&rb);
6695 ID3D11PixelShader_Release(ps);
6696 ID3D11Texture2D_Release(texture);
6697 ID3D11ShaderResourceView_Release(srv);
6698 ID3D11SamplerState_Release(sampler);
6700 ID3D11Buffer_Release(cb);
6701 release_test_context(&test_context);
6704 static void test_cube_maps(void)
6706 struct shader
6708 const DWORD *code;
6709 size_t size;
6712 unsigned int i, j, sub_resource_idx, sub_resource_count;
6713 struct d3d11_test_context test_context;
6714 D3D11_TEXTURE2D_DESC texture_desc;
6715 const struct shader *current_ps;
6716 D3D_FEATURE_LEVEL feature_level;
6717 ID3D11ShaderResourceView *srv;
6718 ID3D11DeviceContext *context;
6719 ID3D11Texture2D *rtv_texture;
6720 ID3D11RenderTargetView *rtv;
6721 struct vec4 expected_result;
6722 ID3D11Resource *texture;
6723 ID3D11PixelShader *ps;
6724 ID3D11Device *device;
6725 float data[64 * 64];
6726 ID3D11Buffer *cb;
6727 HRESULT hr;
6728 RECT rect;
6729 struct
6731 unsigned int face;
6732 unsigned int level;
6733 unsigned int cube;
6734 unsigned int padding;
6735 } constant;
6737 static const DWORD ps_cube_code[] =
6739 #if 0
6740 TextureCube t;
6741 SamplerState s;
6743 uint face;
6744 uint level;
6746 float4 main(float4 position : SV_POSITION) : SV_Target
6748 float2 p;
6749 p.x = position.x / 640.0f;
6750 p.y = position.y / 480.0f;
6752 float3 coord;
6753 switch (face)
6755 case 0:
6756 coord = float3(1.0f, p.x, p.y);
6757 break;
6758 case 1:
6759 coord = float3(-1.0f, p.x, p.y);
6760 break;
6761 case 2:
6762 coord = float3(p.x, 1.0f, p.y);
6763 break;
6764 case 3:
6765 coord = float3(p.x, -1.0f, p.y);
6766 break;
6767 case 4:
6768 coord = float3(p.x, p.y, 1.0f);
6769 break;
6770 case 5:
6771 default:
6772 coord = float3(p.x, p.y, -1.0f);
6773 break;
6775 return t.SampleLevel(s, coord, level);
6777 #endif
6778 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
6779 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6780 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6781 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6782 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
6783 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6784 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6785 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
6786 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
6787 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
6788 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
6789 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
6790 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
6791 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6792 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
6793 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
6794 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
6795 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
6796 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
6797 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
6798 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6799 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
6800 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
6801 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
6802 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
6804 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
6805 static const DWORD ps_cube_array_code[] =
6807 #if 0
6808 TextureCubeArray t;
6809 SamplerState s;
6811 uint face;
6812 uint level;
6813 uint cube;
6815 float4 main(float4 position : SV_POSITION) : SV_Target
6817 float2 p;
6818 p.x = position.x / 640.0f;
6819 p.y = position.y / 480.0f;
6821 float3 coord;
6822 switch (face)
6824 case 0:
6825 coord = float3(1.0f, p.x, p.y);
6826 break;
6827 case 1:
6828 coord = float3(-1.0f, p.x, p.y);
6829 break;
6830 case 2:
6831 coord = float3(p.x, 1.0f, p.y);
6832 break;
6833 case 3:
6834 coord = float3(p.x, -1.0f, p.y);
6835 break;
6836 case 4:
6837 coord = float3(p.x, p.y, 1.0f);
6838 break;
6839 case 5:
6840 default:
6841 coord = float3(p.x, p.y, -1.0f);
6842 break;
6844 return t.SampleLevel(s, float4(coord, cube), level);
6846 #endif
6847 0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
6848 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6849 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6850 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6851 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
6852 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
6853 0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
6854 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
6855 0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
6856 0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6857 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
6858 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
6859 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
6860 0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
6861 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
6862 0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
6863 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
6864 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
6865 0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6866 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
6867 0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
6868 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
6869 0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
6870 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
6871 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
6872 0x00000001, 0x0100003e,
6874 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
6875 static const struct ps_test
6877 const struct shader *ps;
6878 unsigned int miplevel_count;
6879 unsigned int array_size;
6881 ps_tests[] =
6883 {&ps_cube, 1, 6},
6884 {&ps_cube, 2, 6},
6885 {&ps_cube, 3, 6},
6886 {&ps_cube, 0, 6},
6888 {&ps_cube_array, 1, 12},
6889 {&ps_cube_array, 2, 12},
6890 {&ps_cube_array, 3, 12},
6891 {&ps_cube_array, 0, 12},
6894 if (!init_test_context(&test_context, NULL))
6895 return;
6897 device = test_context.device;
6898 context = test_context.immediate_context;
6899 feature_level = ID3D11Device_GetFeatureLevel(device);
6901 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
6902 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
6903 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
6904 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6905 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
6906 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
6908 memset(&constant, 0, sizeof(constant));
6909 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
6911 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6912 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6914 ps = NULL;
6915 current_ps = NULL;
6916 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
6918 const struct ps_test *test = &ps_tests[i];
6920 if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
6922 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
6923 continue;
6926 if (current_ps != test->ps)
6928 if (ps)
6929 ID3D11PixelShader_Release(ps);
6931 current_ps = test->ps;
6933 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6934 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6935 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6938 if (!test->miplevel_count)
6940 srv = NULL;
6941 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6943 memset(&expected_result, 0, sizeof(expected_result));
6945 memset(&constant, 0, sizeof(constant));
6946 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
6947 draw_quad(&test_context);
6948 check_texture_vec4(rtv_texture, &expected_result, 0);
6949 constant.level = 1;
6950 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
6951 draw_quad(&test_context);
6952 check_texture_vec4(rtv_texture, &expected_result, 0);
6953 continue;
6956 texture_desc.Width = 64;
6957 texture_desc.Height = 64;
6958 texture_desc.MipLevels = test->miplevel_count;
6959 texture_desc.ArraySize = test->array_size;
6960 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
6961 texture_desc.SampleDesc.Count = 1;
6962 texture_desc.SampleDesc.Quality = 0;
6963 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6964 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6965 texture_desc.CPUAccessFlags = 0;
6966 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
6967 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
6968 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6970 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
6971 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6972 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6974 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
6975 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
6977 for (j = 0; j < ARRAY_SIZE(data); ++j)
6978 data[j] = sub_resource_idx;
6979 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, sub_resource_idx, NULL,
6980 data, texture_desc.Width * sizeof(*data), 0);
6983 expected_result.y = expected_result.z = 0.0f;
6984 expected_result.w = 1.0f;
6985 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
6987 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
6988 constant.level = sub_resource_idx % texture_desc.MipLevels;
6989 constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
6990 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
6992 draw_quad(&test_context);
6993 expected_result.x = sub_resource_idx;
6994 /* Avoid testing values affected by seamless cube map filtering. */
6995 SetRect(&rect, 100, 100, 540, 380);
6996 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
6999 ID3D11Resource_Release(texture);
7000 ID3D11ShaderResourceView_Release(srv);
7002 ID3D11PixelShader_Release(ps);
7004 ID3D11Buffer_Release(cb);
7005 ID3D11RenderTargetView_Release(rtv);
7006 ID3D11Texture2D_Release(rtv_texture);
7007 release_test_context(&test_context);
7010 static void test_depth_stencil_sampling(void)
7012 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
7013 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
7014 ID3D11SamplerState *cmp_sampler, *sampler;
7015 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
7016 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
7017 struct d3d11_test_context test_context;
7018 ID3D11Texture2D *texture, *rt_texture;
7019 D3D11_TEXTURE2D_DESC texture_desc;
7020 D3D11_SAMPLER_DESC sampler_desc;
7021 ID3D11DeviceContext *context;
7022 ID3D11DepthStencilView *dsv;
7023 ID3D11RenderTargetView *rtv;
7024 struct vec4 ps_constant;
7025 ID3D11Device *device;
7026 ID3D11Buffer *cb;
7027 unsigned int i;
7028 HRESULT hr;
7030 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
7031 static const DWORD ps_compare_code[] =
7033 #if 0
7034 Texture2D t;
7035 SamplerComparisonState s;
7037 float ref;
7039 float4 main(float4 position : SV_Position) : SV_Target
7041 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
7043 #endif
7044 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
7045 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7046 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7047 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7048 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
7049 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
7050 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7051 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
7052 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
7053 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
7054 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
7055 0x0100003e,
7057 static const DWORD ps_sample_code[] =
7059 #if 0
7060 Texture2D t;
7061 SamplerState s;
7063 float4 main(float4 position : SV_Position) : SV_Target
7065 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
7067 #endif
7068 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
7069 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7070 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7071 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7072 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7073 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7074 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7075 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7076 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7077 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7079 static const DWORD ps_stencil_code[] =
7081 #if 0
7082 Texture2D<uint4> t;
7084 float4 main(float4 position : SV_Position) : SV_Target
7086 float2 s;
7087 t.GetDimensions(s.x, s.y);
7088 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
7090 #endif
7091 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
7092 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7093 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7094 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7095 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
7096 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
7097 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
7098 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
7099 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
7100 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
7101 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
7102 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7103 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
7105 static const DWORD ps_depth_stencil_code[] =
7107 #if 0
7108 SamplerState samp;
7109 Texture2D depth_tex;
7110 Texture2D<uint4> stencil_tex;
7112 float main(float4 position: SV_Position) : SV_Target
7114 float2 s, p;
7115 float depth, stencil;
7116 depth_tex.GetDimensions(s.x, s.y);
7117 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
7118 depth = depth_tex.Sample(samp, p).r;
7119 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
7120 return depth + stencil;
7122 #endif
7123 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
7124 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7125 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7126 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7127 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
7128 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7129 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7130 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
7131 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
7132 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
7133 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
7134 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
7135 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
7136 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
7137 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
7138 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
7140 static const struct test
7142 DXGI_FORMAT typeless_format;
7143 DXGI_FORMAT dsv_format;
7144 DXGI_FORMAT depth_view_format;
7145 DXGI_FORMAT stencil_view_format;
7147 tests[] =
7149 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
7150 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
7151 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
7152 DXGI_FORMAT_R32_FLOAT},
7153 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
7154 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
7155 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
7156 DXGI_FORMAT_R16_UNORM},
7159 if (!init_test_context(&test_context, NULL))
7160 return;
7162 device = test_context.device;
7163 context = test_context.immediate_context;
7165 if (is_amd_device(device))
7167 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
7168 win_skip("Some AMD drivers have a bug affecting the test.\n");
7169 release_test_context(&test_context);
7170 return;
7173 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
7174 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7175 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7176 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7177 sampler_desc.MipLODBias = 0.0f;
7178 sampler_desc.MaxAnisotropy = 0;
7179 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
7180 sampler_desc.BorderColor[0] = 0.0f;
7181 sampler_desc.BorderColor[1] = 0.0f;
7182 sampler_desc.BorderColor[2] = 0.0f;
7183 sampler_desc.BorderColor[3] = 0.0f;
7184 sampler_desc.MinLOD = 0.0f;
7185 sampler_desc.MaxLOD = 0.0f;
7186 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
7187 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7189 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7190 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7191 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
7192 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7194 texture_desc.Width = 640;
7195 texture_desc.Height = 480;
7196 texture_desc.MipLevels = 1;
7197 texture_desc.ArraySize = 1;
7198 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7199 texture_desc.SampleDesc.Count = 1;
7200 texture_desc.SampleDesc.Quality = 0;
7201 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7202 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7203 texture_desc.CPUAccessFlags = 0;
7204 texture_desc.MiscFlags = 0;
7205 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
7206 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7207 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
7208 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
7209 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7211 memset(&ps_constant, 0, sizeof(ps_constant));
7212 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
7213 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7215 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
7216 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7217 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
7218 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7219 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
7220 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7221 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
7222 &ps_depth_stencil);
7223 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7225 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7227 texture_desc.Format = tests[i].typeless_format;
7228 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
7229 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7230 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
7231 texture_desc.Format, hr);
7233 dsv_desc.Format = tests[i].dsv_format;
7234 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
7235 dsv_desc.Flags = 0;
7236 U(dsv_desc).Texture2D.MipSlice = 0;
7237 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7238 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
7239 dsv_desc.Format, hr);
7241 srv_desc.Format = tests[i].depth_view_format;
7242 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
7243 U(srv_desc).Texture2D.MostDetailedMip = 0;
7244 U(srv_desc).Texture2D.MipLevels = 1;
7245 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
7246 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
7247 srv_desc.Format, hr);
7249 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
7250 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
7251 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
7253 ps_constant.x = 0.5f;
7254 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7255 NULL, &ps_constant, 0, 0);
7257 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7258 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7259 draw_quad(&test_context);
7260 check_texture_float(rt_texture, 0.0f, 2);
7262 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
7263 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7264 draw_quad(&test_context);
7265 check_texture_float(rt_texture, 1.0f, 2);
7267 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
7268 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7269 draw_quad(&test_context);
7270 check_texture_float(rt_texture, 0.0f, 2);
7272 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
7273 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7274 draw_quad(&test_context);
7275 check_texture_float(rt_texture, 0.0f, 2);
7277 ps_constant.x = 0.7f;
7278 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7279 NULL, &ps_constant, 0, 0);
7281 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7282 draw_quad(&test_context);
7283 check_texture_float(rt_texture, 1.0f, 2);
7285 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
7286 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7288 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7289 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7290 draw_quad(&test_context);
7291 check_texture_float(rt_texture, 1.0f, 2);
7293 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
7294 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7295 draw_quad(&test_context);
7296 check_texture_float(rt_texture, 0.2f, 2);
7298 if (!tests[i].stencil_view_format)
7300 ID3D11DepthStencilView_Release(dsv);
7301 ID3D11ShaderResourceView_Release(depth_srv);
7302 ID3D11Texture2D_Release(texture);
7303 continue;
7306 srv_desc.Format = tests[i].stencil_view_format;
7307 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
7308 if (hr == E_OUTOFMEMORY)
7310 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
7311 ID3D11DepthStencilView_Release(dsv);
7312 ID3D11ShaderResourceView_Release(depth_srv);
7313 ID3D11Texture2D_Release(texture);
7314 continue;
7316 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
7317 srv_desc.Format, hr);
7319 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
7320 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
7322 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
7323 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7324 draw_quad(&test_context);
7325 check_texture_float(rt_texture, 0.0f, 0);
7327 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
7328 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7329 draw_quad(&test_context);
7330 check_texture_float(rt_texture, 100.0f, 0);
7332 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
7333 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7334 draw_quad(&test_context);
7335 check_texture_float(rt_texture, 255.0f, 0);
7337 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
7338 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
7339 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
7341 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
7342 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7343 draw_quad(&test_context);
7344 check_texture_float(rt_texture, 3.3f, 2);
7346 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
7347 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7348 draw_quad(&test_context);
7349 check_texture_float(rt_texture, 4.0f, 2);
7351 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
7352 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7353 draw_quad(&test_context);
7354 check_texture_float(rt_texture, 0.0f, 2);
7356 ID3D11DepthStencilView_Release(dsv);
7357 ID3D11ShaderResourceView_Release(depth_srv);
7358 ID3D11ShaderResourceView_Release(stencil_srv);
7359 ID3D11Texture2D_Release(texture);
7362 ID3D11Buffer_Release(cb);
7363 ID3D11PixelShader_Release(ps_cmp);
7364 ID3D11PixelShader_Release(ps_depth);
7365 ID3D11PixelShader_Release(ps_depth_stencil);
7366 ID3D11PixelShader_Release(ps_stencil);
7367 ID3D11RenderTargetView_Release(rtv);
7368 ID3D11SamplerState_Release(cmp_sampler);
7369 ID3D11SamplerState_Release(sampler);
7370 ID3D11Texture2D_Release(rt_texture);
7371 release_test_context(&test_context);
7374 static void test_multiple_render_targets(void)
7376 D3D11_TEXTURE2D_DESC texture_desc;
7377 ID3D11InputLayout *input_layout;
7378 unsigned int stride, offset, i;
7379 ID3D11RenderTargetView *rtv[4];
7380 ID3D11DeviceContext *context;
7381 ID3D11Texture2D *rt[4];
7382 ID3D11VertexShader *vs;
7383 ID3D11PixelShader *ps;
7384 ID3D11Device *device;
7385 D3D11_VIEWPORT vp;
7386 ID3D11Buffer *vb;
7387 ULONG refcount;
7388 HRESULT hr;
7390 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
7392 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
7394 static const DWORD vs_code[] =
7396 #if 0
7397 float4 main(float4 position : POSITION) : SV_POSITION
7399 return position;
7401 #endif
7402 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
7403 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7404 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7405 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
7406 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
7407 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7408 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
7410 static const DWORD ps_code[] =
7412 #if 0
7413 struct output
7415 float4 t1 : SV_TARGET0;
7416 float4 t2 : SV_Target1;
7417 float4 t3 : SV_TARGET2;
7418 float4 t4 : SV_Target3;
7421 output main(float4 position : SV_POSITION)
7423 struct output o;
7424 o.t1 = (float4)1.0f;
7425 o.t2 = (float4)0.5f;
7426 o.t3 = (float4)0.2f;
7427 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
7428 return o;
7430 #endif
7431 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
7432 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7433 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7434 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
7435 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
7436 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
7437 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
7438 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
7439 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
7440 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
7441 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
7442 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
7443 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
7444 0x3f800000, 0x0100003e,
7446 static const struct vec2 quad[] =
7448 {-1.0f, -1.0f},
7449 {-1.0f, 1.0f},
7450 { 1.0f, -1.0f},
7451 { 1.0f, 1.0f},
7453 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
7455 if (!(device = create_device(NULL)))
7457 skip("Failed to create device.\n");
7458 return;
7461 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
7462 vs_code, sizeof(vs_code), &input_layout);
7463 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7465 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7467 texture_desc.Width = 640;
7468 texture_desc.Height = 480;
7469 texture_desc.MipLevels = 1;
7470 texture_desc.ArraySize = 1;
7471 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7472 texture_desc.SampleDesc.Count = 1;
7473 texture_desc.SampleDesc.Quality = 0;
7474 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7475 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7476 texture_desc.CPUAccessFlags = 0;
7477 texture_desc.MiscFlags = 0;
7479 for (i = 0; i < ARRAY_SIZE(rt); ++i)
7481 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
7482 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
7484 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
7485 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
7488 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
7489 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7490 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7491 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7493 ID3D11Device_GetImmediateContext(device, &context);
7495 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
7496 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
7497 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7498 stride = sizeof(*quad);
7499 offset = 0;
7500 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
7501 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
7502 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7504 vp.TopLeftX = 0.0f;
7505 vp.TopLeftY = 0.0f;
7506 vp.Width = 640.0f;
7507 vp.Height = 480.0f;
7508 vp.MinDepth = 0.0f;
7509 vp.MaxDepth = 1.0f;
7510 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
7512 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7513 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
7515 ID3D11DeviceContext_Draw(context, 4, 0);
7517 check_texture_color(rt[0], 0xffffffff, 2);
7518 check_texture_color(rt[1], 0x7f7f7f7f, 2);
7519 check_texture_color(rt[2], 0x33333333, 2);
7520 check_texture_color(rt[3], 0xff7f3300, 2);
7522 ID3D11Buffer_Release(vb);
7523 ID3D11PixelShader_Release(ps);
7524 ID3D11VertexShader_Release(vs);
7525 ID3D11InputLayout_Release(input_layout);
7526 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7528 ID3D11RenderTargetView_Release(rtv[i]);
7529 ID3D11Texture2D_Release(rt[i]);
7531 ID3D11DeviceContext_Release(context);
7532 refcount = ID3D11Device_Release(device);
7533 ok(!refcount, "Device has %u references left.\n", refcount);
7536 static void test_render_target_views(void)
7538 struct texture
7540 UINT miplevel_count;
7541 UINT array_size;
7544 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
7545 static struct test
7547 struct texture texture;
7548 struct rtv_desc rtv;
7549 DWORD expected_colors[4];
7551 tests[] =
7553 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7554 {0xff0000ff, 0x00000000}},
7555 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
7556 {0x00000000, 0xff0000ff}},
7557 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7558 {0xff0000ff, 0x00000000}},
7559 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7560 {0x00000000, 0xff0000ff}},
7561 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7562 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7563 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7564 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7565 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7566 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7567 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
7568 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7569 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
7570 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7571 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
7572 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7573 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7574 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7575 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7576 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7577 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7578 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7579 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7580 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7581 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
7582 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7585 struct d3d11_test_context test_context;
7586 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7587 D3D11_TEXTURE2D_DESC texture_desc;
7588 ID3D11DeviceContext *context;
7589 ID3D11RenderTargetView *rtv;
7590 ID3D11Texture2D *texture;
7591 ID3D11Device *device;
7592 unsigned int i, j, k;
7593 void *data;
7594 HRESULT hr;
7596 if (!init_test_context(&test_context, NULL))
7597 return;
7599 device = test_context.device;
7600 context = test_context.immediate_context;
7602 texture_desc.Width = 32;
7603 texture_desc.Height = 32;
7604 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7605 texture_desc.SampleDesc.Count = 1;
7606 texture_desc.SampleDesc.Quality = 0;
7607 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7608 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7609 texture_desc.CPUAccessFlags = 0;
7610 texture_desc.MiscFlags = 0;
7612 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, texture_desc.Width * texture_desc.Height * 4);
7613 ok(!!data, "Failed to allocate memory.\n");
7615 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7617 const struct test *test = &tests[i];
7618 unsigned int sub_resource_count;
7620 texture_desc.MipLevels = test->texture.miplevel_count;
7621 texture_desc.ArraySize = test->texture.array_size;
7623 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7624 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
7626 get_rtv_desc(&rtv_desc, &test->rtv);
7627 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7628 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
7630 for (j = 0; j < texture_desc.ArraySize; ++j)
7632 for (k = 0; k < texture_desc.MipLevels; ++k)
7634 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
7635 ID3D11DeviceContext_UpdateSubresource(context,
7636 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
7639 check_texture_color(texture, 0, 0);
7641 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7642 draw_color_quad(&test_context, &red);
7644 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7645 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
7646 for (j = 0; j < sub_resource_count; ++j)
7647 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
7649 ID3D11RenderTargetView_Release(rtv);
7650 ID3D11Texture2D_Release(texture);
7653 HeapFree(GetProcessHeap(), 0, data);
7654 release_test_context(&test_context);
7657 static void test_layered_rendering(void)
7659 struct
7661 unsigned int layer_offset;
7662 unsigned int draw_id;
7663 unsigned int padding[2];
7664 } constant;
7665 struct d3d11_test_context test_context;
7666 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7667 unsigned int i, sub_resource_count;
7668 D3D11_TEXTURE2D_DESC texture_desc;
7669 ID3D11DeviceContext *context;
7670 ID3D11RenderTargetView *rtv;
7671 ID3D11Texture2D *texture;
7672 ID3D11GeometryShader *gs;
7673 ID3D11PixelShader *ps;
7674 ID3D11Device *device;
7675 ID3D11Buffer *cb;
7676 HRESULT hr;
7677 BOOL warp;
7679 static const DWORD gs_5_code[] =
7681 #if 0
7682 uint layer_offset;
7684 struct gs_in
7686 float4 pos : SV_Position;
7689 struct gs_out
7691 float4 pos : SV_Position;
7692 uint layer : SV_RenderTargetArrayIndex;
7695 [instance(4)]
7696 [maxvertexcount(3)]
7697 void main(triangle gs_in vin[3], in uint instance_id : SV_GSInstanceID,
7698 inout TriangleStream<gs_out> vout)
7700 gs_out o;
7701 o.layer = layer_offset + instance_id;
7702 for (uint i = 0; i < 3; ++i)
7704 o.pos = vin[i].pos;
7705 vout.Append(o);
7708 #endif
7709 0x43425844, 0xb52da162, 0x9a13d8ee, 0xf7c30b50, 0xe80bc2e7, 0x00000001, 0x00000218, 0x00000003,
7710 0x0000002c, 0x00000060, 0x000000d0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7711 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
7712 0x3547534f, 0x00000068, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
7713 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000004, 0x00000001,
7714 0x00000001, 0x00000e01, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472,
7715 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x58454853, 0x00000140, 0x00020050, 0x00000050,
7716 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
7717 0x00000000, 0x00000001, 0x0200005f, 0x00025000, 0x02000068, 0x00000001, 0x020000ce, 0x00000004,
7718 0x0100185d, 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
7719 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x00000003, 0x0700001e,
7720 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0002500a, 0x05000036, 0x00100022,
7721 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a,
7722 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000, 0x07000036, 0x001020f2,
7723 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001,
7724 0x0010000a, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x0700001e, 0x00100022, 0x00000000,
7725 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
7727 static const DWORD gs_4_code[] =
7729 #if 0
7730 uint layer_offset;
7732 struct gs_in
7734 float4 pos : SV_Position;
7737 struct gs_out
7739 float4 pos : SV_Position;
7740 uint layer : SV_RenderTargetArrayIndex;
7743 [maxvertexcount(12)]
7744 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
7746 gs_out o;
7747 for (uint instance_id = 0; instance_id < 4; ++instance_id)
7749 o.layer = layer_offset + instance_id;
7750 for (uint i = 0; i < 3; ++i)
7752 o.pos = vin[i].pos;
7753 vout.Append(o);
7755 vout.RestartStrip();
7758 #endif
7759 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
7760 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7761 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
7762 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
7763 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
7764 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
7765 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
7766 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
7767 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
7768 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
7769 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
7770 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
7771 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
7772 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
7773 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
7774 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
7775 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
7776 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
7777 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
7779 static const DWORD ps_code[] =
7781 #if 0
7782 uint layer_offset;
7783 uint draw_id;
7785 float4 main(in float4 pos : SV_Position,
7786 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
7788 return float4(layer, draw_id, 0, 0);
7790 #endif
7791 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
7792 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
7793 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
7794 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
7795 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
7796 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
7797 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
7798 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
7799 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
7800 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
7801 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
7803 static const struct vec4 expected_values[] =
7805 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
7806 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
7807 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
7808 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
7811 if (!init_test_context(&test_context, NULL))
7812 return;
7814 device = test_context.device;
7815 context = test_context.immediate_context;
7817 warp = is_warp_device(device);
7819 memset(&constant, 0, sizeof(constant));
7820 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
7821 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
7822 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7824 /* Geometry shader instancing seems broken on WARP. */
7825 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0 || warp)
7827 hr = ID3D11Device_CreateGeometryShader(device, gs_4_code, sizeof(gs_4_code), NULL, &gs);
7828 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
7830 else
7832 hr = ID3D11Device_CreateGeometryShader(device, gs_5_code, sizeof(gs_5_code), NULL, &gs);
7833 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
7835 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
7837 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7838 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7839 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7841 texture_desc.Width = 32;
7842 texture_desc.Height = 32;
7843 texture_desc.MipLevels = 3;
7844 texture_desc.ArraySize = 8;
7845 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
7846 texture_desc.SampleDesc.Count = 1;
7847 texture_desc.SampleDesc.Quality = 0;
7848 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7849 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7850 texture_desc.CPUAccessFlags = 0;
7851 texture_desc.MiscFlags = 0;
7852 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7853 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7855 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
7856 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7857 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7858 constant.layer_offset = 0;
7859 constant.draw_id = 0;
7860 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7861 draw_quad(&test_context);
7862 constant.layer_offset = 4;
7863 constant.draw_id = 1;
7864 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7865 draw_quad(&test_context);
7866 ID3D11RenderTargetView_Release(rtv);
7868 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
7869 rtv_desc.Format = texture_desc.Format;
7870 U(rtv_desc).Texture2DArray.MipSlice = 0;
7871 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
7872 U(rtv_desc).Texture2DArray.ArraySize = 1;
7873 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7874 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7875 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7876 constant.layer_offset = 1;
7877 constant.draw_id = 2;
7878 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7879 draw_quad(&test_context);
7880 ID3D11RenderTargetView_Release(rtv);
7882 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
7883 U(rtv_desc).Texture2DArray.MipSlice = 1;
7884 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
7885 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
7886 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7887 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7888 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7889 constant.layer_offset = 0;
7890 constant.draw_id = 3;
7891 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7892 draw_quad(&test_context);
7893 constant.layer_offset = 4;
7894 constant.draw_id = 3;
7895 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7896 draw_quad(&test_context);
7897 ID3D11RenderTargetView_Release(rtv);
7899 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
7900 U(rtv_desc).Texture2DArray.MipSlice = 2;
7901 U(rtv_desc).Texture2DArray.ArraySize = 1;
7902 for (i = 0; i < texture_desc.ArraySize; ++i)
7904 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
7905 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7906 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7907 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7908 constant.layer_offset = 0;
7909 constant.draw_id = 4 + i;
7910 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7911 draw_quad(&test_context);
7912 ID3D11RenderTargetView_Release(rtv);
7915 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7916 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
7917 for (i = 0; i < sub_resource_count; ++i)
7919 if (warp && (i == 3 || i == 4)) /* Broken on WARP. */
7920 continue;
7921 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
7924 ID3D11Texture2D_Release(texture);
7926 ID3D11Buffer_Release(cb);
7927 ID3D11GeometryShader_Release(gs);
7928 ID3D11PixelShader_Release(ps);
7929 release_test_context(&test_context);
7932 static void test_scissor(void)
7934 struct d3d11_test_context test_context;
7935 ID3D11DeviceContext *immediate_context;
7936 D3D11_RASTERIZER_DESC rs_desc;
7937 ID3D11RasterizerState *rs;
7938 D3D11_RECT scissor_rect;
7939 ID3D11PixelShader *ps;
7940 ID3D11Device *device;
7941 DWORD color;
7942 HRESULT hr;
7944 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
7945 static const DWORD ps_code[] =
7947 #if 0
7948 float4 main(float4 position : SV_POSITION) : SV_Target
7950 return float4(0.0, 1.0, 0.0, 1.0);
7952 #endif
7953 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
7954 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7955 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7956 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7957 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
7958 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
7959 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
7962 if (!init_test_context(&test_context, NULL))
7963 return;
7965 device = test_context.device;
7966 immediate_context = test_context.immediate_context;
7968 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7969 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7971 rs_desc.FillMode = D3D11_FILL_SOLID;
7972 rs_desc.CullMode = D3D11_CULL_BACK;
7973 rs_desc.FrontCounterClockwise = FALSE;
7974 rs_desc.DepthBias = 0;
7975 rs_desc.DepthBiasClamp = 0.0f;
7976 rs_desc.SlopeScaledDepthBias = 0.0f;
7977 rs_desc.DepthClipEnable = TRUE;
7978 rs_desc.ScissorEnable = TRUE;
7979 rs_desc.MultisampleEnable = FALSE;
7980 rs_desc.AntialiasedLineEnable = FALSE;
7981 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
7982 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
7984 ID3D11DeviceContext_PSSetShader(immediate_context, ps, NULL, 0);
7986 scissor_rect.left = 160;
7987 scissor_rect.top = 120;
7988 scissor_rect.right = 480;
7989 scissor_rect.bottom = 360;
7990 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
7992 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
7993 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
7995 draw_quad(&test_context);
7996 color = get_texture_color(test_context.backbuffer, 320, 60);
7997 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7998 color = get_texture_color(test_context.backbuffer, 80, 240);
7999 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8000 color = get_texture_color(test_context.backbuffer, 320, 240);
8001 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8002 color = get_texture_color(test_context.backbuffer, 560, 240);
8003 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8004 color = get_texture_color(test_context.backbuffer, 320, 420);
8005 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8007 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
8008 ID3D11DeviceContext_RSSetState(immediate_context, rs);
8009 draw_quad(&test_context);
8010 color = get_texture_color(test_context.backbuffer, 320, 60);
8011 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8012 color = get_texture_color(test_context.backbuffer, 80, 240);
8013 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8014 color = get_texture_color(test_context.backbuffer, 320, 240);
8015 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8016 color = get_texture_color(test_context.backbuffer, 560, 240);
8017 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8018 color = get_texture_color(test_context.backbuffer, 320, 420);
8019 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8021 ID3D11RasterizerState_Release(rs);
8022 ID3D11PixelShader_Release(ps);
8023 release_test_context(&test_context);
8026 static void test_clear_state(void)
8028 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
8029 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8031 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8033 #if 0
8034 float4 main(float4 pos : POSITION) : POSITION
8036 return pos;
8038 #endif
8039 static const DWORD simple_vs[] =
8041 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
8042 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8043 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8044 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8045 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
8046 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
8047 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8049 #if 0
8050 struct data
8052 float4 position : SV_Position;
8055 struct patch_constant_data
8057 float edges[3] : SV_TessFactor;
8058 float inside : SV_InsideTessFactor;
8061 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
8063 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
8064 output.inside = 1.0f;
8067 [domain("tri")]
8068 [outputcontrolpoints(3)]
8069 [partitioning("integer")]
8070 [outputtopology("triangle_ccw")]
8071 [patchconstantfunc("patch_constant")]
8072 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
8074 return input[i];
8077 [domain("tri")]
8078 void ds_main(patch_constant_data input,
8079 float3 tess_coord : SV_DomainLocation,
8080 const OutputPatch<data, 3> patch,
8081 out data output)
8083 output.position = tess_coord.x * patch[0].position
8084 + tess_coord.y * patch[1].position
8085 + tess_coord.z * patch[2].position;
8087 #endif
8088 static const DWORD simple_hs[] =
8090 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
8091 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
8092 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
8093 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
8094 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
8095 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
8096 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
8097 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
8098 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
8099 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
8100 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
8101 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
8102 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
8103 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
8104 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
8105 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
8106 0x00004001, 0x3f800000, 0x0100003e,
8108 static const DWORD simple_ds[] =
8110 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
8111 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
8112 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
8113 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
8114 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
8115 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
8116 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
8117 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
8118 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
8119 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
8120 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
8121 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
8122 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
8123 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
8124 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
8126 #if 0
8127 struct gs_out
8129 float4 pos : SV_POSITION;
8132 [maxvertexcount(4)]
8133 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
8135 float offset = 0.1 * vin[0].w;
8136 gs_out v;
8138 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
8139 vout.Append(v);
8140 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
8141 vout.Append(v);
8142 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
8143 vout.Append(v);
8144 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
8145 vout.Append(v);
8147 #endif
8148 static const DWORD simple_gs[] =
8150 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
8151 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8152 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8153 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8154 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
8155 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
8156 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
8157 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
8158 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
8159 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
8160 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
8161 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
8162 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
8163 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
8164 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
8165 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
8166 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
8167 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
8169 #if 0
8170 float4 main(float4 color : COLOR) : SV_TARGET
8172 return color;
8174 #endif
8175 static const DWORD simple_ps[] =
8177 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
8178 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
8179 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
8180 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8181 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8182 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
8183 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8185 #if 0
8186 [numthreads(1, 1, 1)]
8187 void main() { }
8188 #endif
8189 static const DWORD simple_cs[] =
8191 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
8192 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8193 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
8194 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
8197 D3D11_VIEWPORT tmp_viewport[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
8198 ID3D11ShaderResourceView *tmp_srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
8199 ID3D11ShaderResourceView *srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
8200 ID3D11RenderTargetView *tmp_rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8201 RECT tmp_rect[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
8202 ID3D11SamplerState *tmp_sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
8203 ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8204 ID3D11Texture2D *rt_texture[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8205 ID3D11Buffer *cb[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
8206 ID3D11Buffer *tmp_buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8207 ID3D11SamplerState *sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
8208 ID3D11UnorderedAccessView *tmp_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
8209 ID3D11UnorderedAccessView *cs_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
8210 ID3D11Buffer *buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8211 ID3D11Buffer *cs_uav_buffer[D3D11_PS_CS_UAV_REGISTER_COUNT];
8212 UINT offset[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8213 UINT stride[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8214 ID3D11Buffer *so_buffer[D3D11_SO_BUFFER_SLOT_COUNT];
8215 ID3D11InputLayout *tmp_input_layout, *input_layout;
8216 ID3D11DepthStencilState *tmp_ds_state, *ds_state;
8217 ID3D11BlendState *tmp_blend_state, *blend_state;
8218 ID3D11RasterizerState *tmp_rs_state, *rs_state;
8219 ID3D11Predicate *tmp_predicate, *predicate;
8220 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
8221 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8222 ID3D11DepthStencilView *tmp_dsv, *dsv;
8223 ID3D11UnorderedAccessView *ps_uav;
8224 D3D11_PRIMITIVE_TOPOLOGY topology;
8225 D3D11_TEXTURE2D_DESC texture_desc;
8226 ID3D11GeometryShader *tmp_gs, *gs;
8227 ID3D11ComputeShader *tmp_cs, *cs;
8228 D3D11_DEPTH_STENCIL_DESC ds_desc;
8229 ID3D11VertexShader *tmp_vs, *vs;
8230 ID3D11DomainShader *tmp_ds, *ds;
8231 D3D11_SAMPLER_DESC sampler_desc;
8232 D3D11_QUERY_DESC predicate_desc;
8233 struct device_desc device_desc;
8234 ID3D11PixelShader *tmp_ps, *ps;
8235 ID3D11HullShader *tmp_hs, *hs;
8236 D3D11_RASTERIZER_DESC rs_desc;
8237 ID3D11DeviceContext *context;
8238 D3D11_BLEND_DESC blend_desc;
8239 ID3D11Texture2D *ds_texture;
8240 ID3D11Buffer *ps_uav_buffer;
8241 float blend_factor[4];
8242 ID3D11Device *device;
8243 BOOL predicate_value;
8244 DXGI_FORMAT format;
8245 UINT sample_mask;
8246 UINT stencil_ref;
8247 ULONG refcount;
8248 UINT count, i;
8249 HRESULT hr;
8251 device_desc.feature_level = &feature_level;
8252 device_desc.flags = 0;
8253 if (!(device = create_device(&device_desc)))
8255 skip("Failed to create device.\n");
8256 return;
8259 ID3D11Device_GetImmediateContext(device, &context);
8261 /* Verify the initial state after device creation. */
8263 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8264 tmp_buffer);
8265 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8267 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8269 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8270 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8272 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8274 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8275 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8277 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8279 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
8280 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
8282 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8283 tmp_buffer);
8284 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8286 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8288 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8289 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8291 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8293 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8294 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8296 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8298 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
8299 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
8301 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8302 tmp_buffer);
8303 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8305 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8307 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8308 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8310 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8312 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8313 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8315 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8317 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
8318 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
8320 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8321 tmp_buffer);
8322 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8324 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8326 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8327 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8329 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8331 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8332 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8334 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8336 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
8337 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
8339 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8340 tmp_buffer);
8341 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8343 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8345 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
8346 tmp_srv);
8347 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8349 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8351 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8352 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8354 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8356 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
8357 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
8359 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8360 tmp_buffer);
8361 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8363 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8365 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
8366 tmp_srv);
8367 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8369 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8371 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8372 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8374 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8376 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
8377 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
8378 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8379 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8381 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
8384 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
8385 tmp_buffer, stride, offset);
8386 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
8388 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
8389 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
8390 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
8392 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
8393 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
8394 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
8395 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
8396 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
8397 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
8398 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
8399 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
8401 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
8402 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
8403 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
8404 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
8405 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
8406 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
8407 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
8408 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
8409 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
8410 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
8411 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
8412 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8414 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8416 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
8417 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
8418 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
8419 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8420 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8422 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8424 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
8425 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8427 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
8430 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
8431 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
8432 memset(tmp_rect, 0x55, sizeof(tmp_rect));
8433 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
8434 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
8435 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
8437 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
8438 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
8440 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
8441 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
8442 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
8443 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
8444 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
8445 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
8447 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
8448 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
8449 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
8450 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
8451 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
8453 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
8454 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
8456 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
8457 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
8459 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
8462 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
8463 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
8464 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
8466 /* Create resources. */
8468 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8469 cb[i] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 1024, NULL);
8471 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
8473 buffer[i] = create_buffer(device,
8474 D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_SHADER_RESOURCE,
8475 1024, NULL);
8477 stride[i] = (i + 1) * 4;
8478 offset[i] = (i + 1) * 16;
8481 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
8482 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
8484 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8485 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
8486 U(srv_desc).Buffer.ElementOffset = 0;
8487 U(srv_desc).Buffer.ElementWidth = 64;
8489 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8491 hr = ID3D11Device_CreateShaderResourceView(device,
8492 (ID3D11Resource *)buffer[i % D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
8493 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8496 uav_desc.Format = DXGI_FORMAT_R32_UINT;
8497 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
8498 U(uav_desc).Buffer.FirstElement = 0;
8499 U(uav_desc).Buffer.NumElements = 8;
8500 U(uav_desc).Buffer.Flags = 0;
8502 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8504 cs_uav_buffer[i] = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
8505 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_uav_buffer[i],
8506 &uav_desc, &cs_uav[i]);
8507 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
8510 ps_uav_buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
8511 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_uav_buffer,
8512 &uav_desc, &ps_uav);
8513 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
8515 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
8516 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8517 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8518 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8519 sampler_desc.MipLODBias = 0.0f;
8520 sampler_desc.MaxAnisotropy = 16;
8521 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8522 sampler_desc.BorderColor[0] = 0.0f;
8523 sampler_desc.BorderColor[1] = 0.0f;
8524 sampler_desc.BorderColor[2] = 0.0f;
8525 sampler_desc.BorderColor[3] = 0.0f;
8526 sampler_desc.MinLOD = 0.0f;
8527 sampler_desc.MaxLOD = 16.0f;
8529 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8531 sampler_desc.MinLOD = (float)i;
8533 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
8534 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8537 hr = ID3D11Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
8538 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8540 hr = ID3D11Device_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
8541 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
8543 hr = ID3D11Device_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
8544 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
8546 hr = ID3D11Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
8547 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
8549 hr = ID3D11Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
8550 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8552 hr = ID3D11Device_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
8553 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
8555 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8556 simple_vs, sizeof(simple_vs), &input_layout);
8557 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8559 memset(&blend_desc, 0, sizeof(blend_desc));
8560 blend_desc.AlphaToCoverageEnable = FALSE;
8561 blend_desc.IndependentBlendEnable = FALSE;
8562 blend_desc.RenderTarget[0].BlendEnable = TRUE;
8563 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
8564 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
8565 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
8566 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
8567 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
8568 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
8569 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
8571 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
8572 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8574 ds_desc.DepthEnable = TRUE;
8575 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
8576 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
8577 ds_desc.StencilEnable = FALSE;
8578 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
8579 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
8580 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
8581 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
8582 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
8583 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
8584 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
8585 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
8586 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
8587 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
8589 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
8590 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
8592 texture_desc.Width = 512;
8593 texture_desc.Height = 512;
8594 texture_desc.MipLevels = 1;
8595 texture_desc.ArraySize = 1;
8596 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8597 texture_desc.SampleDesc.Count = 1;
8598 texture_desc.SampleDesc.Quality = 0;
8599 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8600 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8601 texture_desc.CPUAccessFlags = 0;
8602 texture_desc.MiscFlags = 0;
8604 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8606 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
8607 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8610 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
8611 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
8613 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
8614 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8616 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8618 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture[i], NULL, &rtv[i]);
8619 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8622 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)ds_texture, NULL, &dsv);
8623 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
8625 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
8627 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
8629 tmp_viewport[i].TopLeftX = i * 3;
8630 tmp_viewport[i].TopLeftY = i * 4;
8631 tmp_viewport[i].Width = 3;
8632 tmp_viewport[i].Height = 4;
8633 tmp_viewport[i].MinDepth = i * 0.01f;
8634 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
8637 rs_desc.FillMode = D3D11_FILL_SOLID;
8638 rs_desc.CullMode = D3D11_CULL_BACK;
8639 rs_desc.FrontCounterClockwise = FALSE;
8640 rs_desc.DepthBias = 0;
8641 rs_desc.DepthBiasClamp = 0.0f;
8642 rs_desc.SlopeScaledDepthBias = 0.0f;
8643 rs_desc.DepthClipEnable = TRUE;
8644 rs_desc.ScissorEnable = FALSE;
8645 rs_desc.MultisampleEnable = FALSE;
8646 rs_desc.AntialiasedLineEnable = FALSE;
8648 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs_state);
8649 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
8651 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
8652 predicate_desc.MiscFlags = 0;
8654 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
8655 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
8657 /* Setup state. */
8659 /* Some versions of Windows AMD drivers hang while the device is being
8660 * released, if the total number of used resource slots exceeds some limit.
8661 * Do not use all constant buffers slots in order to not trigger this
8662 * driver bug. */
8663 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb[0]);
8664 ID3D11DeviceContext_VSSetConstantBuffers(context, 7, 1, &cb[7]);
8665 ID3D11DeviceContext_VSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
8666 ID3D11DeviceContext_VSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
8667 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
8669 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb[0]);
8670 ID3D11DeviceContext_HSSetConstantBuffers(context, 7, 1, &cb[7]);
8671 ID3D11DeviceContext_HSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
8672 ID3D11DeviceContext_HSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
8673 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
8675 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
8676 ID3D11DeviceContext_DSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
8677 ID3D11DeviceContext_DSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
8678 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
8680 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
8681 ID3D11DeviceContext_GSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
8682 ID3D11DeviceContext_GSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
8683 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
8685 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
8686 ID3D11DeviceContext_PSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
8687 ID3D11DeviceContext_PSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
8688 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8690 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
8691 ID3D11DeviceContext_CSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
8692 ID3D11DeviceContext_CSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
8693 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
8694 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, cs_uav, NULL);
8696 ID3D11DeviceContext_IASetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
8697 buffer, stride, offset);
8698 ID3D11DeviceContext_IASetIndexBuffer(context, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
8699 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
8700 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8702 blend_factor[0] = 0.1f;
8703 blend_factor[1] = 0.2f;
8704 blend_factor[2] = 0.3f;
8705 blend_factor[3] = 0.4f;
8706 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, 0xff00ff00);
8707 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 3);
8708 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
8709 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, rtv, dsv,
8710 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, 1, &ps_uav, NULL);
8712 ID3D11DeviceContext_RSSetScissorRects(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
8713 tmp_rect);
8714 ID3D11DeviceContext_RSSetViewports(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
8715 tmp_viewport);
8716 ID3D11DeviceContext_RSSetState(context, rs_state);
8718 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
8720 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
8722 /* Verify the set state. */
8724 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8725 tmp_buffer);
8726 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8728 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
8729 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
8730 tmp_buffer[i], i, expected_cb);
8731 if (tmp_buffer[i])
8732 ID3D11Buffer_Release(tmp_buffer[i]);
8734 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8735 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8737 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
8738 tmp_srv[i], i, srv[i]);
8739 ID3D11ShaderResourceView_Release(tmp_srv[i]);
8741 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8742 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8744 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
8745 tmp_sampler[i], i, sampler[i]);
8746 ID3D11SamplerState_Release(tmp_sampler[i]);
8748 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
8749 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
8750 ID3D11VertexShader_Release(tmp_vs);
8752 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8753 tmp_buffer);
8754 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8756 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
8757 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
8758 tmp_buffer[i], i, expected_cb);
8759 if (tmp_buffer[i])
8760 ID3D11Buffer_Release(tmp_buffer[i]);
8762 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8763 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8765 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
8766 tmp_srv[i], i, srv[i]);
8767 ID3D11ShaderResourceView_Release(tmp_srv[i]);
8769 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8770 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8772 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
8773 tmp_sampler[i], i, sampler[i]);
8774 ID3D11SamplerState_Release(tmp_sampler[i]);
8776 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
8777 ok(tmp_hs == hs, "Got unexpected hull shader %p, expected %p.\n", tmp_hs, hs);
8778 ID3D11HullShader_Release(tmp_hs);
8780 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8781 tmp_buffer);
8782 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8784 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
8785 tmp_buffer[i], i, cb[i]);
8786 ID3D11Buffer_Release(tmp_buffer[i]);
8788 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8789 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8791 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
8792 tmp_srv[i], i, srv[i]);
8793 ID3D11ShaderResourceView_Release(tmp_srv[i]);
8795 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8796 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8798 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
8799 tmp_sampler[i], i, sampler[i]);
8800 ID3D11SamplerState_Release(tmp_sampler[i]);
8802 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
8803 ok(tmp_ds == ds, "Got unexpected domain shader %p, expected %p.\n", tmp_ds, ds);
8804 ID3D11DomainShader_Release(tmp_ds);
8806 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8807 tmp_buffer);
8808 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8810 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
8811 tmp_buffer[i], i, cb[i]);
8812 ID3D11Buffer_Release(tmp_buffer[i]);
8814 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8815 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8817 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
8818 tmp_srv[i], i, srv[i]);
8819 ID3D11ShaderResourceView_Release(tmp_srv[i]);
8821 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8822 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8824 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
8825 tmp_sampler[i], i, sampler[i]);
8826 ID3D11SamplerState_Release(tmp_sampler[i]);
8828 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
8829 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
8830 ID3D11GeometryShader_Release(tmp_gs);
8832 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8833 tmp_buffer);
8834 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8836 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
8837 tmp_buffer[i], i, cb[i]);
8838 ID3D11Buffer_Release(tmp_buffer[i]);
8840 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8841 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8843 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
8844 tmp_srv[i], i, srv[i]);
8845 ID3D11ShaderResourceView_Release(tmp_srv[i]);
8847 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8848 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8850 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
8851 tmp_sampler[i], i, sampler[i]);
8852 ID3D11SamplerState_Release(tmp_sampler[i]);
8854 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
8855 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
8856 ID3D11PixelShader_Release(tmp_ps);
8858 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8859 tmp_buffer);
8860 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8862 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
8863 tmp_buffer[i], i, cb[i]);
8864 ID3D11Buffer_Release(tmp_buffer[i]);
8866 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8867 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8869 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
8870 tmp_srv[i], i, srv[i]);
8871 ID3D11ShaderResourceView_Release(tmp_srv[i]);
8873 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8874 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8876 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
8877 tmp_sampler[i], i, sampler[i]);
8878 ID3D11SamplerState_Release(tmp_sampler[i]);
8880 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
8881 ok(tmp_cs == cs, "Got unexpected compute shader %p, expected %p.\n", tmp_cs, cs);
8882 ID3D11ComputeShader_Release(tmp_cs);
8883 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8884 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8886 ok(tmp_uav[i] == cs_uav[i], "Got unexpected unordered access view %p in slot %u, expected %p.\n",
8887 tmp_uav[i], i, cs_uav[i]);
8888 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
8891 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
8892 tmp_buffer, stride, offset);
8893 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
8895 todo_wine_if(i >= D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
8897 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
8898 tmp_buffer[i], i, buffer[i]);
8899 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
8900 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
8902 if (tmp_buffer[i])
8903 ID3D11Buffer_Release(tmp_buffer[i]);
8905 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
8906 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
8907 ID3D11Buffer_Release(tmp_buffer[0]);
8908 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
8909 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
8910 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
8911 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
8912 tmp_input_layout, input_layout);
8913 ID3D11InputLayout_Release(tmp_input_layout);
8914 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
8915 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
8917 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
8918 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
8919 ID3D11BlendState_Release(tmp_blend_state);
8920 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
8921 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
8922 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
8923 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
8924 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
8925 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
8926 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
8927 ID3D11DepthStencilState_Release(tmp_ds_state);
8928 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
8929 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
8930 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
8932 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
8933 tmp_rtv[i], i, rtv[i]);
8934 ID3D11RenderTargetView_Release(tmp_rtv[i]);
8936 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8937 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
8938 ID3D11DepthStencilView_Release(tmp_dsv);
8939 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
8940 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
8941 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8942 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
8944 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
8945 tmp_rtv[i], i, rtv[i]);
8946 ID3D11RenderTargetView_Release(tmp_rtv[i]);
8948 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8949 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
8950 ID3D11DepthStencilView_Release(tmp_dsv);
8951 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT - 1; ++i)
8953 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
8955 ok(tmp_uav[i] == ps_uav, "Got unexpected unordered access view %p in slot %u, expected %p.\n",
8956 tmp_uav[i], i, ps_uav);
8957 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
8959 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
8960 todo_wine ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
8961 "Got unexpected scissor rect count %u.\n", count);
8962 memset(tmp_rect, 0x55, sizeof(tmp_rect));
8963 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
8964 for (i = 0; i < count; ++i)
8966 ok(tmp_rect[i].left == i
8967 && tmp_rect[i].top == i * 2
8968 && tmp_rect[i].right == i + 1
8969 && tmp_rect[i].bottom == (i + 1) * 2,
8970 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
8972 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
8973 todo_wine ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
8974 "Got unexpected viewport count %u.\n", count);
8975 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
8976 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
8977 for (i = 0; i < count; ++i)
8979 ok(tmp_viewport[i].TopLeftX == i * 3
8980 && tmp_viewport[i].TopLeftY == i * 4
8981 && tmp_viewport[i].Width == 3
8982 && tmp_viewport[i].Height == 4
8983 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
8984 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
8985 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
8986 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
8987 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
8989 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
8990 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
8991 ID3D11RasterizerState_Release(tmp_rs_state);
8993 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
8994 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
8996 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
8997 tmp_buffer[i], i, so_buffer[i]);
8998 ID3D11Buffer_Release(tmp_buffer[i]);
9001 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
9002 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
9003 ID3D11Predicate_Release(tmp_predicate);
9004 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
9006 /* Verify ClearState(). */
9008 ID3D11DeviceContext_ClearState(context);
9010 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9011 tmp_buffer);
9012 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9014 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9016 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9017 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9019 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9021 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9022 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9024 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9026 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
9027 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
9029 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9030 tmp_buffer);
9031 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9033 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9035 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9036 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9038 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9040 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9041 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9043 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9045 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
9046 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
9048 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9049 tmp_buffer);
9050 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9052 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9054 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9055 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9057 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9059 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9060 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9062 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9064 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
9065 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
9067 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9068 tmp_buffer);
9069 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9071 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9073 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9074 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9076 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9078 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9079 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9081 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9083 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
9084 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
9086 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9087 tmp_buffer);
9088 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9090 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9092 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9093 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9095 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9097 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9098 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9100 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9102 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
9103 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
9105 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9106 tmp_buffer);
9107 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9109 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9111 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
9112 tmp_srv);
9113 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9115 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9117 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9118 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9120 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9122 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
9123 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
9124 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9125 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9127 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9130 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
9131 tmp_buffer, stride, offset);
9132 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9134 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
9135 todo_wine_if(i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
9137 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
9138 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
9141 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
9142 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
9143 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
9144 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
9145 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
9146 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
9147 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
9148 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
9150 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
9151 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
9152 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
9153 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
9154 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
9155 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
9156 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
9157 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
9158 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
9159 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
9160 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
9161 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9163 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9165 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
9166 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
9167 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
9168 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9169 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9171 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9173 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
9174 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9176 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9179 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
9180 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
9181 memset(tmp_rect, 0x55, sizeof(tmp_rect));
9182 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
9183 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
9184 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
9186 todo_wine_if(!i)
9187 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
9188 "Got unexpected scissor rect %s in slot %u.\n",
9189 wine_dbgstr_rect(&tmp_rect[i]), i);
9191 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
9192 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
9193 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
9194 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
9195 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
9196 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
9198 todo_wine_if(!i)
9199 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
9200 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
9201 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
9202 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
9203 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
9205 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
9206 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
9208 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
9209 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
9211 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
9214 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
9215 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
9216 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
9218 /* Cleanup. */
9220 ID3D11Predicate_Release(predicate);
9221 ID3D11RasterizerState_Release(rs_state);
9222 ID3D11DepthStencilView_Release(dsv);
9223 ID3D11Texture2D_Release(ds_texture);
9225 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9227 ID3D11RenderTargetView_Release(rtv[i]);
9228 ID3D11Texture2D_Release(rt_texture[i]);
9231 ID3D11DepthStencilState_Release(ds_state);
9232 ID3D11BlendState_Release(blend_state);
9233 ID3D11InputLayout_Release(input_layout);
9234 ID3D11VertexShader_Release(vs);
9235 ID3D11HullShader_Release(hs);
9236 ID3D11DomainShader_Release(ds);
9237 ID3D11GeometryShader_Release(gs);
9238 ID3D11PixelShader_Release(ps);
9239 ID3D11ComputeShader_Release(cs);
9241 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9243 ID3D11SamplerState_Release(sampler[i]);
9246 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9248 ID3D11ShaderResourceView_Release(srv[i]);
9251 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9253 ID3D11UnorderedAccessView_Release(cs_uav[i]);
9254 ID3D11Buffer_Release(cs_uav_buffer[i]);
9256 ID3D11UnorderedAccessView_Release(ps_uav);
9257 ID3D11Buffer_Release(ps_uav_buffer);
9259 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
9261 ID3D11Buffer_Release(so_buffer[i]);
9264 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9266 ID3D11Buffer_Release(buffer[i]);
9269 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9271 ID3D11Buffer_Release(cb[i]);
9274 ID3D11DeviceContext_Release(context);
9275 refcount = ID3D11Device_Release(device);
9276 ok(!refcount, "Device has %u references left.\n", refcount);
9279 static void test_il_append_aligned(void)
9281 struct d3d11_test_context test_context;
9282 ID3D11InputLayout *input_layout;
9283 ID3D11DeviceContext *context;
9284 unsigned int stride, offset;
9285 ID3D11VertexShader *vs;
9286 ID3D11PixelShader *ps;
9287 ID3D11Device *device;
9288 ID3D11Buffer *vb[3];
9289 DWORD color;
9290 HRESULT hr;
9292 /* Semantic names are case-insensitive. */
9293 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9295 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9296 D3D11_INPUT_PER_INSTANCE_DATA, 2},
9297 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
9298 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9299 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
9300 D3D11_INPUT_PER_VERTEX_DATA, 0},
9301 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
9302 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9303 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9304 D3D11_INPUT_PER_INSTANCE_DATA, 2},
9306 static const DWORD vs_code[] =
9308 #if 0
9309 struct vs_in
9311 float4 position : POSITION;
9312 float2 color_xy : COLOR0;
9313 float2 color_zw : COLOR1;
9314 unsigned int instance_id : SV_INSTANCEID;
9317 struct vs_out
9319 float4 position : SV_POSITION;
9320 float2 color_xy : COLOR0;
9321 float2 color_zw : COLOR1;
9324 struct vs_out main(struct vs_in i)
9326 struct vs_out o;
9328 o.position = i.position;
9329 o.position.x += i.instance_id * 0.5;
9330 o.color_xy = i.color_xy;
9331 o.color_zw = i.color_zw;
9333 return o;
9335 #endif
9336 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
9337 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
9338 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
9339 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
9340 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
9341 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
9342 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
9343 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
9344 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
9345 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
9346 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
9347 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
9348 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
9349 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
9350 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
9351 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
9352 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
9354 static const DWORD ps_code[] =
9356 #if 0
9357 struct vs_out
9359 float4 position : SV_POSITION;
9360 float2 color_xy : COLOR0;
9361 float2 color_zw : COLOR1;
9364 float4 main(struct vs_out i) : SV_TARGET
9366 return float4(i.color_xy.xy, i.color_zw.xy);
9368 #endif
9369 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
9370 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
9371 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
9372 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
9373 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
9374 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
9375 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
9376 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9377 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9379 static const struct
9381 struct vec4 position;
9383 stream0[] =
9385 {{-1.0f, -1.0f, 0.0f, 1.0f}},
9386 {{-1.0f, 1.0f, 0.0f, 1.0f}},
9387 {{-0.5f, -1.0f, 0.0f, 1.0f}},
9388 {{-0.5f, 1.0f, 0.0f, 1.0f}},
9390 static const struct
9392 struct vec2 color2;
9393 struct vec2 color1;
9395 stream1[] =
9397 {{0.5f, 0.5f}, {0.0f, 1.0f}},
9398 {{0.5f, 0.5f}, {1.0f, 1.0f}},
9400 static const struct
9402 struct vec2 color3;
9403 struct vec2 color0;
9405 stream2[] =
9407 {{0.5f, 0.5f}, {1.0f, 0.0f}},
9408 {{0.5f, 0.5f}, {0.0f, 1.0f}},
9409 {{0.5f, 0.5f}, {0.0f, 0.0f}},
9410 {{0.5f, 0.5f}, {1.0f, 0.0f}},
9412 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9414 if (!init_test_context(&test_context, NULL))
9415 return;
9417 device = test_context.device;
9418 context = test_context.immediate_context;
9420 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9421 vs_code, sizeof(vs_code), &input_layout);
9422 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9424 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
9425 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
9426 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
9428 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
9429 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9430 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9431 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9433 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
9434 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9435 offset = 0;
9436 stride = sizeof(*stream0);
9437 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
9438 stride = sizeof(*stream1);
9439 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
9440 stride = sizeof(*stream2);
9441 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
9442 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
9443 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9445 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9447 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
9449 color = get_texture_color(test_context.backbuffer, 80, 240);
9450 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9451 color = get_texture_color(test_context.backbuffer, 240, 240);
9452 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9453 color = get_texture_color(test_context.backbuffer, 400, 240);
9454 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9455 color = get_texture_color(test_context.backbuffer, 560, 240);
9456 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
9458 ID3D11PixelShader_Release(ps);
9459 ID3D11VertexShader_Release(vs);
9460 ID3D11Buffer_Release(vb[2]);
9461 ID3D11Buffer_Release(vb[1]);
9462 ID3D11Buffer_Release(vb[0]);
9463 ID3D11InputLayout_Release(input_layout);
9464 release_test_context(&test_context);
9467 static void test_fragment_coords(void)
9469 struct d3d11_test_context test_context;
9470 ID3D11PixelShader *ps, *ps_frac;
9471 ID3D11DeviceContext *context;
9472 ID3D11Device *device;
9473 ID3D11Buffer *ps_cb;
9474 DWORD color;
9475 HRESULT hr;
9477 static const DWORD ps_code[] =
9479 #if 0
9480 float2 cutoff;
9482 float4 main(float4 position : SV_POSITION) : SV_TARGET
9484 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
9486 if (position.x > cutoff.x)
9487 ret.y = 1.0;
9488 if (position.y > cutoff.y)
9489 ret.z = 1.0;
9491 return ret;
9493 #endif
9494 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
9495 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9496 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9497 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9498 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
9499 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
9500 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
9501 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
9502 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
9503 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
9504 0x0100003e,
9506 static const DWORD ps_frac_code[] =
9508 #if 0
9509 float4 main(float4 position : SV_POSITION) : SV_TARGET
9511 return float4(frac(position.xy), 0.0, 1.0);
9513 #endif
9514 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
9515 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9516 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9517 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9518 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
9519 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9520 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
9521 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
9523 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9524 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
9526 if (!init_test_context(&test_context, NULL))
9527 return;
9529 device = test_context.device;
9530 context = test_context.immediate_context;
9532 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
9534 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9535 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9536 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
9537 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9539 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
9540 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9542 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9544 draw_quad(&test_context);
9546 color = get_texture_color(test_context.backbuffer, 319, 239);
9547 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
9548 color = get_texture_color(test_context.backbuffer, 320, 239);
9549 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9550 color = get_texture_color(test_context.backbuffer, 319, 240);
9551 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9552 color = get_texture_color(test_context.backbuffer, 320, 240);
9553 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
9555 ID3D11Buffer_Release(ps_cb);
9556 cutoff.x = 16.0f;
9557 cutoff.y = 16.0f;
9558 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
9559 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
9561 draw_quad(&test_context);
9563 color = get_texture_color(test_context.backbuffer, 14, 14);
9564 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
9565 color = get_texture_color(test_context.backbuffer, 18, 14);
9566 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9567 color = get_texture_color(test_context.backbuffer, 14, 18);
9568 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9569 color = get_texture_color(test_context.backbuffer, 18, 18);
9570 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
9572 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
9573 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9575 ID3D11DeviceContext_Draw(context, 4, 0);
9577 color = get_texture_color(test_context.backbuffer, 14, 14);
9578 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
9580 ID3D11Buffer_Release(ps_cb);
9581 ID3D11PixelShader_Release(ps_frac);
9582 ID3D11PixelShader_Release(ps);
9583 release_test_context(&test_context);
9586 static void test_update_subresource(void)
9588 struct d3d11_test_context test_context;
9589 D3D11_SUBRESOURCE_DATA resource_data;
9590 D3D11_TEXTURE2D_DESC texture_desc;
9591 ID3D11SamplerState *sampler_state;
9592 ID3D11ShaderResourceView *ps_srv;
9593 D3D11_SAMPLER_DESC sampler_desc;
9594 ID3D11DeviceContext *context;
9595 struct resource_readback rb;
9596 ID3D11Texture2D *texture;
9597 ID3D11PixelShader *ps;
9598 ID3D11Device *device;
9599 unsigned int i, j;
9600 D3D11_BOX box;
9601 DWORD color;
9602 HRESULT hr;
9604 static const DWORD ps_code[] =
9606 #if 0
9607 Texture2D t;
9608 SamplerState s;
9610 float4 main(float4 position : SV_POSITION) : SV_Target
9612 float2 p;
9614 p.x = position.x / 640.0f;
9615 p.y = position.y / 480.0f;
9616 return t.Sample(s, p);
9618 #endif
9619 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9620 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9621 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9622 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9623 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9624 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9625 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9626 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9627 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9628 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9630 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9631 static const DWORD initial_data[16] = {0};
9632 static const DWORD bitmap_data[] =
9634 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9635 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9636 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9637 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9639 static const DWORD expected_colors[] =
9641 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
9642 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
9643 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
9644 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
9647 if (!init_test_context(&test_context, NULL))
9648 return;
9650 device = test_context.device;
9651 context = test_context.immediate_context;
9653 texture_desc.Width = 4;
9654 texture_desc.Height = 4;
9655 texture_desc.MipLevels = 1;
9656 texture_desc.ArraySize = 1;
9657 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9658 texture_desc.SampleDesc.Count = 1;
9659 texture_desc.SampleDesc.Quality = 0;
9660 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9661 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
9662 texture_desc.CPUAccessFlags = 0;
9663 texture_desc.MiscFlags = 0;
9665 resource_data.pSysMem = initial_data;
9666 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
9667 resource_data.SysMemSlicePitch = 0;
9669 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
9670 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9672 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
9673 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9675 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
9676 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
9677 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
9678 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
9679 sampler_desc.MipLODBias = 0.0f;
9680 sampler_desc.MaxAnisotropy = 0;
9681 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
9682 sampler_desc.BorderColor[0] = 0.0f;
9683 sampler_desc.BorderColor[1] = 0.0f;
9684 sampler_desc.BorderColor[2] = 0.0f;
9685 sampler_desc.BorderColor[3] = 0.0f;
9686 sampler_desc.MinLOD = 0.0f;
9687 sampler_desc.MaxLOD = 0.0f;
9689 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9690 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9692 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9693 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9695 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
9696 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
9697 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9699 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9700 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
9702 draw_quad(&test_context);
9703 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9705 set_box(&box, 1, 1, 0, 3, 3, 1);
9706 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
9707 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9708 set_box(&box, 0, 3, 0, 3, 4, 1);
9709 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
9710 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
9711 set_box(&box, 0, 0, 0, 4, 1, 1);
9712 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
9713 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
9714 set_box(&box, 0, 1, 0, 1, 3, 1);
9715 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
9716 &bitmap_data[2], sizeof(*bitmap_data), 0);
9717 set_box(&box, 4, 4, 0, 3, 1, 1);
9718 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
9719 bitmap_data, sizeof(*bitmap_data), 0);
9720 set_box(&box, 0, 0, 0, 4, 4, 0);
9721 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
9722 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9723 draw_quad(&test_context);
9724 get_texture_readback(test_context.backbuffer, 0, &rb);
9725 for (i = 0; i < 4; ++i)
9727 for (j = 0; j < 4; ++j)
9729 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9730 ok(compare_color(color, expected_colors[j + i * 4], 1),
9731 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9732 color, j, i, expected_colors[j + i * 4]);
9735 release_resource_readback(&rb);
9737 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
9738 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9739 draw_quad(&test_context);
9740 get_texture_readback(test_context.backbuffer, 0, &rb);
9741 for (i = 0; i < 4; ++i)
9743 for (j = 0; j < 4; ++j)
9745 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9746 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9747 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9748 color, j, i, bitmap_data[j + i * 4]);
9751 release_resource_readback(&rb);
9753 ID3D11PixelShader_Release(ps);
9754 ID3D11SamplerState_Release(sampler_state);
9755 ID3D11ShaderResourceView_Release(ps_srv);
9756 ID3D11Texture2D_Release(texture);
9757 release_test_context(&test_context);
9760 static void test_copy_subresource_region(void)
9762 ID3D11Texture2D *dst_texture, *src_texture;
9763 struct d3d11_test_context test_context;
9764 ID3D11Buffer *dst_buffer, *src_buffer;
9765 D3D11_SUBRESOURCE_DATA resource_data;
9766 D3D11_TEXTURE2D_DESC texture_desc;
9767 ID3D11SamplerState *sampler_state;
9768 ID3D11ShaderResourceView *ps_srv;
9769 D3D11_SAMPLER_DESC sampler_desc;
9770 ID3D11DeviceContext *context;
9771 struct vec4 float_colors[16];
9772 struct resource_readback rb;
9773 ID3D11PixelShader *ps;
9774 ID3D11Device *device;
9775 unsigned int i, j;
9776 D3D11_BOX box;
9777 DWORD color;
9778 HRESULT hr;
9780 static const DWORD ps_code[] =
9782 #if 0
9783 Texture2D t;
9784 SamplerState s;
9786 float4 main(float4 position : SV_POSITION) : SV_Target
9788 float2 p;
9790 p.x = position.x / 640.0f;
9791 p.y = position.y / 480.0f;
9792 return t.Sample(s, p);
9794 #endif
9795 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9796 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9797 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9798 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9799 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9800 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9801 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9802 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9803 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9804 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9806 static const DWORD ps_buffer_code[] =
9808 #if 0
9809 float4 buffer[16];
9811 float4 main(float4 position : SV_POSITION) : SV_TARGET
9813 float2 p = (float2)4;
9814 p *= float2(position.x / 640.0f, position.y / 480.0f);
9815 return buffer[(int)p.y * 4 + (int)p.x];
9817 #endif
9818 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
9819 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9820 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9821 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9822 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
9823 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
9824 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
9825 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
9826 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
9827 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
9828 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
9829 0x0010000a, 0x00000000, 0x0100003e,
9831 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9832 static const DWORD initial_data[16] = {0};
9833 static const DWORD bitmap_data[] =
9835 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9836 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9837 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9838 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9840 static const DWORD expected_colors[] =
9842 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9843 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
9844 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
9845 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
9848 if (!init_test_context(&test_context, NULL))
9849 return;
9851 device = test_context.device;
9852 context = test_context.immediate_context;
9854 texture_desc.Width = 4;
9855 texture_desc.Height = 4;
9856 texture_desc.MipLevels = 1;
9857 texture_desc.ArraySize = 1;
9858 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9859 texture_desc.SampleDesc.Count = 1;
9860 texture_desc.SampleDesc.Quality = 0;
9861 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9862 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
9863 texture_desc.CPUAccessFlags = 0;
9864 texture_desc.MiscFlags = 0;
9866 resource_data.pSysMem = initial_data;
9867 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
9868 resource_data.SysMemSlicePitch = 0;
9870 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
9871 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9873 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
9875 resource_data.pSysMem = bitmap_data;
9876 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
9877 resource_data.SysMemSlicePitch = 0;
9879 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
9880 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9882 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
9883 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9885 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
9886 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
9887 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
9888 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
9889 sampler_desc.MipLODBias = 0.0f;
9890 sampler_desc.MaxAnisotropy = 0;
9891 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
9892 sampler_desc.BorderColor[0] = 0.0f;
9893 sampler_desc.BorderColor[1] = 0.0f;
9894 sampler_desc.BorderColor[2] = 0.0f;
9895 sampler_desc.BorderColor[3] = 0.0f;
9896 sampler_desc.MinLOD = 0.0f;
9897 sampler_desc.MaxLOD = 0.0f;
9899 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9900 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9902 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9903 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9905 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
9906 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
9907 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9909 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9911 set_box(&box, 0, 0, 0, 2, 2, 1);
9912 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9913 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
9914 set_box(&box, 1, 2, 0, 4, 3, 1);
9915 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9916 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
9917 set_box(&box, 0, 3, 0, 4, 4, 1);
9918 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9919 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
9920 set_box(&box, 3, 0, 0, 4, 2, 1);
9921 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9922 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
9923 set_box(&box, 3, 1, 0, 4, 2, 1);
9924 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9925 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
9926 set_box(&box, 0, 0, 0, 4, 4, 0);
9927 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9928 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
9929 draw_quad(&test_context);
9930 get_texture_readback(test_context.backbuffer, 0, &rb);
9931 for (i = 0; i < 4; ++i)
9933 for (j = 0; j < 4; ++j)
9935 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9936 ok(compare_color(color, expected_colors[j + i * 4], 1),
9937 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9938 color, j, i, expected_colors[j + i * 4]);
9941 release_resource_readback(&rb);
9943 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
9944 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
9945 draw_quad(&test_context);
9946 get_texture_readback(test_context.backbuffer, 0, &rb);
9947 for (i = 0; i < 4; ++i)
9949 for (j = 0; j < 4; ++j)
9951 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9952 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9953 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9954 color, j, i, bitmap_data[j + i * 4]);
9957 release_resource_readback(&rb);
9959 ID3D11PixelShader_Release(ps);
9960 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
9961 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9963 ID3D11ShaderResourceView_Release(ps_srv);
9964 ps_srv = NULL;
9966 ID3D11SamplerState_Release(sampler_state);
9967 sampler_state = NULL;
9969 ID3D11Texture2D_Release(dst_texture);
9970 ID3D11Texture2D_Release(src_texture);
9972 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
9973 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
9974 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9976 memset(float_colors, 0, sizeof(float_colors));
9977 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
9978 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
9980 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
9982 for (i = 0; i < 4; ++i)
9984 for (j = 0; j < 4; ++j)
9986 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
9987 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
9988 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
9989 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
9992 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
9993 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
9995 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
9996 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
9997 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
9998 draw_quad(&test_context);
9999 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10001 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
10002 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
10003 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
10004 draw_quad(&test_context);
10005 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10007 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
10008 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
10009 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
10010 draw_quad(&test_context);
10011 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10013 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
10014 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
10015 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
10016 draw_quad(&test_context);
10017 get_texture_readback(test_context.backbuffer, 0, &rb);
10018 for (i = 0; i < 4; ++i)
10020 for (j = 0; j < 4; ++j)
10022 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10023 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10024 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10025 color, j, i, bitmap_data[j + i * 4]);
10028 release_resource_readback(&rb);
10030 ID3D11Buffer_Release(dst_buffer);
10031 ID3D11Buffer_Release(src_buffer);
10032 ID3D11PixelShader_Release(ps);
10033 release_test_context(&test_context);
10036 static void test_resource_map(void)
10038 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
10039 D3D11_TEXTURE3D_DESC texture3d_desc;
10040 D3D11_TEXTURE2D_DESC texture2d_desc;
10041 D3D11_BUFFER_DESC buffer_desc;
10042 ID3D11DeviceContext *context;
10043 ID3D11Texture3D *texture3d;
10044 ID3D11Texture2D *texture2d;
10045 ID3D11Buffer *buffer;
10046 ID3D11Device *device;
10047 ULONG refcount;
10048 HRESULT hr;
10049 DWORD data;
10051 if (!(device = create_device(NULL)))
10053 skip("Failed to create device.\n");
10054 return;
10057 ID3D11Device_GetImmediateContext(device, &context);
10059 buffer_desc.ByteWidth = 1024;
10060 buffer_desc.Usage = D3D11_USAGE_STAGING;
10061 buffer_desc.BindFlags = 0;
10062 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10063 buffer_desc.MiscFlags = 0;
10064 buffer_desc.StructureByteStride = 0;
10066 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
10067 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
10069 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10070 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10072 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10073 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10074 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
10075 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10076 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
10077 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10078 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
10080 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10081 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10082 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
10083 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10084 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
10085 data = *((DWORD *)mapped_subresource.pData);
10086 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10087 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
10089 refcount = ID3D11Buffer_Release(buffer);
10090 ok(!refcount, "Buffer has %u references left.\n", refcount);
10092 texture2d_desc.Width = 512;
10093 texture2d_desc.Height = 512;
10094 texture2d_desc.MipLevels = 1;
10095 texture2d_desc.ArraySize = 1;
10096 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10097 texture2d_desc.SampleDesc.Count = 1;
10098 texture2d_desc.SampleDesc.Quality = 0;
10099 texture2d_desc.Usage = D3D11_USAGE_STAGING;
10100 texture2d_desc.BindFlags = 0;
10101 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10102 texture2d_desc.MiscFlags = 0;
10104 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
10105 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10107 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10108 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10110 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10111 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10112 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10113 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10114 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
10115 mapped_subresource.DepthPitch);
10116 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10117 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
10119 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10120 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10121 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10122 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10123 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
10124 mapped_subresource.DepthPitch);
10125 data = *((DWORD *)mapped_subresource.pData);
10126 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10127 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
10129 refcount = ID3D11Texture2D_Release(texture2d);
10130 ok(!refcount, "2D texture has %u references left.\n", refcount);
10132 texture3d_desc.Width = 64;
10133 texture3d_desc.Height = 64;
10134 texture3d_desc.Depth = 64;
10135 texture3d_desc.MipLevels = 1;
10136 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10137 texture3d_desc.Usage = D3D11_USAGE_STAGING;
10138 texture3d_desc.BindFlags = 0;
10139 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10140 texture3d_desc.MiscFlags = 0;
10142 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
10143 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
10145 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10146 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10148 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10149 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10150 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10151 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10152 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
10153 mapped_subresource.DepthPitch);
10154 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10155 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
10157 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10158 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10159 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10160 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10161 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
10162 mapped_subresource.DepthPitch);
10163 data = *((DWORD *)mapped_subresource.pData);
10164 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10165 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
10167 refcount = ID3D11Texture3D_Release(texture3d);
10168 ok(!refcount, "3D texture has %u references left.\n", refcount);
10170 ID3D11DeviceContext_Release(context);
10172 refcount = ID3D11Device_Release(device);
10173 ok(!refcount, "Device has %u references left.\n", refcount);
10176 static void test_check_multisample_quality_levels(void)
10178 ID3D11Device *device;
10179 UINT quality_levels;
10180 ULONG refcount;
10181 HRESULT hr;
10183 if (!(device = create_device(NULL)))
10185 skip("Failed to create device.\n");
10186 return;
10189 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10190 if (!quality_levels)
10192 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
10193 goto done;
10196 quality_levels = 0xdeadbeef;
10197 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
10198 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10199 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10200 quality_levels = 0xdeadbeef;
10201 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
10202 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10203 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
10205 quality_levels = 0xdeadbeef;
10206 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
10207 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10208 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
10209 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10210 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10212 quality_levels = 0xdeadbeef;
10213 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
10214 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10215 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
10216 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10217 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
10219 quality_levels = 0xdeadbeef;
10220 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
10221 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10222 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10223 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10224 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10226 /* We assume 15 samples multisampling is never supported in practice. */
10227 quality_levels = 0xdeadbeef;
10228 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
10229 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10230 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10231 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
10232 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10233 quality_levels = 0xdeadbeef;
10234 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
10235 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10236 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10237 quality_levels = 0xdeadbeef;
10238 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
10239 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10240 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10242 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
10243 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10244 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10246 done:
10247 refcount = ID3D11Device_Release(device);
10248 ok(!refcount, "Device has %u references left.\n", refcount);
10251 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
10253 DXGI_SWAP_CHAIN_DESC swapchain_desc;
10254 struct device_desc device_desc;
10255 IDXGISwapChain *swapchain;
10256 IDXGIDevice *dxgi_device;
10257 HRESULT hr, expected_hr;
10258 IDXGIAdapter *adapter;
10259 IDXGIFactory *factory;
10260 ID3D11Device *device;
10261 unsigned int i;
10262 ULONG refcount;
10264 swapchain_desc.BufferDesc.Width = 800;
10265 swapchain_desc.BufferDesc.Height = 600;
10266 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
10267 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
10268 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
10269 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
10270 swapchain_desc.SampleDesc.Count = 1;
10271 swapchain_desc.SampleDesc.Quality = 0;
10272 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
10273 swapchain_desc.BufferCount = 1;
10274 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
10275 swapchain_desc.Windowed = TRUE;
10276 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
10277 swapchain_desc.Flags = 0;
10279 device_desc.feature_level = &feature_level;
10280 device_desc.flags = 0;
10281 if (!(device = create_device(&device_desc)))
10283 skip("Failed to create device for feature level %#x.\n", feature_level);
10284 return;
10287 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
10288 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
10289 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
10290 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
10291 IDXGIDevice_Release(dxgi_device);
10292 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
10293 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
10294 IDXGIAdapter_Release(adapter);
10296 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
10297 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10298 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
10299 hr, feature_level);
10300 if (SUCCEEDED(hr))
10301 IDXGISwapChain_Release(swapchain);
10303 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
10305 DXGI_FORMAT format = display_format_support[i].format;
10306 BOOL todo = FALSE;
10308 if (display_format_support[i].fl_required <= feature_level)
10310 expected_hr = S_OK;
10311 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
10312 todo = TRUE;
10314 else if (!display_format_support[i].fl_optional
10315 || display_format_support[i].fl_optional > feature_level)
10317 expected_hr = E_INVALIDARG;
10318 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
10319 todo = TRUE;
10321 else
10323 continue;
10326 swapchain_desc.BufferDesc.Format = format;
10327 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10328 todo_wine_if(todo)
10329 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
10330 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
10331 hr, expected_hr, feature_level, format);
10332 if (FAILED(hr))
10333 continue;
10334 refcount = IDXGISwapChain_Release(swapchain);
10335 ok(!refcount, "Swapchain has %u references left.\n", refcount);
10338 refcount = ID3D11Device_Release(device);
10339 ok(!refcount, "Device has %u references left.\n", refcount);
10340 refcount = IDXGIFactory_Release(factory);
10341 ok(!refcount, "Factory has %u references left.\n", refcount);
10342 DestroyWindow(swapchain_desc.OutputWindow);
10345 static void test_swapchain_views(void)
10347 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10348 struct d3d11_test_context test_context;
10349 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
10350 ID3D11ShaderResourceView *srv;
10351 ID3D11DeviceContext *context;
10352 ID3D11RenderTargetView *rtv;
10353 ID3D11Device *device;
10354 ULONG refcount;
10355 HRESULT hr;
10357 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
10359 if (!init_test_context(&test_context, NULL))
10360 return;
10362 device = test_context.device;
10363 context = test_context.immediate_context;
10365 refcount = get_refcount(test_context.backbuffer);
10366 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
10368 draw_color_quad(&test_context, &color);
10369 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
10371 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10372 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
10373 U(rtv_desc).Texture2D.MipSlice = 0;
10374 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
10375 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10376 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10378 refcount = get_refcount(test_context.backbuffer);
10379 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
10381 draw_color_quad(&test_context, &color);
10382 todo_wine check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
10384 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10385 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
10386 U(srv_desc).Texture2D.MostDetailedMip = 0;
10387 U(srv_desc).Texture2D.MipLevels = 1;
10388 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
10389 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10390 if (SUCCEEDED(hr))
10391 ID3D11ShaderResourceView_Release(srv);
10393 ID3D11RenderTargetView_Release(rtv);
10394 release_test_context(&test_context);
10397 static void test_swapchain_flip(void)
10399 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
10400 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
10401 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
10402 D3D11_TEXTURE2D_DESC texture_desc;
10403 ID3D11InputLayout *input_layout;
10404 ID3D11DeviceContext *context;
10405 unsigned int stride, offset;
10406 struct swapchain_desc desc;
10407 IDXGISwapChain *swapchain;
10408 ID3D11VertexShader *vs;
10409 ID3D11PixelShader *ps;
10410 ID3D11Device *device;
10411 D3D11_VIEWPORT vp;
10412 ID3D11Buffer *vb;
10413 ULONG refcount;
10414 DWORD color;
10415 HWND window;
10416 HRESULT hr;
10417 RECT rect;
10419 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
10421 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10423 static const DWORD vs_code[] =
10425 #if 0
10426 float4 main(float4 position : POSITION) : SV_POSITION
10428 return position;
10430 #endif
10431 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
10432 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10433 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10434 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
10435 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
10436 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10437 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
10440 static const DWORD ps_code[] =
10442 #if 0
10443 Texture2D t0, t1;
10444 SamplerState s;
10446 float4 main(float4 position : SV_POSITION) : SV_Target
10448 float2 p;
10450 p.x = 0.5;
10451 p.y = 0.5;
10452 if (position.x < 320)
10453 return t0.Sample(s, p);
10454 return t1.Sample(s, p);
10456 #endif
10457 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
10458 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10459 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
10460 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10461 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
10462 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10463 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
10464 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
10465 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
10466 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
10467 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
10468 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
10469 0x00000000, 0x0100003e,
10471 static const struct vec2 quad[] =
10473 {-1.0f, -1.0f},
10474 {-1.0f, 1.0f},
10475 { 1.0f, -1.0f},
10476 { 1.0f, 1.0f},
10478 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10479 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
10480 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
10482 if (!(device = create_device(NULL)))
10484 skip("Failed to create device, skipping tests.\n");
10485 return;
10487 SetRect(&rect, 0, 0, 640, 480);
10488 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
10489 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10490 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
10491 desc.buffer_count = 3;
10492 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
10493 desc.windowed = TRUE;
10494 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
10495 swapchain = create_swapchain(device, window, &desc);
10497 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
10498 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10499 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
10500 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10501 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
10502 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10504 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
10505 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10506 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
10507 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10508 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
10509 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10511 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
10512 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
10513 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
10514 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
10515 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
10517 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
10518 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
10519 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
10520 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
10521 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
10523 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
10524 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10525 if (SUCCEEDED(hr))
10526 ID3D11RenderTargetView_Release(offscreen_rtv);
10528 ID3D11Device_GetImmediateContext(device, &context);
10530 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
10531 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
10533 texture_desc.Width = 640;
10534 texture_desc.Height = 480;
10535 texture_desc.MipLevels = 1;
10536 texture_desc.ArraySize = 1;
10537 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10538 texture_desc.SampleDesc.Count = 1;
10539 texture_desc.SampleDesc.Quality = 0;
10540 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10541 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10542 texture_desc.CPUAccessFlags = 0;
10543 texture_desc.MiscFlags = 0;
10544 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
10545 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
10546 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
10547 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10548 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
10549 vp.TopLeftX = 0;
10550 vp.TopLeftY = 0;
10551 vp.Width = 640;
10552 vp.Height = 480;
10553 vp.MinDepth = 0.0f;
10554 vp.MaxDepth = 1.0f;
10555 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
10557 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
10559 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
10560 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10561 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10562 vs_code, sizeof(vs_code), &input_layout);
10563 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10564 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
10565 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10566 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
10567 stride = sizeof(*quad);
10568 offset = 0;
10569 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
10571 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10572 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10573 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10575 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
10577 ID3D11DeviceContext_Draw(context, 4, 0);
10578 color = get_texture_color(offscreen, 120, 240);
10579 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10581 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
10582 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
10583 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
10585 * What is this good for? I don't know. Ad-hoc tests suggest that
10586 * Present() always waits for the next V-sync interval, even if there are
10587 * still untouched buffers. Buffer 0 is the buffer that is shown on the
10588 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
10589 * rendering finishes before the V-sync interval is over. I haven't found
10590 * any productive use for more than one buffer. */
10591 IDXGISwapChain_Present(swapchain, 0, 0);
10593 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
10595 ID3D11DeviceContext_Draw(context, 4, 0);
10596 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
10597 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10598 /* Buffer 1 is still untouched. */
10600 color = get_texture_color(backbuffer_0, 320, 240); /* green */
10601 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10602 color = get_texture_color(backbuffer_2, 320, 240); /* red */
10603 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10605 IDXGISwapChain_Present(swapchain, 0, 0);
10607 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
10609 ID3D11DeviceContext_Draw(context, 4, 0);
10610 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
10611 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
10612 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
10613 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10615 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
10616 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
10617 color = get_texture_color(backbuffer_1, 320, 240); /* red */
10618 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10619 color = get_texture_color(backbuffer_2, 320, 240); /* green */
10620 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10622 ID3D11VertexShader_Release(vs);
10623 ID3D11PixelShader_Release(ps);
10624 ID3D11Buffer_Release(vb);
10625 ID3D11InputLayout_Release(input_layout);
10626 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
10627 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
10628 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
10629 ID3D11RenderTargetView_Release(offscreen_rtv);
10630 ID3D11Texture2D_Release(offscreen);
10631 ID3D11Texture2D_Release(backbuffer_0);
10632 ID3D11Texture2D_Release(backbuffer_1);
10633 ID3D11Texture2D_Release(backbuffer_2);
10634 IDXGISwapChain_Release(swapchain);
10636 ID3D11DeviceContext_Release(context);
10637 refcount = ID3D11Device_Release(device);
10638 ok(!refcount, "Device has %u references left.\n", refcount);
10639 DestroyWindow(window);
10642 static void test_clear_render_target_view(void)
10644 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
10645 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
10646 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
10648 ID3D11Texture2D *texture, *srgb_texture;
10649 struct d3d11_test_context test_context;
10650 ID3D11RenderTargetView *rtv, *srgb_rtv;
10651 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
10652 D3D11_TEXTURE2D_DESC texture_desc;
10653 ID3D11DeviceContext *context;
10654 struct resource_readback rb;
10655 ID3D11Device *device;
10656 unsigned int i, j;
10657 HRESULT hr;
10659 if (!init_test_context(&test_context, NULL))
10660 return;
10662 device = test_context.device;
10663 context = test_context.immediate_context;
10665 texture_desc.Width = 640;
10666 texture_desc.Height = 480;
10667 texture_desc.MipLevels = 1;
10668 texture_desc.ArraySize = 1;
10669 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10670 texture_desc.SampleDesc.Count = 1;
10671 texture_desc.SampleDesc.Quality = 0;
10672 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10673 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10674 texture_desc.CPUAccessFlags = 0;
10675 texture_desc.MiscFlags = 0;
10676 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10677 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10679 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10680 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
10681 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10683 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
10684 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10686 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
10687 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10689 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
10690 check_texture_color(test_context.backbuffer, expected_color, 1);
10692 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
10693 check_texture_color(texture, expected_color, 1);
10695 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
10696 check_texture_color(texture, expected_color, 1);
10698 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
10699 check_texture_color(srgb_texture, expected_srgb_color, 1);
10701 ID3D11RenderTargetView_Release(srgb_rtv);
10702 ID3D11RenderTargetView_Release(rtv);
10703 ID3D11Texture2D_Release(srgb_texture);
10704 ID3D11Texture2D_Release(texture);
10706 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
10707 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10708 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10710 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10711 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
10712 U(rtv_desc).Texture2D.MipSlice = 0;
10713 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
10714 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10716 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10717 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
10718 U(rtv_desc).Texture2D.MipSlice = 0;
10719 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
10720 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10722 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
10723 check_texture_color(texture, expected_color, 1);
10725 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
10726 get_texture_readback(texture, 0, &rb);
10727 for (i = 0; i < 4; ++i)
10729 for (j = 0; j < 4; ++j)
10731 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
10732 DWORD color = get_readback_color(&rb, 80 + i * 160, 60 + j * 120);
10733 ok(compare_color(color, expected_srgb_color, 1)
10734 || broken(compare_color(color, expected_color, 1) && broken_device),
10735 "Got unexpected color 0x%08x.\n", color);
10738 release_resource_readback(&rb);
10740 ID3D11RenderTargetView_Release(srgb_rtv);
10741 ID3D11RenderTargetView_Release(rtv);
10742 ID3D11Texture2D_Release(texture);
10743 release_test_context(&test_context);
10746 static void test_clear_depth_stencil_view(void)
10748 D3D11_TEXTURE2D_DESC texture_desc;
10749 ID3D11Texture2D *depth_texture;
10750 ID3D11DeviceContext *context;
10751 ID3D11DepthStencilView *dsv;
10752 ID3D11Device *device;
10753 ULONG refcount;
10754 HRESULT hr;
10756 if (!(device = create_device(NULL)))
10758 skip("Failed to create device.\n");
10759 return;
10762 ID3D11Device_GetImmediateContext(device, &context);
10764 texture_desc.Width = 640;
10765 texture_desc.Height = 480;
10766 texture_desc.MipLevels = 1;
10767 texture_desc.ArraySize = 1;
10768 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
10769 texture_desc.SampleDesc.Count = 1;
10770 texture_desc.SampleDesc.Quality = 0;
10771 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10772 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
10773 texture_desc.CPUAccessFlags = 0;
10774 texture_desc.MiscFlags = 0;
10775 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
10776 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10778 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
10779 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10781 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10782 check_texture_float(depth_texture, 1.0f, 0);
10784 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
10785 check_texture_float(depth_texture, 0.25f, 0);
10787 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
10788 check_texture_float(depth_texture, 0.25f, 0);
10790 ID3D11Texture2D_Release(depth_texture);
10791 ID3D11DepthStencilView_Release(dsv);
10793 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
10794 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
10795 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10797 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
10798 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10800 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
10801 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
10803 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
10804 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
10806 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
10807 check_texture_color(depth_texture, 0xffffffff, 0);
10809 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
10810 check_texture_color(depth_texture, 0x00000000, 0);
10812 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
10813 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
10815 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
10816 check_texture_color(depth_texture, 0xffffffff, 0);
10818 ID3D11Texture2D_Release(depth_texture);
10819 ID3D11DepthStencilView_Release(dsv);
10821 ID3D11DeviceContext_Release(context);
10823 refcount = ID3D11Device_Release(device);
10824 ok(!refcount, "Device has %u references left.\n", refcount);
10827 static unsigned int to_sint8(unsigned int x)
10829 union
10831 signed int s;
10832 unsigned int u;
10833 } bits;
10834 bits.u = x;
10835 return min(max(bits.s, -128), 127) & 0xff;
10838 #define check_rgba_sint8(data, uvec) check_rgba_sint8_(__LINE__, data, uvec)
10839 static void check_rgba_sint8_(unsigned int line, DWORD data, const struct uvec4 *v)
10841 unsigned int x = to_sint8(v->x);
10842 unsigned int y = to_sint8(v->y);
10843 unsigned int z = to_sint8(v->z);
10844 unsigned int w = to_sint8(v->w);
10845 DWORD expected[] =
10847 /* Windows 7 - Nvidia, WARP */
10848 (v->x & 0xff) | (v->y & 0xff) << 8 | (v->z & 0xff) << 16 | (v->w & 0xff) << 24,
10849 /* Windows 10 - AMD */
10850 x | y << 8 | z << 16 | w << 24,
10851 /* Windows 10 - Intel */
10852 x | x << 8 | x << 16 | x << 24,
10855 ok_(__FILE__, line)(data == expected[0] || data == expected[1] || broken(data == expected[2]),
10856 "Got %#x, expected %#x or %#x at %u, uvec4 %#x, %#x, %#x, %#x.\n",
10857 data, expected[0], expected[1], x, v->x, v->y, v->z, v->w);
10860 static void test_clear_buffer_unordered_access_view(void)
10862 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
10863 ID3D11UnorderedAccessView *uav, *uav2;
10864 struct device_desc device_desc;
10865 D3D11_BUFFER_DESC buffer_desc;
10866 ID3D11DeviceContext *context;
10867 struct resource_readback rb;
10868 ID3D11Buffer *buffer;
10869 ID3D11Device *device;
10870 struct uvec4 uvec4;
10871 unsigned int i, x;
10872 ULONG refcount;
10873 HRESULT hr;
10875 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
10876 static const struct uvec4 fe_uvec4 = {0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe};
10877 static const struct uvec4 uvec4_data[] =
10879 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
10881 {0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
10882 {0xffffffff, 0x00000000, 0x00000000, 0x00000000},
10883 {0x00000000, 0xffffffff, 0x00000000, 0x00000000},
10884 {0x00000000, 0x00000000, 0xffffffff, 0x00000000},
10885 {0x00000000, 0x00000000, 0x00000000, 0xffffffff},
10887 {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff},
10888 {0x80000000, 0x80000000, 0x80000000, 0x80000000},
10889 {0x000000ff, 0x00000080, 0x80000080, 0x00000080},
10890 {0x000000ff, 0x0000007f, 0x000000ef, 0x000000fe},
10891 {0x800000ff, 0x8000007f, 0x800000ef, 0x800000fe},
10892 {0xfefefefe, 0xf0f0f0f0, 0xefefefef, 0x0f0f0f0f},
10893 {0xaaaaaaaa, 0xdeadbeef, 0xdeadbabe, 0xdeadf00d},
10895 {0x00000001, 0x00000002, 0x00000003, 0x00000004},
10896 {0x000000ff, 0x000000fe, 0x000000fd, 0x000000fc},
10897 {0x000000f2, 0x000000f1, 0x000000f0, 0x000000ef},
10898 {0x0000000a, 0x0000000d, 0x0000000e, 0x0000000f},
10899 {0x0000001a, 0x0000002d, 0x0000003e, 0x0000004f},
10900 {0x00000050, 0x00000060, 0x00000070, 0x00000080},
10901 {0x00000090, 0x000000a0, 0x000000b0, 0x000000c0},
10902 {0x000000d0, 0x000000e0, 0x000000f0, 0x000000ff},
10903 {0x00000073, 0x00000077, 0x0000007a, 0x0000007b},
10904 {0x0000007c, 0x0000007d, 0x0000007e, 0x0000007f},
10906 {0x80000001, 0x80000002, 0x80000003, 0x80000004},
10907 {0x800000ff, 0x800000fe, 0x800000fd, 0x800000fc},
10908 {0x800000f2, 0x800000f1, 0x800000f0, 0x800000ef},
10909 {0x8000000a, 0x0000000d, 0x8000000e, 0x8000000f},
10910 {0x8000001a, 0x8000002d, 0x8000003e, 0x8000004f},
10911 {0x80000050, 0x80000060, 0x80000070, 0x00000080},
10912 {0x80000090, 0x800000a0, 0x800000b0, 0x800000c0},
10913 {0x800000d0, 0x800000e0, 0x800000f0, 0x800000ff},
10914 {0x80000073, 0x80000077, 0x8000007a, 0x8000007b},
10915 {0x8000007c, 0x8000007d, 0x8000007e, 0x8000007f},
10917 {0x7fffff01, 0x7fffff02, 0x7fffff03, 0x7fffff04},
10918 {0x7fffffff, 0x7ffffffe, 0x7ffffffd, 0x7ffffffc},
10919 {0x7ffffff2, 0x7ffffff1, 0x7ffffff0, 0x7fffffef},
10920 {0x7fffff0a, 0x7fffff0d, 0x7fffff0e, 0x7fffff0f},
10921 {0x7fffff1a, 0x7fffff2d, 0x7fffff3e, 0x7fffff4f},
10922 {0x7fffff50, 0x7fffff60, 0x7fffff70, 0x7fffff80},
10923 {0x8fffff90, 0x7fffffa0, 0x7fffffb0, 0x7fffffc0},
10924 {0x7fffffd0, 0x7fffffe0, 0x7ffffff0, 0x7fffffff},
10925 {0x7fffff73, 0x7fffff77, 0x7fffff7a, 0x7fffff7b},
10926 {0x7fffff7c, 0x7fffff7d, 0x7fffff7e, 0x7fffff7f},
10928 {0xffffff01, 0xffffff02, 0xffffff03, 0xffffff04},
10929 {0xffffffff, 0xfffffffe, 0xfffffffd, 0xfffffffc},
10930 {0xfffffff2, 0xfffffff1, 0xfffffff0, 0xffffffef},
10931 {0xffffff0a, 0xffffff0d, 0xffffff0e, 0xffffff0f},
10932 {0xffffff1a, 0xffffff2d, 0xffffff3e, 0xffffff4f},
10933 {0xffffff50, 0xffffff60, 0xffffff70, 0xffffff80},
10934 {0xffffff90, 0xffffffa0, 0xffffffb0, 0xffffffc0},
10935 {0xffffffd0, 0xffffffe0, 0xfffffff0, 0xffffffff},
10936 {0xffffff73, 0xffffff77, 0xffffff7a, 0xffffff7b},
10937 {0xffffff7c, 0xffffff7d, 0xffffff7e, 0xffffff7f},
10940 device_desc.feature_level = &feature_level;
10941 device_desc.flags = 0;
10942 if (!(device = create_device(&device_desc)))
10944 skip("Failed to create device for feature level %#x.\n", feature_level);
10945 return;
10948 ID3D11Device_GetImmediateContext(device, &context);
10950 /* Structured buffer views */
10951 buffer_desc.ByteWidth = 64;
10952 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
10953 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
10954 buffer_desc.CPUAccessFlags = 0;
10955 buffer_desc.MiscFlags = 0;
10956 buffer_desc.StructureByteStride = 0;
10957 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
10958 buffer_desc.StructureByteStride = 4;
10959 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
10960 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
10962 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
10963 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
10965 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
10966 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
10967 U(uav_desc).Buffer.FirstElement = 0;
10968 U(uav_desc).Buffer.NumElements = 4;
10969 U(uav_desc).Buffer.Flags = 0;
10970 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
10971 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
10973 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
10975 uvec4 = uvec4_data[i];
10976 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
10977 get_buffer_readback(buffer, &rb);
10978 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
10980 DWORD data = get_readback_color(&rb, x, 0);
10981 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
10983 release_resource_readback(&rb);
10985 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_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 uvec4 = x < U(uav_desc).Buffer.NumElements ? fe_uvec4 : uvec4_data[i];
10991 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
10993 release_resource_readback(&rb);
10996 ID3D11Buffer_Release(buffer);
10997 ID3D11UnorderedAccessView_Release(uav);
10998 ID3D11UnorderedAccessView_Release(uav2);
11000 /* Raw buffer views */
11001 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
11002 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11003 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11005 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
11006 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11007 U(uav_desc).Buffer.FirstElement = 0;
11008 U(uav_desc).Buffer.NumElements = 16;
11009 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
11010 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11011 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11012 U(uav_desc).Buffer.FirstElement = 8;
11013 U(uav_desc).Buffer.NumElements = 8;
11014 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11015 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11017 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11019 uvec4 = uvec4_data[i];
11020 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11021 get_buffer_readback(buffer, &rb);
11022 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11024 DWORD data = get_readback_color(&rb, x, 0);
11025 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11027 release_resource_readback(&rb);
11029 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_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 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11035 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11037 release_resource_readback(&rb);
11040 ID3D11Buffer_Release(buffer);
11041 ID3D11UnorderedAccessView_Release(uav);
11042 ID3D11UnorderedAccessView_Release(uav2);
11044 /* Typed buffer views */
11045 buffer_desc.MiscFlags = 0;
11046 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11047 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11049 uav_desc.Format = DXGI_FORMAT_R32_SINT;
11050 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11051 U(uav_desc).Buffer.FirstElement = 0;
11052 U(uav_desc).Buffer.NumElements = 16;
11053 U(uav_desc).Buffer.Flags = 0;
11054 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11055 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11056 U(uav_desc).Buffer.FirstElement = 9;
11057 U(uav_desc).Buffer.NumElements = 7;
11058 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11059 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11061 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11063 uvec4 = uvec4_data[i];
11064 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11065 get_buffer_readback(buffer, &rb);
11066 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11068 DWORD data = get_readback_color(&rb, x, 0);
11069 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11071 release_resource_readback(&rb);
11073 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11074 get_buffer_readback(buffer, &rb);
11075 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11077 DWORD data = get_readback_color(&rb, x, 0);
11078 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11079 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11081 release_resource_readback(&rb);
11084 ID3D11UnorderedAccessView_Release(uav);
11085 ID3D11UnorderedAccessView_Release(uav2);
11087 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
11088 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11089 U(uav_desc).Buffer.FirstElement = 0;
11090 U(uav_desc).Buffer.NumElements = 4;
11091 U(uav_desc).Buffer.Flags = 0;
11092 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11093 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11094 U(uav_desc).Buffer.FirstElement = 2;
11095 U(uav_desc).Buffer.NumElements = 2;
11096 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11097 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11099 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11101 uvec4 = uvec4_data[i];
11102 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11103 get_buffer_readback(buffer, &rb);
11104 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
11106 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
11107 const struct uvec4 broken_result = {uvec4.x, uvec4.x, uvec4.x, uvec4.x}; /* Intel */
11108 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
11109 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
11110 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
11112 release_resource_readback(&rb);
11114 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11115 get_buffer_readback(buffer, &rb);
11116 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
11118 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
11119 struct uvec4 broken_result;
11120 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11121 broken_result.x = broken_result.y = broken_result.z = broken_result.w = uvec4.x;
11122 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
11123 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
11124 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
11126 release_resource_readback(&rb);
11129 uvec4.x = uvec4.y = uvec4.z = uvec4.w = 0xdeadbeef;
11130 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11131 ID3D11UnorderedAccessView_Release(uav);
11132 ID3D11UnorderedAccessView_Release(uav2);
11134 uav_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT;
11135 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11136 U(uav_desc).Buffer.FirstElement = 0;
11137 U(uav_desc).Buffer.NumElements = 16;
11138 U(uav_desc).Buffer.Flags = 0;
11139 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11140 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11141 U(uav_desc).Buffer.FirstElement = 8;
11142 U(uav_desc).Buffer.NumElements = 8;
11143 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11144 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11146 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11148 uvec4 = uvec4_data[i];
11149 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11150 get_buffer_readback(buffer, &rb);
11151 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11152 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0), &uvec4);
11153 release_resource_readback(&rb);
11155 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11156 get_buffer_readback(buffer, &rb);
11157 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11159 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11160 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0), &uvec4);
11162 release_resource_readback(&rb);
11165 ID3D11UnorderedAccessView_Release(uav);
11166 ID3D11UnorderedAccessView_Release(uav2);
11168 ID3D11Buffer_Release(buffer);
11170 ID3D11DeviceContext_Release(context);
11171 refcount = ID3D11Device_Release(device);
11172 ok(!refcount, "Device has %u references left.\n", refcount);
11175 static void test_draw_depth_only(void)
11177 ID3D11DepthStencilState *depth_stencil_state;
11178 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
11179 struct d3d11_test_context test_context;
11180 ID3D11PixelShader *ps_color, *ps_depth;
11181 D3D11_TEXTURE2D_DESC texture_desc;
11182 ID3D11DeviceContext *context;
11183 ID3D11DepthStencilView *dsv;
11184 struct resource_readback rb;
11185 ID3D11Texture2D *texture;
11186 ID3D11Device *device;
11187 unsigned int i, j;
11188 D3D11_VIEWPORT vp;
11189 struct vec4 depth;
11190 ID3D11Buffer *cb;
11191 HRESULT hr;
11193 static const DWORD ps_color_code[] =
11195 #if 0
11196 float4 main(float4 position : SV_POSITION) : SV_Target
11198 return float4(0.0, 1.0, 0.0, 1.0);
11200 #endif
11201 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
11202 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11203 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
11204 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11205 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
11206 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
11207 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
11209 static const DWORD ps_depth_code[] =
11211 #if 0
11212 float depth;
11214 float main() : SV_Depth
11216 return depth;
11218 #endif
11219 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
11220 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11221 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
11222 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11223 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
11224 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
11227 if (!init_test_context(&test_context, NULL))
11228 return;
11230 device = test_context.device;
11231 context = test_context.immediate_context;
11233 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
11235 texture_desc.Width = 640;
11236 texture_desc.Height = 480;
11237 texture_desc.MipLevels = 1;
11238 texture_desc.ArraySize = 1;
11239 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11240 texture_desc.SampleDesc.Count = 1;
11241 texture_desc.SampleDesc.Quality = 0;
11242 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11243 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
11244 texture_desc.CPUAccessFlags = 0;
11245 texture_desc.MiscFlags = 0;
11247 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11248 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11250 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
11251 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11253 depth_stencil_desc.DepthEnable = TRUE;
11254 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
11255 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS;
11256 depth_stencil_desc.StencilEnable = FALSE;
11258 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
11259 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
11261 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
11262 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11263 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
11264 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11266 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11267 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
11268 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
11269 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
11271 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11272 check_texture_float(texture, 1.0f, 1);
11273 draw_quad(&test_context);
11274 check_texture_float(texture, 0.0f, 1);
11276 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
11278 depth.x = 0.7f;
11279 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11280 draw_quad(&test_context);
11281 check_texture_float(texture, 0.0f, 1);
11282 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11283 check_texture_float(texture, 1.0f, 1);
11284 draw_quad(&test_context);
11285 check_texture_float(texture, 0.7f, 1);
11286 depth.x = 0.8f;
11287 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11288 draw_quad(&test_context);
11289 check_texture_float(texture, 0.7f, 1);
11290 depth.x = 0.5f;
11291 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11292 draw_quad(&test_context);
11293 check_texture_float(texture, 0.5f, 1);
11295 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11296 depth.x = 0.1f;
11297 for (i = 0; i < 4; ++i)
11299 for (j = 0; j < 4; ++j)
11301 depth.x = 1.0f / 16.0f * (j + 4 * i);
11302 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11304 vp.TopLeftX = 160.0f * j;
11305 vp.TopLeftY = 120.0f * i;
11306 vp.Width = 160.0f;
11307 vp.Height = 120.0f;
11308 vp.MinDepth = 0.0f;
11309 vp.MaxDepth = 1.0f;
11310 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11312 draw_quad(&test_context);
11315 get_texture_readback(texture, 0, &rb);
11316 for (i = 0; i < 4; ++i)
11318 for (j = 0; j < 4; ++j)
11320 float obtained_depth, expected_depth;
11322 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
11323 expected_depth = 1.0f / 16.0f * (j + 4 * i);
11324 ok(compare_float(obtained_depth, expected_depth, 1),
11325 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
11326 obtained_depth, j, i, expected_depth);
11329 release_resource_readback(&rb);
11331 ID3D11Buffer_Release(cb);
11332 ID3D11PixelShader_Release(ps_color);
11333 ID3D11PixelShader_Release(ps_depth);
11334 ID3D11DepthStencilView_Release(dsv);
11335 ID3D11DepthStencilState_Release(depth_stencil_state);
11336 ID3D11Texture2D_Release(texture);
11337 release_test_context(&test_context);
11340 static void test_draw_uav_only(void)
11342 struct d3d11_test_context test_context;
11343 D3D11_TEXTURE2D_DESC texture_desc;
11344 ID3D11UnorderedAccessView *uav;
11345 ID3D11DeviceContext *context;
11346 ID3D11Texture2D *texture;
11347 ID3D11PixelShader *ps;
11348 ID3D11Device *device;
11349 D3D11_VIEWPORT vp;
11350 HRESULT hr;
11352 static const DWORD ps_code[] =
11354 #if 0
11355 RWTexture2D<int> u;
11357 void main()
11359 InterlockedAdd(u[uint2(0, 0)], 1);
11361 #endif
11362 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
11363 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11364 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
11365 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
11366 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
11368 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11369 static const UINT values[4] = {0};
11371 if (!init_test_context(&test_context, &feature_level))
11372 return;
11374 device = test_context.device;
11375 context = test_context.immediate_context;
11377 texture_desc.Width = 1;
11378 texture_desc.Height = 1;
11379 texture_desc.MipLevels = 1;
11380 texture_desc.ArraySize = 1;
11381 texture_desc.Format = DXGI_FORMAT_R32_SINT;
11382 texture_desc.SampleDesc.Count = 1;
11383 texture_desc.SampleDesc.Quality = 0;
11384 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11385 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
11386 texture_desc.CPUAccessFlags = 0;
11387 texture_desc.MiscFlags = 0;
11389 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11390 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11392 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
11393 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11395 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11396 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11398 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11399 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
11400 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &test_context.backbuffer_rtv, NULL,
11401 0, 1, &uav, NULL);
11403 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
11404 memset(&vp, 0, sizeof(vp));
11405 vp.Width = 1.0f;
11406 vp.Height = 100.0f;
11407 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11408 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
11409 draw_quad(&test_context);
11410 check_texture_color(texture, 100, 1);
11412 draw_quad(&test_context);
11413 draw_quad(&test_context);
11414 draw_quad(&test_context);
11415 draw_quad(&test_context);
11416 check_texture_color(texture, 500, 1);
11418 ID3D11PixelShader_Release(ps);
11419 ID3D11Texture2D_Release(texture);
11420 ID3D11UnorderedAccessView_Release(uav);
11421 release_test_context(&test_context);
11424 static void test_cb_relative_addressing(void)
11426 struct d3d11_test_context test_context;
11427 ID3D11Buffer *colors_cb, *index_cb;
11428 unsigned int i, index[4] = {0};
11429 ID3D11DeviceContext *context;
11430 ID3D11PixelShader *ps;
11431 ID3D11Device *device;
11432 HRESULT hr;
11434 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11436 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11438 static const DWORD vs_code[] =
11440 #if 0
11441 int color_index;
11443 cbuffer colors
11445 float4 colors[8];
11448 struct vs_in
11450 float4 position : POSITION;
11453 struct vs_out
11455 float4 position : SV_POSITION;
11456 float4 color : COLOR;
11459 vs_out main(const vs_in v)
11461 vs_out o;
11463 o.position = v.position;
11464 o.color = colors[color_index];
11466 return o;
11468 #endif
11469 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
11470 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11471 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11472 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11473 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11474 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
11475 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
11476 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
11477 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
11478 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
11479 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
11480 0x0100003e,
11482 static const DWORD ps_code[] =
11484 #if 0
11485 struct ps_in
11487 float4 position : SV_POSITION;
11488 float4 color : COLOR;
11491 float4 main(const ps_in v) : SV_TARGET
11493 return v.color;
11495 #endif
11496 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
11497 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11498 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
11499 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
11500 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11501 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
11502 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11503 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
11505 static const struct vec2 quad[] =
11507 {-1.0f, -1.0f},
11508 {-1.0f, 1.0f},
11509 { 1.0f, -1.0f},
11510 { 1.0f, 1.0f},
11512 static const struct
11514 float color[4];
11516 colors[10] =
11518 {{0.0f, 0.0f, 0.0f, 1.0f}},
11519 {{0.0f, 0.0f, 1.0f, 0.0f}},
11520 {{0.0f, 0.0f, 1.0f, 1.0f}},
11521 {{0.0f, 1.0f, 0.0f, 0.0f}},
11522 {{0.0f, 1.0f, 0.0f, 1.0f}},
11523 {{0.0f, 1.0f, 1.0f, 0.0f}},
11524 {{0.0f, 1.0f, 1.0f, 1.0f}},
11525 {{1.0f, 0.0f, 0.0f, 0.0f}},
11526 {{1.0f, 0.0f, 0.0f, 1.0f}},
11527 {{1.0f, 0.0f, 1.0f, 0.0f}},
11529 static const struct
11531 unsigned int index;
11532 DWORD expected;
11534 test_data[] =
11536 {0, 0xff000000},
11537 {1, 0x00ff0000},
11538 {2, 0xffff0000},
11539 {3, 0x0000ff00},
11540 {4, 0xff00ff00},
11541 {5, 0x00ffff00},
11542 {6, 0xffffff00},
11543 {7, 0x000000ff},
11545 {8, 0xff0000ff},
11546 {9, 0x00ff00ff},
11548 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
11549 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11551 if (!init_test_context(&test_context, &feature_level))
11552 return;
11554 device = test_context.device;
11555 context = test_context.immediate_context;
11557 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11558 vs_code, sizeof(vs_code), &test_context.input_layout);
11559 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11561 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11562 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
11563 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
11565 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
11566 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11567 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11568 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11570 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
11571 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
11572 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11574 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
11576 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
11578 index[0] = test_data[i].index;
11579 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
11581 draw_quad(&test_context);
11582 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
11585 ID3D11Buffer_Release(index_cb);
11586 ID3D11Buffer_Release(colors_cb);
11587 ID3D11PixelShader_Release(ps);
11589 release_test_context(&test_context);
11592 static void test_getdc(void)
11594 static const struct
11596 const char *name;
11597 DXGI_FORMAT format;
11598 BOOL getdc_supported;
11600 testdata[] =
11602 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
11603 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
11604 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
11605 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
11606 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
11607 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
11609 struct device_desc device_desc;
11610 D3D11_TEXTURE2D_DESC desc;
11611 ID3D11Texture2D *texture;
11612 IDXGISurface1 *surface;
11613 ID3D11Device *device;
11614 unsigned int i;
11615 ULONG refcount;
11616 HRESULT hr;
11617 HDC dc;
11619 device_desc.feature_level = NULL;
11620 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
11621 if (!(device = create_device(&device_desc)))
11623 skip("Failed to create device.\n");
11624 return;
11627 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
11628 desc.Width = 512;
11629 desc.Height = 512;
11630 desc.MipLevels = 1;
11631 desc.ArraySize = 1;
11632 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
11633 desc.SampleDesc.Count = 1;
11634 desc.SampleDesc.Quality = 0;
11635 desc.Usage = D3D11_USAGE_DEFAULT;
11636 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11637 desc.CPUAccessFlags = 0;
11638 desc.MiscFlags = 0;
11639 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
11640 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11642 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
11643 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
11645 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
11646 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
11648 IDXGISurface1_Release(surface);
11649 ID3D11Texture2D_Release(texture);
11651 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
11652 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
11653 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11655 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
11656 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
11658 hr = IDXGISurface1_ReleaseDC(surface, NULL);
11659 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
11661 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
11662 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
11664 hr = IDXGISurface1_ReleaseDC(surface, NULL);
11665 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
11667 IDXGISurface1_Release(surface);
11668 ID3D11Texture2D_Release(texture);
11670 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
11672 static const unsigned int bit_count = 32;
11673 unsigned int width_bytes;
11674 DIBSECTION dib;
11675 HBITMAP bitmap;
11676 DWORD type;
11677 int size;
11679 desc.Width = 64;
11680 desc.Height = 64;
11681 desc.MipLevels = 1;
11682 desc.ArraySize = 1;
11683 desc.Format = testdata[i].format;
11684 desc.SampleDesc.Count = 1;
11685 desc.SampleDesc.Quality = 0;
11686 desc.Usage = D3D11_USAGE_STAGING;
11687 desc.BindFlags = 0;
11688 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
11689 desc.MiscFlags = 0;
11691 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
11692 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11693 ID3D11Texture2D_Release(texture);
11695 /* STAGING usage, requesting GDI compatibility mode. */
11696 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
11697 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
11698 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
11700 desc.Usage = D3D11_USAGE_DEFAULT;
11701 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11702 desc.CPUAccessFlags = 0;
11703 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
11704 if (testdata[i].getdc_supported)
11705 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
11706 else
11707 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
11709 if (FAILED(hr))
11710 continue;
11712 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
11713 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
11715 dc = (void *)0x1234;
11716 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
11717 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
11719 if (FAILED(hr))
11721 IDXGISurface1_Release(surface);
11722 ID3D11Texture2D_Release(texture);
11723 continue;
11726 type = GetObjectType(dc);
11727 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
11728 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
11729 type = GetObjectType(bitmap);
11730 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
11732 size = GetObjectA(bitmap, sizeof(dib), &dib);
11733 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
11734 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
11736 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
11737 dib.dsBm.bmType, testdata[i].name);
11738 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
11739 dib.dsBm.bmWidth, testdata[i].name);
11740 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
11741 dib.dsBm.bmHeight, testdata[i].name);
11742 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
11743 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
11744 dib.dsBm.bmWidthBytes, testdata[i].name);
11745 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
11746 dib.dsBm.bmPlanes, testdata[i].name);
11747 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
11748 dib.dsBm.bmBitsPixel, testdata[i].name);
11750 if (size == sizeof(dib))
11751 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
11752 dib.dsBm.bmBits, testdata[i].name);
11753 else
11754 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
11755 dib.dsBm.bmBits, testdata[i].name);
11757 if (size == sizeof(dib))
11759 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
11760 dib.dsBmih.biSize, testdata[i].name);
11761 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
11762 dib.dsBmih.biHeight, testdata[i].name);
11763 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
11764 dib.dsBmih.biHeight, testdata[i].name);
11765 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
11766 dib.dsBmih.biPlanes, testdata[i].name);
11767 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
11768 dib.dsBmih.biBitCount, testdata[i].name);
11769 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
11770 dib.dsBmih.biCompression, testdata[i].name);
11771 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
11772 dib.dsBmih.biSizeImage, testdata[i].name);
11773 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
11774 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
11775 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
11776 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
11777 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
11778 dib.dsBmih.biClrUsed, testdata[i].name);
11779 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
11780 dib.dsBmih.biClrImportant, testdata[i].name);
11781 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
11782 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11783 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
11784 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
11785 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
11788 hr = IDXGISurface1_ReleaseDC(surface, NULL);
11789 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
11791 IDXGISurface1_Release(surface);
11792 ID3D11Texture2D_Release(texture);
11795 refcount = ID3D11Device_Release(device);
11796 ok(!refcount, "Device has %u references left.\n", refcount);
11799 static void test_shader_stage_input_output_matching(void)
11801 struct d3d11_test_context test_context;
11802 D3D11_TEXTURE2D_DESC texture_desc;
11803 ID3D11Texture2D *render_target;
11804 ID3D11RenderTargetView *rtv[2];
11805 ID3D11DeviceContext *context;
11806 ID3D11VertexShader *vs;
11807 ID3D11PixelShader *ps;
11808 ID3D11Device *device;
11809 HRESULT hr;
11811 static const DWORD vs_code[] =
11813 #if 0
11814 struct output
11816 float4 position : SV_PoSiTion;
11817 float4 color0 : COLOR0;
11818 float4 color1 : COLOR1;
11821 void main(uint id : SV_VertexID, out output o)
11823 float2 coords = float2((id << 1) & 2, id & 2);
11824 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
11825 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
11826 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
11828 #endif
11829 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
11830 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11831 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
11832 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
11833 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11834 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
11835 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
11836 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
11837 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
11838 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
11839 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
11840 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
11841 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
11842 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
11843 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
11844 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
11845 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
11846 0x0100003e,
11848 static const DWORD ps_code[] =
11850 #if 0
11851 struct input
11853 float4 position : SV_PoSiTiOn;
11854 float4 color1 : COLOR1;
11855 float4 color0 : COLOR0;
11858 struct output
11860 float4 target0 : SV_Target0;
11861 float4 target1 : SV_Target1;
11864 void main(const in input i, out output o)
11866 o.target0 = i.color0;
11867 o.target1 = i.color1;
11869 #endif
11870 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
11871 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
11872 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
11873 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
11874 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
11875 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
11876 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
11877 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
11878 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
11879 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
11880 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
11883 if (!init_test_context(&test_context, NULL))
11884 return;
11886 device = test_context.device;
11887 context = test_context.immediate_context;
11889 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11890 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11891 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11892 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11894 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11895 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
11896 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11898 rtv[0] = test_context.backbuffer_rtv;
11899 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
11900 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11902 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11903 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11904 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
11905 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
11906 ID3D11DeviceContext_Draw(context, 3, 0);
11908 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11909 check_texture_color(render_target, 0xff0000ff, 0);
11911 ID3D11RenderTargetView_Release(rtv[1]);
11912 ID3D11Texture2D_Release(render_target);
11913 ID3D11PixelShader_Release(ps);
11914 ID3D11VertexShader_Release(vs);
11915 release_test_context(&test_context);
11918 static void test_sm4_if_instruction(void)
11920 struct d3d11_test_context test_context;
11921 ID3D11PixelShader *ps_if_nz, *ps_if_z;
11922 ID3D11DeviceContext *context;
11923 ID3D11Device *device;
11924 unsigned int bits[4];
11925 DWORD expected_color;
11926 ID3D11Buffer *cb;
11927 unsigned int i;
11928 HRESULT hr;
11930 static const DWORD ps_if_nz_code[] =
11932 #if 0
11933 uint bits;
11935 float4 main() : SV_TARGET
11937 if (bits)
11938 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11939 else
11940 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11942 #endif
11943 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
11944 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11945 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11946 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
11947 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
11948 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
11949 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
11950 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
11952 static const DWORD ps_if_z_code[] =
11954 #if 0
11955 uint bits;
11957 float4 main() : SV_TARGET
11959 if (!bits)
11960 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11961 else
11962 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11964 #endif
11965 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
11966 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11967 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11968 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
11969 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
11970 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
11971 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
11972 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
11974 static unsigned int bit_patterns[] =
11976 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
11979 if (!init_test_context(&test_context, NULL))
11980 return;
11982 device = test_context.device;
11983 context = test_context.immediate_context;
11985 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
11986 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
11987 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
11988 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
11990 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
11991 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11993 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
11995 *bits = bit_patterns[i];
11996 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
11998 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
11999 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
12000 draw_quad(&test_context);
12001 check_texture_color(test_context.backbuffer, expected_color, 0);
12003 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
12004 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
12005 draw_quad(&test_context);
12006 check_texture_color(test_context.backbuffer, expected_color, 0);
12009 ID3D11Buffer_Release(cb);
12010 ID3D11PixelShader_Release(ps_if_z);
12011 ID3D11PixelShader_Release(ps_if_nz);
12012 release_test_context(&test_context);
12015 static void test_sm4_breakc_instruction(void)
12017 struct d3d11_test_context test_context;
12018 ID3D11DeviceContext *context;
12019 ID3D11PixelShader *ps;
12020 ID3D11Device *device;
12021 HRESULT hr;
12023 static const DWORD ps_breakc_nz_code[] =
12025 #if 0
12026 float4 main() : SV_TARGET
12028 uint counter = 0;
12030 for (uint i = 0; i < 255; ++i)
12031 ++counter;
12033 if (counter == 255)
12034 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12035 else
12036 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12038 #endif
12039 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
12040 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12041 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12042 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
12043 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
12044 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
12045 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12046 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
12047 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
12048 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
12049 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
12050 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12051 0x01000015, 0x0100003e,
12053 static const DWORD ps_breakc_z_code[] =
12055 #if 0
12056 float4 main() : SV_TARGET
12058 uint counter = 0;
12060 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
12061 ++counter;
12063 if (counter == 255)
12064 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12065 else
12066 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12068 #endif
12069 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
12070 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12071 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12072 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
12073 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
12074 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
12075 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
12076 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
12077 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
12078 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
12079 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
12080 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12081 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12082 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12085 if (!init_test_context(&test_context, NULL))
12086 return;
12088 device = test_context.device;
12089 context = test_context.immediate_context;
12091 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
12092 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
12093 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12094 draw_quad(&test_context);
12095 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12096 ID3D11PixelShader_Release(ps);
12098 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
12099 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
12100 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12101 draw_quad(&test_context);
12102 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12103 ID3D11PixelShader_Release(ps);
12105 release_test_context(&test_context);
12108 static void test_sm4_continuec_instruction(void)
12110 struct d3d11_test_context test_context;
12111 ID3D11DeviceContext *context;
12112 ID3D11PixelShader *ps;
12113 ID3D11Device *device;
12114 HRESULT hr;
12116 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
12117 * with a normal continue inside, the shaders have been compiled with
12118 * the /Gfa flag. */
12119 static const DWORD ps_continuec_nz_code[] =
12121 #if 0
12122 float4 main() : SV_TARGET
12124 uint counter = 0;
12125 int i = -1;
12127 while (i < 255) {
12128 ++i;
12130 if (i != 0)
12131 continue;
12133 ++counter;
12136 if (counter == 1)
12137 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12138 else
12139 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12141 #endif
12142 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
12143 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12144 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12145 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
12146 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
12147 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12148 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12149 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
12150 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
12151 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
12152 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
12153 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
12154 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
12155 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
12156 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
12157 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
12158 0x3f800000, 0x0100003e,
12161 static const DWORD ps_continuec_z_code[] =
12163 #if 0
12164 float4 main() : SV_TARGET
12166 uint counter = 0;
12167 int i = -1;
12169 while (i < 255) {
12170 ++i;
12172 if (i == 0)
12173 continue;
12175 ++counter;
12178 if (counter == 255)
12179 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12180 else
12181 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12183 #endif
12184 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
12185 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12186 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12187 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
12188 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
12189 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12190 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12191 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
12192 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
12193 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
12194 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
12195 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
12196 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
12197 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
12198 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12201 if (!init_test_context(&test_context, NULL))
12202 return;
12204 device = test_context.device;
12205 context = test_context.immediate_context;
12207 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), NULL, &ps);
12208 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
12209 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12210 draw_quad(&test_context);
12211 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12212 ID3D11PixelShader_Release(ps);
12214 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), NULL, &ps);
12215 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
12216 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12217 draw_quad(&test_context);
12218 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12219 ID3D11PixelShader_Release(ps);
12221 release_test_context(&test_context);
12224 static void test_create_input_layout(void)
12226 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12228 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12230 ULONG refcount, expected_refcount;
12231 ID3D11InputLayout *input_layout;
12232 ID3D11Device *device;
12233 unsigned int i;
12234 HRESULT hr;
12236 static const DWORD vs_code[] =
12238 #if 0
12239 float4 main(float4 position : POSITION) : SV_POSITION
12241 return position;
12243 #endif
12244 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
12245 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12246 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
12247 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
12248 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
12249 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
12250 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
12252 static const DXGI_FORMAT vertex_formats[] =
12254 DXGI_FORMAT_R32G32_FLOAT,
12255 DXGI_FORMAT_R32G32_UINT,
12256 DXGI_FORMAT_R32G32_SINT,
12257 DXGI_FORMAT_R16G16_FLOAT,
12258 DXGI_FORMAT_R16G16_UINT,
12259 DXGI_FORMAT_R16G16_SINT,
12260 DXGI_FORMAT_R32_FLOAT,
12261 DXGI_FORMAT_R32_UINT,
12262 DXGI_FORMAT_R32_SINT,
12263 DXGI_FORMAT_R16_UINT,
12264 DXGI_FORMAT_R16_SINT,
12265 DXGI_FORMAT_R8_UINT,
12266 DXGI_FORMAT_R8_SINT,
12269 if (!(device = create_device(NULL)))
12271 skip("Failed to create device.\n");
12272 return;
12275 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
12277 expected_refcount = get_refcount(device) + 1;
12278 layout_desc->Format = vertex_formats[i];
12279 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12280 vs_code, sizeof(vs_code), &input_layout);
12281 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
12282 vertex_formats[i], hr);
12283 refcount = get_refcount(device);
12284 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
12285 refcount, expected_refcount);
12286 ID3D11InputLayout_Release(input_layout);
12289 refcount = ID3D11Device_Release(device);
12290 ok(!refcount, "Device has %u references left.\n", refcount);
12293 static void test_input_assembler(void)
12295 enum layout_id
12297 LAYOUT_FLOAT32,
12298 LAYOUT_UINT16,
12299 LAYOUT_SINT16,
12300 LAYOUT_UNORM16,
12301 LAYOUT_SNORM16,
12302 LAYOUT_UINT8,
12303 LAYOUT_SINT8,
12304 LAYOUT_UNORM8,
12305 LAYOUT_SNORM8,
12306 LAYOUT_UNORM10_2,
12307 LAYOUT_UINT10_2,
12309 LAYOUT_COUNT,
12312 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
12314 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12315 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12317 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
12318 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
12319 ID3D11Buffer *vb_position, *vb_attribute;
12320 struct d3d11_test_context test_context;
12321 D3D11_TEXTURE2D_DESC texture_desc;
12322 unsigned int i, j, stride, offset;
12323 ID3D11Texture2D *render_target;
12324 ID3D11DeviceContext *context;
12325 ID3D11RenderTargetView *rtv;
12326 ID3D11PixelShader *ps;
12327 ID3D11Device *device;
12328 HRESULT hr;
12330 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
12332 DXGI_FORMAT_R32G32B32A32_FLOAT,
12333 DXGI_FORMAT_R16G16B16A16_UINT,
12334 DXGI_FORMAT_R16G16B16A16_SINT,
12335 DXGI_FORMAT_R16G16B16A16_UNORM,
12336 DXGI_FORMAT_R16G16B16A16_SNORM,
12337 DXGI_FORMAT_R8G8B8A8_UINT,
12338 DXGI_FORMAT_R8G8B8A8_SINT,
12339 DXGI_FORMAT_R8G8B8A8_UNORM,
12340 DXGI_FORMAT_R8G8B8A8_SNORM,
12341 DXGI_FORMAT_R10G10B10A2_UNORM,
12342 DXGI_FORMAT_R10G10B10A2_UINT,
12344 static const struct vec2 quad[] =
12346 {-1.0f, -1.0f},
12347 {-1.0f, 1.0f},
12348 { 1.0f, -1.0f},
12349 { 1.0f, 1.0f},
12351 static const DWORD ps_code[] =
12353 #if 0
12354 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
12356 return color;
12358 #endif
12359 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
12360 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
12361 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
12362 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
12363 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12364 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
12365 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
12366 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12368 static const DWORD vs_float_code[] =
12370 #if 0
12371 struct output
12373 float4 position : SV_Position;
12374 float4 color : COLOR;
12377 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
12379 o.position = position;
12380 o.color = color;
12382 #endif
12383 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
12384 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12385 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12386 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12387 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12388 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12389 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12390 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12391 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12392 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12393 0x0100003e,
12395 static const DWORD vs_uint_code[] =
12397 #if 0
12398 struct output
12400 float4 position : SV_Position;
12401 float4 color : COLOR;
12404 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
12406 o.position = position;
12407 o.color = color;
12409 #endif
12410 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
12411 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12412 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12413 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12414 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12415 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12416 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12417 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12418 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12419 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12420 0x0100003e,
12422 static const DWORD vs_sint_code[] =
12424 #if 0
12425 struct output
12427 float4 position : SV_Position;
12428 float4 color : COLOR;
12431 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
12433 o.position = position;
12434 o.color = color;
12436 #endif
12437 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
12438 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12439 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12440 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12441 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12442 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12443 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12444 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12445 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12446 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12447 0x0100003e,
12449 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
12450 static const unsigned short uint16_data[] = {6, 8, 55, 777};
12451 static const short sint16_data[] = {-1, 33, 8, -77};
12452 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
12453 static const short snorm16_data[] = {-32768, 0, 32767, 0};
12454 static const unsigned char uint8_data[] = {0, 64, 128, 255};
12455 static const signed char sint8_data[] = {-128, 0, 127, 64};
12456 static const unsigned int uint32_zero = 0;
12457 static const unsigned int uint32_max = 0xffffffff;
12458 static const unsigned int unorm10_2_data= 0xa00003ff;
12459 static const unsigned int g10_data = 0x000ffc00;
12460 static const unsigned int a2_data = 0xc0000000;
12461 static const struct
12463 enum layout_id layout_id;
12464 unsigned int stride;
12465 const void *data;
12466 struct vec4 expected_color;
12467 BOOL todo;
12469 tests[] =
12471 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
12472 {1.0f, 2.0f, 3.0f, 4.0f}},
12473 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
12474 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
12475 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
12476 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
12477 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
12478 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
12479 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
12480 {-1.0f, 0.0f, 1.0f, 0.0f}},
12481 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
12482 {0.0f, 0.0f, 0.0f, 0.0f}},
12483 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
12484 {255.0f, 255.0f, 255.0f, 255.0f}},
12485 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
12486 {0.0f, 64.0f, 128.0f, 255.0f}},
12487 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
12488 {0.0f, 0.0f, 0.0f, 0.0f}},
12489 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
12490 {-1.0f, -1.0f, -1.0f, -1.0f}},
12491 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
12492 {-128.0f, 0.0f, 127.0f, 64.0f}},
12493 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
12494 {0.0f, 0.0f, 0.0f, 0.0f}},
12495 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
12496 {1.0f, 1.0f, 1.0f, 1.0f}},
12497 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
12498 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
12499 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
12500 {0.0f, 0.0f, 0.0f, 0.0f}},
12501 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
12502 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
12503 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
12504 {0.0f, 0.0f, 0.0f, 0.0f}},
12505 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
12506 {1.0f, 1.0f, 1.0f, 1.0f}},
12507 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
12508 {0.0f, 1.0f, 0.0f, 0.0f}},
12509 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
12510 {0.0f, 0.0f, 0.0f, 1.0f}},
12511 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
12512 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
12513 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
12514 {0.0f, 0.0f, 0.0f, 0.0f}},
12515 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
12516 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
12517 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
12518 {0.0f, 1023.0f, 0.0f, 0.0f}},
12519 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
12520 {0.0f, 0.0f, 0.0f, 3.0f}},
12521 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
12522 {1023.0f, 0.0f, 512.0f, 2.0f}},
12525 if (!init_test_context(&test_context, NULL))
12526 return;
12528 device = test_context.device;
12529 context = test_context.immediate_context;
12531 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12532 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12534 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
12535 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
12536 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
12537 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
12538 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
12539 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
12541 for (i = 0; i < LAYOUT_COUNT; ++i)
12543 input_layout_desc[1].Format = layout_formats[i];
12544 input_layout[i] = NULL;
12545 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
12546 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
12547 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
12548 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
12551 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
12552 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
12554 texture_desc.Width = 640;
12555 texture_desc.Height = 480;
12556 texture_desc.MipLevels = 1;
12557 texture_desc.ArraySize = 1;
12558 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12559 texture_desc.SampleDesc.Count = 1;
12560 texture_desc.SampleDesc.Quality = 0;
12561 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12562 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12563 texture_desc.CPUAccessFlags = 0;
12564 texture_desc.MiscFlags = 0;
12566 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
12567 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
12569 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
12570 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12572 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12573 offset = 0;
12574 stride = sizeof(*quad);
12575 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
12576 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12577 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
12579 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12581 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
12583 if (tests[i].layout_id == LAYOUT_UINT10_2)
12584 continue;
12586 assert(tests[i].layout_id < LAYOUT_COUNT);
12587 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
12589 assert(4 * tests[i].stride <= 1024);
12590 box.right = tests[i].stride;
12591 for (j = 0; j < 4; ++j)
12593 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
12594 &box, tests[i].data, 0, 0);
12595 box.left += tests[i].stride;
12596 box.right += tests[i].stride;
12599 stride = tests[i].stride;
12600 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
12602 switch (layout_formats[tests[i].layout_id])
12604 case DXGI_FORMAT_R16G16B16A16_UINT:
12605 case DXGI_FORMAT_R10G10B10A2_UINT:
12606 case DXGI_FORMAT_R8G8B8A8_UINT:
12607 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
12608 break;
12609 case DXGI_FORMAT_R16G16B16A16_SINT:
12610 case DXGI_FORMAT_R8G8B8A8_SINT:
12611 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
12612 break;
12614 default:
12615 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
12616 /* Fall through. */
12617 case DXGI_FORMAT_R32G32B32A32_FLOAT:
12618 case DXGI_FORMAT_R16G16B16A16_UNORM:
12619 case DXGI_FORMAT_R16G16B16A16_SNORM:
12620 case DXGI_FORMAT_R10G10B10A2_UNORM:
12621 case DXGI_FORMAT_R8G8B8A8_UNORM:
12622 case DXGI_FORMAT_R8G8B8A8_SNORM:
12623 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
12624 break;
12627 ID3D11DeviceContext_Draw(context, 4, 0);
12628 check_texture_vec4(render_target, &tests[i].expected_color, 2);
12631 ID3D11Texture2D_Release(render_target);
12632 ID3D11RenderTargetView_Release(rtv);
12633 ID3D11Buffer_Release(vb_attribute);
12634 ID3D11Buffer_Release(vb_position);
12635 for (i = 0; i < LAYOUT_COUNT; ++i)
12637 if (input_layout[i])
12638 ID3D11InputLayout_Release(input_layout[i]);
12640 ID3D11PixelShader_Release(ps);
12641 ID3D11VertexShader_Release(vs_float);
12642 ID3D11VertexShader_Release(vs_uint);
12643 ID3D11VertexShader_Release(vs_sint);
12644 release_test_context(&test_context);
12647 static void test_null_sampler(void)
12649 struct d3d11_test_context test_context;
12650 D3D11_TEXTURE2D_DESC texture_desc;
12651 ID3D11ShaderResourceView *srv;
12652 ID3D11DeviceContext *context;
12653 ID3D11RenderTargetView *rtv;
12654 ID3D11SamplerState *sampler;
12655 ID3D11Texture2D *texture;
12656 ID3D11PixelShader *ps;
12657 ID3D11Device *device;
12658 HRESULT hr;
12660 static const DWORD ps_code[] =
12662 #if 0
12663 Texture2D t;
12664 SamplerState s;
12666 float4 main(float4 position : SV_POSITION) : SV_Target
12668 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
12670 #endif
12671 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
12672 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12673 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
12674 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12675 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
12676 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
12677 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12678 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
12679 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
12680 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
12682 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
12684 if (!init_test_context(&test_context, NULL))
12685 return;
12687 device = test_context.device;
12688 context = test_context.immediate_context;
12690 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12691 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12693 texture_desc.Width = 64;
12694 texture_desc.Height = 64;
12695 texture_desc.MipLevels = 1;
12696 texture_desc.ArraySize = 1;
12697 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12698 texture_desc.SampleDesc.Count = 1;
12699 texture_desc.SampleDesc.Quality = 0;
12700 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12701 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
12702 texture_desc.CPUAccessFlags = 0;
12703 texture_desc.MiscFlags = 0;
12705 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12706 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12708 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
12709 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12711 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
12712 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12714 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
12716 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12717 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
12718 sampler = NULL;
12719 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
12720 draw_quad(&test_context);
12721 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
12723 ID3D11ShaderResourceView_Release(srv);
12724 ID3D11RenderTargetView_Release(rtv);
12725 ID3D11Texture2D_Release(texture);
12726 ID3D11PixelShader_Release(ps);
12727 release_test_context(&test_context);
12730 static void test_check_feature_support(void)
12732 D3D11_FEATURE_DATA_THREADING threading[2];
12733 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
12734 ID3D11Device *device;
12735 ULONG refcount;
12736 HRESULT hr;
12738 if (!(device = create_device(NULL)))
12740 skip("Failed to create device.\n");
12741 return;
12744 memset(threading, 0xef, sizeof(threading));
12746 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
12747 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12748 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
12749 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12750 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
12751 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12752 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
12753 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12754 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
12755 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12756 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
12757 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12759 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
12760 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
12761 ok(threading[0].DriverCommandLists == 0xefefefef,
12762 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
12763 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
12764 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
12765 ok(threading[1].DriverCommandLists == 0xefefefef,
12766 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
12768 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
12769 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
12770 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
12771 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
12772 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
12773 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
12775 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
12776 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12777 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
12778 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12779 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
12780 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12781 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
12782 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12783 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
12784 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12785 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
12786 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12788 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
12789 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
12790 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
12792 refcount = ID3D11Device_Release(device);
12793 ok(!refcount, "Device has %u references left.\n", refcount);
12796 static void test_create_unordered_access_view(void)
12798 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12799 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
12800 D3D11_TEXTURE3D_DESC texture3d_desc;
12801 D3D11_TEXTURE2D_DESC texture2d_desc;
12802 ULONG refcount, expected_refcount;
12803 D3D11_SUBRESOURCE_DATA data = {0};
12804 ID3D11UnorderedAccessView *uav;
12805 struct device_desc device_desc;
12806 D3D11_BUFFER_DESC buffer_desc;
12807 ID3D11Device *device, *tmp;
12808 ID3D11Texture3D *texture3d;
12809 ID3D11Texture2D *texture2d;
12810 ID3D11Resource *texture;
12811 ID3D11Buffer *buffer;
12812 unsigned int i;
12813 HRESULT hr;
12815 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
12816 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
12817 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
12818 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
12819 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
12820 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
12821 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
12822 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
12823 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
12824 static const struct
12826 struct
12828 unsigned int miplevel_count;
12829 unsigned int depth_or_array_size;
12830 DXGI_FORMAT format;
12831 } texture;
12832 struct uav_desc uav_desc;
12833 struct uav_desc expected_uav_desc;
12835 tests[] =
12837 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
12838 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
12839 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
12840 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
12841 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
12842 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
12843 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
12844 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
12845 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
12846 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
12847 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
12848 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
12849 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
12850 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
12851 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
12852 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
12853 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
12854 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
12855 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
12856 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
12857 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
12858 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
12859 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
12860 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
12861 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
12862 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
12863 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
12864 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
12865 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
12866 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
12867 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
12868 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
12869 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
12870 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
12872 static const struct
12874 struct
12876 D3D11_UAV_DIMENSION dimension;
12877 unsigned int miplevel_count;
12878 unsigned int depth_or_array_size;
12879 DXGI_FORMAT format;
12880 } texture;
12881 struct uav_desc uav_desc;
12883 invalid_desc_tests[] =
12885 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
12886 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
12887 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
12888 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
12889 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
12890 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
12891 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
12892 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
12893 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
12894 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
12895 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
12896 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
12897 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
12898 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
12899 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
12900 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
12901 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
12902 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
12903 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
12904 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
12905 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
12906 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
12907 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
12908 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
12909 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
12910 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
12911 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
12912 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
12913 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
12914 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
12915 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
12916 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
12917 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
12919 #undef FMT_UNKNOWN
12920 #undef RGBA8_UNORM
12921 #undef RGBA8_TL
12922 #undef DIM_UNKNOWN
12923 #undef TEX_1D
12924 #undef TEX_1D_ARRAY
12925 #undef TEX_2D
12926 #undef TEX_2D_ARRAY
12927 #undef TEX_3D
12929 device_desc.feature_level = &feature_level;
12930 device_desc.flags = 0;
12931 if (!(device = create_device(&device_desc)))
12933 skip("Failed to create device.\n");
12934 return;
12937 buffer_desc.ByteWidth = 1024;
12938 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
12939 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
12940 buffer_desc.CPUAccessFlags = 0;
12941 buffer_desc.MiscFlags = 0;
12942 buffer_desc.StructureByteStride = 0;
12944 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
12945 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12947 expected_refcount = get_refcount(device) + 1;
12948 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
12949 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
12950 refcount = get_refcount(device);
12951 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
12952 tmp = NULL;
12953 expected_refcount = refcount + 1;
12954 ID3D11Buffer_GetDevice(buffer, &tmp);
12955 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
12956 refcount = get_refcount(device);
12957 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
12958 ID3D11Device_Release(tmp);
12960 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12961 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
12962 U(uav_desc).Buffer.FirstElement = 0;
12963 U(uav_desc).Buffer.NumElements = 64;
12964 U(uav_desc).Buffer.Flags = 0;
12966 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
12967 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12969 expected_refcount = get_refcount(device) + 1;
12970 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
12971 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12972 refcount = get_refcount(device);
12973 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
12974 tmp = NULL;
12975 expected_refcount = refcount + 1;
12976 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
12977 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
12978 refcount = get_refcount(device);
12979 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
12980 ID3D11Device_Release(tmp);
12982 ID3D11UnorderedAccessView_Release(uav);
12983 ID3D11Buffer_Release(buffer);
12985 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
12986 buffer_desc.StructureByteStride = 4;
12988 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
12989 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
12991 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
12992 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
12994 memset(&uav_desc, 0, sizeof(uav_desc));
12995 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
12997 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
12998 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
12999 uav_desc.ViewDimension);
13000 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
13001 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
13002 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
13004 ID3D11UnorderedAccessView_Release(uav);
13005 ID3D11Buffer_Release(buffer);
13007 texture2d_desc.Width = 512;
13008 texture2d_desc.Height = 512;
13009 texture2d_desc.SampleDesc.Count = 1;
13010 texture2d_desc.SampleDesc.Quality = 0;
13011 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
13012 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
13013 texture2d_desc.CPUAccessFlags = 0;
13014 texture2d_desc.MiscFlags = 0;
13016 texture3d_desc.Width = 64;
13017 texture3d_desc.Height = 64;
13018 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
13019 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
13020 texture3d_desc.CPUAccessFlags = 0;
13021 texture3d_desc.MiscFlags = 0;
13023 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13025 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
13027 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
13029 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
13030 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
13031 texture2d_desc.Format = tests[i].texture.format;
13033 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
13034 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
13035 texture = (ID3D11Resource *)texture2d;
13037 else
13039 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
13040 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
13041 texture3d_desc.Format = tests[i].texture.format;
13043 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
13044 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
13045 texture = (ID3D11Resource *)texture3d;
13048 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
13050 current_desc = NULL;
13052 else
13054 current_desc = &uav_desc;
13055 get_uav_desc(current_desc, &tests[i].uav_desc);
13058 expected_refcount = get_refcount(texture);
13059 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
13060 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
13061 refcount = get_refcount(texture);
13062 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
13064 memset(&uav_desc, 0, sizeof(uav_desc));
13065 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
13066 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
13068 ID3D11UnorderedAccessView_Release(uav);
13069 ID3D11Resource_Release(texture);
13072 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
13074 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
13075 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
13077 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
13079 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
13080 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
13081 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
13083 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
13084 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
13085 texture = (ID3D11Resource *)texture2d;
13087 else
13089 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
13090 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
13091 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
13093 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
13094 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
13095 texture = (ID3D11Resource *)texture3d;
13098 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
13099 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
13100 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
13102 ID3D11Resource_Release(texture);
13105 refcount = ID3D11Device_Release(device);
13106 ok(!refcount, "Device has %u references left.\n", refcount);
13109 static void test_immediate_constant_buffer(void)
13111 struct d3d11_test_context test_context;
13112 D3D11_TEXTURE2D_DESC texture_desc;
13113 ID3D11DeviceContext *context;
13114 ID3D11RenderTargetView *rtv;
13115 unsigned int index[4] = {0};
13116 ID3D11Texture2D *texture;
13117 ID3D11PixelShader *ps;
13118 ID3D11Device *device;
13119 ID3D11Buffer *cb;
13120 unsigned int i;
13121 HRESULT hr;
13123 static const DWORD ps_code[] =
13125 #if 0
13126 uint index;
13128 static const int int_array[6] =
13130 310, 111, 212, -513, -318, 0,
13133 static const uint uint_array[6] =
13135 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
13138 static const float float_array[6] =
13140 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
13143 float4 main() : SV_Target
13145 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
13147 #endif
13148 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
13149 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13150 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13151 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
13152 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
13153 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
13154 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
13155 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
13156 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
13157 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
13158 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
13159 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
13160 0x0100003e,
13162 static struct vec4 expected_result[] =
13164 { 310.0f, 2.0f, 76.00f, 1.0f},
13165 { 111.0f, 7.0f, 83.50f, 1.0f},
13166 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
13167 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
13168 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
13169 { 0.0f, 0.0f, 0.0f, 1.0f},
13172 if (!init_test_context(&test_context, NULL))
13173 return;
13175 device = test_context.device;
13176 context = test_context.immediate_context;
13178 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13179 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13180 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13182 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
13183 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13185 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13186 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
13187 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13188 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13190 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13191 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13192 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13194 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
13196 *index = i;
13197 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
13199 draw_quad(&test_context);
13200 check_texture_vec4(texture, &expected_result[i], 0);
13203 ID3D11Buffer_Release(cb);
13204 ID3D11PixelShader_Release(ps);
13205 ID3D11Texture2D_Release(texture);
13206 ID3D11RenderTargetView_Release(rtv);
13207 release_test_context(&test_context);
13210 static void test_fp_specials(void)
13212 struct d3d11_test_context test_context;
13213 D3D11_TEXTURE2D_DESC texture_desc;
13214 ID3D11DeviceContext *context;
13215 ID3D11RenderTargetView *rtv;
13216 ID3D11Texture2D *texture;
13217 ID3D11PixelShader *ps;
13218 ID3D11Device *device;
13219 HRESULT hr;
13221 static const DWORD ps_code[] =
13223 #if 0
13224 float4 main() : SV_Target
13226 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
13228 #endif
13229 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
13230 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13231 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13232 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
13233 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
13234 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
13236 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
13238 if (!init_test_context(&test_context, NULL))
13239 return;
13241 device = test_context.device;
13242 context = test_context.immediate_context;
13244 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13245 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13246 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13248 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13249 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
13250 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13251 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13253 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13254 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13256 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13258 draw_quad(&test_context);
13259 check_texture_uvec4(texture, &expected_result);
13261 ID3D11PixelShader_Release(ps);
13262 ID3D11Texture2D_Release(texture);
13263 ID3D11RenderTargetView_Release(rtv);
13264 release_test_context(&test_context);
13267 static void test_uint_shader_instructions(void)
13269 struct shader
13271 const DWORD *code;
13272 size_t size;
13273 D3D_FEATURE_LEVEL required_feature_level;
13276 struct d3d11_test_context test_context;
13277 D3D11_TEXTURE2D_DESC texture_desc;
13278 D3D_FEATURE_LEVEL feature_level;
13279 ID3D11DeviceContext *context;
13280 ID3D11RenderTargetView *rtv;
13281 ID3D11Texture2D *texture;
13282 ID3D11PixelShader *ps;
13283 ID3D11Device *device;
13284 ID3D11Buffer *cb;
13285 unsigned int i;
13286 HRESULT hr;
13288 static const DWORD ps_bfi_code[] =
13290 #if 0
13291 uint bits, offset, insert, base;
13293 uint4 main() : SV_Target
13295 uint mask = ((1 << bits) - 1) << offset;
13296 return ((insert << offset) & mask) | (base & ~mask);
13298 #endif
13299 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
13300 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13301 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13302 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
13303 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13304 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
13305 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
13307 static const DWORD ps_ibfe_code[] =
13309 #if 0
13310 ps_5_0
13311 dcl_globalFlags refactoringAllowed
13312 dcl_constantbuffer cb0[1], immediateIndexed
13313 dcl_output o0.xyzw
13314 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
13316 #endif
13317 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
13318 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13319 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13320 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
13321 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13322 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
13323 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
13325 static const DWORD ps_ubfe_code[] =
13327 #if 0
13328 uint u;
13330 uint4 main() : SV_Target
13332 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
13334 #endif
13335 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
13336 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13337 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13338 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
13339 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13340 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
13341 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
13342 0x0100003e,
13344 static const DWORD ps_bfrev_code[] =
13346 #if 0
13347 uint bits;
13349 uint4 main() : SV_Target
13351 return uint4(reversebits(bits), reversebits(reversebits(bits)),
13352 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
13354 #endif
13355 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
13356 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13357 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13358 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
13359 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13360 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
13361 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
13362 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
13363 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
13364 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
13365 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
13367 static const DWORD ps_bits_code[] =
13369 #if 0
13370 uint u;
13371 int i;
13373 uint4 main() : SV_Target
13375 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
13377 #endif
13378 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
13379 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13380 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13381 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
13382 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13383 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
13384 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
13385 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
13386 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
13387 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
13388 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
13389 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
13390 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
13391 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
13393 static const DWORD ps_ftou_code[] =
13395 #if 0
13396 float f;
13398 uint4 main() : SV_Target
13400 return uint4(f, -f, 0, 0);
13402 #endif
13403 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
13404 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13405 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13406 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
13407 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
13408 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
13409 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
13410 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
13412 static const DWORD ps_f16tof32_code[] =
13414 #if 0
13415 uint4 hf;
13417 uint4 main() : SV_Target
13419 return f16tof32(hf);
13421 #endif
13422 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
13423 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13424 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13425 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
13426 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13427 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
13428 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
13430 static const DWORD ps_f32tof16_code[] =
13432 #if 0
13433 float4 f;
13435 uint4 main() : SV_Target
13437 return f32tof16(f);
13439 #endif
13440 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
13441 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13442 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13443 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
13444 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13445 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
13447 static const DWORD ps_not_code[] =
13449 #if 0
13450 uint2 bits;
13452 uint4 main() : SV_Target
13454 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
13456 #endif
13457 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
13458 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13459 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13460 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
13461 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13462 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
13463 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
13464 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
13466 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
13467 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
13468 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
13469 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
13470 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
13471 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
13472 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
13473 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
13474 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
13475 static const struct
13477 const struct shader *ps;
13478 unsigned int bits[4];
13479 struct uvec4 expected_result;
13481 tests[] =
13483 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
13484 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
13485 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
13486 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
13487 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
13488 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
13489 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
13490 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
13491 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
13492 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
13493 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
13494 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
13495 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
13496 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
13497 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
13498 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
13499 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
13500 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
13501 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
13503 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13504 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13505 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13506 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13507 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
13508 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
13509 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13510 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13511 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
13512 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13513 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13514 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13515 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13516 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13517 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13518 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13519 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13520 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13521 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
13522 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
13523 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13524 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
13525 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13526 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13527 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
13528 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13530 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13531 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
13532 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
13533 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
13534 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
13535 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
13536 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
13538 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
13539 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
13540 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
13542 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
13543 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
13544 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
13545 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
13546 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
13547 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
13548 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
13549 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
13550 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
13551 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
13552 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
13553 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
13555 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
13556 {&ps_ftou, {BITS_NAN}, { 0, 0}},
13557 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
13558 {&ps_ftou, {BITS_INF}, {~0u, 0}},
13559 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
13560 {&ps_ftou, {BITS_1_0}, { 1, 0}},
13562 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
13563 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
13564 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
13565 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
13567 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
13569 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
13570 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
13573 if (!init_test_context(&test_context, NULL))
13574 return;
13576 device = test_context.device;
13577 context = test_context.immediate_context;
13578 feature_level = ID3D11Device_GetFeatureLevel(device);
13580 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
13581 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13583 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13584 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
13585 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13586 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13588 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13589 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13591 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13593 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13595 if (feature_level < tests[i].ps->required_feature_level)
13596 continue;
13598 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
13599 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13600 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13602 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
13604 draw_quad(&test_context);
13605 check_texture_uvec4(texture, &tests[i].expected_result);
13607 ID3D11PixelShader_Release(ps);
13610 ID3D11Buffer_Release(cb);
13611 ID3D11Texture2D_Release(texture);
13612 ID3D11RenderTargetView_Release(rtv);
13613 release_test_context(&test_context);
13616 static void test_index_buffer_offset(void)
13618 struct d3d11_test_context test_context;
13619 ID3D11Buffer *vb, *ib, *so_buffer;
13620 ID3D11InputLayout *input_layout;
13621 ID3D11DeviceContext *context;
13622 struct resource_readback rb;
13623 ID3D11GeometryShader *gs;
13624 const struct vec4 *data;
13625 ID3D11VertexShader *vs;
13626 ID3D11Device *device;
13627 UINT stride, offset;
13628 unsigned int i;
13629 HRESULT hr;
13631 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13632 static const DWORD vs_code[] =
13634 #if 0
13635 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
13636 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
13638 out_position = position;
13639 out_attrib = attrib;
13641 #endif
13642 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
13643 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13644 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13645 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
13646 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13647 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13648 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
13649 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13650 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13651 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13652 0x0100003e,
13654 static const DWORD gs_code[] =
13656 #if 0
13657 struct vertex
13659 float4 position : SV_POSITION;
13660 float4 attrib : ATTRIB;
13663 [maxvertexcount(1)]
13664 void main(point vertex input[1], inout PointStream<vertex> output)
13666 output.Append(input[0]);
13667 output.RestartStrip();
13669 #endif
13670 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
13671 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13672 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13673 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
13674 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13675 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13676 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
13677 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
13678 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
13679 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
13680 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
13681 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
13683 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
13685 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13686 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
13688 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
13690 {0, "SV_Position", 0, 0, 4, 0},
13691 {0, "ATTRIB", 0, 0, 4, 0},
13693 static const struct
13695 struct vec4 position;
13696 struct vec4 attrib;
13698 vertices[] =
13700 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
13701 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
13702 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
13703 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
13705 static const unsigned int indices[] =
13707 0, 1, 2, 3,
13708 3, 2, 1, 0,
13709 1, 3, 2, 0,
13711 static const struct vec4 expected_data[] =
13713 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13714 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13715 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13716 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13718 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13719 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13720 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13721 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13723 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13724 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13725 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13726 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13728 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
13730 if (!init_test_context(&test_context, &feature_level))
13731 return;
13733 device = test_context.device;
13734 context = test_context.immediate_context;
13736 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
13737 vs_code, sizeof(vs_code), &input_layout);
13738 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13740 stride = 32;
13741 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
13742 so_declaration, ARRAY_SIZE(so_declaration),
13743 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
13744 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
13746 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13747 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13749 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
13750 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
13751 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
13753 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13754 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
13756 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13757 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
13758 stride = sizeof(*vertices);
13759 offset = 0;
13760 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
13762 offset = 0;
13763 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
13765 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
13766 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
13768 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
13769 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
13771 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
13772 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
13774 get_buffer_readback(so_buffer, &rb);
13775 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
13777 data = get_readback_vec4(&rb, i, 0);
13778 ok(compare_vec4(data, &expected_data[i], 0)
13779 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
13780 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
13781 data->x, data->y, data->z, data->w, i);
13783 release_resource_readback(&rb);
13785 ID3D11Buffer_Release(so_buffer);
13786 ID3D11Buffer_Release(ib);
13787 ID3D11Buffer_Release(vb);
13788 ID3D11VertexShader_Release(vs);
13789 ID3D11GeometryShader_Release(gs);
13790 ID3D11InputLayout_Release(input_layout);
13791 release_test_context(&test_context);
13794 static void test_face_culling(void)
13796 struct d3d11_test_context test_context;
13797 D3D11_RASTERIZER_DESC rasterizer_desc;
13798 ID3D11RasterizerState *state;
13799 ID3D11DeviceContext *context;
13800 ID3D11Buffer *cw_vb, *ccw_vb;
13801 ID3D11Device *device;
13802 BOOL broken_warp;
13803 unsigned int i;
13804 HRESULT hr;
13806 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
13807 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
13808 static const DWORD ps_code[] =
13810 #if 0
13811 float4 main(uint front : SV_IsFrontFace) : SV_Target
13813 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
13815 #endif
13816 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
13817 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
13818 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
13819 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
13820 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
13821 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
13822 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
13823 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
13824 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
13825 0x3f800000, 0x0100003e,
13827 static const struct vec2 ccw_quad[] =
13829 {-1.0f, 1.0f},
13830 {-1.0f, -1.0f},
13831 { 1.0f, 1.0f},
13832 { 1.0f, -1.0f},
13834 static const struct
13836 D3D11_CULL_MODE cull_mode;
13837 BOOL front_ccw;
13838 BOOL expected_cw;
13839 BOOL expected_ccw;
13841 tests[] =
13843 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
13844 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
13845 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
13846 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
13847 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
13848 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
13851 if (!init_test_context(&test_context, NULL))
13852 return;
13854 device = test_context.device;
13855 context = test_context.immediate_context;
13857 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13858 draw_color_quad(&test_context, &green);
13859 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13861 cw_vb = test_context.vb;
13862 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
13864 test_context.vb = ccw_vb;
13865 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13866 draw_color_quad(&test_context, &green);
13867 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
13869 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
13870 rasterizer_desc.CullMode = D3D11_CULL_BACK;
13871 rasterizer_desc.FrontCounterClockwise = FALSE;
13872 rasterizer_desc.DepthBias = 0;
13873 rasterizer_desc.DepthBiasClamp = 0.0f;
13874 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
13875 rasterizer_desc.DepthClipEnable = TRUE;
13876 rasterizer_desc.ScissorEnable = FALSE;
13877 rasterizer_desc.MultisampleEnable = FALSE;
13878 rasterizer_desc.AntialiasedLineEnable = FALSE;
13880 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13882 rasterizer_desc.CullMode = tests[i].cull_mode;
13883 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
13884 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13885 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
13887 ID3D11DeviceContext_RSSetState(context, state);
13889 test_context.vb = cw_vb;
13890 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13891 draw_color_quad(&test_context, &green);
13892 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
13894 test_context.vb = ccw_vb;
13895 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13896 draw_color_quad(&test_context, &green);
13897 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
13899 ID3D11RasterizerState_Release(state);
13902 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1;
13904 /* Test SV_IsFrontFace. */
13905 ID3D11PixelShader_Release(test_context.ps);
13906 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
13907 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13909 rasterizer_desc.CullMode = D3D11_CULL_NONE;
13910 rasterizer_desc.FrontCounterClockwise = FALSE;
13911 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13912 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13913 ID3D11DeviceContext_RSSetState(context, state);
13915 test_context.vb = cw_vb;
13916 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13917 draw_color_quad(&test_context, &green);
13918 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13919 test_context.vb = ccw_vb;
13920 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13921 draw_color_quad(&test_context, &green);
13922 if (!broken_warp)
13923 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
13924 else
13925 win_skip("Broken WARP.\n");
13927 ID3D11RasterizerState_Release(state);
13929 rasterizer_desc.CullMode = D3D11_CULL_NONE;
13930 rasterizer_desc.FrontCounterClockwise = TRUE;
13931 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13932 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13933 ID3D11DeviceContext_RSSetState(context, state);
13935 test_context.vb = cw_vb;
13936 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13937 draw_color_quad(&test_context, &green);
13938 if (!broken_warp)
13939 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
13940 else
13941 win_skip("Broken WARP.\n");
13942 test_context.vb = ccw_vb;
13943 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13944 draw_color_quad(&test_context, &green);
13945 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13947 ID3D11RasterizerState_Release(state);
13949 test_context.vb = cw_vb;
13950 ID3D11Buffer_Release(ccw_vb);
13951 release_test_context(&test_context);
13954 static void test_line_antialiasing_blending(void)
13956 ID3D11RasterizerState *rasterizer_state;
13957 struct d3d11_test_context test_context;
13958 D3D11_RASTERIZER_DESC rasterizer_desc;
13959 ID3D11BlendState *blend_state;
13960 ID3D11DeviceContext *context;
13961 D3D11_BLEND_DESC blend_desc;
13962 ID3D11Device *device;
13963 HRESULT hr;
13965 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
13966 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
13968 if (!init_test_context(&test_context, NULL))
13969 return;
13971 device = test_context.device;
13972 context = test_context.immediate_context;
13974 memset(&blend_desc, 0, sizeof(blend_desc));
13975 blend_desc.AlphaToCoverageEnable = FALSE;
13976 blend_desc.IndependentBlendEnable = FALSE;
13977 blend_desc.RenderTarget[0].BlendEnable = TRUE;
13978 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
13979 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
13980 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
13981 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
13982 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
13983 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
13984 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
13986 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
13987 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
13988 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
13990 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
13991 draw_color_quad(&test_context, &green);
13992 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
13994 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
13995 draw_color_quad(&test_context, &red);
13996 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
13998 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
13999 ID3D11BlendState_Release(blend_state);
14001 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
14002 draw_color_quad(&test_context, &green);
14003 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
14005 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
14006 draw_color_quad(&test_context, &red);
14007 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
14009 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
14010 rasterizer_desc.CullMode = D3D11_CULL_BACK;
14011 rasterizer_desc.FrontCounterClockwise = FALSE;
14012 rasterizer_desc.DepthBias = 0;
14013 rasterizer_desc.DepthBiasClamp = 0.0f;
14014 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
14015 rasterizer_desc.DepthClipEnable = TRUE;
14016 rasterizer_desc.ScissorEnable = FALSE;
14017 rasterizer_desc.MultisampleEnable = FALSE;
14018 rasterizer_desc.AntialiasedLineEnable = TRUE;
14020 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
14021 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
14022 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
14024 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
14025 draw_color_quad(&test_context, &green);
14026 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
14028 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
14029 draw_color_quad(&test_context, &red);
14030 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
14032 ID3D11RasterizerState_Release(rasterizer_state);
14033 release_test_context(&test_context);
14036 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
14037 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
14038 const char *feature_name)
14040 unsigned int i;
14042 for (i = 0; i < format_count; ++i)
14044 DXGI_FORMAT format = formats[i].format;
14045 unsigned int supported = format_support[format] & feature_flag;
14047 if (formats[i].fl_required <= feature_level)
14049 ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
14050 format, feature_name, feature_level, format_support[format]);
14051 continue;
14054 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
14056 if (supported)
14057 trace("Optional format %#x - %s supported, feature level %#x.\n",
14058 format, feature_name, feature_level);
14059 continue;
14062 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
14063 format, feature_name, feature_level, format_support[format]);
14067 static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
14069 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
14070 struct device_desc device_desc;
14071 ID3D11Device *device;
14072 DXGI_FORMAT format;
14073 ULONG refcount;
14074 HRESULT hr;
14076 static const struct format_support index_buffers[] =
14078 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
14079 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
14082 device_desc.feature_level = &feature_level;
14083 device_desc.flags = 0;
14084 if (!(device = create_device(&device_desc)))
14086 skip("Failed to create device for feature level %#x.\n", feature_level);
14087 return;
14090 memset(format_support, 0, sizeof(format_support));
14091 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
14093 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
14094 todo_wine ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
14095 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
14096 format, hr, format_support[format]);
14098 if (hr == E_NOTIMPL)
14100 skip("CheckFormatSupport not implemented.\n");
14101 ID3D11Device_Release(device);
14102 return;
14105 check_format_support(format_support, feature_level,
14106 index_buffers, ARRAY_SIZE(index_buffers),
14107 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
14109 check_format_support(format_support, feature_level,
14110 display_format_support, ARRAY_SIZE(display_format_support),
14111 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
14113 refcount = ID3D11Device_Release(device);
14114 ok(!refcount, "Device has %u references left.\n", refcount);
14117 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
14119 struct d3d11_test_context test_context;
14120 D3D11_SUBRESOURCE_DATA resource_data;
14121 D3D11_TEXTURE2D_DESC texture_desc;
14122 ID3D11ShaderResourceView *srv;
14123 ID3D11DeviceContext *context;
14124 ID3D11Texture2D *texture;
14125 ID3D11PixelShader *ps;
14126 ID3D11Device *device;
14127 HRESULT hr;
14129 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
14130 static const DWORD ps_code[] =
14132 #if 0
14133 float4 main() : SV_TARGET
14135 return float4(1.0f, 0.0f, 0.0f, 0.5f);
14137 #endif
14138 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
14139 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
14140 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
14141 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
14142 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
14143 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
14144 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
14145 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
14146 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
14147 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
14148 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
14149 0x45475241, 0xabab0054,
14151 static const DWORD ps_texture_code[] =
14153 #if 0
14154 Texture2D t;
14155 SamplerState s;
14157 float4 main() : SV_TARGET
14159 return t.Sample(s, (float2)0);
14161 #endif
14162 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
14163 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
14164 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
14165 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
14166 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
14167 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
14168 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
14169 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
14170 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
14171 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
14172 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
14173 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
14174 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
14175 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14176 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
14178 static const DWORD texture_data[] = {0xffffff00};
14180 if (!init_test_context(&test_context, &feature_level))
14181 return;
14183 device = test_context.device;
14184 context = test_context.immediate_context;
14186 texture_desc.Width = 1;
14187 texture_desc.Height = 1;
14188 texture_desc.MipLevels = 0;
14189 texture_desc.ArraySize = 1;
14190 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14191 texture_desc.SampleDesc.Count = 1;
14192 texture_desc.SampleDesc.Quality = 0;
14193 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14194 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14195 texture_desc.CPUAccessFlags = 0;
14196 texture_desc.MiscFlags = 0;
14197 resource_data.pSysMem = texture_data;
14198 resource_data.SysMemPitch = sizeof(texture_data);
14199 resource_data.SysMemSlicePitch = 0;
14200 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
14201 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14202 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
14203 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14205 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14206 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
14207 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14208 draw_quad(&test_context);
14209 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
14210 ID3D11PixelShader_Release(ps);
14212 draw_color_quad(&test_context, &color);
14213 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
14215 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
14216 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
14217 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14218 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
14219 draw_quad(&test_context);
14220 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
14221 ID3D11PixelShader_Release(ps);
14223 ID3D11ShaderResourceView_Release(srv);
14224 ID3D11Texture2D_Release(texture);
14225 release_test_context(&test_context);
14228 static void run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
14229 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
14231 static const D3D_FEATURE_LEVEL feature_levels[] =
14233 D3D_FEATURE_LEVEL_11_1,
14234 D3D_FEATURE_LEVEL_11_0,
14235 D3D_FEATURE_LEVEL_10_1,
14236 D3D_FEATURE_LEVEL_10_0,
14237 D3D_FEATURE_LEVEL_9_3,
14238 D3D_FEATURE_LEVEL_9_2,
14239 D3D_FEATURE_LEVEL_9_1
14241 unsigned int i;
14243 assert(begin <= end);
14244 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
14246 if (begin <= feature_levels[i] && feature_levels[i] <= end)
14247 test_func(feature_levels[i]);
14251 static void run_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
14253 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
14254 D3D_FEATURE_LEVEL_11_1, test_func);
14257 static void run_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
14259 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
14260 D3D_FEATURE_LEVEL_9_3, test_func);
14263 static void test_ddy(void)
14265 static const struct
14267 struct vec4 position;
14268 unsigned int color;
14270 quad[] =
14272 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
14273 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
14274 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
14275 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
14277 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
14279 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
14280 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
14282 #if 0
14283 struct vs_data
14285 float4 pos : SV_POSITION;
14286 float4 color : COLOR;
14289 void main(in struct vs_data vs_input, out struct vs_data vs_output)
14291 vs_output.pos = vs_input.pos;
14292 vs_output.color = vs_input.color;
14294 #endif
14295 static const DWORD vs_code[] =
14297 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
14298 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14299 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
14300 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14301 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
14302 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
14303 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
14304 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
14305 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
14306 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
14307 0x0100003e,
14309 #if 0
14310 struct ps_data
14312 float4 pos : SV_POSITION;
14313 float4 color : COLOR;
14316 float4 main(struct ps_data ps_input) : SV_Target
14318 return ddy(ps_input.color) * 240.0 + 0.5;
14320 #endif
14321 static const DWORD ps_code_ddy[] =
14323 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
14324 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14325 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14326 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14327 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14328 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
14329 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14330 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
14331 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
14332 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
14334 #if 0
14335 struct ps_data
14337 float4 pos : SV_POSITION;
14338 float4 color : COLOR;
14341 float4 main(struct ps_data ps_input) : SV_Target
14343 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
14345 #endif
14346 static const DWORD ps_code_ddy_coarse[] =
14348 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
14349 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14350 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14351 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14352 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14353 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
14354 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14355 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
14356 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
14357 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
14359 #if 0
14360 struct ps_data
14362 float4 pos : SV_POSITION;
14363 float4 color : COLOR;
14366 float4 main(struct ps_data ps_input) : SV_Target
14368 return ddy_fine(ps_input.color) * 240.0 + 0.5;
14370 #endif
14371 static const DWORD ps_code_ddy_fine[] =
14373 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
14374 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14375 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14376 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14377 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14378 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
14379 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14380 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
14381 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
14382 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
14384 static const struct
14386 D3D_FEATURE_LEVEL min_feature_level;
14387 const DWORD *ps_code;
14388 unsigned int ps_code_size;
14390 tests[] =
14392 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
14393 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
14394 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
14396 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
14397 struct d3d11_test_context test_context;
14398 D3D11_TEXTURE2D_DESC texture_desc;
14399 D3D_FEATURE_LEVEL feature_level;
14400 ID3D11InputLayout *input_layout;
14401 ID3D11DeviceContext *context;
14402 unsigned int stride, offset;
14403 struct resource_readback rb;
14404 ID3D11RenderTargetView *rtv;
14405 ID3D11Texture2D *texture;
14406 ID3D11VertexShader *vs;
14407 ID3D11PixelShader *ps;
14408 ID3D11Device *device;
14409 ID3D11Buffer *vb;
14410 unsigned int i;
14411 DWORD color;
14412 HRESULT hr;
14414 if (!init_test_context(&test_context, NULL))
14415 return;
14417 device = test_context.device;
14418 context = test_context.immediate_context;
14419 feature_level = ID3D11Device_GetFeatureLevel(device);
14421 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14422 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14423 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14425 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14426 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14428 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
14429 vs_code, sizeof(vs_code), &input_layout);
14430 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
14432 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
14434 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
14435 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
14437 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
14438 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
14439 stride = sizeof(*quad);
14440 offset = 0;
14441 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
14442 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
14444 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14446 if (feature_level < tests[i].min_feature_level)
14448 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
14449 feature_level, tests[i].min_feature_level);
14450 continue;
14453 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
14454 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14456 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14458 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14459 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
14460 ID3D11DeviceContext_Draw(context, 4, 0);
14462 get_texture_readback(texture, 0, &rb);
14463 color = get_readback_color(&rb, 320, 190);
14464 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14465 color = get_readback_color(&rb, 255, 240);
14466 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14467 color = get_readback_color(&rb, 320, 240);
14468 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14469 color = get_readback_color(&rb, 385, 240);
14470 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14471 color = get_readback_color(&rb, 320, 290);
14472 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14473 release_resource_readback(&rb);
14475 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
14476 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14477 ID3D11DeviceContext_Draw(context, 4, 0);
14479 get_texture_readback(test_context.backbuffer, 0, &rb);
14480 color = get_readback_color(&rb, 320, 190);
14481 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14482 color = get_readback_color(&rb, 255, 240);
14483 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14484 color = get_readback_color(&rb, 320, 240);
14485 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14486 color = get_readback_color(&rb, 385, 240);
14487 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14488 color = get_readback_color(&rb, 320, 290);
14489 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
14490 release_resource_readback(&rb);
14492 ID3D11PixelShader_Release(ps);
14495 ID3D11VertexShader_Release(vs);
14496 ID3D11Buffer_Release(vb);
14497 ID3D11InputLayout_Release(input_layout);
14498 ID3D11Texture2D_Release(texture);
14499 ID3D11RenderTargetView_Release(rtv);
14500 release_test_context(&test_context);
14503 static void test_shader_input_registers_limits(void)
14505 struct d3d11_test_context test_context;
14506 D3D11_SUBRESOURCE_DATA resource_data;
14507 D3D11_TEXTURE2D_DESC texture_desc;
14508 D3D11_SAMPLER_DESC sampler_desc;
14509 ID3D11ShaderResourceView *srv;
14510 ID3D11DeviceContext *context;
14511 ID3D11SamplerState *sampler;
14512 ID3D11Texture2D *texture;
14513 ID3D11PixelShader *ps;
14514 ID3D11Device *device;
14515 HRESULT hr;
14517 static const DWORD ps_last_register_code[] =
14519 #if 0
14520 Texture2D t : register(t127);
14521 SamplerState s : register(s15);
14523 void main(out float4 target : SV_Target)
14525 target = t.Sample(s, float2(0, 0));
14527 #endif
14528 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
14529 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14530 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14531 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
14532 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
14533 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
14534 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
14536 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
14537 static const DWORD texture_data[] = {0xff00ff00};
14539 if (!init_test_context(&test_context, NULL))
14540 return;
14542 device = test_context.device;
14543 context = test_context.immediate_context;
14545 texture_desc.Width = 1;
14546 texture_desc.Height = 1;
14547 texture_desc.MipLevels = 0;
14548 texture_desc.ArraySize = 1;
14549 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14550 texture_desc.SampleDesc.Count = 1;
14551 texture_desc.SampleDesc.Quality = 0;
14552 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14553 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14554 texture_desc.CPUAccessFlags = 0;
14555 texture_desc.MiscFlags = 0;
14557 resource_data.pSysMem = texture_data;
14558 resource_data.SysMemPitch = sizeof(texture_data);
14559 resource_data.SysMemSlicePitch = 0;
14561 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
14562 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
14564 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
14565 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14567 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
14568 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
14569 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
14570 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
14571 sampler_desc.MipLODBias = 0.0f;
14572 sampler_desc.MaxAnisotropy = 0;
14573 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
14574 sampler_desc.BorderColor[0] = 0.0f;
14575 sampler_desc.BorderColor[1] = 0.0f;
14576 sampler_desc.BorderColor[2] = 0.0f;
14577 sampler_desc.BorderColor[3] = 0.0f;
14578 sampler_desc.MinLOD = 0.0f;
14579 sampler_desc.MaxLOD = 0.0f;
14581 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
14582 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
14584 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
14585 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14586 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14588 ID3D11DeviceContext_PSSetShaderResources(context,
14589 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
14590 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
14591 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
14592 draw_quad(&test_context);
14593 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14595 ID3D11PixelShader_Release(ps);
14596 ID3D11SamplerState_Release(sampler);
14597 ID3D11ShaderResourceView_Release(srv);
14598 ID3D11Texture2D_Release(texture);
14599 release_test_context(&test_context);
14602 static void test_unbind_shader_resource_view(void)
14604 struct d3d11_test_context test_context;
14605 D3D11_SUBRESOURCE_DATA resource_data;
14606 ID3D11ShaderResourceView *srv, *srv2;
14607 D3D11_TEXTURE2D_DESC texture_desc;
14608 ID3D11DeviceContext *context;
14609 ID3D11Texture2D *texture;
14610 ID3D11PixelShader *ps;
14611 ID3D11Device *device;
14612 HRESULT hr;
14614 static const DWORD ps_code[] =
14616 #if 0
14617 Texture2D t0;
14618 Texture2D t1;
14619 SamplerState s;
14621 float4 main() : SV_Target
14623 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
14625 #endif
14626 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
14627 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14628 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14629 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
14630 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
14631 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
14632 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
14633 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
14634 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
14635 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
14636 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
14637 0x3f800000, 0x0100003e,
14639 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
14640 static const DWORD texture_data[] = {0xff00ff00};
14642 if (!init_test_context(&test_context, NULL))
14643 return;
14645 device = test_context.device;
14646 context = test_context.immediate_context;
14648 texture_desc.Width = 1;
14649 texture_desc.Height = 1;
14650 texture_desc.MipLevels = 0;
14651 texture_desc.ArraySize = 1;
14652 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14653 texture_desc.SampleDesc.Count = 1;
14654 texture_desc.SampleDesc.Quality = 0;
14655 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14656 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14657 texture_desc.CPUAccessFlags = 0;
14658 texture_desc.MiscFlags = 0;
14660 resource_data.pSysMem = texture_data;
14661 resource_data.SysMemPitch = sizeof(texture_data);
14662 resource_data.SysMemSlicePitch = 0;
14664 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
14665 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
14666 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
14667 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14668 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14669 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14670 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14672 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
14673 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
14674 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
14675 draw_quad(&test_context);
14676 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14678 srv2 = NULL;
14679 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
14680 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
14681 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
14682 draw_quad(&test_context);
14683 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
14685 ID3D11PixelShader_Release(ps);
14686 ID3D11ShaderResourceView_Release(srv);
14687 ID3D11Texture2D_Release(texture);
14688 release_test_context(&test_context);
14691 static void test_stencil_separate(void)
14693 struct d3d11_test_context test_context;
14694 D3D11_TEXTURE2D_DESC texture_desc;
14695 D3D11_DEPTH_STENCIL_DESC ds_desc;
14696 ID3D11DepthStencilState *ds_state;
14697 ID3D11DepthStencilView *ds_view;
14698 D3D11_RASTERIZER_DESC rs_desc;
14699 ID3D11DeviceContext *context;
14700 ID3D11RasterizerState *rs;
14701 ID3D11Texture2D *texture;
14702 ID3D11Device *device;
14703 HRESULT hr;
14705 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
14706 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
14707 static const struct vec2 ccw_quad[] =
14709 {-1.0f, -1.0f},
14710 { 1.0f, -1.0f},
14711 {-1.0f, 1.0f},
14712 { 1.0f, 1.0f},
14715 if (!init_test_context(&test_context, NULL))
14716 return;
14718 device = test_context.device;
14719 context = test_context.immediate_context;
14721 texture_desc.Width = 640;
14722 texture_desc.Height = 480;
14723 texture_desc.MipLevels = 1;
14724 texture_desc.ArraySize = 1;
14725 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
14726 texture_desc.SampleDesc.Count = 1;
14727 texture_desc.SampleDesc.Quality = 0;
14728 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14729 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
14730 texture_desc.CPUAccessFlags = 0;
14731 texture_desc.MiscFlags = 0;
14732 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14733 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14734 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
14735 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
14737 ds_desc.DepthEnable = TRUE;
14738 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
14739 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
14740 ds_desc.StencilEnable = TRUE;
14741 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
14742 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
14743 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
14744 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
14745 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
14746 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
14747 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
14748 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
14749 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
14750 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
14751 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
14752 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
14754 rs_desc.FillMode = D3D11_FILL_SOLID;
14755 rs_desc.CullMode = D3D11_CULL_NONE;
14756 rs_desc.FrontCounterClockwise = FALSE;
14757 rs_desc.DepthBias = 0;
14758 rs_desc.DepthBiasClamp = 0.0f;
14759 rs_desc.SlopeScaledDepthBias = 0.0f;
14760 rs_desc.DepthClipEnable = TRUE;
14761 rs_desc.ScissorEnable = FALSE;
14762 rs_desc.MultisampleEnable = FALSE;
14763 rs_desc.AntialiasedLineEnable = FALSE;
14764 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
14765 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
14767 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14768 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
14769 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
14770 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
14771 ID3D11DeviceContext_RSSetState(context, rs);
14773 draw_color_quad(&test_context, &green);
14774 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14776 ID3D11Buffer_Release(test_context.vb);
14777 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
14779 draw_color_quad(&test_context, &green);
14780 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14782 ID3D11RasterizerState_Release(rs);
14783 rs_desc.FrontCounterClockwise = TRUE;
14784 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
14785 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
14786 ID3D11DeviceContext_RSSetState(context, rs);
14788 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14789 draw_color_quad(&test_context, &green);
14790 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14792 ID3D11DepthStencilState_Release(ds_state);
14793 ID3D11DepthStencilView_Release(ds_view);
14794 ID3D11RasterizerState_Release(rs);
14795 ID3D11Texture2D_Release(texture);
14796 release_test_context(&test_context);
14799 static void test_uav_load(void)
14801 struct shader
14803 const DWORD *code;
14804 size_t size;
14806 struct texture
14808 UINT width;
14809 UINT height;
14810 UINT miplevel_count;
14811 UINT array_size;
14812 DXGI_FORMAT format;
14813 D3D11_SUBRESOURCE_DATA data[3];
14816 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
14817 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
14818 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
14819 struct d3d11_test_context test_context;
14820 const struct texture *current_texture;
14821 ID3D11Texture2D *texture, *rt_texture;
14822 D3D11_TEXTURE2D_DESC texture_desc;
14823 const struct shader *current_ps;
14824 ID3D11UnorderedAccessView *uav;
14825 ID3D11DeviceContext *context;
14826 struct resource_readback rb;
14827 ID3D11PixelShader *ps;
14828 ID3D11Device *device;
14829 unsigned int i, x, y;
14830 ID3D11Buffer *cb;
14831 HRESULT hr;
14833 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
14834 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
14835 static const DWORD ps_ld_2d_float_code[] =
14837 #if 0
14838 RWTexture2D<float> u;
14840 float main(float4 position : SV_Position) : SV_Target
14842 float2 s;
14843 u.GetDimensions(s.x, s.y);
14844 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
14846 #endif
14847 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
14848 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14849 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
14850 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14851 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
14852 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
14853 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
14854 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
14855 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
14856 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
14857 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
14858 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
14859 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
14861 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
14862 static const DWORD ps_ld_2d_uint_code[] =
14864 #if 0
14865 RWTexture2D<uint> u;
14867 uint main(float4 position : SV_Position) : SV_Target
14869 float2 s;
14870 u.GetDimensions(s.x, s.y);
14871 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
14873 #endif
14874 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
14875 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14876 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
14877 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
14878 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
14879 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
14880 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
14881 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
14882 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
14883 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
14884 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
14885 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
14886 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
14888 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
14889 static const DWORD ps_ld_2d_int_code[] =
14891 #if 0
14892 RWTexture2D<int> u;
14894 int main(float4 position : SV_Position) : SV_Target
14896 float2 s;
14897 u.GetDimensions(s.x, s.y);
14898 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
14900 #endif
14901 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
14902 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14903 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
14904 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
14905 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
14906 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
14907 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
14908 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
14909 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
14910 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
14911 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
14912 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
14913 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
14915 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
14916 static const DWORD ps_ld_2d_uint_arr_code[] =
14918 #if 0
14919 RWTexture2DArray<uint> u;
14921 uint layer;
14923 uint main(float4 position : SV_Position) : SV_Target
14925 float3 s;
14926 u.GetDimensions(s.x, s.y, s.z);
14927 s.z = layer;
14928 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
14930 #endif
14931 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
14932 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14933 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
14934 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
14935 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
14936 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
14937 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
14938 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
14939 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
14940 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
14941 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
14942 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
14943 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
14944 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
14946 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
14947 static const float float_data[] =
14949 0.50f, 0.25f, 1.00f, 0.00f,
14950 -1.00f, -2.00f, -3.00f, -4.00f,
14951 -0.50f, -0.25f, -1.00f, -0.00f,
14952 1.00f, 2.00f, 3.00f, 4.00f,
14954 static const unsigned int uint_data[] =
14956 0x00, 0x10, 0x20, 0x30,
14957 0x40, 0x50, 0x60, 0x70,
14958 0x80, 0x90, 0xa0, 0xb0,
14959 0xc0, 0xd0, 0xe0, 0xf0,
14961 static const unsigned int uint_data2[] =
14963 0xffff, 0xffff, 0xffff, 0xffff,
14964 0xffff, 0xc000, 0xc000, 0xffff,
14965 0xffff, 0xc000, 0xc000, 0xffff,
14966 0xffff, 0xffff, 0xffff, 0xffff,
14968 static const unsigned int uint_data3[] =
14970 0xaa, 0xaa, 0xcc, 0xcc,
14971 0xaa, 0xaa, 0xdd, 0xdd,
14972 0xbb, 0xbb, 0xee, 0xee,
14973 0xbb, 0xbb, 0xff, 0xff,
14975 static const int int_data[] =
14977 -1, 0x10, 0x20, 0x30,
14978 0x40, 0x50, 0x60, -777,
14979 -666, 0x90, -555, 0xb0,
14980 0xc0, 0xd0, 0xe0, -101,
14982 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
14983 {{float_data, 4 * sizeof(*float_data), 0}}};
14984 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
14985 {{uint_data, 4 * sizeof(*uint_data), 0}}};
14986 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
14987 {{uint_data, 4 * sizeof(*uint_data), 0},
14988 {uint_data2, 4 * sizeof(*uint_data2), 0},
14989 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
14990 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
14991 {{int_data, 4 * sizeof(*int_data), 0}}};
14993 static const struct test
14995 const struct shader *ps;
14996 const struct texture *texture;
14997 struct uav_desc uav_desc;
14998 struct uvec4 constant;
14999 const DWORD *expected_colors;
15001 tests[] =
15003 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
15004 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
15005 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
15006 #define R32_UINT DXGI_FORMAT_R32_UINT
15007 #define R32_SINT DXGI_FORMAT_R32_SINT
15008 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {}, (const DWORD *)float_data},
15009 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {}, (const DWORD *)uint_data},
15010 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {}, (const DWORD *)int_data},
15011 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
15012 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
15013 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
15014 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
15015 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
15016 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
15017 #undef TEX_2D
15018 #undef TEX_2D_ARRAY
15019 #undef R32_FLOAT
15020 #undef R32_UINT
15021 #undef R32_SINT
15024 if (!init_test_context(&test_context, &feature_level))
15025 return;
15027 device = test_context.device;
15028 context = test_context.immediate_context;
15030 texture_desc.Width = 640;
15031 texture_desc.Height = 480;
15032 texture_desc.MipLevels = 1;
15033 texture_desc.ArraySize = 1;
15034 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
15035 texture_desc.SampleDesc.Count = 1;
15036 texture_desc.SampleDesc.Quality = 0;
15037 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15038 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15039 texture_desc.CPUAccessFlags = 0;
15040 texture_desc.MiscFlags = 0;
15041 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
15042 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15044 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15045 U(rtv_desc).Texture2D.MipSlice = 0;
15047 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
15048 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
15049 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15051 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
15052 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
15053 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15055 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
15056 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
15057 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15059 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15061 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
15062 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
15064 ps = NULL;
15065 uav = NULL;
15066 texture = NULL;
15067 current_ps = NULL;
15068 current_texture = NULL;
15069 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15071 const struct test *test = &tests[i];
15072 ID3D11RenderTargetView *current_rtv;
15074 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15075 NULL, &test->constant, 0, 0);
15077 if (current_ps != test->ps)
15079 if (ps)
15080 ID3D11PixelShader_Release(ps);
15082 current_ps = test->ps;
15084 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
15085 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
15087 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15090 if (current_texture != test->texture)
15092 if (texture)
15093 ID3D11Texture2D_Release(texture);
15095 current_texture = test->texture;
15097 texture_desc.Width = current_texture->width;
15098 texture_desc.Height = current_texture->height;
15099 texture_desc.MipLevels = current_texture->miplevel_count;
15100 texture_desc.ArraySize = current_texture->array_size;
15101 texture_desc.Format = current_texture->format;
15103 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
15104 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
15107 if (uav)
15108 ID3D11UnorderedAccessView_Release(uav);
15110 get_uav_desc(&uav_desc, &test->uav_desc);
15111 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
15112 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
15114 switch (uav_desc.Format)
15116 case DXGI_FORMAT_R32_FLOAT:
15117 current_rtv = rtv_float;
15118 break;
15119 case DXGI_FORMAT_R32_UINT:
15120 current_rtv = rtv_uint;
15121 break;
15122 case DXGI_FORMAT_R32_SINT:
15123 current_rtv = rtv_sint;
15124 break;
15125 default:
15126 trace("Unhandled format %#x.\n", uav_desc.Format);
15127 current_rtv = NULL;
15128 break;
15131 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
15133 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
15134 1, 1, &uav, NULL);
15136 draw_quad(&test_context);
15138 get_texture_readback(rt_texture, 0, &rb);
15139 for (y = 0; y < 4; ++y)
15141 for (x = 0; x < 4; ++x)
15143 DWORD expected = test->expected_colors[y * 4 + x];
15144 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
15145 ok(compare_color(color, expected, 0),
15146 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
15147 i, color, expected, x, y);
15150 release_resource_readback(&rb);
15152 ID3D11PixelShader_Release(ps);
15153 ID3D11Texture2D_Release(texture);
15154 ID3D11UnorderedAccessView_Release(uav);
15156 ID3D11Buffer_Release(cb);
15157 ID3D11RenderTargetView_Release(rtv_float);
15158 ID3D11RenderTargetView_Release(rtv_sint);
15159 ID3D11RenderTargetView_Release(rtv_uint);
15160 ID3D11Texture2D_Release(rt_texture);
15161 release_test_context(&test_context);
15164 static void test_cs_uav_store(void)
15166 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15167 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
15168 static const float zero[4] = {0.0f};
15169 D3D11_TEXTURE2D_DESC texture_desc;
15170 ID3D11UnorderedAccessView *uav;
15171 struct device_desc device_desc;
15172 ID3D11DeviceContext *context;
15173 struct vec4 input = {1.0f};
15174 ID3D11Texture2D *texture;
15175 ID3D11ComputeShader *cs;
15176 ID3D11Device *device;
15177 ID3D11Buffer *cb;
15178 ULONG refcount;
15179 HRESULT hr;
15180 RECT rect;
15182 static const DWORD cs_1_thread_code[] =
15184 #if 0
15185 RWTexture2D<float> u;
15187 float value;
15189 [numthreads(1, 1, 1)]
15190 void main()
15192 uint x, y, width, height;
15193 u.GetDimensions(width, height);
15194 for (y = 0; y < height; ++y)
15196 for (x = 0; x < width; ++x)
15197 u[uint2(x, y)] = value;
15200 #endif
15201 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
15202 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15203 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
15204 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
15205 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
15206 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
15207 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
15208 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
15209 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
15210 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
15211 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
15212 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
15213 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
15214 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
15215 0x01000016, 0x0100003e,
15217 static const DWORD cs_1_group_code[] =
15219 #if 0
15220 RWTexture2D<float> u;
15222 float value;
15224 [numthreads(16, 16, 1)]
15225 void main(uint3 threadID : SV_GroupThreadID)
15227 uint2 count, size ;
15228 u.GetDimensions(size.x, size.y);
15229 count = size / (uint2)16;
15230 for (uint y = 0; y < count.y; ++y)
15231 for (uint x = 0; x < count.x; ++x)
15232 u[count * threadID.xy + uint2(x, y)] = value;
15234 #endif
15235 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
15236 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15237 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
15238 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
15239 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
15240 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
15241 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
15242 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
15243 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
15244 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
15245 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
15246 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
15247 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
15248 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
15249 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
15250 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
15251 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
15253 static const DWORD cs_1_store_code[] =
15255 #if 0
15256 RWTexture2D<float> u;
15258 float value;
15260 [numthreads(1, 1, 1)]
15261 void main(uint3 groupID : SV_GroupID)
15263 u[groupID.xy] = value;
15265 #endif
15266 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
15267 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15268 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
15269 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
15270 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
15271 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
15273 static const DWORD cs_dispatch_id_code[] =
15275 #if 0
15276 RWTexture2D<float> u;
15278 float value;
15280 [numthreads(4, 4, 1)]
15281 void main(uint3 id : SV_DispatchThreadID)
15283 u[id.xy] = value;
15285 #endif
15286 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
15287 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15288 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
15289 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
15290 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
15291 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
15293 static const DWORD cs_group_index_code[] =
15295 #if 0
15296 RWTexture2D<float> u;
15298 float value;
15300 [numthreads(32, 1, 1)]
15301 void main(uint index : SV_GroupIndex)
15303 uint2 size;
15304 u.GetDimensions(size.x, size.y);
15305 uint count = size.x * size.y / 32;
15306 index *= count;
15307 for (uint i = 0; i < count; ++i, ++index)
15308 u[uint2(index % size.x, index / size.x)] = value;
15310 #endif
15311 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
15312 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15313 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
15314 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
15315 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
15316 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
15317 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
15318 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
15319 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
15320 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
15321 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
15322 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
15323 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
15324 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
15325 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
15326 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
15329 device_desc.feature_level = &feature_level;
15330 device_desc.flags = 0;
15331 if (!(device = create_device(&device_desc)))
15333 skip("Failed to create device for feature level %#x.\n", feature_level);
15334 return;
15337 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
15339 texture_desc.Width = 64;
15340 texture_desc.Height = 64;
15341 texture_desc.MipLevels = 1;
15342 texture_desc.ArraySize = 1;
15343 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
15344 texture_desc.SampleDesc.Count = 1;
15345 texture_desc.SampleDesc.Quality = 0;
15346 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15347 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15348 texture_desc.CPUAccessFlags = 0;
15349 texture_desc.MiscFlags = 0;
15351 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15352 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15354 uav_desc.Format = texture_desc.Format;
15355 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
15356 U(uav_desc).Texture2D.MipSlice = 0;
15358 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
15359 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15361 ID3D11Device_GetImmediateContext(device, &context);
15363 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
15364 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
15366 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
15367 check_texture_float(texture, 0.0f, 2);
15369 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
15370 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15371 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15373 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15374 check_texture_float(texture, 1.0f, 2);
15376 input.x = 0.5f;
15377 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15378 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15379 check_texture_float(texture, 0.5f, 2);
15381 ID3D11ComputeShader_Release(cs);
15383 input.x = 2.0f;
15384 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15385 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
15386 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15387 check_texture_float(texture, 0.5f, 2);
15389 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
15390 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15391 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15393 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15394 check_texture_float(texture, 2.0f, 2);
15396 input.x = 4.0f;
15397 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15398 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15399 check_texture_float(texture, 4.0f, 2);
15401 ID3D11ComputeShader_Release(cs);
15403 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
15404 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15405 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15407 input.x = 1.0f;
15408 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15409 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
15410 check_texture_float(texture, 1.0f, 2);
15412 input.x = 0.5f;
15413 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15414 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
15415 SetRect(&rect, 0, 0, 16, 32);
15416 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
15417 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
15418 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
15419 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
15420 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
15422 ID3D11ComputeShader_Release(cs);
15424 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
15425 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15426 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15428 input.x = 0.6f;
15429 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15430 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
15431 SetRect(&rect, 0, 0, 60, 60);
15432 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
15433 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
15434 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
15435 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
15436 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
15438 input.x = 0.7f;
15439 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15440 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
15441 check_texture_float(texture, 0.7f, 2);
15443 ID3D11ComputeShader_Release(cs);
15445 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
15446 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15447 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15449 input.x = 0.3f;
15450 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15451 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15452 check_texture_float(texture, 0.3f, 2);
15454 input.x = 0.1f;
15455 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
15456 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
15457 check_texture_float(texture, 0.1f, 2);
15459 ID3D11ComputeShader_Release(cs);
15461 ID3D11Buffer_Release(cb);
15462 ID3D11Texture2D_Release(texture);
15463 ID3D11UnorderedAccessView_Release(uav);
15464 ID3D11DeviceContext_Release(context);
15465 refcount = ID3D11Device_Release(device);
15466 ok(!refcount, "Device has %u references left.\n", refcount);
15469 static void test_ps_cs_uav_binding(void)
15471 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15472 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
15473 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
15474 ID3D11Texture2D *cs_texture, *ps_texture;
15475 struct d3d11_test_context test_context;
15476 static const float zero[4] = {0.0f};
15477 D3D11_TEXTURE2D_DESC texture_desc;
15478 ID3D11DeviceContext *context;
15479 ID3D11Buffer *cs_cb, *ps_cb;
15480 struct vec4 input = {1.0f};
15481 ID3D11ComputeShader *cs;
15482 ID3D11PixelShader *ps;
15483 ID3D11Device *device;
15484 HRESULT hr;
15486 static const DWORD cs_code[] =
15488 #if 0
15489 RWTexture2D<float> u;
15491 float value;
15493 [numthreads(1, 1, 1)]
15494 void main()
15496 uint x, y, width, height;
15497 u.GetDimensions(width, height);
15498 for (y = 0; y < height; ++y)
15500 for (x = 0; x < width; ++x)
15501 u[uint2(x, y)] = value;
15504 #endif
15505 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
15506 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15507 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
15508 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
15509 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
15510 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
15511 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
15512 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
15513 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
15514 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
15515 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
15516 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
15517 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
15518 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
15519 0x01000016, 0x0100003e,
15521 static const DWORD ps_code[] =
15523 #if 0
15524 RWTexture2D<float> u : register(u1);
15526 float value;
15528 void main()
15530 uint x, y, width, height;
15531 u.GetDimensions(width, height);
15532 for (y = 0; y < height; ++y)
15534 for (x = 0; x < width; ++x)
15535 u[uint2(x, y)] = value;
15538 #endif
15539 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
15540 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15541 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
15542 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
15543 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
15544 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
15545 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
15546 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
15547 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
15548 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
15549 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
15550 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
15551 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
15552 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
15555 if (!init_test_context(&test_context, &feature_level))
15556 return;
15558 device = test_context.device;
15559 context = test_context.immediate_context;
15561 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
15562 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
15564 texture_desc.Width = 64;
15565 texture_desc.Height = 64;
15566 texture_desc.MipLevels = 1;
15567 texture_desc.ArraySize = 1;
15568 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
15569 texture_desc.SampleDesc.Count = 1;
15570 texture_desc.SampleDesc.Quality = 0;
15571 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15572 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15573 texture_desc.CPUAccessFlags = 0;
15574 texture_desc.MiscFlags = 0;
15575 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
15576 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15577 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
15578 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15580 uav_desc.Format = texture_desc.Format;
15581 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
15582 U(uav_desc).Texture2D.MipSlice = 0;
15583 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
15584 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15585 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
15586 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15588 ID3D11Device_GetImmediateContext(device, &context);
15590 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
15591 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
15592 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
15593 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
15594 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
15595 1, &test_context.backbuffer_rtv, NULL, 1, 1, &ps_uav, NULL);
15597 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
15598 check_texture_float(cs_texture, 0.0f, 2);
15599 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
15600 check_texture_float(ps_texture, 0.0f, 2);
15602 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
15603 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15604 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15605 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15606 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15607 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15609 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15610 check_texture_float(cs_texture, 1.0f, 2);
15611 check_texture_float(ps_texture, 0.0f, 2);
15612 draw_quad(&test_context);
15613 check_texture_float(cs_texture, 1.0f, 2);
15614 check_texture_float(ps_texture, 1.0f, 2);
15616 input.x = 0.5f;
15617 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
15618 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15619 check_texture_float(cs_texture, 0.5f, 2);
15620 check_texture_float(ps_texture, 1.0f, 2);
15621 input.x = 2.0f;
15622 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
15623 draw_quad(&test_context);
15624 check_texture_float(cs_texture, 0.5f, 2);
15625 check_texture_float(ps_texture, 2.0f, 2);
15627 input.x = 8.0f;
15628 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
15629 input.x = 4.0f;
15630 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
15631 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15632 check_texture_float(cs_texture, 8.0f, 2);
15633 check_texture_float(ps_texture, 2.0f, 2);
15634 draw_quad(&test_context);
15635 check_texture_float(cs_texture, 8.0f, 2);
15636 check_texture_float(ps_texture, 4.0f, 2);
15638 ID3D11ComputeShader_Release(cs);
15639 ID3D11PixelShader_Release(ps);
15640 ID3D11Buffer_Release(cs_cb);
15641 ID3D11Buffer_Release(ps_cb);
15642 ID3D11Texture2D_Release(cs_texture);
15643 ID3D11Texture2D_Release(ps_texture);
15644 ID3D11UnorderedAccessView_Release(cs_uav);
15645 ID3D11UnorderedAccessView_Release(ps_uav);
15646 ID3D11DeviceContext_Release(context);
15647 release_test_context(&test_context);
15650 static void test_atomic_instructions(void)
15652 ID3D11UnorderedAccessView *in_uav, *out_uav;
15653 ID3D11Buffer *cb, *in_buffer, *out_buffer;
15654 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
15655 struct d3d11_test_context test_context;
15656 struct resource_readback rb, out_rb;
15657 D3D11_TEXTURE2D_DESC texture_desc;
15658 D3D11_BUFFER_DESC buffer_desc;
15659 ID3D11DeviceContext *context;
15660 ID3D11RenderTargetView *rtv;
15661 ID3D11Texture2D *texture;
15662 ID3D11ComputeShader *cs;
15663 ID3D11PixelShader *ps;
15664 ID3D11Device *device;
15665 D3D11_VIEWPORT vp;
15666 unsigned int i, j;
15667 HRESULT hr;
15669 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15670 static const unsigned int zero[4] = {0, 0, 0, 0};
15671 static const DWORD ps_atomics_code[] =
15673 #if 0
15674 RWByteAddressBuffer u;
15676 uint4 v;
15677 int4 i;
15679 void main()
15681 u.InterlockedAnd(0 * 4, v.x);
15682 u.InterlockedCompareStore(1 * 4, v.y, v.x);
15683 u.InterlockedAdd(2 * 4, v.x);
15684 u.InterlockedOr(3 * 4, v.x);
15685 u.InterlockedMax(4 * 4, i.x);
15686 u.InterlockedMin(5 * 4, i.x);
15687 u.InterlockedMax(6 * 4, v.x);
15688 u.InterlockedMin(7 * 4, v.x);
15689 u.InterlockedXor(8 * 4, v.x);
15691 #endif
15692 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
15693 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15694 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
15695 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
15696 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
15697 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
15698 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
15699 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
15700 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
15701 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
15702 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
15703 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
15704 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
15705 0x00000000, 0x00000000, 0x0100003e,
15707 static const DWORD cs_atomics_code[] =
15709 #if 0
15710 RWByteAddressBuffer u;
15711 RWByteAddressBuffer u2;
15713 uint4 v;
15714 int4 i;
15716 [numthreads(1, 1, 1)]
15717 void main()
15719 uint r;
15720 u.InterlockedAnd(0 * 4, v.x, r);
15721 u2.Store(0 * 4, r);
15722 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
15723 u2.Store(1 * 4, r);
15724 u.InterlockedAdd(2 * 4, v.x, r);
15725 u2.Store(2 * 4, r);
15726 u.InterlockedOr(3 * 4, v.x, r);
15727 u2.Store(3 * 4, r);
15728 u.InterlockedMax(4 * 4, i.x, r);
15729 u2.Store(4 * 4, r);
15730 u.InterlockedMin(5 * 4, i.x, r);
15731 u2.Store(5 * 4, r);
15732 u.InterlockedMax(6 * 4, v.x, r);
15733 u2.Store(6 * 4, r);
15734 u.InterlockedMin(7 * 4, v.x, r);
15735 u2.Store(7 * 4, r);
15736 u.InterlockedXor(8 * 4, v.x, r);
15737 u2.Store(8 * 4, r);
15739 #endif
15740 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
15741 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15742 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
15743 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
15744 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
15745 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
15746 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
15747 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
15748 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
15749 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
15750 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
15751 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
15752 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
15753 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
15754 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
15755 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
15756 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
15757 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
15758 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
15759 0x0010000a, 0x00000000, 0x0100003e,
15762 static const char * const instructions[] =
15764 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
15765 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
15767 static const char * const imm_instructions[] =
15769 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
15770 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
15772 static const struct test
15774 struct uvec4 v;
15775 struct ivec4 i;
15776 unsigned int input[ARRAY_SIZE(instructions)];
15777 unsigned int expected_result[ARRAY_SIZE(instructions)];
15779 tests[] =
15781 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
15782 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
15785 if (!init_test_context(&test_context, &feature_level))
15786 return;
15788 device = test_context.device;
15789 context = test_context.immediate_context;
15791 texture_desc.Width = 1;
15792 texture_desc.Height = 1;
15793 texture_desc.MipLevels = 1;
15794 texture_desc.ArraySize = 1;
15795 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
15796 texture_desc.SampleDesc.Count = 1;
15797 texture_desc.SampleDesc.Quality = 0;
15798 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15799 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15800 texture_desc.CPUAccessFlags = 0;
15801 texture_desc.MiscFlags = 0;
15802 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15803 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15804 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15805 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15807 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
15808 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
15809 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
15811 buffer_desc.ByteWidth = sizeof(tests->input);
15812 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
15813 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15814 buffer_desc.CPUAccessFlags = 0;
15815 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
15816 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
15817 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
15818 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
15819 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
15821 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
15822 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
15823 U(uav_desc).Buffer.FirstElement = 0;
15824 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
15825 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
15826 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
15827 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15828 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
15829 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15831 vp.TopLeftX = 0.0f;
15832 vp.TopLeftY = 0.0f;
15833 vp.Width = texture_desc.Width;
15834 vp.Height = texture_desc.Height;
15835 vp.MinDepth = 0.0f;
15836 vp.MaxDepth = 1.0f;
15837 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
15839 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
15840 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15841 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15843 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
15844 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15845 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15847 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15849 const struct test *test = &tests[i];
15851 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15852 NULL, &test->v, 0, 0);
15854 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
15855 NULL, test->input, 0, 0);
15857 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
15858 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
15859 0, 1, &in_uav, NULL);
15861 draw_quad(&test_context);
15862 get_buffer_readback(in_buffer, &rb);
15863 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
15865 unsigned int value = get_readback_color(&rb, j, 0);
15866 unsigned int expected = test->expected_result[j];
15868 todo_wine_if(expected != test->input[j]
15869 && (!strcmp(instructions[j], "atomic_imax")
15870 || !strcmp(instructions[j], "atomic_imin")))
15871 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
15872 "with inputs (%u, %u), (%d), %#x (%d).\n",
15873 i, value, value, expected, expected, instructions[j],
15874 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
15876 release_resource_readback(&rb);
15878 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
15879 NULL, test->input, 0, 0);
15880 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
15882 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
15883 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
15885 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15886 get_buffer_readback(in_buffer, &rb);
15887 get_buffer_readback(out_buffer, &out_rb);
15888 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
15890 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
15891 || !strcmp(imm_instructions[j], "imm_atomic_imin");
15892 unsigned int out_value = get_readback_color(&out_rb, j, 0);
15893 unsigned int value = get_readback_color(&rb, j, 0);
15894 unsigned int expected = test->expected_result[j];
15896 todo_wine_if(expected != test->input[j] && todo_instruction)
15897 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
15898 "with inputs (%u, %u), (%d), %#x (%d).\n",
15899 i, value, value, expected, expected, imm_instructions[j],
15900 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
15902 todo_wine_if(todo_instruction && out_value != test->input[j])
15903 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
15904 out_value, test->input[j], imm_instructions[j]);
15906 release_resource_readback(&out_rb);
15907 release_resource_readback(&rb);
15910 ID3D11Buffer_Release(cb);
15911 ID3D11Buffer_Release(in_buffer);
15912 ID3D11Buffer_Release(out_buffer);
15913 ID3D11ComputeShader_Release(cs);
15914 ID3D11PixelShader_Release(ps);
15915 ID3D11RenderTargetView_Release(rtv);
15916 ID3D11Texture2D_Release(texture);
15917 ID3D11UnorderedAccessView_Release(in_uav);
15918 ID3D11UnorderedAccessView_Release(out_uav);
15919 release_test_context(&test_context);
15922 static void test_sm4_ret_instruction(void)
15924 struct d3d11_test_context test_context;
15925 ID3D11DeviceContext *context;
15926 ID3D11PixelShader *ps;
15927 struct uvec4 constant;
15928 ID3D11Device *device;
15929 ID3D11Buffer *cb;
15930 HRESULT hr;
15932 static const DWORD ps_code[] =
15934 #if 0
15935 uint c;
15937 float4 main() : SV_TARGET
15939 if (c == 1)
15940 return float4(1, 0, 0, 1);
15941 if (c == 2)
15942 return float4(0, 1, 0, 1);
15943 if (c == 3)
15944 return float4(0, 0, 1, 1);
15945 return float4(1, 1, 1, 1);
15947 #endif
15948 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
15949 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15950 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15951 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
15952 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
15953 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
15954 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
15955 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
15956 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
15957 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
15958 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
15959 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
15960 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
15961 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
15962 0x0100003e,
15965 if (!init_test_context(&test_context, NULL))
15966 return;
15968 device = test_context.device;
15969 context = test_context.immediate_context;
15971 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15972 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
15973 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15974 memset(&constant, 0, sizeof(constant));
15975 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
15976 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
15978 draw_quad(&test_context);
15979 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
15981 constant.x = 1;
15982 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
15983 draw_quad(&test_context);
15984 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15986 constant.x = 2;
15987 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
15988 draw_quad(&test_context);
15989 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15991 constant.x = 3;
15992 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
15993 draw_quad(&test_context);
15994 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
15996 constant.x = 4;
15997 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
15998 draw_quad(&test_context);
15999 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
16001 ID3D11Buffer_Release(cb);
16002 ID3D11PixelShader_Release(ps);
16003 release_test_context(&test_context);
16006 static void test_primitive_restart(void)
16008 struct d3d11_test_context test_context;
16009 ID3D11Buffer *ib32, *ib16, *vb;
16010 ID3D11DeviceContext *context;
16011 unsigned int stride, offset;
16012 ID3D11InputLayout *layout;
16013 ID3D11VertexShader *vs;
16014 ID3D11PixelShader *ps;
16015 ID3D11Device *device;
16016 unsigned int i;
16017 HRESULT hr;
16018 RECT rect;
16020 static const DWORD ps_code[] =
16022 #if 0
16023 struct vs_out
16025 float4 position : SV_Position;
16026 float4 color : color;
16029 float4 main(vs_out input) : SV_TARGET
16031 return input.color;
16033 #endif
16034 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
16035 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16036 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
16037 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
16038 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16039 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
16040 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
16041 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
16043 static const DWORD vs_code[] =
16045 #if 0
16046 struct vs_out
16048 float4 position : SV_Position;
16049 float4 color : color;
16052 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
16054 output.position = position;
16055 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
16057 #endif
16058 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
16059 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
16060 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
16061 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
16062 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
16063 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
16064 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
16065 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
16066 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
16067 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
16068 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
16069 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
16070 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
16072 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
16074 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
16076 static const struct vec2 vertices[] =
16078 {-1.00f, -1.0f},
16079 {-1.00f, 1.0f},
16080 {-0.25f, -1.0f},
16081 {-0.25f, 1.0f},
16082 { 0.25f, -1.0f},
16083 { 0.25f, 1.0f},
16084 { 1.00f, -1.0f},
16085 { 1.00f, 1.0f},
16087 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
16088 static const unsigned short indices16[] =
16090 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
16092 static const unsigned int indices32[] =
16094 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
16097 if (!init_test_context(&test_context, NULL))
16098 return;
16100 device = test_context.device;
16101 context = test_context.immediate_context;
16103 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
16104 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
16105 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16106 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
16108 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
16109 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
16111 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
16112 vs_code, sizeof(vs_code), &layout);
16113 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
16115 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
16117 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
16118 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16120 ID3D11DeviceContext_IASetInputLayout(context, layout);
16121 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
16122 stride = sizeof(*vertices);
16123 offset = 0;
16124 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
16126 for (i = 0; i < 2; ++i)
16128 if (!i)
16129 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
16130 else
16131 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
16133 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
16134 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
16135 SetRect(&rect, 0, 0, 240, 480);
16136 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
16137 SetRect(&rect, 240, 0, 400, 480);
16138 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
16139 SetRect(&rect, 400, 0, 640, 480);
16140 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
16143 ID3D11Buffer_Release(ib16);
16144 ID3D11Buffer_Release(ib32);
16145 ID3D11Buffer_Release(vb);
16146 ID3D11InputLayout_Release(layout);
16147 ID3D11PixelShader_Release(ps);
16148 ID3D11VertexShader_Release(vs);
16149 release_test_context(&test_context);
16152 static void test_resinfo_instruction(void)
16154 struct shader
16156 const DWORD *code;
16157 size_t size;
16160 struct d3d11_test_context test_context;
16161 D3D11_TEXTURE3D_DESC texture3d_desc;
16162 D3D11_TEXTURE2D_DESC texture_desc;
16163 const struct shader *current_ps;
16164 D3D_FEATURE_LEVEL feature_level;
16165 ID3D11ShaderResourceView *srv;
16166 ID3D11DeviceContext *context;
16167 ID3D11Texture2D *rtv_texture;
16168 ID3D11RenderTargetView *rtv;
16169 ID3D11Resource *texture;
16170 struct uvec4 constant;
16171 ID3D11PixelShader *ps;
16172 ID3D11Device *device;
16173 unsigned int i, type;
16174 ID3D11Buffer *cb;
16175 HRESULT hr;
16177 static const DWORD ps_2d_code[] =
16179 #if 0
16180 Texture2D t;
16182 uint type;
16183 uint level;
16185 float4 main() : SV_TARGET
16187 if (!type)
16189 float width, height, miplevels;
16190 t.GetDimensions(level, width, height, miplevels);
16191 return float4(width, height, miplevels, 0);
16193 else
16195 uint width, height, miplevels;
16196 t.GetDimensions(level, width, height, miplevels);
16197 return float4(width, height, miplevels, 0);
16200 #endif
16201 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
16202 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16203 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16204 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
16205 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
16206 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
16207 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
16208 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
16209 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
16210 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
16211 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
16212 0x01000015, 0x0100003e,
16214 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
16215 static const DWORD ps_2d_array_code[] =
16217 #if 0
16218 Texture2DArray t;
16220 uint type;
16221 uint level;
16223 float4 main() : SV_TARGET
16225 if (!type)
16227 float width, height, elements, miplevels;
16228 t.GetDimensions(level, width, height, elements, miplevels);
16229 return float4(width, height, elements, miplevels);
16231 else
16233 uint width, height, elements, miplevels;
16234 t.GetDimensions(level, width, height, elements, miplevels);
16235 return float4(width, height, elements, miplevels);
16238 #endif
16239 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
16240 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16241 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16242 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
16243 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
16244 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
16245 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
16246 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
16247 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
16248 0x0100003e, 0x01000015, 0x0100003e,
16250 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
16251 static const DWORD ps_3d_code[] =
16253 #if 0
16254 Texture3D t;
16256 uint type;
16257 uint level;
16259 float4 main() : SV_TARGET
16261 if (!type)
16263 float width, height, depth, miplevels;
16264 t.GetDimensions(level, width, height, depth, miplevels);
16265 return float4(width, height, depth, miplevels);
16267 else
16269 uint width, height, depth, miplevels;
16270 t.GetDimensions(level, width, height, depth, miplevels);
16271 return float4(width, height, depth, miplevels);
16274 #endif
16275 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
16276 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16277 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16278 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
16279 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
16280 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
16281 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
16282 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
16283 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
16284 0x0100003e, 0x01000015, 0x0100003e,
16286 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
16287 static const DWORD ps_cube_code[] =
16289 #if 0
16290 TextureCube t;
16292 uint type;
16293 uint level;
16295 float4 main() : SV_TARGET
16297 if (!type)
16299 float width, height, miplevels;
16300 t.GetDimensions(level, width, height, miplevels);
16301 return float4(width, height, miplevels, 0);
16303 else
16305 uint width, height, miplevels;
16306 t.GetDimensions(level, width, height, miplevels);
16307 return float4(width, height, miplevels, 0);
16310 #endif
16311 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
16312 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16313 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16314 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
16315 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
16316 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
16317 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
16318 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
16319 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
16320 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
16321 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
16322 0x01000015, 0x0100003e,
16324 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
16325 static const DWORD ps_cube_array_code[] =
16327 #if 0
16328 TextureCubeArray t;
16330 uint type;
16331 uint level;
16333 float4 main() : SV_TARGET
16335 if (!type)
16337 float width, height, elements, miplevels;
16338 t.GetDimensions(level, width, height, elements, miplevels);
16339 return float4(width, height, miplevels, 0);
16341 else
16343 uint width, height, elements, miplevels;
16344 t.GetDimensions(level, width, height, elements, miplevels);
16345 return float4(width, height, miplevels, 0);
16348 #endif
16349 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
16350 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16351 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16352 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
16353 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
16354 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
16355 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
16356 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
16357 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
16358 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
16359 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
16360 0x0100003e, 0x01000015, 0x0100003e,
16362 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
16363 static const struct ps_test
16365 const struct shader *ps;
16366 struct
16368 unsigned int width;
16369 unsigned int height;
16370 unsigned int depth;
16371 unsigned int miplevel_count;
16372 unsigned int array_size;
16373 unsigned int cube_count;
16374 } texture_desc;
16375 unsigned int miplevel;
16376 struct vec4 expected_result;
16378 ps_tests[] =
16380 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
16381 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
16382 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
16383 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
16385 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
16386 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
16387 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
16388 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
16390 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
16391 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
16392 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
16393 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
16394 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
16395 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
16396 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
16397 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
16398 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
16400 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
16401 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
16402 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
16403 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
16404 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
16406 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
16407 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
16408 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
16411 if (!init_test_context(&test_context, NULL))
16412 return;
16414 device = test_context.device;
16415 context = test_context.immediate_context;
16416 feature_level = ID3D11Device_GetFeatureLevel(device);
16418 texture_desc.Width = 64;
16419 texture_desc.Height = 64;
16420 texture_desc.MipLevels = 1;
16421 texture_desc.ArraySize = 1;
16422 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
16423 texture_desc.SampleDesc.Count = 1;
16424 texture_desc.SampleDesc.Quality = 0;
16425 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16426 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16427 texture_desc.CPUAccessFlags = 0;
16428 texture_desc.MiscFlags = 0;
16429 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
16430 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16431 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
16432 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16434 memset(&constant, 0, sizeof(constant));
16435 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
16437 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
16438 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16440 ps = NULL;
16441 current_ps = NULL;
16442 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
16444 const struct ps_test *test = &ps_tests[i];
16446 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
16448 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
16449 continue;
16452 if (current_ps != test->ps)
16454 if (ps)
16455 ID3D11PixelShader_Release(ps);
16457 current_ps = test->ps;
16459 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
16460 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
16461 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16464 if (test->texture_desc.depth != 1)
16466 texture3d_desc.Width = test->texture_desc.width;
16467 texture3d_desc.Height = test->texture_desc.height;
16468 texture3d_desc.Depth = test->texture_desc.depth;
16469 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
16470 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
16471 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
16472 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
16473 texture3d_desc.CPUAccessFlags = 0;
16474 texture3d_desc.MiscFlags = 0;
16475 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
16476 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
16478 else
16480 texture_desc.Width = test->texture_desc.width;
16481 texture_desc.Height = test->texture_desc.height;
16482 texture_desc.MipLevels = test->texture_desc.miplevel_count;
16483 texture_desc.ArraySize = test->texture_desc.array_size;
16484 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
16485 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
16486 texture_desc.MiscFlags = 0;
16487 if (test->texture_desc.cube_count)
16488 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
16489 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
16490 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
16493 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
16494 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
16495 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
16497 for (type = 0; type < 2; ++type)
16499 constant.x = type;
16500 constant.y = test->miplevel;
16501 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
16503 draw_quad(&test_context);
16504 check_texture_vec4(rtv_texture, &test->expected_result, 0);
16507 ID3D11Resource_Release(texture);
16508 ID3D11ShaderResourceView_Release(srv);
16510 ID3D11PixelShader_Release(ps);
16512 ID3D11Buffer_Release(cb);
16513 ID3D11RenderTargetView_Release(rtv);
16514 ID3D11Texture2D_Release(rtv_texture);
16515 release_test_context(&test_context);
16518 static void test_sm5_bufinfo_instruction(void)
16520 struct shader
16522 const DWORD *code;
16523 size_t size;
16526 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16527 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
16528 struct d3d11_test_context test_context;
16529 D3D11_TEXTURE2D_DESC texture_desc;
16530 const struct shader *current_ps;
16531 ID3D11UnorderedAccessView *uav;
16532 ID3D11ShaderResourceView *srv;
16533 D3D11_BUFFER_DESC buffer_desc;
16534 ID3D11DeviceContext *context;
16535 ID3D11RenderTargetView *rtv;
16536 ID3D11Texture2D *texture;
16537 ID3D11PixelShader *ps;
16538 ID3D11Buffer *buffer;
16539 ID3D11Device *device;
16540 unsigned int i;
16541 HRESULT hr;
16543 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16544 static const DWORD ps_uav_structured_code[] =
16546 #if 0
16547 struct s
16549 uint4 u;
16550 bool b;
16553 RWStructuredBuffer<s> b;
16555 uint4 main(void) : SV_Target
16557 uint count, stride;
16558 b.GetDimensions(count, stride);
16559 return uint4(count, stride, 0, 1);
16561 #endif
16562 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
16563 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16564 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16565 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
16566 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
16567 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
16568 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
16569 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
16571 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
16572 static const DWORD ps_uav_structured32_code[] =
16574 #if 0
16575 struct s
16577 uint4 u;
16578 bool4 b;
16581 RWStructuredBuffer<s> b;
16583 uint4 main(void) : SV_Target
16585 uint count, stride;
16586 b.GetDimensions(count, stride);
16587 return uint4(count, stride, 0, 1);
16589 #endif
16590 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
16591 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16592 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16593 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
16594 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
16595 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
16596 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
16597 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
16599 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
16600 static const DWORD ps_srv_structured_code[] =
16602 #if 0
16603 StructuredBuffer<bool> b;
16605 uint4 main(void) : SV_Target
16607 uint count, stride;
16608 b.GetDimensions(count, stride);
16609 return uint4(count, stride, 0, 1);
16611 #endif
16612 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
16613 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16614 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16615 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
16616 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
16617 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
16618 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
16619 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
16621 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
16622 static const DWORD ps_uav_raw_code[] =
16624 #if 0
16625 RWByteAddressBuffer b;
16627 uint4 main(void) : SV_Target
16629 uint width;
16630 b.GetDimensions(width);
16631 return width;
16633 #endif
16634 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
16635 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16636 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16637 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
16638 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
16639 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
16640 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
16642 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
16643 static const DWORD ps_srv_raw_code[] =
16645 #if 0
16646 ByteAddressBuffer b;
16648 uint4 main(void) : SV_Target
16650 uint width;
16651 b.GetDimensions(width);
16652 return width;
16654 #endif
16655 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
16656 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16657 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16658 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
16659 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
16660 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
16661 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
16663 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
16664 static const DWORD ps_uav_typed_code[] =
16666 #if 0
16667 RWBuffer<float> b;
16669 uint4 main(void) : SV_Target
16671 uint width;
16672 b.GetDimensions(width);
16673 return width;
16675 #endif
16676 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
16677 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16678 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16679 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
16680 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
16681 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
16682 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
16684 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
16685 static const DWORD ps_srv_typed_code[] =
16687 #if 0
16688 Buffer<float> b;
16690 uint4 main(void) : SV_Target
16692 uint width;
16693 b.GetDimensions(width);
16694 return width;
16696 #endif
16697 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
16698 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16699 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
16700 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
16701 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
16702 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
16703 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
16705 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
16706 static const struct test
16708 const struct shader *ps;
16709 BOOL uav;
16710 unsigned int buffer_size;
16711 unsigned int buffer_misc_flags;
16712 unsigned int buffer_structure_byte_stride;
16713 DXGI_FORMAT view_format;
16714 unsigned int view_element_idx;
16715 unsigned int view_element_count;
16716 struct uvec4 expected_result;
16718 tests[] =
16720 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
16721 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
16722 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
16723 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
16724 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
16725 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
16726 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
16727 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
16728 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
16729 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
16730 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
16731 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
16732 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
16733 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
16734 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
16735 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
16736 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
16737 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
16738 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
16739 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
16740 #undef RAW
16741 #undef STRUCTURED
16744 if (!init_test_context(&test_context, &feature_level))
16745 return;
16747 device = test_context.device;
16748 context = test_context.immediate_context;
16750 texture_desc.Width = 64;
16751 texture_desc.Height = 64;
16752 texture_desc.MipLevels = 1;
16753 texture_desc.ArraySize = 1;
16754 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
16755 texture_desc.SampleDesc.Count = 1;
16756 texture_desc.SampleDesc.Quality = 0;
16757 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16758 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16759 texture_desc.CPUAccessFlags = 0;
16760 texture_desc.MiscFlags = 0;
16761 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16762 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16763 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
16764 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16766 ps = NULL;
16767 current_ps = NULL;
16768 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16770 const struct test *test = &tests[i];
16772 if (current_ps != test->ps)
16774 if (ps)
16775 ID3D11PixelShader_Release(ps);
16777 current_ps = test->ps;
16779 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
16780 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
16781 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16784 buffer_desc.ByteWidth = test->buffer_size;
16785 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
16786 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
16787 buffer_desc.CPUAccessFlags = 0;
16788 buffer_desc.MiscFlags = test->buffer_misc_flags;
16789 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
16790 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16791 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
16793 if (test->uav)
16795 uav_desc.Format = test->view_format;
16796 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16797 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
16798 U(uav_desc).Buffer.NumElements = test->view_element_count;
16799 U(uav_desc).Buffer.Flags = 0;
16800 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
16801 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
16802 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16803 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
16804 srv = NULL;
16806 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
16807 1, 1, &uav, NULL);
16809 else
16811 srv_desc.Format = test->view_format;
16812 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
16813 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
16814 U(srv_desc).BufferEx.NumElements = test->view_element_count;
16815 U(srv_desc).BufferEx.Flags = 0;
16816 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
16817 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
16818 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
16819 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
16820 uav = NULL;
16822 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
16823 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
16826 draw_quad(&test_context);
16827 check_texture_uvec4(texture, &test->expected_result);
16829 if (srv)
16830 ID3D11ShaderResourceView_Release(srv);
16831 if (uav)
16832 ID3D11UnorderedAccessView_Release(uav);
16833 ID3D11Buffer_Release(buffer);
16835 ID3D11PixelShader_Release(ps);
16837 ID3D11RenderTargetView_Release(rtv);
16838 ID3D11Texture2D_Release(texture);
16839 release_test_context(&test_context);
16842 static void test_render_target_device_mismatch(void)
16844 struct d3d11_test_context test_context;
16845 struct device_desc device_desc = {0};
16846 ID3D11DeviceContext *context;
16847 ID3D11RenderTargetView *rtv;
16848 ID3D11Device *device;
16849 ULONG refcount;
16851 if (!init_test_context(&test_context, NULL))
16852 return;
16854 device = create_device(&device_desc);
16855 ok(!!device, "Failed to create device.\n");
16857 ID3D11Device_GetImmediateContext(device, &context);
16859 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
16860 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
16861 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
16862 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
16863 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
16864 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
16865 ID3D11RenderTargetView_Release(rtv);
16867 rtv = NULL;
16868 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
16870 ID3D11DeviceContext_Release(context);
16871 refcount = ID3D11Device_Release(device);
16872 ok(!refcount, "Device has %u references left.\n", refcount);
16873 release_test_context(&test_context);
16876 static void test_buffer_srv(void)
16878 struct shader
16880 const DWORD *code;
16881 size_t size;
16882 BOOL requires_raw_and_structured_buffers;
16884 struct buffer
16886 unsigned int byte_count;
16887 unsigned int data_offset;
16888 const void *data;
16889 unsigned int structure_byte_stride;
16892 BOOL raw_and_structured_buffers_supported;
16893 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
16894 struct d3d11_test_context test_context;
16895 D3D11_SUBRESOURCE_DATA resource_data;
16896 const struct buffer *current_buffer;
16897 const struct shader *current_shader;
16898 ID3D11ShaderResourceView *srv;
16899 D3D11_BUFFER_DESC buffer_desc;
16900 ID3D11DeviceContext *context;
16901 DWORD color, expected_color;
16902 struct resource_readback rb;
16903 ID3D11Buffer *cb, *buffer;
16904 ID3D11PixelShader *ps;
16905 ID3D11Device *device;
16906 unsigned int i, x, y;
16907 struct vec4 cb_size;
16908 HRESULT hr;
16910 static const DWORD ps_float4_code[] =
16912 #if 0
16913 Buffer<float4> b;
16915 float2 size;
16917 float4 main(float4 position : SV_POSITION) : SV_Target
16919 float2 p;
16920 int2 coords;
16921 p.x = position.x / 640.0f;
16922 p.y = position.y / 480.0f;
16923 coords = int2(p.x * size.x, p.y * size.y);
16924 return b.Load(coords.y * size.x + coords.x);
16926 #endif
16927 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
16928 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16929 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
16930 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16931 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
16932 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
16933 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16934 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
16935 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
16936 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
16937 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
16938 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
16939 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
16941 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
16942 static const DWORD ps_structured_code[] =
16944 #if 0
16945 StructuredBuffer<float4> b;
16947 float2 size;
16949 float4 main(float4 position : SV_POSITION) : SV_Target
16951 float2 p;
16952 int2 coords;
16953 p.x = position.x / 640.0f;
16954 p.y = position.y / 480.0f;
16955 coords = int2(p.x * size.x, p.y * size.y);
16956 return b[coords.y * size.x + coords.x];
16958 #endif
16959 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
16960 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
16961 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
16962 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
16963 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
16964 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
16965 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
16966 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
16967 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
16968 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
16969 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
16970 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
16971 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
16972 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
16974 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
16975 static const DWORD rgba16[] =
16977 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
16978 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
16979 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
16980 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
16982 static const DWORD rgba4[] =
16984 0xffffffff, 0xff0000ff,
16985 0xff000000, 0xff00ff00,
16987 static const BYTE r4[] =
16989 0xde, 0xad,
16990 0xba, 0xbe,
16992 static const struct vec4 rgba_float[] =
16994 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
16995 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
16997 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
16998 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
16999 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
17000 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
17001 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
17002 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
17003 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
17004 &rgba_float, sizeof(*rgba_float)};
17005 static const DWORD rgba16_colors2x2[] =
17007 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
17008 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
17009 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
17010 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
17012 static const DWORD rgba16_colors1x1[] =
17014 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
17015 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
17016 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
17017 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
17019 static const DWORD rgba4_colors[] =
17021 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
17022 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
17023 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
17024 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
17026 static const DWORD r4_colors[] =
17028 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
17029 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
17030 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
17031 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
17033 static const DWORD zero_colors[16] = {0};
17034 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
17036 static const struct test
17038 const struct shader *shader;
17039 const struct buffer *buffer;
17040 DXGI_FORMAT srv_format;
17041 unsigned int srv_first_element;
17042 unsigned int srv_element_count;
17043 struct vec2 size;
17044 const DWORD *expected_colors;
17046 tests[] =
17048 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
17049 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
17050 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
17051 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
17052 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
17053 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
17054 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
17055 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
17056 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
17057 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
17058 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
17061 if (!init_test_context(&test_context, NULL))
17062 return;
17064 device = test_context.device;
17065 context = test_context.immediate_context;
17066 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
17067 || check_compute_shaders_via_sm4_support(device);
17069 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
17070 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17072 ps = NULL;
17073 srv = NULL;
17074 buffer = NULL;
17075 current_shader = NULL;
17076 current_buffer = NULL;
17077 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17079 const struct test *test = &tests[i];
17081 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
17083 skip("Test %u: Raw and structured buffers are not supported.\n", i);
17084 continue;
17086 /* Structured buffer views with an offset don't seem to work on WARP. */
17087 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
17088 && is_warp_device(device))
17090 skip("Test %u: Broken WARP.\n", i);
17091 continue;
17094 if (current_shader != test->shader)
17096 if (ps)
17097 ID3D11PixelShader_Release(ps);
17099 current_shader = test->shader;
17101 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
17102 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
17103 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17106 if (current_buffer != test->buffer)
17108 if (buffer)
17109 ID3D11Buffer_Release(buffer);
17111 current_buffer = test->buffer;
17112 if (current_buffer)
17114 BYTE *data = NULL;
17116 buffer_desc.ByteWidth = current_buffer->byte_count;
17117 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17118 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
17119 buffer_desc.CPUAccessFlags = 0;
17120 buffer_desc.MiscFlags = 0;
17121 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
17122 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
17123 resource_data.SysMemPitch = 0;
17124 resource_data.SysMemSlicePitch = 0;
17125 if (current_buffer->data_offset)
17127 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, current_buffer->byte_count);
17128 ok(!!data, "Failed to allocate memory.\n");
17129 memcpy(data + current_buffer->data_offset, current_buffer->data,
17130 current_buffer->byte_count - current_buffer->data_offset);
17131 resource_data.pSysMem = data;
17133 else
17135 resource_data.pSysMem = current_buffer->data;
17137 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
17138 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
17139 HeapFree(GetProcessHeap(), 0, data);
17141 else
17143 buffer = NULL;
17147 if (srv)
17148 ID3D11ShaderResourceView_Release(srv);
17149 if (current_buffer)
17151 srv_desc.Format = test->srv_format;
17152 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
17153 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
17154 U(srv_desc).Buffer.NumElements = test->srv_element_count;
17155 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
17156 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
17158 else
17160 srv = NULL;
17162 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
17164 cb_size.x = test->size.x;
17165 cb_size.y = test->size.y;
17166 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
17168 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
17169 draw_quad(&test_context);
17171 get_texture_readback(test_context.backbuffer, 0, &rb);
17172 for (y = 0; y < 4; ++y)
17174 for (x = 0; x < 4; ++x)
17176 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
17177 expected_color = test->expected_colors[y * 4 + x];
17178 ok(compare_color(color, expected_color, 1),
17179 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
17180 i, color, expected_color, x, y);
17183 release_resource_readback(&rb);
17185 if (srv)
17186 ID3D11ShaderResourceView_Release(srv);
17187 if (buffer)
17188 ID3D11Buffer_Release(buffer);
17190 ID3D11Buffer_Release(cb);
17191 ID3D11PixelShader_Release(ps);
17192 release_test_context(&test_context);
17195 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
17197 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
17198 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
17199 struct d3d11_test_context test_context;
17200 D3D11_SUBRESOURCE_DATA resource_data;
17201 D3D11_TEXTURE2D_DESC texture_desc;
17202 ID3D11UnorderedAccessView *uav;
17203 ID3D11ShaderResourceView *srv;
17204 D3D11_BUFFER_DESC buffer_desc;
17205 ID3D11Buffer *cb, *raw_buffer;
17206 ID3D11DeviceContext *context;
17207 struct resource_readback rb;
17208 ID3D11RenderTargetView *rtv;
17209 ID3D11Texture2D *texture;
17210 ID3D11ComputeShader *cs;
17211 ID3D11PixelShader *ps;
17212 ID3D11Device *device;
17213 unsigned int i, data;
17214 struct uvec4 offset;
17215 HRESULT hr;
17217 static const unsigned int buffer_data[] =
17219 0xffffffff, 0x00000000,
17221 static const DWORD ps_code[] =
17223 #if 0
17224 ByteAddressBuffer buffer;
17226 uint offset;
17228 uint main() : SV_Target0
17230 return buffer.Load(offset);
17232 #endif
17233 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
17234 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
17235 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
17236 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
17237 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
17238 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
17239 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
17240 0x00000000,
17242 static const DWORD cs_code[] =
17244 #if 0
17245 RWByteAddressBuffer buffer;
17247 uint2 input;
17249 [numthreads(1, 1, 1)]
17250 void main()
17252 buffer.Store(input.x, input.y);
17254 #endif
17255 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
17256 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17257 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
17258 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
17259 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
17260 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
17262 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
17264 if (!init_test_context(&test_context, &feature_level))
17265 return;
17267 device = test_context.device;
17268 context = test_context.immediate_context;
17270 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
17272 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17273 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
17274 if (SUCCEEDED(hr))
17275 ID3D11PixelShader_Release(ps);
17276 skip("Raw buffers are not supported.\n");
17277 release_test_context(&test_context);
17278 return;
17281 if (is_intel_device(device))
17283 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
17284 * This test checks what happens when offsets are not properly aligned.
17285 * The behavior seems to be undefined on Intel hardware. */
17286 win_skip("Skipping the test on Intel hardware.\n");
17287 release_test_context(&test_context);
17288 return;
17291 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17292 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17294 memset(&offset, 0, sizeof(offset));
17295 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
17297 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17298 texture_desc.Format = DXGI_FORMAT_R32_UINT;
17299 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17300 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17301 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
17302 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17304 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17306 buffer_desc.ByteWidth = sizeof(buffer_data);
17307 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17308 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
17309 buffer_desc.CPUAccessFlags = 0;
17310 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
17311 resource_data.pSysMem = buffer_data;
17312 resource_data.SysMemPitch = 0;
17313 resource_data.SysMemSlicePitch = 0;
17314 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
17315 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17317 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
17318 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
17319 U(srv_desc).BufferEx.FirstElement = 0;
17320 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
17321 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
17322 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
17323 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
17325 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17326 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17327 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
17329 offset.x = 0;
17330 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17331 NULL, &offset, 0, 0);
17332 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17333 draw_quad(&test_context);
17334 check_texture_color(texture, buffer_data[0], 0);
17335 offset.x = 1;
17336 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17337 NULL, &offset, 0, 0);
17338 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17339 draw_quad(&test_context);
17340 check_texture_color(texture, buffer_data[0], 0);
17341 offset.x = 2;
17342 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17343 NULL, &offset, 0, 0);
17344 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17345 draw_quad(&test_context);
17346 check_texture_color(texture, buffer_data[0], 0);
17347 offset.x = 3;
17348 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17349 NULL, &offset, 0, 0);
17350 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17351 draw_quad(&test_context);
17352 check_texture_color(texture, buffer_data[0], 0);
17354 offset.x = 4;
17355 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17356 NULL, &offset, 0, 0);
17357 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17358 draw_quad(&test_context);
17359 check_texture_color(texture, buffer_data[1], 0);
17360 offset.x = 7;
17361 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17362 NULL, &offset, 0, 0);
17363 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17364 draw_quad(&test_context);
17365 check_texture_color(texture, buffer_data[1], 0);
17367 if (feature_level < D3D_FEATURE_LEVEL_11_0)
17369 skip("Feature level 11_0 required for unaligned UAV test.\n");
17370 goto done;
17373 ID3D11Buffer_Release(raw_buffer);
17374 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17375 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
17376 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17378 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
17379 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
17380 U(uav_desc).Buffer.FirstElement = 0;
17381 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
17382 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
17383 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
17384 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17386 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
17387 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17389 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
17390 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
17391 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
17393 offset.x = 0;
17394 offset.y = 0xffffffff;
17395 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17396 NULL, &offset, 0, 0);
17397 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
17398 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17399 get_buffer_readback(raw_buffer, &rb);
17400 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
17402 data = get_readback_color(&rb, i, 0);
17403 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
17405 release_resource_readback(&rb);
17407 offset.x = 1;
17408 offset.y = 0xffffffff;
17409 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17410 NULL, &offset, 0, 0);
17411 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
17412 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17413 get_buffer_readback(raw_buffer, &rb);
17414 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
17416 data = get_readback_color(&rb, i, 0);
17417 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
17419 release_resource_readback(&rb);
17421 offset.x = 2;
17422 offset.y = 0xffffffff;
17423 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17424 NULL, &offset, 0, 0);
17425 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
17426 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17427 get_buffer_readback(raw_buffer, &rb);
17428 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
17430 data = get_readback_color(&rb, i, 0);
17431 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
17433 release_resource_readback(&rb);
17435 offset.x = 3;
17436 offset.y = 0xffffffff;
17437 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17438 NULL, &offset, 0, 0);
17439 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
17440 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17441 get_buffer_readback(raw_buffer, &rb);
17442 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
17444 data = get_readback_color(&rb, i, 0);
17445 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
17447 release_resource_readback(&rb);
17449 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
17450 offset.x = 3;
17451 offset.y = 0xffff;
17452 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17453 NULL, &offset, 0, 0);
17454 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17455 offset.x = 4;
17456 offset.y = 0xa;
17457 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17458 NULL, &offset, 0, 0);
17459 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17460 get_buffer_readback(raw_buffer, &rb);
17461 data = get_readback_color(&rb, 0, 0);
17462 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
17463 data = get_readback_color(&rb, 1, 0);
17464 ok(data == 0xa, "Got unexpected result %#x.\n", data);
17465 release_resource_readback(&rb);
17467 ID3D11ComputeShader_Release(cs);
17468 ID3D11UnorderedAccessView_Release(uav);
17470 done:
17471 ID3D11Buffer_Release(cb);
17472 ID3D11Buffer_Release(raw_buffer);
17473 ID3D11PixelShader_Release(ps);
17474 ID3D11RenderTargetView_Release(rtv);
17475 ID3D11ShaderResourceView_Release(srv);
17476 ID3D11Texture2D_Release(texture);
17477 release_test_context(&test_context);
17480 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
17481 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
17483 D3D11_MAPPED_SUBRESOURCE map_desc;
17484 unsigned int counter;
17486 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
17488 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
17489 D3D11_MAP_READ, 0, &map_desc)))
17490 return 0xdeadbeef;
17491 counter = *(unsigned int *)map_desc.pData;
17492 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
17493 return counter;
17496 static int compare_id(const void *a, const void *b)
17498 return *(int *)a - *(int *)b;
17501 static void test_uav_counters(void)
17503 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
17504 ID3D11ComputeShader *cs_producer, *cs_consumer;
17505 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
17506 struct d3d11_test_context test_context;
17507 ID3D11UnorderedAccessView *uav, *uav2;
17508 unsigned int data, id[128], i;
17509 D3D11_BUFFER_DESC buffer_desc;
17510 ID3D11DeviceContext *context;
17511 struct resource_readback rb;
17512 ID3D11Device *device;
17513 D3D11_BOX box;
17514 HRESULT hr;
17516 static const DWORD cs_producer_code[] =
17518 #if 0
17519 RWStructuredBuffer<uint> u;
17521 [numthreads(4, 1, 1)]
17522 void main(uint3 dispatch_id : SV_DispatchThreadID)
17524 uint counter = u.IncrementCounter();
17525 u[counter] = dispatch_id.x;
17527 #endif
17528 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
17529 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17530 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
17531 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
17532 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
17533 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
17534 0x0002000a, 0x0100003e,
17536 static const DWORD cs_consumer_code[] =
17538 #if 0
17539 RWStructuredBuffer<uint> u;
17540 RWStructuredBuffer<uint> u2;
17542 [numthreads(4, 1, 1)]
17543 void main()
17545 uint counter = u.DecrementCounter();
17546 u2[counter] = u[counter];
17548 #endif
17549 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
17550 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17551 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
17552 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
17553 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
17554 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
17555 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
17556 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
17558 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17560 if (!init_test_context(&test_context, &feature_level))
17561 return;
17563 device = test_context.device;
17564 context = test_context.immediate_context;
17566 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
17567 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17568 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
17569 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17571 memset(&buffer_desc, 0, sizeof(buffer_desc));
17572 buffer_desc.ByteWidth = sizeof(unsigned int);
17573 buffer_desc.Usage = D3D11_USAGE_STAGING;
17574 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
17575 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
17576 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
17578 buffer_desc.ByteWidth = 1024;
17579 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17580 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17581 buffer_desc.CPUAccessFlags = 0;
17582 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
17583 buffer_desc.StructureByteStride = sizeof(unsigned int);
17584 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
17585 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
17586 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
17587 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
17588 U(uav_desc).Buffer.FirstElement = 0;
17589 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
17590 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
17591 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
17592 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17593 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
17594 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
17595 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
17596 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17598 data = read_uav_counter(context, staging_buffer, uav);
17599 ok(!data, "Got unexpected initial value %u.\n", data);
17600 data = 8;
17601 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
17602 data = read_uav_counter(context, staging_buffer, uav);
17603 todo_wine ok(data == 8, "Got unexpected value %u.\n", data);
17605 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
17606 data = 0;
17607 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
17608 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
17609 data = read_uav_counter(context, staging_buffer, uav);
17610 ok(!data, "Got unexpected value %u.\n", data);
17612 /* produce */
17613 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
17614 data = read_uav_counter(context, staging_buffer, uav);
17615 todo_wine ok(data == 64, "Got unexpected value %u.\n", data);
17616 get_buffer_readback(buffer, &rb);
17617 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
17618 release_resource_readback(&rb);
17619 qsort(id, 64, sizeof(*id), compare_id);
17620 for (i = 0; i < 64; ++i)
17622 if (id[i] != i)
17623 break;
17625 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
17627 /* consume */
17628 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
17629 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
17630 data = read_uav_counter(context, staging_buffer, uav);
17631 ok(!data, "Got unexpected value %u.\n", data);
17632 get_buffer_readback(buffer2, &rb);
17633 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
17634 release_resource_readback(&rb);
17635 qsort(id, 64, sizeof(*id), compare_id);
17636 for (i = 0; i < 64; ++i)
17638 if (id[i] != i)
17639 break;
17641 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
17643 /* produce on CPU */
17644 for (i = 0; i < 8; ++i)
17645 id[i] = 0xdeadbeef;
17646 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
17647 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
17648 data = 8;
17649 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
17650 data = read_uav_counter(context, staging_buffer, uav);
17651 todo_wine ok(data == 8, "Got unexpected value %u.\n", data);
17653 /* consume */
17654 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17655 data = read_uav_counter(context, staging_buffer, uav);
17656 todo_wine ok(data == 4, "Got unexpected value %u.\n", data);
17657 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17658 data = read_uav_counter(context, staging_buffer, uav);
17659 ok(!data, "Got unexpected value %u.\n", data);
17660 get_buffer_readback(buffer2, &rb);
17661 for (i = 0; i < 8; ++i)
17663 data = get_readback_color(&rb, i, 0);
17664 todo_wine ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
17666 release_resource_readback(&rb);
17668 ID3D11Buffer_Release(buffer);
17669 ID3D11Buffer_Release(buffer2);
17670 ID3D11Buffer_Release(staging_buffer);
17671 ID3D11ComputeShader_Release(cs_producer);
17672 ID3D11ComputeShader_Release(cs_consumer);
17673 ID3D11UnorderedAccessView_Release(uav);
17674 ID3D11UnorderedAccessView_Release(uav2);
17675 release_test_context(&test_context);
17678 static void test_compute_shader_registers(void)
17680 struct data
17682 unsigned int group_id[3];
17683 unsigned int group_index;
17684 unsigned int dispatch_id[3];
17685 unsigned int thread_id[3];
17688 struct d3d11_test_context test_context;
17689 unsigned int i, x, y, group_x, group_y;
17690 ID3D11UnorderedAccessView *uav;
17691 D3D11_BUFFER_DESC buffer_desc;
17692 ID3D11DeviceContext *context;
17693 struct resource_readback rb;
17694 ID3D11Buffer *cb, *buffer;
17695 struct uvec4 dimensions;
17696 ID3D11ComputeShader *cs;
17697 const struct data *data;
17698 ID3D11Device *device;
17699 HRESULT hr;
17701 static const DWORD cs_code[] =
17703 #if 0
17704 struct data
17706 uint3 group_id;
17707 uint group_index;
17708 uint3 dispatch_id;
17709 uint3 group_thread_id;
17712 RWStructuredBuffer<data> u;
17714 uint2 dim;
17716 [numthreads(3, 2, 1)]
17717 void main(uint3 group_id : SV_GroupID,
17718 uint group_index : SV_GroupIndex,
17719 uint3 dispatch_id : SV_DispatchThreadID,
17720 uint3 group_thread_id : SV_GroupThreadID)
17722 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
17723 u[i].group_id = group_id;
17724 u[i].group_index = group_index;
17725 u[i].dispatch_id = dispatch_id;
17726 u[i].group_thread_id = group_thread_id;
17728 #endif
17729 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
17730 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17731 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
17732 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
17733 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
17734 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
17735 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
17736 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
17737 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
17738 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
17739 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
17740 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
17741 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
17742 0x0100003e,
17744 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17746 if (!init_test_context(&test_context, &feature_level))
17747 return;
17749 device = test_context.device;
17750 context = test_context.immediate_context;
17752 buffer_desc.ByteWidth = 10240;
17753 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17754 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17755 buffer_desc.CPUAccessFlags = 0;
17756 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
17757 buffer_desc.StructureByteStride = 40;
17758 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
17759 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
17760 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
17761 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
17762 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17764 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
17766 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
17767 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17769 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
17770 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
17771 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
17773 dimensions.x = 2;
17774 dimensions.y = 3;
17775 dimensions.z = 1;
17776 dimensions.w = 0;
17777 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17778 NULL, &dimensions, 0, 0);
17779 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
17781 get_buffer_readback(buffer, &rb);
17782 i = 0;
17783 data = rb.map_desc.pData;
17784 for (y = 0; y < dimensions.y; ++y)
17786 for (group_y = 0; group_y < 2; ++group_y)
17788 for (x = 0; x < dimensions.x; ++x)
17790 for (group_x = 0; group_x < 3; ++group_x)
17792 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
17793 const unsigned int group_index = group_y * 3 + group_x;
17794 const struct data *d = &data[i];
17796 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
17797 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
17798 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
17799 i, x, y, group_x, group_y);
17800 ok(d->group_index == group_index,
17801 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
17802 d->group_index, group_index, i, x, y, group_x, group_y);
17803 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
17804 && !d->dispatch_id[2],
17805 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
17806 "at %u (%u, %u, %u, %u).\n",
17807 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
17808 dispatch_id[0], dispatch_id[1], 0,
17809 i, x, y, group_x, group_y);
17810 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
17811 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
17812 "at %u (%u, %u, %u, %u).\n",
17813 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
17814 i, x, y, group_x, group_y);
17815 ++i;
17820 release_resource_readback(&rb);
17822 ID3D11Buffer_Release(cb);
17823 ID3D11Buffer_Release(buffer);
17824 ID3D11ComputeShader_Release(cs);
17825 ID3D11UnorderedAccessView_Release(uav);
17826 release_test_context(&test_context);
17829 static void test_tgsm(void)
17831 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
17832 struct d3d11_test_context test_context;
17833 ID3D11UnorderedAccessView *uav, *uav2;
17834 struct resource_readback rb, rb2;
17835 unsigned int i, data, expected;
17836 ID3D11Buffer *buffer, *buffer2;
17837 D3D11_BUFFER_DESC buffer_desc;
17838 ID3D11DeviceContext *context;
17839 ID3D11ComputeShader *cs;
17840 ID3D11Device *device;
17841 float float_data;
17842 HRESULT hr;
17844 static const DWORD raw_tgsm_code[] =
17846 #if 0
17847 RWByteAddressBuffer u;
17848 groupshared uint m;
17850 [numthreads(32, 1, 1)]
17851 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
17853 if (!local_idx)
17854 m = group_id.x;
17855 GroupMemoryBarrierWithGroupSync();
17856 InterlockedAdd(m, group_id.x);
17857 GroupMemoryBarrierWithGroupSync();
17858 if (!local_idx)
17859 u.Store(4 * group_id.x, m);
17861 #endif
17862 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
17863 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17864 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
17865 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
17866 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
17867 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
17868 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
17869 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
17870 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
17871 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
17872 0x01000015, 0x0100003e,
17874 static const DWORD structured_tgsm_code[] =
17876 #if 0
17877 #define GROUP_SIZE 32
17879 RWByteAddressBuffer u;
17880 RWByteAddressBuffer u2;
17881 groupshared uint m[GROUP_SIZE];
17883 [numthreads(GROUP_SIZE, 1, 1)]
17884 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
17886 uint sum, original, i;
17888 if (!local_idx)
17890 for (i = 0; i < GROUP_SIZE; ++i)
17891 m[i] = 2 * group_id.x;
17893 GroupMemoryBarrierWithGroupSync();
17894 InterlockedAdd(m[local_idx], 1);
17895 GroupMemoryBarrierWithGroupSync();
17896 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
17897 u.InterlockedExchange(4 * group_id.x, sum, original);
17898 u2.Store(4 * group_id.x, original);
17900 #endif
17901 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
17902 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17903 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
17904 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
17905 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
17906 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
17907 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
17908 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
17909 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
17910 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
17911 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
17912 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
17913 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
17914 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
17915 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
17916 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
17917 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
17918 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
17919 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
17920 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
17921 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
17922 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
17924 static const DWORD structured_tgsm_float_code[] =
17926 #if 0
17927 #define GROUP_SIZE 32
17929 struct data
17931 float f;
17932 uint u;
17935 RWBuffer<float> u;
17936 RWBuffer<uint> u2;
17937 groupshared data m[GROUP_SIZE];
17939 [numthreads(GROUP_SIZE, 1, 1)]
17940 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
17941 uint thread_id : SV_DispatchThreadID)
17943 uint i;
17944 if (!local_idx)
17946 for (i = 0; i < GROUP_SIZE; ++i)
17948 m[i].f = group_id.x;
17949 m[i].u = group_id.x;
17952 GroupMemoryBarrierWithGroupSync();
17953 for (i = 0; i < local_idx; ++i)
17955 m[local_idx].f += group_id.x;
17956 m[local_idx].u += group_id.x;
17958 u[thread_id.x] = m[local_idx].f;
17959 u2[thread_id.x] = m[local_idx].u;
17961 #endif
17962 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
17963 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17964 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
17965 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
17966 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
17967 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
17968 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
17969 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
17970 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
17971 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
17972 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
17973 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
17974 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
17975 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
17976 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
17977 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
17978 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
17979 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
17980 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
17981 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
17982 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
17983 0x00100556, 0x00000000, 0x0100003e,
17985 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17986 static const unsigned int zero[4] = {0};
17988 if (!init_test_context(&test_context, &feature_level))
17989 return;
17991 device = test_context.device;
17992 context = test_context.immediate_context;
17994 buffer_desc.ByteWidth = 1024;
17995 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17996 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17997 buffer_desc.CPUAccessFlags = 0;
17998 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
17999 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18000 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18002 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
18003 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
18004 U(uav_desc).Buffer.FirstElement = 0;
18005 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
18006 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
18007 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
18008 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18010 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
18011 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18013 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18014 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
18016 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
18017 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
18018 get_buffer_readback(buffer, &rb);
18019 for (i = 0; i < 64; ++i)
18021 data = get_readback_color(&rb, i, 0);
18022 expected = 33 * i;
18023 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
18025 release_resource_readback(&rb);
18027 ID3D11Buffer_Release(buffer);
18028 ID3D11ComputeShader_Release(cs);
18029 ID3D11UnorderedAccessView_Release(uav);
18031 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18032 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18033 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
18034 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18035 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
18036 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18037 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
18038 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18039 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
18040 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18042 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18043 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
18044 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
18046 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
18047 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
18048 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
18049 get_buffer_readback(buffer, &rb);
18050 get_buffer_readback(buffer2, &rb2);
18051 for (i = 0; i < 32; ++i)
18053 expected = 64 * i + 32;
18054 data = get_readback_color(&rb, i, 0);
18055 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
18056 data = get_readback_color(&rb2, i, 0);
18057 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
18059 release_resource_readback(&rb);
18060 release_resource_readback(&rb2);
18062 ID3D11Buffer_Release(buffer);
18063 ID3D11Buffer_Release(buffer2);
18064 ID3D11ComputeShader_Release(cs);
18065 ID3D11UnorderedAccessView_Release(uav);
18066 ID3D11UnorderedAccessView_Release(uav2);
18068 buffer_desc.MiscFlags = 0;
18069 U(uav_desc).Buffer.Flags = 0;
18070 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18071 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18072 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
18073 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
18074 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18075 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
18076 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18077 uav_desc.Format = DXGI_FORMAT_R32_UINT;
18078 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
18079 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18080 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
18081 sizeof(structured_tgsm_float_code), NULL, &cs);
18082 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18084 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18085 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
18086 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
18088 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
18089 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
18090 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
18091 get_buffer_readback(buffer, &rb);
18092 get_buffer_readback(buffer2, &rb2);
18093 for (i = 0; i < 96; ++i)
18095 expected = (i % 32 + 1) * (i / 32);
18096 float_data = get_readback_float(&rb, i, 0);
18097 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
18098 data = get_readback_color(&rb2, i, 0);
18099 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
18101 release_resource_readback(&rb);
18102 release_resource_readback(&rb2);
18104 ID3D11Buffer_Release(buffer);
18105 ID3D11Buffer_Release(buffer2);
18106 ID3D11ComputeShader_Release(cs);
18107 ID3D11UnorderedAccessView_Release(uav);
18108 ID3D11UnorderedAccessView_Release(uav2);
18109 release_test_context(&test_context);
18112 static void test_geometry_shader(void)
18114 static const struct
18116 struct vec4 position;
18117 unsigned int color;
18119 vertex[] =
18121 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
18123 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
18125 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18126 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
18128 #if 0
18129 struct vs_data
18131 float4 pos : SV_POSITION;
18132 float4 color : COLOR;
18135 void main(in struct vs_data vs_input, out struct vs_data vs_output)
18137 vs_output.pos = vs_input.pos;
18138 vs_output.color = vs_input.color;
18140 #endif
18141 static const DWORD vs_code[] =
18143 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
18144 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18145 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
18146 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
18147 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18148 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18149 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18150 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18151 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18152 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18153 0x0100003e,
18155 #if 0
18156 struct gs_data
18158 float4 pos : SV_POSITION;
18159 float4 color : COLOR;
18162 [maxvertexcount(4)]
18163 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
18165 float offset = 0.2 * vin[0].pos.w;
18166 gs_data v;
18168 v.color = vin[0].color;
18170 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
18171 vout.Append(v);
18172 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
18173 vout.Append(v);
18174 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
18175 vout.Append(v);
18176 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
18177 vout.Append(v);
18179 #endif
18180 static const DWORD gs_code[] =
18182 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
18183 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18184 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
18185 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
18186 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18187 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18188 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
18189 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
18190 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
18191 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
18192 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
18193 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
18194 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
18195 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
18196 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
18197 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
18198 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
18199 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
18200 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
18201 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
18202 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
18203 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
18204 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
18205 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
18206 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
18207 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
18208 0x00000001, 0x01000013, 0x0100003e,
18210 static const DWORD gs_5_0_code[] =
18212 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
18213 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18214 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
18215 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
18216 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
18217 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
18218 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
18219 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
18220 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
18221 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18222 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
18223 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
18224 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
18225 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
18226 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
18227 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
18228 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
18229 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
18230 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
18231 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
18232 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
18233 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
18234 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
18235 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
18236 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
18237 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
18238 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
18239 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
18240 0x0100003e,
18242 #if 0
18243 struct ps_data
18245 float4 pos : SV_POSITION;
18246 float4 color : COLOR;
18249 float4 main(struct ps_data ps_input) : SV_Target
18251 return ps_input.color;
18253 #endif
18254 static const DWORD ps_code[] =
18256 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
18257 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18258 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
18259 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
18260 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18261 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
18262 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
18263 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
18265 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
18266 struct d3d11_test_context test_context;
18267 ID3D11InputLayout *input_layout;
18268 ID3D11DeviceContext *context;
18269 unsigned int stride, offset;
18270 struct resource_readback rb;
18271 ID3D11GeometryShader *gs;
18272 ID3D11VertexShader *vs;
18273 ID3D11PixelShader *ps;
18274 ID3D11Device *device;
18275 ID3D11Buffer *vb;
18276 DWORD color;
18277 HRESULT hr;
18279 if (!init_test_context(&test_context, NULL))
18280 return;
18282 device = test_context.device;
18283 context = test_context.immediate_context;
18285 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
18286 vs_code, sizeof(vs_code), &input_layout);
18287 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
18289 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
18291 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
18292 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
18293 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
18294 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
18295 else
18296 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
18297 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
18298 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18299 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18301 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
18302 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
18303 stride = sizeof(*vertex);
18304 offset = 0;
18305 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
18306 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
18307 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
18308 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18310 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
18311 ID3D11DeviceContext_Draw(context, 1, 0);
18313 get_texture_readback(test_context.backbuffer, 0, &rb);
18314 color = get_readback_color(&rb, 320, 190);
18315 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
18316 color = get_readback_color(&rb, 255, 240);
18317 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
18318 color = get_readback_color(&rb, 320, 240);
18319 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
18320 color = get_readback_color(&rb, 385, 240);
18321 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
18322 color = get_readback_color(&rb, 320, 290);
18323 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
18324 release_resource_readback(&rb);
18326 ID3D11PixelShader_Release(ps);
18327 ID3D11GeometryShader_Release(gs);
18328 ID3D11VertexShader_Release(vs);
18329 ID3D11Buffer_Release(vb);
18330 ID3D11InputLayout_Release(input_layout);
18331 release_test_context(&test_context);
18334 struct triangle
18336 struct vec4 v[3];
18339 #define check_triangles(buffer, triangles, count) check_triangles_(__LINE__, buffer, triangles, count)
18340 static void check_triangles_(unsigned int line, ID3D11Buffer *buffer,
18341 const struct triangle *triangles, unsigned int triangle_count)
18343 const struct triangle *current, *expected;
18344 struct resource_readback rb;
18345 unsigned int i, j, offset;
18346 BOOL all_match = TRUE;
18348 get_buffer_readback(buffer, &rb);
18350 for (i = 0; i < triangle_count; ++i)
18352 current = get_readback_data(&rb, i, 0, sizeof(*current));
18353 expected = &triangles[i];
18355 offset = ~0u;
18356 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
18358 if (compare_vec4(&current->v[0], &expected->v[j], 0))
18360 offset = j;
18361 break;
18365 if (offset == ~0u)
18367 all_match = FALSE;
18368 break;
18371 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
18373 if (!compare_vec4(&current->v[j], &expected->v[(j + offset) % 3], 0))
18375 all_match = FALSE;
18376 break;
18379 if (!all_match)
18380 break;
18383 ok_(__FILE__, line)(all_match, "Triangle %u vertices {%.8e, %.8e, %.8e, %.8e}, "
18384 "{%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e} "
18385 "do not match {%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e}, "
18386 "{%.8e, %.8e, %.8e, %.8e}.\n", i,
18387 current->v[0].x, current->v[0].y, current->v[0].z, current->v[0].w,
18388 current->v[1].x, current->v[1].y, current->v[1].z, current->v[1].w,
18389 current->v[2].x, current->v[2].y, current->v[2].z, current->v[2].w,
18390 expected->v[0].x, expected->v[0].y, expected->v[0].z, expected->v[0].w,
18391 expected->v[1].x, expected->v[1].y, expected->v[1].z, expected->v[1].w,
18392 expected->v[2].x, expected->v[2].y, expected->v[2].z, expected->v[2].w);
18394 release_resource_readback(&rb);
18397 static void test_quad_tessellation(void)
18399 #if 0
18400 struct point_data
18402 float4 position : SV_POSITION;
18405 struct patch_constant_data
18407 float edges[4] : SV_TessFactor;
18408 float inside[2] : SV_InsideTessFactor;
18411 float4 tess_factors;
18412 float2 inside_tess_factors;
18414 patch_constant_data patch_constant(InputPatch<point_data, 4> input)
18416 patch_constant_data output;
18418 output.edges[0] = tess_factors.x;
18419 output.edges[1] = tess_factors.y;
18420 output.edges[2] = tess_factors.z;
18421 output.edges[3] = tess_factors.w;
18422 output.inside[0] = inside_tess_factors.x;
18423 output.inside[1] = inside_tess_factors.y;
18425 return output;
18428 [domain("quad")]
18429 [outputcontrolpoints(4)]
18430 [outputtopology("triangle_ccw")]
18431 [partitioning("integer")]
18432 [patchconstantfunc("patch_constant")]
18433 point_data hs_main(InputPatch<point_data, 4> input,
18434 uint i : SV_OutputControlPointID)
18436 return input[i];
18439 [domain("quad")]
18440 point_data ds_main(patch_constant_data input,
18441 float2 tess_coord : SV_DomainLocation,
18442 const OutputPatch<point_data, 4> patch)
18444 point_data output;
18446 float4 a = lerp(patch[0].position, patch[1].position, tess_coord.x);
18447 float4 b = lerp(patch[2].position, patch[3].position, tess_coord.x);
18448 output.position = lerp(a, b, tess_coord.y);
18450 return output;
18452 #endif
18453 static const DWORD hs_quad_ccw_code[] =
18455 0x43425844, 0xdf8df700, 0x58b08fb1, 0xbd23d2c3, 0xcf884094, 0x00000001, 0x000002b8, 0x00000004,
18456 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
18457 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
18458 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
18459 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
18460 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
18461 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
18462 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
18463 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
18464 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
18465 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
18466 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
18467 0x01002097, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
18468 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
18469 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
18470 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
18471 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
18472 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
18473 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
18474 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
18475 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
18476 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
18478 static const DWORD ds_quad_code[] =
18480 0x43425844, 0xeb6b7631, 0x07f5469e, 0xed0cbf4a, 0x7158b3a6, 0x00000001, 0x00000284, 0x00000004,
18481 0x00000030, 0x00000064, 0x00000128, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
18482 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
18483 0x004e4f49, 0x47534350, 0x000000bc, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b,
18484 0x00000003, 0x00000000, 0x00000001, 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001,
18485 0x00000001, 0x00000098, 0x00000002, 0x0000000b, 0x00000003, 0x00000002, 0x00000001, 0x00000098,
18486 0x00000003, 0x0000000b, 0x00000003, 0x00000003, 0x00000001, 0x000000a6, 0x00000000, 0x0000000c,
18487 0x00000003, 0x00000004, 0x00000001, 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005,
18488 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365,
18489 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
18490 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853,
18491 0x00000120, 0x00040050, 0x00000048, 0x01002093, 0x01001895, 0x0100086a, 0x0200005f, 0x0001c032,
18492 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18493 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, 0x80219e46, 0x00000041, 0x00000002,
18494 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, 0x001000f2, 0x00000000, 0x0001c006,
18495 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, 0x0a000000, 0x001000f2, 0x00000001,
18496 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, 0x00000001, 0x00000000, 0x09000032,
18497 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, 0x00219e46, 0x00000000, 0x00000000,
18498 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x80100e46, 0x00000041, 0x00000001,
18499 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
18500 0x0100003e,
18502 #if 0
18504 [outputtopology("triangle_cw")]
18506 #endif
18507 static const DWORD hs_quad_cw_code[] =
18509 0x43425844, 0x1ab30cc8, 0x94174771, 0x61f4cdd0, 0xa287f62c, 0x00000001, 0x000002b8, 0x00000004,
18510 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
18511 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
18512 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
18513 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
18514 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
18515 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
18516 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
18517 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
18518 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
18519 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
18520 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
18521 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
18522 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
18523 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
18524 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
18525 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
18526 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
18527 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
18528 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
18529 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
18530 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
18532 #if 0
18533 struct point_data
18535 float4 pos : SV_POSITION;
18538 [maxvertexcount(3)]
18539 void main(triangle point_data vin[3], inout TriangleStream<point_data> vout)
18541 for (uint i = 0; i < 3; ++i)
18542 vout.Append(vin[i]);
18544 #endif
18545 static const DWORD gs_code[] =
18547 0x43425844, 0x8e49d18d, 0x6d08d6e5, 0xb7015628, 0xf9351fdd, 0x00000001, 0x00000164, 0x00000003,
18548 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18549 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
18550 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
18551 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000000c8, 0x00020040,
18552 0x00000032, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068, 0x00000001,
18553 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000003,
18554 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
18555 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010001a, 0x00000000,
18556 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x01000013,
18557 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016,
18558 0x0100003e,
18560 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
18562 {0, "SV_POSITION", 0, 0, 4, 0},
18564 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18565 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
18566 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
18567 static const BYTE zero_data[1024];
18568 static const struct triangle expected_quad_ccw[] =
18570 {{{-1.0f, -1.0f, 0.0f, 1.0f},
18571 { 1.0f, -1.0f, 0.0f, 1.0f},
18572 {-1.0f, 1.0f, 0.0f, 1.0f}}},
18573 {{{-1.0f, 1.0f, 0.0f, 1.0f},
18574 { 1.0f, -1.0f, 0.0f, 1.0f},
18575 { 1.0f, 1.0f, 0.0f, 1.0f}}},
18576 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
18577 { 0.0f, 0.0f, 0.0f, 0.0f},
18578 { 0.0f, 0.0f, 0.0f, 0.0f}}},
18580 static const struct triangle expected_quad_cw[] =
18582 {{{-1.0f, -1.0f, 0.0f, 1.0f},
18583 {-1.0f, 1.0f, 0.0f, 1.0f},
18584 { 1.0f, -1.0f, 0.0f, 1.0f}}},
18585 {{{-1.0f, 1.0f, 0.0f, 1.0f},
18586 { 1.0f, 1.0f, 0.0f, 1.0f},
18587 { 1.0f, -1.0f, 0.0f, 1.0f}}},
18588 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
18589 { 0.0f, 0.0f, 0.0f, 0.0f},
18590 { 0.0f, 0.0f, 0.0f, 0.0f}}},
18592 struct
18594 float tess_factors[4];
18595 float inside_tess_factors[2];
18596 DWORD padding[2];
18597 } constant;
18599 D3D11_QUERY_DATA_SO_STATISTICS so_statistics;
18600 struct d3d11_test_context test_context;
18601 ID3D11DeviceContext *context;
18602 ID3D11Buffer *cb, *so_buffer;
18603 D3D11_QUERY_DESC query_desc;
18604 ID3D11Asynchronous *query;
18605 ID3D11GeometryShader *gs;
18606 ID3D11DomainShader *ds;
18607 const UINT offset = 0;
18608 ID3D11HullShader *hs;
18609 ID3D11Device *device;
18610 unsigned int i;
18611 HRESULT hr;
18613 if (!init_test_context(&test_context, &feature_level))
18614 return;
18616 device = test_context.device;
18617 context = test_context.immediate_context;
18619 draw_color_quad(&test_context, &white);
18620 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
18622 set_quad_color(&test_context, &green);
18623 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
18625 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
18626 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
18627 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0, NULL, &gs);
18628 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
18629 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
18631 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
18632 constant.tess_factors[i] = 1.0f;
18633 for (i = 0; i < ARRAY_SIZE(constant.inside_tess_factors); ++i)
18634 constant.inside_tess_factors[i] = 1.0f;
18635 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
18636 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb);
18637 hr = ID3D11Device_CreateHullShader(device, hs_quad_ccw_code, sizeof(hs_quad_ccw_code), NULL, &hs);
18638 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
18639 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
18640 hr = ID3D11Device_CreateDomainShader(device, ds_quad_code, sizeof(ds_quad_code), NULL, &ds);
18641 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
18642 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
18644 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
18645 ID3D11DeviceContext_Draw(context, 4, 0);
18646 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
18647 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
18648 check_triangles(so_buffer, expected_quad_ccw, ARRAY_SIZE(expected_quad_ccw));
18650 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
18652 ID3D11HullShader_Release(hs);
18653 hr = ID3D11Device_CreateHullShader(device, hs_quad_cw_code, sizeof(hs_quad_cw_code), NULL, &hs);
18654 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
18655 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
18657 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
18658 ID3D11DeviceContext_Draw(context, 4, 0);
18659 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
18660 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
18661 check_triangles(so_buffer, expected_quad_cw, ARRAY_SIZE(expected_quad_cw));
18663 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
18665 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
18666 query_desc.Query = D3D11_QUERY_SO_STATISTICS_STREAM0;
18667 query_desc.MiscFlags = 0;
18668 query = NULL;
18669 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
18670 todo_wine ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
18671 if (query)
18672 ID3D11DeviceContext_Begin(context, query);
18674 set_quad_color(&test_context, &white);
18675 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
18676 constant.tess_factors[i] = 2.0f;
18677 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
18678 ID3D11DeviceContext_Draw(context, 4, 0);
18679 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
18681 set_quad_color(&test_context, &green);
18682 constant.tess_factors[0] = 0.0f; /* A patch is discarded. */
18683 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
18684 ID3D11DeviceContext_Draw(context, 4, 0);
18685 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
18687 if (query)
18689 ID3D11DeviceContext_End(context, query);
18690 for (i = 0; i < 500; ++i)
18692 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
18693 break;
18694 Sleep(10);
18696 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18697 hr = ID3D11DeviceContext_GetData(context, query, &so_statistics, sizeof(so_statistics), 0);
18698 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18699 ok(so_statistics.NumPrimitivesWritten == 8, "Got unexpected primitives written %u.\n",
18700 (unsigned int)so_statistics.NumPrimitivesWritten);
18701 ok(so_statistics.PrimitivesStorageNeeded == 8, "Got unexpected primitives storage needed %u.\n",
18702 (unsigned int)so_statistics.PrimitivesStorageNeeded);
18703 ID3D11DeviceContext_Begin(context, query);
18706 constant.tess_factors[0] = 5.0f;
18707 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
18708 ID3D11DeviceContext_Draw(context, 4, 0);
18709 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
18711 if (query)
18713 ID3D11DeviceContext_End(context, query);
18714 for (i = 0; i < 500; ++i)
18716 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
18717 break;
18718 Sleep(10);
18720 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18721 hr = ID3D11DeviceContext_GetData(context, query, &so_statistics, sizeof(so_statistics), 0);
18722 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18723 ok(so_statistics.NumPrimitivesWritten == 11, "Got unexpected primitives written %u.\n",
18724 (unsigned int)so_statistics.NumPrimitivesWritten);
18725 ok(so_statistics.PrimitivesStorageNeeded == 11, "Got unexpected primitives storage needed %u.\n",
18726 (unsigned int)so_statistics.PrimitivesStorageNeeded);
18727 ID3D11Asynchronous_Release(query);
18730 ID3D11Buffer_Release(so_buffer);
18731 ID3D11GeometryShader_Release(gs);
18732 ID3D11DomainShader_Release(ds);
18733 ID3D11HullShader_Release(hs);
18734 ID3D11Buffer_Release(cb);
18735 release_test_context(&test_context);
18738 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
18739 static void check_so_desc_(unsigned int line, ID3D11Device *device,
18740 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
18741 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
18742 unsigned int rasterizer_stream)
18744 ID3D11GeometryShader *gs;
18745 HRESULT hr;
18747 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
18748 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
18749 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18750 if (SUCCEEDED(hr))
18751 ID3D11GeometryShader_Release(gs);
18754 #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)
18755 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
18756 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
18757 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
18758 unsigned int rasterizer_stream)
18760 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
18761 HRESULT hr;
18763 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
18764 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
18765 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18766 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
18767 if (SUCCEEDED(hr))
18768 ID3D11GeometryShader_Release(gs);
18771 static void test_stream_output(void)
18773 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
18774 struct d3d11_test_context test_context;
18775 unsigned int i, count;
18776 ID3D11Device *device;
18778 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18779 static const DWORD vs_code[] =
18781 #if 0
18782 struct data
18784 float4 position : SV_Position;
18785 float4 attrib1 : ATTRIB1;
18786 float3 attrib2 : attrib2;
18787 float2 attrib3 : ATTriB3;
18788 float attrib4 : ATTRIB4;
18791 void main(in data i, out data o)
18793 o = i;
18795 #endif
18796 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
18797 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
18798 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
18799 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
18800 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
18801 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
18802 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
18803 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
18804 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
18805 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
18806 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
18807 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
18808 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
18809 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
18810 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18811 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
18812 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
18813 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
18814 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
18815 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
18817 static const DWORD gs_code[] =
18819 #if 0
18820 struct data
18822 float4 position : SV_Position;
18823 float4 attrib1 : ATTRIB1;
18824 float3 attrib2 : attrib2;
18825 float2 attrib3 : ATTriB3;
18826 float attrib4 : ATTRIB4;
18829 [maxvertexcount(1)]
18830 void main(point data i[1], inout PointStream<data> o)
18832 o.Append(i[0]);
18834 #endif
18835 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
18836 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
18837 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
18838 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
18839 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
18840 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
18841 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
18842 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
18843 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
18844 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
18845 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
18846 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
18847 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
18848 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
18849 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
18850 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18851 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
18852 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
18853 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
18854 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
18855 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
18857 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
18859 {0, "SV_Position", 0, 0, 4, 0},
18861 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
18863 {0, "SV_Position", 0, 0, 4, 0},
18864 {0, NULL, 0, 0, 0, 0},
18866 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
18868 /* SemanticName and SemanticIndex */
18870 {0, "sv_position", 0, 0, 4, 0},
18871 {0, "attrib", 1, 0, 4, 0},
18874 {0, "sv_position", 0, 0, 4, 0},
18875 {0, "ATTRIB", 1, 0, 4, 0},
18877 /* Gaps */
18879 {0, "SV_POSITION", 0, 0, 4, 0},
18880 {0, NULL, 0, 0, 8, 0},
18881 {0, "ATTRIB", 1, 0, 4, 0},
18884 {0, "SV_POSITION", 0, 0, 4, 0},
18885 {0, NULL, 0, 0, 4, 0},
18886 {0, NULL, 0, 0, 4, 0},
18887 {0, "ATTRIB", 1, 0, 4, 0},
18889 /* ComponentCount */
18891 {0, "ATTRIB", 1, 0, 4, 0},
18894 {0, "ATTRIB", 2, 0, 3, 0},
18897 {0, "ATTRIB", 3, 0, 2, 0},
18900 {0, "ATTRIB", 4, 0, 1, 0},
18902 /* ComponentIndex */
18904 {0, "ATTRIB", 1, 1, 3, 0},
18907 {0, "ATTRIB", 1, 2, 2, 0},
18910 {0, "ATTRIB", 1, 3, 1, 0},
18913 {0, "ATTRIB", 3, 1, 1, 0},
18915 /* OutputSlot */
18917 {0, "attrib", 1, 0, 4, 0},
18920 {0, "attrib", 1, 0, 4, 1},
18923 {0, "attrib", 1, 0, 4, 2},
18926 {0, "attrib", 1, 0, 4, 3},
18929 {0, "attrib", 1, 0, 4, 0},
18930 {0, "attrib", 2, 0, 3, 1},
18931 {0, NULL, 0, 0, 1, 1},
18932 {0, "attrib", 3, 0, 2, 2},
18933 {0, NULL, 0, 0, 2, 2},
18934 {0, "attrib", 4, 0, 1, 3},
18935 {0, NULL, 0, 0, 7, 3},
18938 {0, "attrib", 1, 0, 4, 0},
18939 {0, "attrib", 2, 0, 3, 1},
18940 {0, NULL, 0, 0, 1, 1},
18941 {0, "attrib", 3, 0, 2, 2},
18942 {0, NULL, 0, 0, 1, 2},
18943 {0, NULL, 0, 0, 1, 2},
18944 {0, "attrib", 4, 0, 1, 3},
18945 {0, NULL, 0, 0, 3, 3},
18946 {0, NULL, 0, 0, 1, 3},
18947 {0, NULL, 0, 0, 1, 3},
18948 {0, NULL, 0, 0, 1, 3},
18949 {0, NULL, 0, 0, 1, 3},
18952 {0, "attrib", 1, 0, 4, 0},
18953 {0, "attrib", 2, 0, 3, 0},
18954 {0, "attrib", 3, 0, 2, 0},
18955 {0, NULL, 0, 0, 1, 0},
18956 {0, "attrib", 4, 0, 1, 0},
18959 {0, "attrib", 1, 0, 4, 0},
18960 {0, "attrib", 2, 0, 3, 0},
18961 {0, "attrib", 3, 0, 2, 3},
18962 {0, NULL, 0, 0, 1, 3},
18963 {0, "attrib", 4, 0, 1, 3},
18965 /* Multiple occurrences of the same output */
18967 {0, "ATTRIB", 1, 0, 2, 0},
18968 {0, "ATTRIB", 1, 2, 2, 1},
18971 {0, "ATTRIB", 1, 0, 1, 0},
18972 {0, "ATTRIB", 1, 1, 3, 0},
18975 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
18977 /* SemanticName and SemanticIndex */
18979 {0, "SV_Position", 0, 0, 4, 0},
18980 {0, "ATTRIB", 0, 0, 4, 0},
18983 {0, "sv_position", 0, 0, 4, 0},
18984 {0, "ATTRIB_", 1, 0, 4, 0},
18986 /* Gaps */
18988 {0, "SV_POSITION", 0, 0, 4, 0},
18989 {0, NULL, 0, 1, 8, 0},
18990 {0, "ATTRIB", 1, 0, 4, 0},
18993 {0, "SV_POSITION", 0, 0, 4, 0},
18994 {0, NULL, 1, 0, 8, 0},
18995 {0, "ATTRIB", 1, 0, 4, 0},
18997 /* Buffer stride */
18999 {0, "SV_POSITION", 0, 0, 4, 0},
19000 {0, NULL, 0, 0, 8, 0},
19001 {0, NULL, 0, 0, 8, 0},
19002 {0, "ATTRIB", 1, 0, 4, 0},
19004 /* ComponentCount */
19006 {0, "ATTRIB", 2, 0, 5, 0},
19009 {0, "ATTRIB", 2, 0, 4, 0},
19012 {0, "ATTRIB", 3, 0, 3, 0},
19015 {0, "ATTRIB", 4, 0, 2, 0},
19017 /* ComponentIndex */
19019 {0, "ATTRIB", 1, 1, 4, 0},
19022 {0, "ATTRIB", 1, 2, 3, 0},
19025 {0, "ATTRIB", 1, 3, 2, 0},
19028 {0, "ATTRIB", 1, 4, 0, 0},
19031 {0, "ATTRIB", 1, 4, 1, 0},
19034 {0, "ATTRIB", 3, 2, 1, 0},
19037 {0, "ATTRIB", 3, 2, 0, 0},
19039 /* OutputSlot */
19041 {0, "attrib", 1, 0, 4, 4},
19044 {0, "attrib", 1, 0, 4, 4},
19047 {0, "attrib", 1, 0, 4, 4},
19050 {0, "attrib", 1, 0, 4, 4},
19053 {0, "attrib", 1, 0, 4, 0},
19054 {0, "attrib", 2, 0, 3, 1},
19055 {0, NULL, 0, 0, 1, 1},
19056 {0, "attrib", 3, 0, 2, 2},
19057 {0, NULL, 0, 0, 2, 2},
19058 {0, "attrib", 4, 0, 1, 3},
19059 {0, NULL, 0, 0, 3, 4},
19062 {0, "attrib", 1, 0, 4, 0},
19063 {0, "attrib", 2, 0, 3, 0},
19064 {0, "attrib", 3, 0, 2, 0},
19065 {0, NULL, 0, 0, 1, 0},
19066 {0, "attrib", 4, 0, 1, 0},
19067 {0, NULL, 0, 0, 3, 3},
19068 {0, NULL, 0, 0, 1, 3},
19069 {0, NULL, 0, 0, 1, 3},
19070 {0, NULL, 0, 0, 1, 3},
19071 {0, NULL, 0, 0, 1, 3},
19074 {0, "attrib", 1, 0, 4, 0},
19075 {0, NULL, 0, 0, 3, 1},
19076 {0, NULL, 0, 0, 1, 1},
19077 {0, NULL, 0, 0, 1, 2},
19078 {0, "attrib", 2, 0, 3, 3},
19079 {0, NULL, 0, 0, 1, 3},
19082 {0, "attrib", 2, 0, 3, 3},
19083 {0, NULL, 0, 0, 3, 1},
19084 {0, NULL, 0, 0, 1, 3},
19085 {0, "attrib", 1, 0, 4, 0},
19086 {0, NULL, 0, 0, 1, 2},
19087 {0, NULL, 0, 0, 1, 1},
19089 /* Stream */
19091 {1, "attrib", 1, 0, 4, 0},
19094 {4, "attrib", 1, 0, 4, 0},
19096 /* Multiple occurrences of the same output */
19098 {0, "ATTRIB", 1, 0, 4, 0},
19099 {0, "ATTRIB", 1, 0, 4, 1},
19102 {0, "ATTRIB", 1, 0, 4, 0},
19103 {0, "ATTRIB", 1, 0, 3, 0},
19107 if (!init_test_context(&test_context, &feature_level))
19108 return;
19110 device = test_context.device;
19112 for (i = 0; i < ARRAY_SIZE(stride); ++i)
19113 stride[i] = 64;
19115 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19116 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19117 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19118 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19119 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19120 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19122 todo_wine
19123 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
19124 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19125 todo_wine
19126 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
19127 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19129 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
19130 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19131 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
19132 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
19133 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19135 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
19136 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19137 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
19138 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19140 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
19142 unsigned int max_output_slot = 0;
19143 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
19145 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
19146 max_output_slot = max(max_output_slot, e->OutputSlot);
19147 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
19148 break;
19151 /* Buffer strides are required for all buffers. */
19152 if (!max_output_slot)
19154 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19155 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19156 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19157 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19158 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19159 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
19160 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19161 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
19162 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19163 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
19165 else
19167 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19168 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19169 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
19170 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
19174 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
19176 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
19178 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
19179 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
19180 break;
19183 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19184 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19185 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19186 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
19187 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19188 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
19189 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19190 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
19193 /* Buffer strides */
19194 stride[1] = 63;
19195 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19196 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
19197 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19198 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
19199 stride[1] = 1;
19200 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19201 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
19202 stride[0] = 0;
19203 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19204 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
19206 /* Rasterizer stream */
19207 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
19208 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
19209 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19210 NULL, 0, D3D11_SO_STREAM_COUNT);
19212 release_test_context(&test_context);
19215 static void test_fl10_stream_output_desc(void)
19217 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
19218 struct d3d11_test_context test_context;
19219 unsigned int i, count;
19220 ID3D11Device *device;
19222 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
19223 static const DWORD vs_code[] =
19225 #if 0
19226 struct data
19228 float4 position : SV_Position;
19229 float4 attrib1 : ATTRIB1;
19230 float3 attrib2 : attrib2;
19231 float2 attrib3 : ATTriB3;
19232 float attrib4 : ATTRIB4;
19235 void main(in data i, out data o)
19237 o = i;
19239 #endif
19240 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
19241 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
19242 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
19243 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
19244 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
19245 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
19246 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
19247 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
19248 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
19249 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
19250 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
19251 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
19252 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
19253 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
19254 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
19255 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
19256 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
19257 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
19258 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
19259 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
19261 static const DWORD gs_code[] =
19263 #if 0
19264 struct data
19266 float4 position : SV_Position;
19267 float4 attrib1 : ATTRIB1;
19268 float3 attrib2 : attrib2;
19269 float2 attrib3 : ATTriB3;
19270 float attrib4 : ATTRIB4;
19273 [maxvertexcount(1)]
19274 void main(point data i[1], inout PointStream<data> o)
19276 o.Append(i[0]);
19278 #endif
19279 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
19280 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
19281 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
19282 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
19283 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
19284 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
19285 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
19286 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
19287 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
19288 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
19289 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
19290 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
19291 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
19292 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
19293 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
19294 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
19295 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
19296 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
19297 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
19298 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
19299 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
19301 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
19303 {0, "SV_Position", 0, 0, 4, 0},
19305 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
19307 {0, "SV_Position", 0, 0, 4, 0},
19308 {0, NULL, 0, 0, 0, 0},
19310 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
19312 /* Gaps */
19314 {0, "SV_POSITION", 0, 0, 4, 0},
19315 {0, NULL, 0, 0, 8, 0},
19316 {0, "ATTRIB", 1, 0, 4, 0},
19319 {0, "SV_POSITION", 0, 0, 4, 0},
19320 {0, NULL, 0, 0, 4, 0},
19321 {0, NULL, 0, 0, 4, 0},
19322 {0, "ATTRIB", 1, 0, 4, 0},
19324 /* OutputSlot */
19326 {0, "attrib", 1, 0, 4, 0},
19327 {0, "attrib", 2, 0, 3, 0},
19328 {0, "attrib", 3, 0, 2, 0},
19329 {0, "attrib", 4, 0, 1, 0},
19332 {0, "attrib", 1, 0, 4, 0},
19333 {0, "attrib", 2, 0, 3, 1},
19334 {0, "attrib", 3, 0, 2, 2},
19335 {0, "attrib", 4, 0, 1, 3},
19338 {0, "attrib", 1, 0, 4, 0},
19339 {0, "attrib", 2, 0, 3, 3},
19342 {0, "attrib", 1, 0, 4, 0},
19343 {0, "attrib", 2, 0, 3, 0},
19344 {0, "attrib", 3, 0, 2, 0},
19345 {0, NULL, 0, 0, 1, 0},
19346 {0, "attrib", 4, 0, 1, 0},
19348 /* Multiple occurrences of the same output */
19350 {0, "ATTRIB", 1, 0, 2, 0},
19351 {0, "ATTRIB", 1, 2, 2, 1},
19354 {0, "ATTRIB", 1, 0, 1, 0},
19355 {0, "ATTRIB", 1, 1, 3, 0},
19358 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
19360 /* OutputSlot */
19362 {0, "attrib", 1, 0, 4, 0},
19363 {0, NULL, 0, 0, 4, 0},
19364 {0, "attrib", 4, 0, 1, 3},
19367 {0, "attrib", 1, 0, 4, 0},
19368 {0, NULL, 0, 0, 4, 0},
19369 {0, NULL, 0, 0, 4, 0},
19370 {0, "attrib", 4, 0, 1, 3},
19373 {0, "attrib", 1, 0, 4, 0},
19374 {0, "attrib", 2, 0, 3, 0},
19375 {0, "attrib", 3, 0, 2, 0},
19376 {0, "attrib", 4, 0, 1, 1},
19379 {0, "attrib", 1, 0, 4, 0},
19380 {0, "attrib", 2, 0, 3, 0},
19381 {0, "attrib", 3, 0, 2, 3},
19382 {0, NULL, 0, 0, 1, 3},
19383 {0, "attrib", 4, 0, 1, 3},
19386 {0, "attrib", 1, 0, 4, 0},
19387 {0, "attrib", 1, 0, 3, 1},
19388 {0, "attrib", 1, 0, 2, 2},
19389 {0, "attrib", 1, 0, 1, 3},
19390 {0, NULL, 0, 0, 3, 3},
19394 if (!init_test_context(&test_context, &feature_level))
19395 return;
19397 device = test_context.device;
19399 for (i = 0; i < ARRAY_SIZE(stride); ++i)
19400 stride[i] = 64;
19402 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
19403 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
19404 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
19405 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
19407 todo_wine
19408 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
19409 todo_wine
19410 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
19412 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
19413 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
19414 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
19415 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
19416 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
19418 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
19419 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
19421 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
19423 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
19425 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
19426 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
19427 break;
19430 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
19433 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
19435 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
19437 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
19438 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
19439 break;
19442 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19443 stride, 1, 0);
19444 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19445 stride, 2, 0);
19446 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19447 stride, 3, 0);
19448 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
19449 stride, 4, 0);
19452 /* Buffer strides */
19453 stride[1] = 63;
19454 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19455 &stride[1], 1, 0);
19456 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19457 stride, 2, 0);
19458 stride[0] = 0;
19459 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19460 stride, 1, 0);
19462 /* Rasterizer stream */
19463 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19464 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
19465 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
19466 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
19467 NULL, 0, i);
19468 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
19470 release_test_context(&test_context);
19473 static void test_stream_output_resume(void)
19475 struct d3d11_test_context test_context;
19476 ID3D11Buffer *cb, *so_buffer, *buffer;
19477 unsigned int i, j, idx, offset;
19478 ID3D11DeviceContext *context;
19479 struct resource_readback rb;
19480 ID3D11GeometryShader *gs;
19481 const struct vec4 *data;
19482 ID3D11Device *device;
19483 HRESULT hr;
19485 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19486 static const DWORD gs_code[] =
19488 #if 0
19489 float4 constant;
19491 struct vertex
19493 float4 position : SV_POSITION;
19496 struct element
19498 float4 position : SV_POSITION;
19499 float4 so_output : so_output;
19502 [maxvertexcount(3)]
19503 void main(triangle vertex input[3], inout PointStream<element> output)
19505 element o;
19506 o.so_output = constant;
19507 o.position = input[0].position;
19508 output.Append(o);
19509 o.position = input[1].position;
19510 output.Append(o);
19511 o.position = input[2].position;
19512 output.Append(o);
19514 #endif
19515 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
19516 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19517 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
19518 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19519 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19520 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
19521 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
19522 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
19523 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
19524 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
19525 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
19526 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
19527 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
19528 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
19530 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
19532 {0, "so_output", 0, 0, 4, 0},
19534 static const struct vec4 constants[] =
19536 {0.5f, 0.250f, 0.0f, 0.0f},
19537 {0.0f, 0.125f, 0.0f, 1.0f},
19538 {1.0f, 1.000f, 1.0f, 0.0f}
19540 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
19541 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
19542 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
19544 if (!init_test_context(&test_context, &feature_level))
19545 return;
19547 device = test_context.device;
19548 context = test_context.immediate_context;
19550 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
19551 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
19552 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
19554 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
19555 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
19557 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
19558 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
19560 offset = 0;
19561 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
19563 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
19564 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
19566 draw_color_quad(&test_context, &red);
19567 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
19569 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
19570 draw_color_quad(&test_context, &green);
19571 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
19573 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
19574 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
19575 draw_color_quad(&test_context, &red);
19576 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
19578 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
19579 draw_color_quad(&test_context, &red);
19580 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
19582 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
19583 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
19584 draw_color_quad(&test_context, &white);
19585 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
19587 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
19588 draw_color_quad(&test_context, &green);
19589 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
19591 buffer = NULL;
19592 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
19593 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
19594 draw_color_quad(&test_context, &white);
19595 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
19597 idx = 0;
19598 get_buffer_readback(so_buffer, &rb);
19599 for (i = 0; i < ARRAY_SIZE(constants); ++i)
19601 for (j = 0; j < 6; ++j) /* 2 triangles */
19603 data = get_readback_vec4(&rb, idx++, 0);
19604 ok(compare_vec4(data, &constants[i], 0),
19605 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
19606 data->x, data->y, data->z, data->w, idx, i, j);
19609 release_resource_readback(&rb);
19611 ID3D11Buffer_Release(cb);
19612 ID3D11Buffer_Release(so_buffer);
19613 ID3D11GeometryShader_Release(gs);
19614 release_test_context(&test_context);
19617 static void test_gather(void)
19619 struct
19621 int width, height;
19622 int offset_x, offset_y;
19623 } constant;
19624 struct d3d11_test_context test_context;
19625 D3D11_TEXTURE2D_DESC texture_desc;
19626 ID3D11ShaderResourceView *srv;
19627 ID3D11Texture2D *texture, *rt;
19628 ID3D11DeviceContext *context;
19629 ID3D11RenderTargetView *rtv;
19630 struct resource_readback rb;
19631 ID3D11PixelShader *ps;
19632 ID3D11Device *device;
19633 unsigned int x, y;
19634 ID3D11Buffer *cb;
19635 HRESULT hr;
19637 static const DWORD gather4_code[] =
19639 #if 0
19640 SamplerState s;
19641 Texture2D<float4> t;
19643 int2 size;
19645 float4 main(float4 position : SV_Position) : SV_Target
19647 return t.Gather(s, position.xy / size);
19649 #endif
19650 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
19651 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19652 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19653 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19654 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
19655 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
19656 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
19657 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
19658 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
19659 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
19660 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
19662 static const DWORD gather4_offset_code[] =
19664 #if 0
19665 SamplerState s;
19666 Texture2D<float4> t;
19668 int2 size;
19670 float4 main(float4 position : SV_Position) : SV_Target
19672 return t.Gather(s, position.xy / size, int2(1, 1));
19674 #endif
19675 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
19676 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19677 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19678 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19679 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
19680 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
19681 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
19682 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
19683 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
19684 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
19685 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
19687 static const DWORD gather4_green_code[] =
19689 #if 0
19690 SamplerState s;
19691 Texture2D<float4> t;
19693 int2 size;
19695 float4 main(float4 position : SV_Position) : SV_Target
19697 return t.GatherGreen(s, position.xy / size);
19699 #endif
19700 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
19701 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19702 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19703 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19704 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
19705 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
19706 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
19707 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
19708 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
19709 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
19710 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
19712 static const DWORD gather4_po_code[] =
19714 #if 0
19715 SamplerState s;
19716 Texture2D<float4> t;
19718 int2 size;
19719 int2 offset;
19721 float4 main(float4 position : SV_Position) : SV_Target
19723 return t.Gather(s, position.xy / size, offset);
19725 #endif
19726 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
19727 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19728 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19729 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19730 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
19731 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
19732 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
19733 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
19734 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
19735 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
19736 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
19737 0x00000000, 0x0100003e,
19739 static const struct vec4 texture_data[] =
19741 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
19742 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
19743 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
19744 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
19746 static const struct vec4 expected_gather4[] =
19748 {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},
19749 {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},
19750 {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},
19751 {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},
19753 static const struct vec4 expected_gather4_offset[] =
19755 {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},
19756 {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},
19757 {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},
19758 {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},
19760 static const struct vec4 expected_gather4_green[] =
19762 {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},
19763 {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},
19764 {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},
19765 {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},
19767 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
19768 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
19770 if (!init_test_context(&test_context, NULL))
19771 return;
19773 device = test_context.device;
19774 context = test_context.immediate_context;
19776 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
19778 skip("Shader model 4.1 required for gather4 instruction.\n");
19779 release_test_context(&test_context);
19780 return;
19783 texture_desc.Width = 4;
19784 texture_desc.Height = 4;
19785 texture_desc.MipLevels = 1;
19786 texture_desc.ArraySize = 1;
19787 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19788 texture_desc.SampleDesc.Count = 1;
19789 texture_desc.SampleDesc.Quality = 0;
19790 texture_desc.Usage = D3D11_USAGE_DEFAULT;
19791 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
19792 texture_desc.CPUAccessFlags = 0;
19793 texture_desc.MiscFlags = 0;
19794 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
19795 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19796 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
19797 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19798 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19800 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
19801 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
19802 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19803 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
19804 ok(SUCCEEDED(hr), "Fialed to create shader resource view, hr %#x.\n", hr);
19805 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
19807 constant.width = texture_desc.Width;
19808 constant.height = texture_desc.Height;
19809 constant.offset_x = 1;
19810 constant.offset_y = 1;
19811 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
19812 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
19814 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
19815 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19816 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19818 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
19819 draw_quad(&test_context);
19820 get_texture_readback(rt, 0, &rb);
19821 for (y = 0; y < texture_desc.Height; ++y)
19823 for (x = 0; x < texture_desc.Width; ++x)
19825 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
19826 const struct vec4 *got = get_readback_vec4(&rb, x, y);
19827 ok(compare_vec4(got, expected, 0),
19828 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
19829 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
19832 release_resource_readback(&rb);
19834 ID3D11PixelShader_Release(ps);
19835 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
19836 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19837 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19839 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
19840 draw_quad(&test_context);
19841 get_texture_readback(rt, 0, &rb);
19842 for (y = 0; y < texture_desc.Height; ++y)
19844 for (x = 0; x < texture_desc.Width; ++x)
19846 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
19847 const struct vec4 *got = get_readback_vec4(&rb, x, y);
19848 ok(compare_vec4(got, expected, 0),
19849 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
19850 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
19853 release_resource_readback(&rb);
19855 ID3D11PixelShader_Release(ps);
19857 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
19859 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
19860 goto done;
19863 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
19864 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19865 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19867 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
19868 draw_quad(&test_context);
19869 get_texture_readback(rt, 0, &rb);
19870 for (y = 0; y < texture_desc.Height; ++y)
19872 for (x = 0; x < texture_desc.Width; ++x)
19874 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
19875 const struct vec4 *got = get_readback_vec4(&rb, x, y);
19876 ok(compare_vec4(got, expected, 0),
19877 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
19878 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
19881 release_resource_readback(&rb);
19883 ID3D11PixelShader_Release(ps);
19884 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
19885 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19886 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19888 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
19889 draw_quad(&test_context);
19890 get_texture_readback(rt, 0, &rb);
19891 for (y = 0; y < texture_desc.Height; ++y)
19893 for (x = 0; x < texture_desc.Width; ++x)
19895 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
19896 const struct vec4 *got = get_readback_vec4(&rb, x, y);
19897 ok(compare_vec4(got, expected, 0),
19898 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
19899 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
19902 release_resource_readback(&rb);
19904 constant.offset_x = 0;
19905 constant.offset_y = 0;
19906 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
19907 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
19908 draw_quad(&test_context);
19909 get_texture_readback(rt, 0, &rb);
19910 for (y = 0; y < texture_desc.Height; ++y)
19912 for (x = 0; x < texture_desc.Width; ++x)
19914 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
19915 const struct vec4 *got = get_readback_vec4(&rb, x, y);
19916 ok(compare_vec4(got, expected, 0),
19917 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
19918 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
19921 release_resource_readback(&rb);
19923 ID3D11PixelShader_Release(ps);
19925 done:
19926 ID3D11Buffer_Release(cb);
19927 ID3D11Texture2D_Release(rt);
19928 ID3D11Texture2D_Release(texture);
19929 ID3D11RenderTargetView_Release(rtv);
19930 ID3D11ShaderResourceView_Release(srv);
19931 release_test_context(&test_context);
19934 static void test_gather_c(void)
19936 struct
19938 int width, height;
19939 int offset_x, offset_y;
19940 float compare_value;
19941 int padding[3];
19942 } constant;
19943 struct d3d11_test_context test_context;
19944 D3D11_TEXTURE2D_DESC texture_desc;
19945 D3D11_SAMPLER_DESC sampler_desc;
19946 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
19947 ID3D11ShaderResourceView *srv;
19948 ID3D11Texture2D *texture, *rt;
19949 ID3D11DeviceContext *context;
19950 ID3D11SamplerState *sampler;
19951 ID3D11RenderTargetView *rtv;
19952 struct resource_readback rb;
19953 ID3D11PixelShader *ps;
19954 ID3D11Device *device;
19955 unsigned int x, y;
19956 ID3D11Buffer *cb;
19957 HRESULT hr;
19959 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19960 static const DWORD gather4_c_code[] =
19962 #if 0
19963 SamplerComparisonState s;
19964 Texture2D<float4> t;
19966 int2 size;
19967 int2 offset;
19968 float compare;
19970 float4 main(float4 position : SV_Position) : SV_Target
19972 return t.GatherCmp(s, position.xy / size, compare);
19974 #endif
19975 0x43425844, 0xd3d04479, 0x901e9208, 0x7074fd0c, 0xbcadb2da, 0x00000001, 0x00000168, 0x00000003,
19976 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19977 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
19978 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19979 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
19980 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
19981 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
19982 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
19983 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
19984 0x00000000, 0x00100046, 0x00000000, 0x8e00007e, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
19985 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0020800a, 0x00000000,
19986 0x00000001, 0x0100003e,
19988 static const DWORD gather4_po_c_code[] =
19990 #if 0
19991 SamplerComparisonState s;
19992 Texture2D<float4> t;
19994 int2 size;
19995 int2 offset;
19996 float compare;
19998 float4 main(float4 position : SV_Position) : SV_Target
20000 return t.GatherCmp(s, position.xy / size, compare, offset);
20002 #endif
20003 0x43425844, 0x501de13e, 0x472d2d20, 0x6df0fee4, 0xef27d9e6, 0x00000001, 0x00000174, 0x00000003,
20004 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
20005 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
20006 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20007 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d8, 0x00000050,
20008 0x00000036, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
20009 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
20010 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
20011 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
20012 0x00000000, 0x00100046, 0x00000000, 0x91000080, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
20013 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
20014 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
20016 static const float texture_data[] =
20018 0.00f, 0.10f, 0.20f, 0.30f,
20019 0.40f, 0.50f, 0.60f, 0.70f,
20020 0.80f, 0.90f, 0.05f, 0.15f,
20021 0.25f, 0.35f, 0.45f, 0.55f,
20023 static const struct vec4 expected_gather4_c[] =
20025 {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},
20026 {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},
20027 {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},
20028 {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},
20030 static const struct vec4 expected_gather4_po_c[] =
20032 {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},
20033 {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},
20034 {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},
20035 {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},
20037 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
20038 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
20040 if (!init_test_context(&test_context, &feature_level))
20041 return;
20043 device = test_context.device;
20044 context = test_context.immediate_context;
20046 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
20047 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
20048 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
20049 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
20050 sampler_desc.MipLODBias = 0.0f;
20051 sampler_desc.MaxAnisotropy = 0;
20052 sampler_desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
20053 sampler_desc.BorderColor[0] = 0.0f;
20054 sampler_desc.BorderColor[1] = 0.0f;
20055 sampler_desc.BorderColor[2] = 0.0f;
20056 sampler_desc.BorderColor[3] = 0.0f;
20057 sampler_desc.MinLOD = 0.0f;
20058 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
20060 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
20061 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
20062 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
20064 texture_desc.Width = 4;
20065 texture_desc.Height = 4;
20066 texture_desc.MipLevels = 1;
20067 texture_desc.ArraySize = 1;
20068 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
20069 texture_desc.SampleDesc.Count = 1;
20070 texture_desc.SampleDesc.Quality = 0;
20071 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20072 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
20073 texture_desc.CPUAccessFlags = 0;
20074 texture_desc.MiscFlags = 0;
20075 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
20076 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20077 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
20078 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
20079 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
20081 constant.width = texture_desc.Width;
20082 constant.height = texture_desc.Height;
20083 constant.offset_x = 1;
20084 constant.offset_y = 1;
20085 constant.compare_value = 0.5f;
20086 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
20087 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
20089 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
20090 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
20091 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
20092 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20094 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
20095 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
20096 U(srv_desc).Texture2D.MostDetailedMip = 0;
20097 U(srv_desc).Texture2D.MipLevels = 1;
20098 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
20099 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
20100 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
20102 hr = ID3D11Device_CreatePixelShader(device, gather4_c_code, sizeof(gather4_c_code), NULL, &ps);
20103 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20104 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20106 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
20107 draw_quad(&test_context);
20108 get_texture_readback(rt, 0, &rb);
20109 for (y = 0; y < texture_desc.Height; ++y)
20111 for (x = 0; x < texture_desc.Width; ++x)
20113 const struct vec4 *expected = &expected_gather4_c[y * texture_desc.Width + x];
20114 const struct vec4 *got = get_readback_vec4(&rb, x, y);
20115 ok(compare_vec4(got, expected, 0),
20116 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
20117 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
20120 release_resource_readback(&rb);
20121 ID3D11PixelShader_Release(ps);
20123 hr = ID3D11Device_CreatePixelShader(device, gather4_po_c_code, sizeof(gather4_po_c_code), NULL, &ps);
20124 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20125 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20127 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
20128 draw_quad(&test_context);
20129 get_texture_readback(rt, 0, &rb);
20130 for (y = 0; y < texture_desc.Height; ++y)
20132 for (x = 0; x < texture_desc.Width; ++x)
20134 const struct vec4 *expected = &expected_gather4_po_c[y * texture_desc.Width + x];
20135 const struct vec4 *got = get_readback_vec4(&rb, x, y);
20136 ok(compare_vec4(got, expected, 0),
20137 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
20138 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
20141 release_resource_readback(&rb);
20142 ID3D11PixelShader_Release(ps);
20144 ID3D11ShaderResourceView_Release(srv);
20145 ID3D11Texture2D_Release(texture);
20147 ID3D11Buffer_Release(cb);
20148 ID3D11Texture2D_Release(rt);
20149 ID3D11RenderTargetView_Release(rtv);
20150 ID3D11SamplerState_Release(sampler);
20151 release_test_context(&test_context);
20154 static void test_fractional_viewports(void)
20156 struct d3d11_test_context test_context;
20157 D3D11_TEXTURE2D_DESC texture_desc;
20158 ID3D11InputLayout *input_layout;
20159 ID3D11DeviceContext *context;
20160 struct resource_readback rb;
20161 ID3D11RenderTargetView *rtv;
20162 ID3D11VertexShader *vs;
20163 ID3D11PixelShader *ps;
20164 unsigned int i, x, y;
20165 ID3D11Device *device;
20166 ID3D11Texture2D *rt;
20167 UINT offset, stride;
20168 D3D11_VIEWPORT vp;
20169 ID3D11Buffer *vb;
20170 HRESULT hr;
20172 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20173 static const DWORD vs_code[] =
20175 #if 0
20176 void main(in float4 in_position : POSITION,
20177 in float2 in_texcoord : TEXCOORD,
20178 out float4 position : SV_Position,
20179 out float2 texcoord : TEXCOORD)
20181 position = in_position;
20182 texcoord = in_texcoord;
20184 #endif
20185 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
20186 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20187 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
20188 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
20189 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
20190 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
20191 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
20192 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
20193 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
20194 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
20195 0x00000001, 0x0100003e,
20197 static const DWORD ps_code[] =
20199 #if 0
20200 float4 main(float4 position : SV_Position,
20201 float2 texcoord : TEXCOORD) : SV_Target
20203 return float4(position.xy, texcoord);
20205 #endif
20206 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
20207 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
20208 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
20209 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
20210 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20211 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
20212 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
20213 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
20214 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
20216 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
20218 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
20219 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
20221 static const struct
20223 struct vec2 position;
20224 struct vec2 texcoord;
20226 quad[] =
20228 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
20229 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
20230 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
20231 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
20233 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
20234 static const float viewport_offsets[] =
20236 0.0f, 0.5f, 0.25f, 0.125f, 0.0625f, 0.03125f, 0.015625f, 0.0078125f, 0.00390625f,
20237 1.0f / 128.0f, 63.0f / 128.0f,
20240 if (!init_test_context(&test_context, &feature_level))
20241 return;
20242 device = test_context.device;
20243 context = test_context.immediate_context;
20245 texture_desc.Width = 4;
20246 texture_desc.Height = 4;
20247 texture_desc.MipLevels = 1;
20248 texture_desc.ArraySize = 1;
20249 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
20250 texture_desc.SampleDesc.Count = 1;
20251 texture_desc.SampleDesc.Quality = 0;
20252 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20253 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
20254 texture_desc.CPUAccessFlags = 0;
20255 texture_desc.MiscFlags = 0;
20256 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
20257 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20258 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
20259 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
20260 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
20262 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
20263 vs_code, sizeof(vs_code), &input_layout);
20264 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
20265 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
20267 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
20268 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
20269 stride = sizeof(*quad);
20270 offset = 0;
20271 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
20273 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
20274 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
20275 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
20277 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20278 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20279 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20281 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
20283 vp.TopLeftX = viewport_offsets[i];
20284 vp.TopLeftY = viewport_offsets[i];
20285 vp.Width = texture_desc.Width;
20286 vp.Height = texture_desc.Height;
20287 vp.MinDepth = 0.0f;
20288 vp.MaxDepth = 1.0f;
20289 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
20290 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
20291 ID3D11DeviceContext_Draw(context, 4, 0);
20292 get_texture_readback(rt, 0, &rb);
20293 for (y = 0; y < texture_desc.Height; ++y)
20295 for (x = 0; x < texture_desc.Width; ++x)
20297 const struct vec4 *v = get_readback_vec4(&rb, x, y);
20298 struct vec4 expected = {x + 0.5f, y + 0.5f,
20299 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
20300 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
20301 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
20302 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
20303 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
20304 todo_wine
20305 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
20306 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
20307 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
20310 release_resource_readback(&rb);
20313 ID3D11InputLayout_Release(input_layout);
20314 ID3D11Buffer_Release(vb);
20315 ID3D11VertexShader_Release(vs);
20316 ID3D11PixelShader_Release(ps);
20317 ID3D11RenderTargetView_Release(rtv);
20318 ID3D11Texture2D_Release(rt);
20319 release_test_context(&test_context);
20322 START_TEST(d3d11)
20324 test_create_device();
20325 run_for_each_feature_level(test_device_interfaces);
20326 test_get_immediate_context();
20327 test_create_texture2d();
20328 test_texture2d_interfaces();
20329 test_create_texture3d();
20330 test_texture3d_interfaces();
20331 test_create_buffer();
20332 test_create_depthstencil_view();
20333 test_depthstencil_view_interfaces();
20334 test_create_rendertarget_view();
20335 test_create_shader_resource_view();
20336 run_for_each_feature_level(test_create_shader);
20337 test_create_sampler_state();
20338 test_create_blend_state();
20339 test_create_depthstencil_state();
20340 test_create_rasterizer_state();
20341 test_create_query();
20342 test_occlusion_query();
20343 test_timestamp_query();
20344 test_device_removed_reason();
20345 test_private_data();
20346 run_for_each_feature_level(test_state_refcounting);
20347 test_device_context_state();
20348 test_blend();
20349 test_texture();
20350 test_cube_maps();
20351 test_depth_stencil_sampling();
20352 test_multiple_render_targets();
20353 test_render_target_views();
20354 test_layered_rendering();
20355 test_scissor();
20356 test_clear_state();
20357 test_il_append_aligned();
20358 test_fragment_coords();
20359 test_update_subresource();
20360 test_copy_subresource_region();
20361 test_resource_map();
20362 test_check_multisample_quality_levels();
20363 run_for_each_feature_level(test_swapchain_formats);
20364 test_swapchain_views();
20365 test_swapchain_flip();
20366 test_clear_render_target_view();
20367 test_clear_depth_stencil_view();
20368 test_clear_buffer_unordered_access_view();
20369 test_draw_depth_only();
20370 test_draw_uav_only();
20371 test_cb_relative_addressing();
20372 test_getdc();
20373 test_shader_stage_input_output_matching();
20374 test_sm4_if_instruction();
20375 test_sm4_breakc_instruction();
20376 test_sm4_continuec_instruction();
20377 test_create_input_layout();
20378 test_input_assembler();
20379 test_null_sampler();
20380 test_check_feature_support();
20381 test_create_unordered_access_view();
20382 test_immediate_constant_buffer();
20383 test_fp_specials();
20384 test_uint_shader_instructions();
20385 test_index_buffer_offset();
20386 test_face_culling();
20387 test_line_antialiasing_blending();
20388 run_for_each_feature_level(test_required_format_support);
20389 run_for_each_9_x_feature_level(test_fl9_draw);
20390 test_ddy();
20391 test_shader_input_registers_limits();
20392 test_unbind_shader_resource_view();
20393 test_stencil_separate();
20394 test_uav_load();
20395 test_cs_uav_store();
20396 test_ps_cs_uav_binding();
20397 test_atomic_instructions();
20398 test_sm4_ret_instruction();
20399 test_primitive_restart();
20400 test_resinfo_instruction();
20401 test_sm5_bufinfo_instruction();
20402 test_render_target_device_mismatch();
20403 test_buffer_srv();
20404 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
20405 test_unaligned_raw_buffer_access);
20406 test_uav_counters();
20407 test_compute_shader_registers();
20408 test_tgsm();
20409 test_geometry_shader();
20410 test_quad_tessellation();
20411 test_stream_output();
20412 test_fl10_stream_output_desc();
20413 test_stream_output_resume();
20414 test_gather();
20415 test_gather_c();
20416 test_fractional_viewports();